blob: ac32f9908dc25f6c1d8c4ddcc449c1b4f08375b2 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Dave Houlton3c9fca72017-03-27 17:25:54 -060038#include "vk_format_utils.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060039#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060040#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070041
42#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060043#include <limits.h>
44#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060045
Mark Lobodzinski3780e142015-05-14 15:08:13 -050046#define GLM_FORCE_RADIANS
47#include "glm/glm.hpp"
48#include <glm/gtc/matrix_transform.hpp>
49
50//--------------------------------------------------------------------------------------
51// Mesh and VertexFormat Data
52//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070053struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070054 float posX, posY, posZ, posW; // Position data
55 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050056};
57
Karl Schultz6addd812016-02-02 17:17:23 -070058#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050059
60typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070061 BsoFailNone = 0x00000000,
62 BsoFailLineWidth = 0x00000001,
63 BsoFailDepthBias = 0x00000002,
64 BsoFailViewport = 0x00000004,
65 BsoFailScissor = 0x00000008,
66 BsoFailBlend = 0x00000010,
67 BsoFailDepthBounds = 0x00000020,
68 BsoFailStencilReadMask = 0x00000040,
69 BsoFailStencilWriteMask = 0x00000080,
70 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060071 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060072 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050073} BsoFailSelect;
74
75struct vktriangle_vs_uniform {
76 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070077 float mvp[4][4];
78 float position[3][4];
79 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050080};
81
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070082static const char bindStateVertShaderText[] =
83 "#version 450\n"
84 "vec2 vertices[3];\n"
85 "out gl_PerVertex {\n"
86 " vec4 gl_Position;\n"
87 "};\n"
88 "void main() {\n"
89 " vertices[0] = vec2(-1.0, -1.0);\n"
90 " vertices[1] = vec2( 1.0, -1.0);\n"
91 " vertices[2] = vec2( 0.0, 1.0);\n"
92 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
93 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050094
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070095static const char bindStateFragShaderText[] =
96 "#version 450\n"
97 "\n"
98 "layout(location = 0) out vec4 uFragColor;\n"
99 "void main(){\n"
100 " uFragColor = vec4(0,1,0,1);\n"
101 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500102
Dave Houlton1d2022c2017-03-29 11:43:58 -0600103// Format search helper
104VkFormat FindSupportedDepthStencilFormat(VkPhysicalDevice phy) {
Dave Houltond7472002017-03-30 09:48:28 -0600105 VkFormat ds_formats[] = {VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT};
Dave Houlton1d2022c2017-03-29 11:43:58 -0600106 for (uint32_t i = 0; i < sizeof(ds_formats); i++) {
107 VkFormatProperties format_props;
108 vkGetPhysicalDeviceFormatProperties(phy, ds_formats[i], &format_props);
109
110 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
111 return ds_formats[i];
112 }
113 }
114 return (VkFormat)0;
115}
116
117// Validation report callback prototype
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600118static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
119 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
120 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600121
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600122// ErrorMonitor Usage:
123//
Dave Houltonfbf52152017-01-06 12:55:29 -0700124// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600125// encountered log messages, or a validation error enum identifying
126// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
127// will match all log messages. logMsg will return true for skipCall
128// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129//
Dave Houltonfbf52152017-01-06 12:55:29 -0700130// Call VerifyFound to determine if all desired failure messages
131// were encountered. Call VerifyNotFound to determine if any unexpected
132// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600133class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700134 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700135 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700136 test_platform_thread_create_mutex(&mutex_);
137 test_platform_thread_lock_mutex(&mutex_);
138 Reset();
139 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141
Dave Houltonfbf52152017-01-06 12:55:29 -0700142 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600143
Dave Houltonfbf52152017-01-06 12:55:29 -0700144 // Set monitor to pristine state
145 void Reset() {
146 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
147 bailout_ = NULL;
148 message_found_ = VK_FALSE;
149 failure_message_strings_.clear();
150 desired_message_strings_.clear();
151 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700152 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700153 other_messages_.clear();
154 message_outstanding_count_ = 0;
155 }
156
157 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700158 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700159 test_platform_thread_lock_mutex(&mutex_);
160 desired_message_strings_.insert(msgString);
161 message_flags_ |= msgFlags;
162 message_outstanding_count_++;
163 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600164 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600165
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700166 // ErrorMonitor will look for an error message containing the specified string(s)
167 template <typename Iter>
168 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
169 for (; iter != end; ++iter) {
170 SetDesiredFailureMsg(msgFlags, *iter);
171 }
172 }
173
Dave Houltonfbf52152017-01-06 12:55:29 -0700174 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700175 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700176 test_platform_thread_lock_mutex(&mutex_);
177 desired_message_ids_.insert(msg_id);
178 message_flags_ |= msgFlags;
179 message_outstanding_count_++;
180 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600181 }
182
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700183 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
184 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
185 // function and its definition.
186 void SetUnexpectedError(const char *const msg) {
187 test_platform_thread_lock_mutex(&mutex_);
188
189 ignore_message_strings_.emplace_back(msg);
190
191 test_platform_thread_unlock_mutex(&mutex_);
192 }
193
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700194 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600195 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700196 test_platform_thread_lock_mutex(&mutex_);
197 if (bailout_ != NULL) {
198 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600199 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600200 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600201 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600202
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700203 if (!IgnoreMessage(errorString)) {
204 for (auto desired_msg : desired_message_strings_) {
205 if (desired_msg.length() == 0) {
206 // An empty desired_msg string "" indicates a positive test - not expecting an error.
207 // Return true to avoid calling layers/driver with this error.
208 // And don't erase the "" string, so it remains if another error is found.
209 result = VK_TRUE;
210 found_expected = true;
211 message_found_ = VK_TRUE;
212 failure_message_strings_.insert(errorString);
213 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600214 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700215 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700216 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700217 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700218 result = VK_TRUE;
219 // We only want one match for each expected error so remove from set here
220 // Since we're about the break the loop it's ok to remove from set we're iterating over
221 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600222 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600223 }
224 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700225 for (auto desired_id : desired_message_ids_) {
226 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
227 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
228 // Return true to avoid calling layers/driver with this error.
229 result = VK_TRUE;
230 } else if (desired_id == message_code) {
231 // Double-check that the string matches the error enum
232 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
233 found_expected = true;
234 message_outstanding_count_--;
235 result = VK_TRUE;
236 message_found_ = VK_TRUE;
237 desired_message_ids_.erase(desired_id);
238 break;
239 } else {
240 // Treat this message as a regular unexpected error, but print a warning jic
241 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
242 errorString.c_str(), desired_id, validation_error_map[desired_id]);
243 }
244 }
245 }
246
247 if (!found_expected) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600248 printf("Unexpected: %s\n", msgString);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700249 other_messages_.push_back(errorString);
250 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600251 }
252
Dave Houltonfbf52152017-01-06 12:55:29 -0700253 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600254 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600255 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600256
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600257 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
258
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700259 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600260
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700261 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600262
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700263 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700264
265 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600266
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600267 void DumpFailureMsgs(void) const {
268 vector<string> otherMsgs = GetOtherFailureMsgs();
269 if (otherMsgs.size()) {
270 cout << "Other error messages logged for this test were:" << endl;
271 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
272 cout << " " << *iter << endl;
Tony Barbour59b42282016-11-03 13:31:28 -0600273 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600274 }
275 }
276
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600277 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200278
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700280 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600281 // Match ANY message matching specified type
282 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700283 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200284 }
285
286 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600287 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 if (!AllDesiredMsgsFound()) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600289 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700290 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700291 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600292 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700293 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700294 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600295 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200296 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700297 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200298 }
299
300 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600301 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700302 if (AnyDesiredMsgFound()) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600303 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700304 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700305 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600306 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200307 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700308 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200309 }
310
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700311 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
313 // function and its definition.
314 bool IgnoreMessage(std::string const &msg) const {
315 if (ignore_message_strings_.empty()) {
316 return false;
317 }
318
319 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
320 return msg.find(str) != std::string::npos;
321 }) != ignore_message_strings_.end();
322 }
323
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700324 VkFlags message_flags_;
325 std::unordered_set<uint32_t> desired_message_ids_;
326 std::unordered_set<string> desired_message_strings_;
327 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700328 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700329 vector<string> other_messages_;
330 test_platform_thread_mutex mutex_;
331 bool *bailout_;
332 VkBool32 message_found_;
333 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600334};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500335
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600336static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
337 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
338 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600339 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
340 if (msgFlags & errMonitor->GetMessageFlags()) {
Dave Houltonc85c4a82017-04-25 15:56:45 -0600341#ifdef _DEBUG
342 char embedded_code_string[2048];
343 snprintf(embedded_code_string, 2048, "%s [%05d]", pMsg, msgCode);
344 return errMonitor->CheckForDesiredMsg(msgCode, embedded_code_string);
345#else
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600346 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Dave Houltonc85c4a82017-04-25 15:56:45 -0600347#endif
Tony Barbour0b4d9562015-04-09 10:48:04 -0600348 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600349 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600350}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500351
Karl Schultz6addd812016-02-02 17:17:23 -0700352class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700353 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600354 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
355 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700356 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600357 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
358 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700359 }
Tony Barbour300a6082015-04-07 13:44:53 -0600360
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600361 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
362 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700363 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600364 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700365 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600366 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700367 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600368 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
369 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
370 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700371 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
372 }
373 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
374 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
375 }
Tony Barbour1fa09702017-03-16 12:09:08 -0600376 void Init(VkPhysicalDeviceFeatures *features = nullptr, const VkCommandPoolCreateFlags flags = 0) {
377 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
378 InitState(features, flags);
379 }
380
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700381 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700382 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600383 bool m_enableWSI;
Tony Barbour1fa09702017-03-16 12:09:08 -0600384 std::vector<const char *> instance_layer_names;
385 std::vector<const char *> instance_extension_names;
386 std::vector<const char *> device_extension_names;
Tony Barbour300a6082015-04-07 13:44:53 -0600387
388 virtual void SetUp() {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700389 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600390 /*
391 * Since CreateDbgMsgCallback is an instance level extension call
392 * any extension / layer that utilizes that feature also needs
393 * to be enabled at create instance time.
394 */
Karl Schultz6addd812016-02-02 17:17:23 -0700395 // Use Threading layer first to protect others from
396 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700397 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600398 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800399 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700400 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600401 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700402 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600403
Ian Elliott2c1daf52016-05-12 09:41:46 -0600404 if (m_enableWSI) {
405 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
406 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
407#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
408#if defined(VK_USE_PLATFORM_ANDROID_KHR)
409 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700410#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600411#if defined(VK_USE_PLATFORM_MIR_KHR)
412 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700413#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600414#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
415 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700416#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600417#if defined(VK_USE_PLATFORM_WIN32_KHR)
418 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700419#endif // VK_USE_PLATFORM_WIN32_KHR
420#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600421#if defined(VK_USE_PLATFORM_XCB_KHR)
422 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
423#elif defined(VK_USE_PLATFORM_XLIB_KHR)
424 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700425#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600426 }
427
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600428 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600429 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800430 this->app_info.pApplicationName = "layer_tests";
431 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600432 this->app_info.pEngineName = "unittest";
433 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600434 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600435
Tony Barbour15524c32015-04-29 17:34:29 -0600436 m_errorMonitor = new ErrorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600437 }
438
439 virtual void TearDown() {
440 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600441 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600442 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600443 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600444
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600445 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600446};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600448void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500449 // Create identity matrix
450 int i;
451 struct vktriangle_vs_uniform data;
452
453 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700454 glm::mat4 View = glm::mat4(1.0f);
455 glm::mat4 Model = glm::mat4(1.0f);
456 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700458 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500459
460 memcpy(&data.mvp, &MVP[0][0], matrixSize);
461
Karl Schultz6addd812016-02-02 17:17:23 -0700462 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600463 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500464 };
465
Karl Schultz6addd812016-02-02 17:17:23 -0700466 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 data.position[i][0] = tri_data[i].posX;
468 data.position[i][1] = tri_data[i].posY;
469 data.position[i][2] = tri_data[i].posZ;
470 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700471 data.color[i][0] = tri_data[i].r;
472 data.color[i][1] = tri_data[i].g;
473 data.color[i][2] = tri_data[i].b;
474 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475 }
476
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500477 ASSERT_NO_FATAL_FAILURE(InitViewport());
478
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200479 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
480 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500481
Karl Schultz6addd812016-02-02 17:17:23 -0700482 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600483 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
485 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800486 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500487 pipelineobj.AddShader(&vs);
488 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600489 if (failMask & BsoFailLineWidth) {
490 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600491 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600492 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600493 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
494 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600495 }
496 if (failMask & BsoFailDepthBias) {
497 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600498 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600500 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600501 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600502 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600503 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700504 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700505 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600506 if (failMask & BsoFailViewport) {
507 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
508 }
509 if (failMask & BsoFailScissor) {
510 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
511 }
512 if (failMask & BsoFailBlend) {
513 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600514 VkPipelineColorBlendAttachmentState att_state = {};
515 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
516 att_state.blendEnable = VK_TRUE;
517 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600518 }
519 if (failMask & BsoFailDepthBounds) {
520 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
521 }
522 if (failMask & BsoFailStencilReadMask) {
523 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
524 }
525 if (failMask & BsoFailStencilWriteMask) {
526 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
527 }
528 if (failMask & BsoFailStencilReference) {
529 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
530 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531
532 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600533 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534
535 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700536 m_commandBuffer->BeginCommandBuffer();
537 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538
Tony Barbourfe3351b2015-07-28 10:17:20 -0600539 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500540
541 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600542 if (failMask & BsoFailIndexBuffer) {
543 // Use DrawIndexed w/o an index buffer bound
544 DrawIndexed(3, 1, 0, 0, 0);
545 } else {
546 Draw(3, 1, 0, 0);
547 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500548
Mark Muellerd4914412016-06-13 17:52:06 -0600549 if (failMask & BsoFailCmdClearAttachments) {
550 VkClearAttachment color_attachment = {};
551 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700552 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600553 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
554
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600555 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600556 }
557
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500558 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700559 m_commandBuffer->EndRenderPass();
560 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600561 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500562}
563
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600564void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
565 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500566 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600567 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500568 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600569 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500570 }
571
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800572 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700573 // Make sure depthWriteEnable is set so that Depth fail test will work
574 // correctly
575 // Make sure stencilTestEnable is set so that Stencil fail test will work
576 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600577 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800578 stencil.failOp = VK_STENCIL_OP_KEEP;
579 stencil.passOp = VK_STENCIL_OP_KEEP;
580 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
581 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600582
583 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
584 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600585 ds_ci.pNext = NULL;
586 ds_ci.depthTestEnable = VK_FALSE;
587 ds_ci.depthWriteEnable = VK_TRUE;
588 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
589 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600590 if (failMask & BsoFailDepthBounds) {
591 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600592 ds_ci.maxDepthBounds = 0.0f;
593 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600594 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600595 ds_ci.stencilTestEnable = VK_TRUE;
596 ds_ci.front = stencil;
597 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600598
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600599 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600600 pipelineobj.SetViewport(m_viewports);
601 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800602 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600603 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600604 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800605 commandBuffer->BindPipeline(pipelineobj);
606 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500607}
608
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600609class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700610 public:
611 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600612};
613
Ian Elliott2c1daf52016-05-12 09:41:46 -0600614class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700615 public:
616 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600617 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600618};
619
Mark Muellerdfe37552016-07-07 14:47:42 -0600620class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700621 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 enum eTestEnFlags {
623 eDoubleDelete,
624 eInvalidDeviceOffset,
625 eInvalidMemoryOffset,
626 eBindNullBuffer,
627 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600628 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600629 };
630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
634 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600635 return true;
636 }
637 VkDeviceSize offset_limit = 0;
638 if (eInvalidMemoryOffset == aTestFlag) {
639 VkBuffer vulkanBuffer;
640 VkBufferCreateInfo buffer_create_info = {};
641 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
642 buffer_create_info.size = 32;
643 buffer_create_info.usage = aBufferUsage;
644
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600645 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600646 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600647
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600648 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600649 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
650 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
652 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600654 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600655 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600656 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600657 }
658 if (eOffsetAlignment < offset_limit) {
659 return true;
660 }
661 return false;
662 }
663
664 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600665 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
666 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600667 if (eBindNullBuffer == aTestFlag) {
668 VulkanMemory = 0;
669 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
670 } else {
671 VkBufferCreateInfo buffer_create_info = {};
672 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
673 buffer_create_info.size = 32;
674 buffer_create_info.usage = aBufferUsage;
675
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600676 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600677
678 CreateCurrent = true;
679
680 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600681 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600682
683 VkMemoryAllocateInfo memory_allocate_info = {};
684 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Stratton77a0d592017-02-17 13:14:13 -0800685 memory_allocate_info.allocationSize = memory_requirements.size + eOffsetAlignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600686 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
687 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600688 if (!pass) {
689 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
690 return;
691 }
692
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600693 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600694 AllocateCurrent = true;
695 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600696 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
697 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600698 BoundCurrent = true;
699
700 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
701 }
702 }
703
704 ~VkBufferTest() {
705 if (CreateCurrent) {
706 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
707 }
708 if (AllocateCurrent) {
709 if (InvalidDeleteEn) {
710 union {
711 VkDeviceMemory device_memory;
712 unsigned long long index_access;
713 } bad_index;
714
715 bad_index.device_memory = VulkanMemory;
716 bad_index.index_access++;
717
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 }
720 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
721 }
722 }
723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600725
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600726 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600727
728 void TestDoubleDestroy() {
729 // Destroy the buffer but leave the flag set, which will cause
730 // the buffer to be destroyed again in the destructor.
731 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
732 }
733
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700734 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600735 bool AllocateCurrent;
736 bool BoundCurrent;
737 bool CreateCurrent;
738 bool InvalidDeleteEn;
739
740 VkBuffer VulkanBuffer;
741 VkDevice VulkanDevice;
742 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600743};
744
745class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700746 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600748 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700749 : BoundCurrent(false),
750 AttributeCount(aAttributeCount),
751 BindingCount(aBindingCount),
752 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600753 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600754 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
755 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700756 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600757
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
759 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600760
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600761 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
762 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
763 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
764 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
765 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600766
767 unsigned i = 0;
768 do {
769 VertexInputAttributeDescription[i].binding = BindId;
770 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
772 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600773 i++;
774 } while (AttributeCount < i);
775
776 i = 0;
777 do {
778 VertexInputBindingDescription[i].binding = BindId;
779 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600780 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600781 i++;
782 } while (BindingCount < i);
783 }
784
785 ~VkVerticesObj() {
786 if (VertexInputAttributeDescription) {
787 delete[] VertexInputAttributeDescription;
788 }
789 if (VertexInputBindingDescription) {
790 delete[] VertexInputBindingDescription;
791 }
792 }
793
794 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600795 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
796 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600797 return true;
798 }
799
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600800 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600801 VkDeviceSize *offsetList;
802 unsigned offsetCount;
803
804 if (aOffsetCount) {
805 offsetList = aOffsetList;
806 offsetCount = aOffsetCount;
807 } else {
808 offsetList = new VkDeviceSize[1]();
809 offsetCount = 1;
810 }
811
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600812 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600813 BoundCurrent = true;
814
815 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600817 }
818 }
819
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700820 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600821 static uint32_t BindIdGenerator;
822
823 bool BoundCurrent;
824 unsigned AttributeCount;
825 unsigned BindingCount;
826 uint32_t BindId;
827
828 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
829 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
830 VkVertexInputBindingDescription *VertexInputBindingDescription;
831 VkConstantBufferObj VulkanMemoryBuffer;
832};
833
834uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500835// ********************************************************************************************************************
836// ********************************************************************************************************************
837// ********************************************************************************************************************
838// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600839TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700840 TEST_DESCRIPTION(
841 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
842 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600843
Tony Barbour1fa09702017-03-16 12:09:08 -0600844 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600847 // Specify NULL for a pointer to a handle
848 // Expected to trigger an error with
849 // parameter_validation::validate_required_pointer
850 vkGetPhysicalDeviceFeatures(gpu(), NULL);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
854 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600855 // Specify NULL for pointer to array count
856 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600857 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required array count
862 // Expected to trigger an error with parameter_validation::validate_array
863 VkViewport view_port = {};
864 m_commandBuffer->SetViewport(0, 0, &view_port);
865 m_errorMonitor->VerifyFound();
866
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600868 // Specify NULL for a required array
869 // Expected to trigger an error with parameter_validation::validate_array
870 m_commandBuffer->SetViewport(0, 1, NULL);
871 m_errorMonitor->VerifyFound();
872
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600874 // Specify VK_NULL_HANDLE for a required handle
875 // Expected to trigger an error with
876 // parameter_validation::validate_required_handle
877 vkUnmapMemory(device(), VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
881 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600882 // Specify VK_NULL_HANDLE for a required handle array entry
883 // Expected to trigger an error with
884 // parameter_validation::validate_required_handle_array
885 VkFence fence = VK_NULL_HANDLE;
886 vkResetFences(device(), 1, &fence);
887 m_errorMonitor->VerifyFound();
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600890 // Specify NULL for a required struct pointer
891 // Expected to trigger an error with
892 // parameter_validation::validate_struct_type
893 VkDeviceMemory memory = VK_NULL_HANDLE;
894 vkAllocateMemory(device(), NULL, NULL, &memory);
895 m_errorMonitor->VerifyFound();
896
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600898 // Specify 0 for a required VkFlags parameter
899 // Expected to trigger an error with parameter_validation::validate_flags
900 m_commandBuffer->SetStencilReference(0, 0);
901 m_errorMonitor->VerifyFound();
902
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600904 // Specify 0 for a required VkFlags array entry
905 // Expected to trigger an error with
906 // parameter_validation::validate_flags_array
907 VkSemaphore semaphore = VK_NULL_HANDLE;
908 VkPipelineStageFlags stageFlags = 0;
909 VkSubmitInfo submitInfo = {};
910 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
911 submitInfo.waitSemaphoreCount = 1;
912 submitInfo.pWaitSemaphores = &semaphore;
913 submitInfo.pWaitDstStageMask = &stageFlags;
914 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
915 m_errorMonitor->VerifyFound();
916}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600917
Dustin Gravesfce74c02016-05-10 11:42:58 -0600918TEST_F(VkLayerTest, ReservedParameter) {
919 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
920
Tony Barbour1fa09702017-03-16 12:09:08 -0600921 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesfce74c02016-05-10 11:42:58 -0600922
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600924 // Specify 0 for a reserved VkFlags parameter
925 // Expected to trigger an error with
926 // parameter_validation::validate_reserved_flags
927 VkEvent event_handle = VK_NULL_HANDLE;
928 VkEventCreateInfo event_info = {};
929 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
930 event_info.flags = 1;
931 vkCreateEvent(device(), &event_info, NULL, &event_handle);
932 m_errorMonitor->VerifyFound();
933}
934
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600935TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700936 TEST_DESCRIPTION(
937 "Specify an invalid VkStructureType for a Vulkan "
938 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600939
Tony Barbour1fa09702017-03-16 12:09:08 -0600940 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600943 // Zero struct memory, effectively setting sType to
944 // VK_STRUCTURE_TYPE_APPLICATION_INFO
945 // Expected to trigger an error with
946 // parameter_validation::validate_struct_type
947 VkMemoryAllocateInfo alloc_info = {};
948 VkDeviceMemory memory = VK_NULL_HANDLE;
949 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
950 m_errorMonitor->VerifyFound();
951
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 // Zero struct memory, effectively setting sType to
954 // VK_STRUCTURE_TYPE_APPLICATION_INFO
955 // Expected to trigger an error with
956 // parameter_validation::validate_struct_type_array
957 VkSubmitInfo submit_info = {};
958 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
959 m_errorMonitor->VerifyFound();
960}
961
962TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600963 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600964
Tony Barbour1fa09702017-03-16 12:09:08 -0600965 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600966
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600968 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600969 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600970 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600971 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600972 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600973 // Zero-initialization will provide the correct sType
974 VkApplicationInfo app_info = {};
975 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
976 event_alloc_info.pNext = &app_info;
977 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
978 m_errorMonitor->VerifyFound();
979
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
981 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600982 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
983 // a function that has allowed pNext structure types and specify
984 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600985 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600986 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600987 VkMemoryAllocateInfo memory_alloc_info = {};
988 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
989 memory_alloc_info.pNext = &app_info;
990 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600991 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600992}
Dustin Graves5d33d532016-05-09 16:21:12 -0600993
994TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600995 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600996
Tony Barbour1fa09702017-03-16 12:09:08 -0600997 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Graves5d33d532016-05-09 16:21:12 -0600998
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1000 "does not fall within the begin..end "
1001 "range of the core VkFormat "
1002 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -06001003 // Specify an invalid VkFormat value
1004 // Expected to trigger an error with
1005 // parameter_validation::validate_ranged_enum
1006 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001007 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001008 m_errorMonitor->VerifyFound();
1009
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -06001011 // Specify an invalid VkFlags bitmask value
1012 // Expected to trigger an error with parameter_validation::validate_flags
1013 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001014 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1015 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001016 m_errorMonitor->VerifyFound();
1017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -06001019 // Specify an invalid VkFlags array entry
1020 // Expected to trigger an error with
1021 // parameter_validation::validate_flags_array
1022 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001023 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001024 VkSubmitInfo submit_info = {};
1025 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1026 submit_info.waitSemaphoreCount = 1;
1027 submit_info.pWaitSemaphores = &semaphore;
1028 submit_info.pWaitDstStageMask = &stage_flags;
1029 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1030 m_errorMonitor->VerifyFound();
1031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001033 // Specify an invalid VkBool32 value
1034 // Expected to trigger a warning with
1035 // parameter_validation::validate_bool32
1036 VkSampler sampler = VK_NULL_HANDLE;
1037 VkSamplerCreateInfo sampler_info = {};
1038 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1039 sampler_info.pNext = NULL;
1040 sampler_info.magFilter = VK_FILTER_NEAREST;
1041 sampler_info.minFilter = VK_FILTER_NEAREST;
1042 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1043 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1044 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1045 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1046 sampler_info.mipLodBias = 1.0;
1047 sampler_info.maxAnisotropy = 1;
1048 sampler_info.compareEnable = VK_FALSE;
1049 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1050 sampler_info.minLod = 1.0;
1051 sampler_info.maxLod = 1.0;
1052 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1053 sampler_info.unnormalizedCoordinates = VK_FALSE;
1054 // Not VK_TRUE or VK_FALSE
1055 sampler_info.anisotropyEnable = 3;
1056 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1057 m_errorMonitor->VerifyFound();
1058}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001059
1060TEST_F(VkLayerTest, FailedReturnValue) {
1061 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1062
Tony Barbour1fa09702017-03-16 12:09:08 -06001063 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesfce74c02016-05-10 11:42:58 -06001064
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001065 // Find an unsupported image format
1066 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1067 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1068 VkFormat format = static_cast<VkFormat>(f);
1069 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001070 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001071 unsupported = format;
1072 break;
1073 }
1074 }
1075
1076 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1078 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001079 // Specify an unsupported VkFormat value to generate a
1080 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1081 // Expected to trigger a warning from
1082 // parameter_validation::validate_result
1083 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1085 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001086 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1087 m_errorMonitor->VerifyFound();
1088 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001089}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001090
1091TEST_F(VkLayerTest, UpdateBufferAlignment) {
1092 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001093 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001094
Tony Barbour1fa09702017-03-16 12:09:08 -06001095 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001096
1097 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1098 vk_testing::Buffer buffer;
1099 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1100
Tony Barbour552f6c02016-12-21 14:34:07 -07001101 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001102 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001104 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1105 m_errorMonitor->VerifyFound();
1106
1107 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001109 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1110 m_errorMonitor->VerifyFound();
1111
1112 // Introduce failure by using dataSize that is < 0
1113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001114 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001115 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1116 m_errorMonitor->VerifyFound();
1117
1118 // Introduce failure by using dataSize that is > 65536
1119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001120 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001121 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1122 m_errorMonitor->VerifyFound();
1123
Tony Barbour552f6c02016-12-21 14:34:07 -07001124 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001125}
1126
1127TEST_F(VkLayerTest, FillBufferAlignment) {
1128 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1129
Tony Barbour1fa09702017-03-16 12:09:08 -06001130 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001131
1132 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1133 vk_testing::Buffer buffer;
1134 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1135
Tony Barbour552f6c02016-12-21 14:34:07 -07001136 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001137
1138 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001140 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1141 m_errorMonitor->VerifyFound();
1142
1143 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001145 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1146 m_errorMonitor->VerifyFound();
1147
1148 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001150 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1151 m_errorMonitor->VerifyFound();
1152
Tony Barbour552f6c02016-12-21 14:34:07 -07001153 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001154}
Dustin Graves40f35822016-06-23 11:12:53 -06001155
Cortd889ff92016-07-27 09:51:27 -07001156TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1157 VkResult err;
1158
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001159 TEST_DESCRIPTION(
1160 "Attempt to use a non-solid polygon fill mode in a "
1161 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001162
Tony Barbour1fa09702017-03-16 12:09:08 -06001163 ASSERT_NO_FATAL_FAILURE(Init());
Cortd889ff92016-07-27 09:51:27 -07001164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1165
1166 std::vector<const char *> device_extension_names;
1167 auto features = m_device->phy().features();
1168 // Artificially disable support for non-solid fill modes
1169 features.fillModeNonSolid = false;
1170 // The sacrificial device object
1171 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1172
1173 VkRenderpassObj render_pass(&test_device);
1174
1175 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1176 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1177 pipeline_layout_ci.setLayoutCount = 0;
1178 pipeline_layout_ci.pSetLayouts = NULL;
1179
1180 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001181 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001182 ASSERT_VK_SUCCESS(err);
1183
1184 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1185 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1186 rs_ci.pNext = nullptr;
1187 rs_ci.lineWidth = 1.0f;
1188 rs_ci.rasterizerDiscardEnable = true;
1189
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001190 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1191 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001192
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001193 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1195 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001196 {
1197 VkPipelineObj pipe(&test_device);
1198 pipe.AddShader(&vs);
1199 pipe.AddShader(&fs);
1200 pipe.AddColorAttachment();
1201 // Introduce failure by setting unsupported polygon mode
1202 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1203 pipe.SetRasterization(&rs_ci);
1204 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1205 }
1206 m_errorMonitor->VerifyFound();
1207
1208 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1210 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001211 {
1212 VkPipelineObj pipe(&test_device);
1213 pipe.AddShader(&vs);
1214 pipe.AddShader(&fs);
1215 pipe.AddColorAttachment();
1216 // Introduce failure by setting unsupported polygon mode
1217 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1218 pipe.SetRasterization(&rs_ci);
1219 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1220 }
1221 m_errorMonitor->VerifyFound();
1222
Cortd889ff92016-07-27 09:51:27 -07001223 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1224}
1225
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001226#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001227TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228{
1229 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001230 VkFenceCreateInfo fenceInfo = {};
1231 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1232 fenceInfo.pNext = NULL;
1233 fenceInfo.flags = 0;
1234
Mike Weiblencce7ec72016-10-17 19:33:05 -06001235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001236
Tony Barbour1fa09702017-03-16 12:09:08 -06001237 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001238
1239 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1240 vk_testing::Buffer buffer;
1241 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001242
Tony Barbourfe3351b2015-07-28 10:17:20 -06001243 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001244 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001245 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001246
1247 testFence.init(*m_device, fenceInfo);
1248
1249 // Bypass framework since it does the waits automatically
1250 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001251 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001252 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1253 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001254 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001255 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001256 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001257 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001258 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001259 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001260 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001261
1262 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001263 ASSERT_VK_SUCCESS( err );
1264
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001265 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001266 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001267
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001268 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001269}
1270
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001271TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001272{
1273 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001274 VkFenceCreateInfo fenceInfo = {};
1275 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1276 fenceInfo.pNext = NULL;
1277 fenceInfo.flags = 0;
1278
Mike Weiblencce7ec72016-10-17 19:33:05 -06001279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001280
Tony Barbour1fa09702017-03-16 12:09:08 -06001281 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001282 ASSERT_NO_FATAL_FAILURE(InitViewport());
1283 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1284
Tony Barbourfe3351b2015-07-28 10:17:20 -06001285 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001286 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001287 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001288
1289 testFence.init(*m_device, fenceInfo);
1290
1291 // Bypass framework since it does the waits automatically
1292 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001293 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001294 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1295 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001296 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001297 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001298 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001299 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001300 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001301 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001302 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001303
1304 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001305 ASSERT_VK_SUCCESS( err );
1306
Jon Ashburnf19916e2016-01-11 13:12:43 -07001307 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001308 VkCommandBufferBeginInfo info = {};
1309 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1310 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001311 info.renderPass = VK_NULL_HANDLE;
1312 info.subpass = 0;
1313 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001314 info.occlusionQueryEnable = VK_FALSE;
1315 info.queryFlags = 0;
1316 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001317
1318 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001319 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001320
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001321 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001322}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001323#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001324
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001325TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1326 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1327
Tony Barbour1fa09702017-03-16 12:09:08 -06001328 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001329
1330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1331 VkBuffer buffer;
1332 VkBufferCreateInfo buf_info = {};
1333 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1334 buf_info.pNext = NULL;
1335 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1336 buf_info.size = 2048;
1337 buf_info.queueFamilyIndexCount = 0;
1338 buf_info.pQueueFamilyIndices = NULL;
1339 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1340 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1341 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1342 m_errorMonitor->VerifyFound();
1343
1344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1345 VkImage image;
1346 VkImageCreateInfo image_create_info = {};
1347 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1348 image_create_info.pNext = NULL;
1349 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1350 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1351 image_create_info.extent.width = 512;
1352 image_create_info.extent.height = 64;
1353 image_create_info.extent.depth = 1;
1354 image_create_info.mipLevels = 1;
1355 image_create_info.arrayLayers = 1;
1356 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1357 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1358 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1359 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1360 image_create_info.queueFamilyIndexCount = 0;
1361 image_create_info.pQueueFamilyIndices = NULL;
1362 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1363 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1364 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1365 m_errorMonitor->VerifyFound();
1366}
1367
Dave Houlton829c0d82017-01-24 15:09:17 -07001368TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1369 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1370
1371 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001372 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001373 ASSERT_NO_FATAL_FAILURE(
1374 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001375 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001376
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001377 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001378 device_features.sparseResidencyImage2D = VK_FALSE;
1379 device_features.sparseResidencyImage3D = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001380 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001381
1382 VkImage image = VK_NULL_HANDLE;
1383 VkResult result = VK_RESULT_MAX_ENUM;
1384 VkImageCreateInfo image_create_info = {};
1385 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1386 image_create_info.pNext = NULL;
1387 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1388 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1389 image_create_info.extent.width = 512;
1390 image_create_info.extent.height = 1;
1391 image_create_info.extent.depth = 1;
1392 image_create_info.mipLevels = 1;
1393 image_create_info.arrayLayers = 1;
1394 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1395 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1396 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1397 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1398 image_create_info.queueFamilyIndexCount = 0;
1399 image_create_info.pQueueFamilyIndices = NULL;
1400 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1401 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1402
1403 // 1D image w/ sparse residency is an error
1404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1405 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1406 m_errorMonitor->VerifyFound();
1407 if (VK_SUCCESS == result) {
1408 vkDestroyImage(m_device->device(), image, NULL);
1409 image = VK_NULL_HANDLE;
1410 }
1411
1412 // 2D image w/ sparse residency when feature isn't available
1413 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1414 image_create_info.extent.height = 64;
1415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1416 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1417 m_errorMonitor->VerifyFound();
1418 if (VK_SUCCESS == result) {
1419 vkDestroyImage(m_device->device(), image, NULL);
1420 image = VK_NULL_HANDLE;
1421 }
1422
1423 // 3D image w/ sparse residency when feature isn't available
1424 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1425 image_create_info.extent.depth = 8;
1426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1427 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1428 m_errorMonitor->VerifyFound();
1429 if (VK_SUCCESS == result) {
1430 vkDestroyImage(m_device->device(), image, NULL);
1431 image = VK_NULL_HANDLE;
1432 }
1433}
1434
1435TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1436 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1437
1438 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001439 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001440 ASSERT_NO_FATAL_FAILURE(
1441 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001442 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001443
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001444 // These tests require that the device support sparse residency for 2D images
1445 if (VK_TRUE != device_features.sparseResidencyImage2D) {
1446 printf(" Test requires unsupported SparseResidencyImage2D feature. Skipped.\n");
Dave Houlton829c0d82017-01-24 15:09:17 -07001447 return;
1448 }
1449
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001450 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001451 device_features.sparseResidency2Samples = VK_FALSE;
1452 device_features.sparseResidency4Samples = VK_FALSE;
1453 device_features.sparseResidency8Samples = VK_FALSE;
1454 device_features.sparseResidency16Samples = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001455 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001456
1457 VkImage image = VK_NULL_HANDLE;
1458 VkResult result = VK_RESULT_MAX_ENUM;
1459 VkImageCreateInfo image_create_info = {};
1460 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1461 image_create_info.pNext = NULL;
1462 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1463 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1464 image_create_info.extent.width = 64;
1465 image_create_info.extent.height = 64;
1466 image_create_info.extent.depth = 1;
1467 image_create_info.mipLevels = 1;
1468 image_create_info.arrayLayers = 1;
1469 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1470 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1471 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1472 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1473 image_create_info.queueFamilyIndexCount = 0;
1474 image_create_info.pQueueFamilyIndices = NULL;
1475 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1476 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1477
1478 // 2D image w/ sparse residency and linear tiling is an error
1479 m_errorMonitor->SetDesiredFailureMsg(
1480 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1481 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1482 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1483 m_errorMonitor->VerifyFound();
1484 if (VK_SUCCESS == result) {
1485 vkDestroyImage(m_device->device(), image, NULL);
1486 image = VK_NULL_HANDLE;
1487 }
1488 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1489
1490 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1491 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1493 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1494 m_errorMonitor->VerifyFound();
1495 if (VK_SUCCESS == result) {
1496 vkDestroyImage(m_device->device(), image, NULL);
1497 image = VK_NULL_HANDLE;
1498 }
1499
1500 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1502 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1503 m_errorMonitor->VerifyFound();
1504 if (VK_SUCCESS == result) {
1505 vkDestroyImage(m_device->device(), image, NULL);
1506 image = VK_NULL_HANDLE;
1507 }
1508
1509 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1511 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1512 m_errorMonitor->VerifyFound();
1513 if (VK_SUCCESS == result) {
1514 vkDestroyImage(m_device->device(), image, NULL);
1515 image = VK_NULL_HANDLE;
1516 }
1517
1518 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1520 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1521 m_errorMonitor->VerifyFound();
1522 if (VK_SUCCESS == result) {
1523 vkDestroyImage(m_device->device(), image, NULL);
1524 image = VK_NULL_HANDLE;
1525 }
1526}
1527
Tobin Ehlisf11be982016-05-11 13:52:53 -06001528TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001529 TEST_DESCRIPTION(
1530 "Create a buffer and image, allocate memory, and bind the "
1531 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001532 VkResult err;
1533 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001534 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf11be982016-05-11 13:52:53 -06001535
Tobin Ehlis077ded32016-05-12 17:39:13 -06001536 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001537 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001538 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001539 VkDeviceMemory mem; // buffer will be bound first
1540 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001541 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001542 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001543
1544 VkBufferCreateInfo buf_info = {};
1545 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1546 buf_info.pNext = NULL;
1547 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1548 buf_info.size = 256;
1549 buf_info.queueFamilyIndexCount = 0;
1550 buf_info.pQueueFamilyIndices = NULL;
1551 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1552 buf_info.flags = 0;
1553 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1554 ASSERT_VK_SUCCESS(err);
1555
Tobin Ehlis077ded32016-05-12 17:39:13 -06001556 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001557
1558 VkImageCreateInfo image_create_info = {};
1559 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1560 image_create_info.pNext = NULL;
1561 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1562 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1563 image_create_info.extent.width = 64;
1564 image_create_info.extent.height = 64;
1565 image_create_info.extent.depth = 1;
1566 image_create_info.mipLevels = 1;
1567 image_create_info.arrayLayers = 1;
1568 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001569 // Image tiling must be optimal to trigger error when aliasing linear buffer
1570 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001571 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1572 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1573 image_create_info.queueFamilyIndexCount = 0;
1574 image_create_info.pQueueFamilyIndices = NULL;
1575 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1576 image_create_info.flags = 0;
1577
Tobin Ehlisf11be982016-05-11 13:52:53 -06001578 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1579 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001580 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1581 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001582
Tobin Ehlis077ded32016-05-12 17:39:13 -06001583 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1584
1585 VkMemoryAllocateInfo alloc_info = {};
1586 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1587 alloc_info.pNext = NULL;
1588 alloc_info.memoryTypeIndex = 0;
1589 // Ensure memory is big enough for both bindings
1590 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001591 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1592 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001593 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001594 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001595 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001596 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001597 return;
1598 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001599 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1600 ASSERT_VK_SUCCESS(err);
1601 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1602 ASSERT_VK_SUCCESS(err);
1603
Rene Lindsayd14f5572016-12-16 14:57:18 -07001604 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1605
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001607 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001608 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1609 m_errorMonitor->VerifyFound();
1610
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001611 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001612 // aliasing buffer2
1613 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1614 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001615 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1616 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001617 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001618 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001620 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001621 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001622 m_errorMonitor->VerifyFound();
1623
1624 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001625 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001626 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001627 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001628 vkFreeMemory(m_device->device(), mem, NULL);
1629 vkFreeMemory(m_device->device(), mem_img, NULL);
1630}
1631
Tobin Ehlis35372522016-05-12 08:32:31 -06001632TEST_F(VkLayerTest, InvalidMemoryMapping) {
1633 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1634 VkResult err;
1635 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001636 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis35372522016-05-12 08:32:31 -06001637
1638 VkBuffer buffer;
1639 VkDeviceMemory mem;
1640 VkMemoryRequirements mem_reqs;
1641
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001642 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1643
Tobin Ehlis35372522016-05-12 08:32:31 -06001644 VkBufferCreateInfo buf_info = {};
1645 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1646 buf_info.pNext = NULL;
1647 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1648 buf_info.size = 256;
1649 buf_info.queueFamilyIndexCount = 0;
1650 buf_info.pQueueFamilyIndices = NULL;
1651 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1652 buf_info.flags = 0;
1653 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1654 ASSERT_VK_SUCCESS(err);
1655
1656 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1657 VkMemoryAllocateInfo alloc_info = {};
1658 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1659 alloc_info.pNext = NULL;
1660 alloc_info.memoryTypeIndex = 0;
1661
1662 // Ensure memory is big enough for both bindings
1663 static const VkDeviceSize allocation_size = 0x10000;
1664 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001665 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001666 if (!pass) {
1667 vkDestroyBuffer(m_device->device(), buffer, NULL);
1668 return;
1669 }
1670 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1671 ASSERT_VK_SUCCESS(err);
1672
1673 uint8_t *pData;
1674 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001676 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1677 m_errorMonitor->VerifyFound();
1678 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001679 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001680 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1682 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1683 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001684 m_errorMonitor->VerifyFound();
1685
1686 // Unmap the memory to avoid re-map error
1687 vkUnmapMemory(m_device->device(), mem);
1688 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1690 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1691 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001692 m_errorMonitor->VerifyFound();
1693 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1695 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001696 m_errorMonitor->VerifyFound();
1697 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001699 vkUnmapMemory(m_device->device(), mem);
1700 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001701
Tobin Ehlis35372522016-05-12 08:32:31 -06001702 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001703 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001704 ASSERT_VK_SUCCESS(err);
1705 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001706 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001707 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001708 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001710 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1711 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001712
Tobin Ehlis35372522016-05-12 08:32:31 -06001713 // Now flush range that oversteps mapped range
1714 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001715 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001716 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001717 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001718 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1720 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1721 m_errorMonitor->VerifyFound();
1722
1723 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1724 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001725 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001726 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001727 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001728 mmr.size = VK_WHOLE_SIZE;
1729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001730 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1731 m_errorMonitor->VerifyFound();
1732
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001733#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001734 // Some platforms have an atomsize of 1 which makes the test meaningless
1735 if (atom_size > 3) {
1736 // Now with an offset NOT a multiple of the device limit
1737 vkUnmapMemory(m_device->device(), mem);
1738 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1739 ASSERT_VK_SUCCESS(err);
1740 mmr.offset = 3; // Not a multiple of atom_size
1741 mmr.size = VK_WHOLE_SIZE;
1742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1743 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1744 m_errorMonitor->VerifyFound();
1745
1746 // Now with a size NOT a multiple of the device limit
1747 vkUnmapMemory(m_device->device(), mem);
1748 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1749 ASSERT_VK_SUCCESS(err);
1750 mmr.offset = atom_size;
1751 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1753 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1754 m_errorMonitor->VerifyFound();
1755 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001756#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001757 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1758 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001759 if (!pass) {
1760 vkFreeMemory(m_device->device(), mem, NULL);
1761 vkDestroyBuffer(m_device->device(), buffer, NULL);
1762 return;
1763 }
1764 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1765 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1766
1767 vkDestroyBuffer(m_device->device(), buffer, NULL);
1768 vkFreeMemory(m_device->device(), mem, NULL);
1769}
1770
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001771#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001772TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1773 VkResult err;
1774 bool pass;
1775
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001776 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1777 // following declaration (which is temporarily being moved below):
1778 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001779 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001780 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001781 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001782 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001783 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001784 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001785
Tony Barbour1fa09702017-03-16 12:09:08 -06001786 ASSERT_NO_FATAL_FAILURE(Init());
Ian Elliott1c32c772016-04-28 14:47:13 -06001787
Ian Elliott3f06ce52016-04-29 14:46:21 -06001788#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1789#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1790 // Use the functions from the VK_KHR_android_surface extension without
1791 // enabling that extension:
1792
1793 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001794 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1796 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001797 pass = (err != VK_SUCCESS);
1798 ASSERT_TRUE(pass);
1799 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001800#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001801
Ian Elliott3f06ce52016-04-29 14:46:21 -06001802#if defined(VK_USE_PLATFORM_MIR_KHR)
1803 // Use the functions from the VK_KHR_mir_surface extension without enabling
1804 // that extension:
1805
1806 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001807 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001809 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1810 pass = (err != VK_SUCCESS);
1811 ASSERT_TRUE(pass);
1812 m_errorMonitor->VerifyFound();
1813
1814 // Tell whether an mir_connection supports presentation:
1815 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1817 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001818 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001819#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001820
Ian Elliott3f06ce52016-04-29 14:46:21 -06001821#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1822 // Use the functions from the VK_KHR_wayland_surface extension without
1823 // enabling that extension:
1824
1825 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001826 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1828 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001829 pass = (err != VK_SUCCESS);
1830 ASSERT_TRUE(pass);
1831 m_errorMonitor->VerifyFound();
1832
1833 // Tell whether an wayland_display supports presentation:
1834 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1836 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001837 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001838#endif // VK_USE_PLATFORM_WAYLAND_KHR
1839#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001840
Ian Elliott3f06ce52016-04-29 14:46:21 -06001841#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001842 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1843 // TO NON-LINUX PLATFORMS:
1844 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001845 // Use the functions from the VK_KHR_win32_surface extension without
1846 // enabling that extension:
1847
1848 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001849 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1851 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001852 pass = (err != VK_SUCCESS);
1853 ASSERT_TRUE(pass);
1854 m_errorMonitor->VerifyFound();
1855
1856 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001858 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001859 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001860// Set this (for now, until all platforms are supported and tested):
1861#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001862#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001863#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001864 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1865 // TO NON-LINUX PLATFORMS:
1866 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001867#endif
1868#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001869 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1870 // that extension:
1871
1872 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001873 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001875 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1876 pass = (err != VK_SUCCESS);
1877 ASSERT_TRUE(pass);
1878 m_errorMonitor->VerifyFound();
1879
1880 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001881 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001882 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1884 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001885 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001886// Set this (for now, until all platforms are supported and tested):
1887#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001888#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001889
Ian Elliott12630812016-04-29 14:35:43 -06001890#if defined(VK_USE_PLATFORM_XLIB_KHR)
1891 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1892 // that extension:
1893
1894 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001895 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001897 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1898 pass = (err != VK_SUCCESS);
1899 ASSERT_TRUE(pass);
1900 m_errorMonitor->VerifyFound();
1901
1902 // Tell whether an Xlib VisualID supports presentation:
1903 Display *dpy = NULL;
1904 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001906 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1907 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001908// Set this (for now, until all platforms are supported and tested):
1909#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001910#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001912// Use the functions from the VK_KHR_surface extension without enabling
1913// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001914
Ian Elliott489eec02016-05-05 14:12:44 -06001915#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001916 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001918 vkDestroySurfaceKHR(instance(), surface, NULL);
1919 m_errorMonitor->VerifyFound();
1920
1921 // Check if surface supports presentation:
1922 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001924 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1925 pass = (err != VK_SUCCESS);
1926 ASSERT_TRUE(pass);
1927 m_errorMonitor->VerifyFound();
1928
1929 // Check surface capabilities:
1930 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1932 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001933 pass = (err != VK_SUCCESS);
1934 ASSERT_TRUE(pass);
1935 m_errorMonitor->VerifyFound();
1936
1937 // Check surface formats:
1938 uint32_t format_count = 0;
1939 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1941 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001942 pass = (err != VK_SUCCESS);
1943 ASSERT_TRUE(pass);
1944 m_errorMonitor->VerifyFound();
1945
1946 // Check surface present modes:
1947 uint32_t present_mode_count = 0;
1948 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1950 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001951 pass = (err != VK_SUCCESS);
1952 ASSERT_TRUE(pass);
1953 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001954#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001955
Ian Elliott1c32c772016-04-28 14:47:13 -06001956 // Use the functions from the VK_KHR_swapchain extension without enabling
1957 // that extension:
1958
1959 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001961 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1962 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001963 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001964 pass = (err != VK_SUCCESS);
1965 ASSERT_TRUE(pass);
1966 m_errorMonitor->VerifyFound();
1967
1968 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1970 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001971 pass = (err != VK_SUCCESS);
1972 ASSERT_TRUE(pass);
1973 m_errorMonitor->VerifyFound();
1974
Chris Forbeseb7d5502016-09-13 18:19:21 +12001975 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1976 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1977 VkFence fence;
1978 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1979
Ian Elliott1c32c772016-04-28 14:47:13 -06001980 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001982 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001983 pass = (err != VK_SUCCESS);
1984 ASSERT_TRUE(pass);
1985 m_errorMonitor->VerifyFound();
1986
Chris Forbeseb7d5502016-09-13 18:19:21 +12001987 vkDestroyFence(m_device->device(), fence, nullptr);
1988
Ian Elliott1c32c772016-04-28 14:47:13 -06001989 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001990 //
1991 // NOTE: Currently can't test this because a real swapchain is needed (as
1992 // opposed to the fake one we created) in order for the layer to lookup the
1993 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001994
1995 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001997 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1998 m_errorMonitor->VerifyFound();
1999}
Chris Forbes09368e42016-10-13 11:59:22 +13002000#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06002001
Karl Schultz6addd812016-02-02 17:17:23 -07002002TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
2003 VkResult err;
2004 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002005
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2007 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002008
Tony Barbour1fa09702017-03-16 12:09:08 -06002009 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002010
2011 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002012 VkImage image;
2013 VkDeviceMemory mem;
2014 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002015
Karl Schultz6addd812016-02-02 17:17:23 -07002016 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2017 const int32_t tex_width = 32;
2018 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002019
Tony Barboureb254902015-07-15 12:50:33 -06002020 VkImageCreateInfo image_create_info = {};
2021 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002022 image_create_info.pNext = NULL;
2023 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2024 image_create_info.format = tex_format;
2025 image_create_info.extent.width = tex_width;
2026 image_create_info.extent.height = tex_height;
2027 image_create_info.extent.depth = 1;
2028 image_create_info.mipLevels = 1;
2029 image_create_info.arrayLayers = 1;
2030 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2031 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2032 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2033 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002034 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002035
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002036 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002037 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002038 mem_alloc.pNext = NULL;
2039 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002040
Chia-I Wuf7458c52015-10-26 21:10:41 +08002041 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002042 ASSERT_VK_SUCCESS(err);
2043
Karl Schultz6addd812016-02-02 17:17:23 -07002044 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002045
Mark Lobodzinski23065352015-05-29 09:32:35 -05002046 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002047
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002048 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002049 if (!pass) { // If we can't find any unmappable memory this test doesn't
2050 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002051 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002052 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002053 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002054
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002055 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002056 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002057 ASSERT_VK_SUCCESS(err);
2058
2059 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002060 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002061 ASSERT_VK_SUCCESS(err);
2062
2063 // Map memory as if to initialize the image
2064 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002065 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002066
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002067 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002068
Chia-I Wuf7458c52015-10-26 21:10:41 +08002069 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002070 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002071}
2072
Karl Schultz6addd812016-02-02 17:17:23 -07002073TEST_F(VkLayerTest, RebindMemory) {
2074 VkResult err;
2075 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002076
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002078
Tony Barbour1fa09702017-03-16 12:09:08 -06002079 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002080
2081 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002082 VkImage image;
2083 VkDeviceMemory mem1;
2084 VkDeviceMemory mem2;
2085 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002086
Karl Schultz6addd812016-02-02 17:17:23 -07002087 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2088 const int32_t tex_width = 32;
2089 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002090
Tony Barboureb254902015-07-15 12:50:33 -06002091 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002092 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2093 image_create_info.pNext = NULL;
2094 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2095 image_create_info.format = tex_format;
2096 image_create_info.extent.width = tex_width;
2097 image_create_info.extent.height = tex_height;
2098 image_create_info.extent.depth = 1;
2099 image_create_info.mipLevels = 1;
2100 image_create_info.arrayLayers = 1;
2101 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2102 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2103 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2104 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002105
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002106 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002107 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2108 mem_alloc.pNext = NULL;
2109 mem_alloc.allocationSize = 0;
2110 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002111
Karl Schultz6addd812016-02-02 17:17:23 -07002112 // Introduce failure, do NOT set memProps to
2113 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002114 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002115 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116 ASSERT_VK_SUCCESS(err);
2117
Karl Schultz6addd812016-02-02 17:17:23 -07002118 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002119
2120 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002121 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002122 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002123
2124 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002125 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002126 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002127 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002128 ASSERT_VK_SUCCESS(err);
2129
2130 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002131 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002132 ASSERT_VK_SUCCESS(err);
2133
Karl Schultz6addd812016-02-02 17:17:23 -07002134 // Introduce validation failure, try to bind a different memory object to
2135 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002136 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002137
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002138 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002139
Chia-I Wuf7458c52015-10-26 21:10:41 +08002140 vkDestroyImage(m_device->device(), image, NULL);
2141 vkFreeMemory(m_device->device(), mem1, NULL);
2142 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002143}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002144
Karl Schultz6addd812016-02-02 17:17:23 -07002145TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002146 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002147
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2149 "submitted in SIGNALED state. Fences "
2150 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002151
2152 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002153 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2154 fenceInfo.pNext = NULL;
2155 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002156
Tony Barbour1fa09702017-03-16 12:09:08 -06002157 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour300a6082015-04-07 13:44:53 -06002158 ASSERT_NO_FATAL_FAILURE(InitViewport());
2159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2160
Tony Barbour552f6c02016-12-21 14:34:07 -07002161 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002162 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002163 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002164
2165 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002166
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002167 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002168 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2169 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002170 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002171 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002172 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002173 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002174 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002175 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002176 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002177
2178 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002179 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002180
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002181 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002182}
Chris Forbes4e44c912016-06-16 10:20:00 +12002183
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002184TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002185 TEST_DESCRIPTION(
2186 "Specify wrong usage for image then create conflicting view of image "
2187 "Initialize buffer with wrong usage then perform copy expecting errors "
2188 "from both the image and the buffer (2 calls)");
Mark Lobodzinski33826372017-04-13 11:10:11 -06002189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for Image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002190
Tony Barbour1fa09702017-03-16 12:09:08 -06002191 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06002192 auto format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07002193 if (!format) {
2194 printf(" No Depth + Stencil format found. Skipped.\n");
2195 return;
2196 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002197
Tony Barbourf92621a2016-05-02 14:28:12 -06002198 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002199 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06002200 image.Init(128, 128, 1, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002201 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002202
Tony Barbourf92621a2016-05-02 14:28:12 -06002203 VkImageView dsv;
2204 VkImageViewCreateInfo dsvci = {};
2205 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2206 dsvci.image = image.handle();
2207 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002208 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002209 dsvci.subresourceRange.layerCount = 1;
2210 dsvci.subresourceRange.baseMipLevel = 0;
2211 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002212 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002213
Tony Barbourf92621a2016-05-02 14:28:12 -06002214 // Create a view with depth / stencil aspect for image with different usage
2215 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002216
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002217 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002218
2219 // Initialize buffer with TRANSFER_DST usage
2220 vk_testing::Buffer buffer;
2221 VkMemoryPropertyFlags reqs = 0;
2222 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2223 VkBufferImageCopy region = {};
2224 region.bufferRowLength = 128;
2225 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002226 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002227 region.imageSubresource.layerCount = 1;
2228 region.imageExtent.height = 16;
2229 region.imageExtent.width = 16;
2230 region.imageExtent.depth = 1;
2231
Mark Lobodzinski80871462017-02-16 10:37:27 -07002232 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002233 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002234
Chris Forbesda581202016-10-06 18:25:26 +13002235 // two separate errors from this call:
Mark Lobodzinski33826372017-04-13 11:10:11 -06002236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
Chris Forbesda581202016-10-06 18:25:26 +13002238
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002239 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2240 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002241 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002242}
Tony Barbour75d79f02016-08-30 09:39:07 -06002243
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002244TEST_F(VkLayerTest, LeakAnObject) {
2245 VkResult err;
2246
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002247 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002248
2249 // Note that we have to create a new device since destroying the
2250 // framework's device causes Teardown() to fail and just calling Teardown
2251 // will destroy the errorMonitor.
2252
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002254
Tony Barbour1fa09702017-03-16 12:09:08 -06002255 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002257 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002258 std::vector<VkDeviceQueueCreateInfo> queue_info;
2259 queue_info.reserve(queue_props.size());
2260 std::vector<std::vector<float>> queue_priorities;
2261 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2262 VkDeviceQueueCreateInfo qi = {};
2263 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2264 qi.pNext = NULL;
2265 qi.queueFamilyIndex = i;
2266 qi.queueCount = queue_props[i].queueCount;
2267 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2268 qi.pQueuePriorities = queue_priorities[i].data();
2269 queue_info.push_back(qi);
2270 }
2271
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002272 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002273
2274 // The sacrificial device object
2275 VkDevice testDevice;
2276 VkDeviceCreateInfo device_create_info = {};
2277 auto features = m_device->phy().features();
2278 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2279 device_create_info.pNext = NULL;
2280 device_create_info.queueCreateInfoCount = queue_info.size();
2281 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002282 device_create_info.enabledLayerCount = 0;
2283 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002284 device_create_info.pEnabledFeatures = &features;
2285 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2286 ASSERT_VK_SUCCESS(err);
2287
2288 VkFence fence;
2289 VkFenceCreateInfo fence_create_info = {};
2290 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2291 fence_create_info.pNext = NULL;
2292 fence_create_info.flags = 0;
2293 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2294 ASSERT_VK_SUCCESS(err);
2295
2296 // Induce failure by not calling vkDestroyFence
2297 vkDestroyDevice(testDevice, NULL);
2298 m_errorMonitor->VerifyFound();
2299}
2300
2301TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002302 TEST_DESCRIPTION(
2303 "Allocate command buffers from one command pool and "
2304 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002305
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002307
Tony Barbour1fa09702017-03-16 12:09:08 -06002308 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002309 VkCommandPool command_pool_one;
2310 VkCommandPool command_pool_two;
2311
2312 VkCommandPoolCreateInfo pool_create_info{};
2313 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2314 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2315 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2316
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002317 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002318
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002319 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002320
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002321 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002322 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002323 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002324 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002325 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002326 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002327 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002328
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002329 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002330
2331 m_errorMonitor->VerifyFound();
2332
2333 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2334 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2335}
2336
2337TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2338 VkResult err;
2339
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002340 TEST_DESCRIPTION(
2341 "Allocate descriptor sets from one DS pool and "
2342 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002343
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002345
Tony Barbour1fa09702017-03-16 12:09:08 -06002346 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002347 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2348
2349 VkDescriptorPoolSize ds_type_count = {};
2350 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2351 ds_type_count.descriptorCount = 1;
2352
2353 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2354 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2355 ds_pool_ci.pNext = NULL;
2356 ds_pool_ci.flags = 0;
2357 ds_pool_ci.maxSets = 1;
2358 ds_pool_ci.poolSizeCount = 1;
2359 ds_pool_ci.pPoolSizes = &ds_type_count;
2360
2361 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002362 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002363 ASSERT_VK_SUCCESS(err);
2364
2365 // Create a second descriptor pool
2366 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002367 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002368 ASSERT_VK_SUCCESS(err);
2369
2370 VkDescriptorSetLayoutBinding dsl_binding = {};
2371 dsl_binding.binding = 0;
2372 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2373 dsl_binding.descriptorCount = 1;
2374 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2375 dsl_binding.pImmutableSamplers = NULL;
2376
2377 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2378 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2379 ds_layout_ci.pNext = NULL;
2380 ds_layout_ci.bindingCount = 1;
2381 ds_layout_ci.pBindings = &dsl_binding;
2382
2383 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002384 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002385 ASSERT_VK_SUCCESS(err);
2386
2387 VkDescriptorSet descriptorSet;
2388 VkDescriptorSetAllocateInfo alloc_info = {};
2389 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2390 alloc_info.descriptorSetCount = 1;
2391 alloc_info.descriptorPool = ds_pool_one;
2392 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002393 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002394 ASSERT_VK_SUCCESS(err);
2395
2396 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2397
2398 m_errorMonitor->VerifyFound();
2399
2400 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2401 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2402 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2403}
2404
2405TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002407
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002408 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002409
Tony Barbour1fa09702017-03-16 12:09:08 -06002410 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002411
2412 // Pass bogus handle into GetImageMemoryRequirements
2413 VkMemoryRequirements mem_reqs;
2414 uint64_t fakeImageHandle = 0xCADECADE;
2415 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2416
2417 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2418
2419 m_errorMonitor->VerifyFound();
2420}
2421
Mike Schuchardt17838902017-02-21 09:48:06 -07002422TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2423 TEST_DESCRIPTION(
2424 "Try to destroy a render pass object using a device other than the one it was created on. "
2425 "This should generate a distinct error from the invalid handle error.");
2426 // Create first device and renderpass
Tony Barbour1fa09702017-03-16 12:09:08 -06002427 ASSERT_NO_FATAL_FAILURE(Init());
Mike Schuchardt17838902017-02-21 09:48:06 -07002428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2429
2430 // Create second device
2431 float priorities[] = {1.0f};
2432 VkDeviceQueueCreateInfo queue_info{};
2433 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2434 queue_info.pNext = NULL;
2435 queue_info.flags = 0;
2436 queue_info.queueFamilyIndex = 0;
2437 queue_info.queueCount = 1;
2438 queue_info.pQueuePriorities = &priorities[0];
2439
2440 VkDeviceCreateInfo device_create_info = {};
2441 auto features = m_device->phy().features();
2442 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2443 device_create_info.pNext = NULL;
2444 device_create_info.queueCreateInfoCount = 1;
2445 device_create_info.pQueueCreateInfos = &queue_info;
2446 device_create_info.enabledLayerCount = 0;
2447 device_create_info.ppEnabledLayerNames = NULL;
2448 device_create_info.pEnabledFeatures = &features;
2449
2450 VkDevice second_device;
2451 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2452
2453 // Try to destroy the renderpass from the first device using the second device
2454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2455 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2456 m_errorMonitor->VerifyFound();
2457
2458 vkDestroyDevice(second_device, NULL);
2459}
2460
Karl Schultz6addd812016-02-02 17:17:23 -07002461TEST_F(VkLayerTest, PipelineNotBound) {
2462 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002463
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002464 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002465
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002467
Tony Barbour1fa09702017-03-16 12:09:08 -06002468 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002469 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002470
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002471 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002472 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2473 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002474
2475 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002476 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2477 ds_pool_ci.pNext = NULL;
2478 ds_pool_ci.maxSets = 1;
2479 ds_pool_ci.poolSizeCount = 1;
2480 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002481
2482 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002483 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002484 ASSERT_VK_SUCCESS(err);
2485
2486 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002487 dsl_binding.binding = 0;
2488 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2489 dsl_binding.descriptorCount = 1;
2490 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2491 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002492
2493 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002494 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2495 ds_layout_ci.pNext = NULL;
2496 ds_layout_ci.bindingCount = 1;
2497 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002498
2499 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002500 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002501 ASSERT_VK_SUCCESS(err);
2502
2503 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002504 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002505 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002506 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002507 alloc_info.descriptorPool = ds_pool;
2508 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002509 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002510 ASSERT_VK_SUCCESS(err);
2511
2512 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002513 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2514 pipeline_layout_ci.pNext = NULL;
2515 pipeline_layout_ci.setLayoutCount = 1;
2516 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002517
2518 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002519 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002520 ASSERT_VK_SUCCESS(err);
2521
Mark Youngad779052016-01-06 14:26:04 -07002522 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002523
Tony Barbour552f6c02016-12-21 14:34:07 -07002524 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002525 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002526
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002527 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002528
Chia-I Wuf7458c52015-10-26 21:10:41 +08002529 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2530 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2531 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002532}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002533
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002534TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2535 VkResult err;
2536
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002537 TEST_DESCRIPTION(
2538 "Test validation check for an invalid memory type index "
2539 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002540
Tony Barbour1fa09702017-03-16 12:09:08 -06002541 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002542
2543 // Create an image, allocate memory, set a bad typeIndex and then try to
2544 // bind it
2545 VkImage image;
2546 VkDeviceMemory mem;
2547 VkMemoryRequirements mem_reqs;
2548 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2549 const int32_t tex_width = 32;
2550 const int32_t tex_height = 32;
2551
2552 VkImageCreateInfo image_create_info = {};
2553 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2554 image_create_info.pNext = NULL;
2555 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2556 image_create_info.format = tex_format;
2557 image_create_info.extent.width = tex_width;
2558 image_create_info.extent.height = tex_height;
2559 image_create_info.extent.depth = 1;
2560 image_create_info.mipLevels = 1;
2561 image_create_info.arrayLayers = 1;
2562 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2563 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2564 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2565 image_create_info.flags = 0;
2566
2567 VkMemoryAllocateInfo mem_alloc = {};
2568 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2569 mem_alloc.pNext = NULL;
2570 mem_alloc.allocationSize = 0;
2571 mem_alloc.memoryTypeIndex = 0;
2572
2573 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2574 ASSERT_VK_SUCCESS(err);
2575
2576 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2577 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002578
2579 // Introduce Failure, select invalid TypeIndex
2580 VkPhysicalDeviceMemoryProperties memory_info;
2581
2582 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2583 unsigned int i;
2584 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2585 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2586 mem_alloc.memoryTypeIndex = i;
2587 break;
2588 }
2589 }
2590 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002591 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002592 vkDestroyImage(m_device->device(), image, NULL);
2593 return;
2594 }
2595
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002597
2598 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2599 ASSERT_VK_SUCCESS(err);
2600
2601 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2602 (void)err;
2603
2604 m_errorMonitor->VerifyFound();
2605
2606 vkDestroyImage(m_device->device(), image, NULL);
2607 vkFreeMemory(m_device->device(), mem, NULL);
2608}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002609
Karl Schultz6addd812016-02-02 17:17:23 -07002610TEST_F(VkLayerTest, BindInvalidMemory) {
2611 VkResult err;
2612 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002613
Tony Barbour1fa09702017-03-16 12:09:08 -06002614 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002615
Cortf801b982017-01-17 18:10:21 -08002616 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002617 const int32_t tex_width = 256;
2618 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002619
2620 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002621 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2622 image_create_info.pNext = NULL;
2623 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2624 image_create_info.format = tex_format;
2625 image_create_info.extent.width = tex_width;
2626 image_create_info.extent.height = tex_height;
2627 image_create_info.extent.depth = 1;
2628 image_create_info.mipLevels = 1;
2629 image_create_info.arrayLayers = 1;
2630 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002631 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002632 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2633 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002634
Cortf801b982017-01-17 18:10:21 -08002635 VkBufferCreateInfo buffer_create_info = {};
2636 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2637 buffer_create_info.pNext = NULL;
2638 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002639 buffer_create_info.size = 4 * 1024 * 1024;
2640 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002641 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002642
Cortf801b982017-01-17 18:10:21 -08002643 // Create an image/buffer, allocate memory, free it, and then try to bind it
2644 {
2645 VkImage image = VK_NULL_HANDLE;
2646 VkBuffer buffer = VK_NULL_HANDLE;
2647 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2648 ASSERT_VK_SUCCESS(err);
2649 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2650 ASSERT_VK_SUCCESS(err);
2651 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2652 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2653 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002654
Cortf801b982017-01-17 18:10:21 -08002655 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2656 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2657 image_mem_alloc.allocationSize = image_mem_reqs.size;
2658 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2659 ASSERT_TRUE(pass);
2660 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2661 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2662 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2663 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002664
Cortf801b982017-01-17 18:10:21 -08002665 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2666 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2667 ASSERT_VK_SUCCESS(err);
2668 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2669 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002670
Cortf801b982017-01-17 18:10:21 -08002671 vkFreeMemory(device(), image_mem, NULL);
2672 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002673
Cortf801b982017-01-17 18:10:21 -08002674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2675 err = vkBindImageMemory(device(), image, image_mem, 0);
2676 (void)err; // This may very well return an error.
2677 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002678
Cortf801b982017-01-17 18:10:21 -08002679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2680 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2681 (void)err; // This may very well return an error.
2682 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002683
Cortf801b982017-01-17 18:10:21 -08002684 vkDestroyImage(m_device->device(), image, NULL);
2685 vkDestroyBuffer(m_device->device(), buffer, NULL);
2686 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002687
2688 // Try to bind memory to an object that already has a memory binding
2689 {
2690 VkImage image = VK_NULL_HANDLE;
2691 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2692 ASSERT_VK_SUCCESS(err);
2693 VkBuffer buffer = VK_NULL_HANDLE;
2694 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2695 ASSERT_VK_SUCCESS(err);
2696 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2697 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2698 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2699 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2700 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2701 image_alloc_info.allocationSize = image_mem_reqs.size;
2702 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2703 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2704 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2705 ASSERT_TRUE(pass);
2706 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2707 ASSERT_TRUE(pass);
2708 VkDeviceMemory image_mem, buffer_mem;
2709 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2710 ASSERT_VK_SUCCESS(err);
2711 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2712 ASSERT_VK_SUCCESS(err);
2713
2714 err = vkBindImageMemory(device(), image, image_mem, 0);
2715 ASSERT_VK_SUCCESS(err);
2716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2717 err = vkBindImageMemory(device(), image, image_mem, 0);
2718 (void)err; // This may very well return an error.
2719 m_errorMonitor->VerifyFound();
2720
2721 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2722 ASSERT_VK_SUCCESS(err);
2723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2724 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2725 (void)err; // This may very well return an error.
2726 m_errorMonitor->VerifyFound();
2727
2728 vkFreeMemory(device(), image_mem, NULL);
2729 vkFreeMemory(device(), buffer_mem, NULL);
2730 vkDestroyImage(device(), image, NULL);
2731 vkDestroyBuffer(device(), buffer, NULL);
2732 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002733
Cort Strattonde748202017-02-17 12:50:01 -08002734 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002735 {
2736 VkImage image = VK_NULL_HANDLE;
2737 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2738 ASSERT_VK_SUCCESS(err);
2739 VkBuffer buffer = VK_NULL_HANDLE;
2740 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2741 ASSERT_VK_SUCCESS(err);
2742 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2743 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2744 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2745 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2746 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002747 // Leave some extra space for alignment wiggle room
2748 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002749 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002750 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002751 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2752 ASSERT_TRUE(pass);
2753 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2754 ASSERT_TRUE(pass);
2755 VkDeviceMemory image_mem, buffer_mem;
2756 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2757 ASSERT_VK_SUCCESS(err);
2758 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2759 ASSERT_VK_SUCCESS(err);
2760
Cort Strattonde748202017-02-17 12:50:01 -08002761 // Test unaligned memory offset
2762 {
2763 if (image_mem_reqs.alignment > 1) {
2764 VkDeviceSize image_offset = 1;
2765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2766 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2767 (void)err; // This may very well return an error.
2768 m_errorMonitor->VerifyFound();
2769 }
Cort6c7dff72017-01-27 18:34:50 -08002770
Cort Strattonde748202017-02-17 12:50:01 -08002771 if (buffer_mem_reqs.alignment > 1) {
2772 VkDeviceSize buffer_offset = 1;
2773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2774 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2775 (void)err; // This may very well return an error.
2776 m_errorMonitor->VerifyFound();
2777 }
2778 }
2779
2780 // Test memory offsets outside the memory allocation
2781 {
2782 VkDeviceSize image_offset =
2783 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2785 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2786 (void)err; // This may very well return an error.
2787 m_errorMonitor->VerifyFound();
2788
2789 VkDeviceSize buffer_offset =
2790 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2792 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2793 (void)err; // This may very well return an error.
2794 m_errorMonitor->VerifyFound();
2795 }
2796
2797 // Test memory offsets within the memory allocation, but which leave too little memory for
2798 // the resource.
2799 {
2800 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
Tony Barbour02d08552017-03-24 16:36:01 -06002801 if ((image_offset > 0) && (image_mem_reqs.size < (image_alloc_info.allocationSize - image_mem_reqs.alignment))) {
Cort Strattonde748202017-02-17 12:50:01 -08002802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2803 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2804 (void)err; // This may very well return an error.
2805 m_errorMonitor->VerifyFound();
2806 }
2807
2808 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2809 if (buffer_offset > 0) {
2810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2811 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2812 (void)err; // This may very well return an error.
2813 m_errorMonitor->VerifyFound();
2814 }
2815 }
Cort6c7dff72017-01-27 18:34:50 -08002816
2817 vkFreeMemory(device(), image_mem, NULL);
2818 vkFreeMemory(device(), buffer_mem, NULL);
2819 vkDestroyImage(device(), image, NULL);
2820 vkDestroyBuffer(device(), buffer, NULL);
2821 }
2822
Cort Stratton4c38bb52017-01-28 13:33:10 -08002823 // Try to bind memory to an object with an invalid memory type
2824 {
2825 VkImage image = VK_NULL_HANDLE;
2826 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2827 ASSERT_VK_SUCCESS(err);
2828 VkBuffer buffer = VK_NULL_HANDLE;
2829 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2830 ASSERT_VK_SUCCESS(err);
2831 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2832 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2833 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2834 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2835 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2836 image_alloc_info.allocationSize = image_mem_reqs.size;
2837 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2838 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002839 // Create a mask of available memory types *not* supported by these resources,
2840 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002841 VkPhysicalDeviceMemoryProperties memory_properties = {};
2842 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002843 VkDeviceMemory image_mem, buffer_mem;
2844
Cort Stratton4c38bb52017-01-28 13:33:10 -08002845 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002846 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002847 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2848 ASSERT_TRUE(pass);
2849 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2850 ASSERT_VK_SUCCESS(err);
2851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2852 err = vkBindImageMemory(device(), image, image_mem, 0);
2853 (void)err; // This may very well return an error.
2854 m_errorMonitor->VerifyFound();
2855 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002856 }
2857
Cort Stratton4c38bb52017-01-28 13:33:10 -08002858 uint32_t buffer_unsupported_mem_type_bits =
2859 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002860 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002861 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2862 ASSERT_TRUE(pass);
2863 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2864 ASSERT_VK_SUCCESS(err);
2865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2866 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2867 (void)err; // This may very well return an error.
2868 m_errorMonitor->VerifyFound();
2869 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002870 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002871
Cort Stratton4c38bb52017-01-28 13:33:10 -08002872 vkDestroyImage(device(), image, NULL);
2873 vkDestroyBuffer(device(), buffer, NULL);
2874 }
2875
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002876 // Try to bind memory to an image created with sparse memory flags
2877 {
2878 VkImageCreateInfo sparse_image_create_info = image_create_info;
2879 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2880 VkImageFormatProperties image_format_properties = {};
2881 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2882 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2883 sparse_image_create_info.usage, sparse_image_create_info.flags,
2884 &image_format_properties);
2885 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2886 // most likely means sparse formats aren't supported here; skip this test.
2887 } else {
2888 ASSERT_VK_SUCCESS(err);
2889 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002890 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002891 return;
2892 } else {
2893 VkImage sparse_image = VK_NULL_HANDLE;
2894 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2895 ASSERT_VK_SUCCESS(err);
2896 VkMemoryRequirements sparse_mem_reqs = {};
2897 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2898 if (sparse_mem_reqs.memoryTypeBits != 0) {
2899 VkMemoryAllocateInfo sparse_mem_alloc = {};
2900 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2901 sparse_mem_alloc.pNext = NULL;
2902 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2903 sparse_mem_alloc.memoryTypeIndex = 0;
2904 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2905 ASSERT_TRUE(pass);
2906 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2907 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2908 ASSERT_VK_SUCCESS(err);
2909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2910 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2911 // This may very well return an error.
2912 (void)err;
2913 m_errorMonitor->VerifyFound();
2914 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2915 }
2916 vkDestroyImage(m_device->device(), sparse_image, NULL);
2917 }
2918 }
2919 }
2920
2921 // Try to bind memory to a buffer created with sparse memory flags
2922 {
2923 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2924 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2925 if (!m_device->phy().features().sparseResidencyBuffer) {
2926 // most likely means sparse formats aren't supported here; skip this test.
2927 } else {
2928 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2929 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2930 ASSERT_VK_SUCCESS(err);
2931 VkMemoryRequirements sparse_mem_reqs = {};
2932 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2933 if (sparse_mem_reqs.memoryTypeBits != 0) {
2934 VkMemoryAllocateInfo sparse_mem_alloc = {};
2935 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2936 sparse_mem_alloc.pNext = NULL;
2937 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2938 sparse_mem_alloc.memoryTypeIndex = 0;
2939 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2940 ASSERT_TRUE(pass);
2941 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2942 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2943 ASSERT_VK_SUCCESS(err);
2944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2945 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2946 // This may very well return an error.
2947 (void)err;
2948 m_errorMonitor->VerifyFound();
2949 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2950 }
2951 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2952 }
2953 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002954}
2955
Karl Schultz6addd812016-02-02 17:17:23 -07002956TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2957 VkResult err;
2958 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002959
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002961
Tony Barbour1fa09702017-03-16 12:09:08 -06002962 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002963
Karl Schultz6addd812016-02-02 17:17:23 -07002964 // Create an image object, allocate memory, destroy the object and then try
2965 // to bind it
2966 VkImage image;
2967 VkDeviceMemory mem;
2968 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002969
Karl Schultz6addd812016-02-02 17:17:23 -07002970 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2971 const int32_t tex_width = 32;
2972 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002973
2974 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002975 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2976 image_create_info.pNext = NULL;
2977 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2978 image_create_info.format = tex_format;
2979 image_create_info.extent.width = tex_width;
2980 image_create_info.extent.height = tex_height;
2981 image_create_info.extent.depth = 1;
2982 image_create_info.mipLevels = 1;
2983 image_create_info.arrayLayers = 1;
2984 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2985 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2986 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2987 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002988
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002989 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002990 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2991 mem_alloc.pNext = NULL;
2992 mem_alloc.allocationSize = 0;
2993 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002994
Chia-I Wuf7458c52015-10-26 21:10:41 +08002995 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002996 ASSERT_VK_SUCCESS(err);
2997
Karl Schultz6addd812016-02-02 17:17:23 -07002998 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002999
3000 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003001 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06003002 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06003003
3004 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003005 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06003006 ASSERT_VK_SUCCESS(err);
3007
3008 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08003009 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06003010 ASSERT_VK_SUCCESS(err);
3011
3012 // Now Try to bind memory to this destroyed object
3013 err = vkBindImageMemory(m_device->device(), image, mem, 0);
3014 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07003015 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003016
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003017 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003018
Chia-I Wuf7458c52015-10-26 21:10:41 +08003019 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003020}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003021
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003022TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
3023 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
3024
Tony Barbour1fa09702017-03-16 12:09:08 -06003025 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3027
3028 VkVertexInputBindingDescription input_binding;
3029 memset(&input_binding, 0, sizeof(input_binding));
3030
3031 VkVertexInputAttributeDescription input_attribs;
3032 memset(&input_attribs, 0, sizeof(input_attribs));
3033
3034 // Pick a really bad format for this purpose and make sure it should fail
3035 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3036 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3037 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003038 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003039 return;
3040 }
3041
3042 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003043 char const *vsSource =
3044 "#version 450\n"
3045 "\n"
3046 "out gl_PerVertex {\n"
3047 " vec4 gl_Position;\n"
3048 "};\n"
3049 "void main(){\n"
3050 " gl_Position = vec4(1);\n"
3051 "}\n";
3052 char const *fsSource =
3053 "#version 450\n"
3054 "\n"
3055 "layout(location=0) out vec4 color;\n"
3056 "void main(){\n"
3057 " color = vec4(1);\n"
3058 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003059
3060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3061 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3062 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3063
3064 VkPipelineObj pipe(m_device);
3065 pipe.AddColorAttachment();
3066 pipe.AddShader(&vs);
3067 pipe.AddShader(&fs);
3068
3069 pipe.AddVertexInputBindings(&input_binding, 1);
3070 pipe.AddVertexInputAttribs(&input_attribs, 1);
3071
3072 VkDescriptorSetObj descriptorSet(m_device);
3073 descriptorSet.AppendDummy();
3074 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3075
3076 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3077
3078 m_errorMonitor->VerifyFound();
3079}
3080
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003081TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003082 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003083 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003084
3085 VkMemoryPropertyFlags reqs = 0;
3086 VkImageCreateInfo image_create_info = {};
3087 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3088 image_create_info.pNext = NULL;
3089 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3090 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3091 image_create_info.extent.width = 256;
3092 image_create_info.extent.height = 256;
3093 image_create_info.extent.depth = 1;
3094 image_create_info.mipLevels = 1;
3095 image_create_info.arrayLayers = 1;
3096 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3097 image_create_info.flags = 0;
3098
3099 VkImageBlit blit_region = {};
3100 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3101 blit_region.srcSubresource.baseArrayLayer = 0;
3102 blit_region.srcSubresource.layerCount = 1;
3103 blit_region.srcSubresource.mipLevel = 0;
3104 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3105 blit_region.dstSubresource.baseArrayLayer = 0;
3106 blit_region.dstSubresource.layerCount = 1;
3107 blit_region.dstSubresource.mipLevel = 0;
3108
3109 // Create two images, the source with sampleCount = 2, and attempt to blit
3110 // between them
3111 {
3112 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003113 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003114 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003115 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003116 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003117 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003118 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003119 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003120 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003121 m_errorMonitor->SetDesiredFailureMsg(
3122 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3123 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003124 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3125 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003126 m_errorMonitor->VerifyFound();
3127 m_commandBuffer->EndCommandBuffer();
3128 }
3129
3130 // Create two images, the dest with sampleCount = 4, and attempt to blit
3131 // between them
3132 {
3133 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003134 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003135 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003136 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003137 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003138 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003139 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003140 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003141 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003142 m_errorMonitor->SetDesiredFailureMsg(
3143 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3144 "was created with a sample count of VK_SAMPLE_COUNT_4_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003145 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3146 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003147 m_errorMonitor->VerifyFound();
3148 m_commandBuffer->EndCommandBuffer();
3149 }
3150
3151 VkBufferImageCopy copy_region = {};
3152 copy_region.bufferRowLength = 128;
3153 copy_region.bufferImageHeight = 128;
3154 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3155 copy_region.imageSubresource.layerCount = 1;
3156 copy_region.imageExtent.height = 64;
3157 copy_region.imageExtent.width = 64;
3158 copy_region.imageExtent.depth = 1;
3159
3160 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3161 // buffer to image
3162 {
3163 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003164 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3165 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003166 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003167 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003168 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003169 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003170 m_errorMonitor->SetDesiredFailureMsg(
3171 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3172 "was created with a sample count of VK_SAMPLE_COUNT_8_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003173 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3174 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003175 m_errorMonitor->VerifyFound();
3176 m_commandBuffer->EndCommandBuffer();
3177 }
3178
3179 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3180 // image to buffer
3181 {
3182 vk_testing::Buffer dst_buffer;
3183 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3184 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003185 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003186 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003187 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003188 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003189 m_errorMonitor->SetDesiredFailureMsg(
3190 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3191 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003192 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003193 dst_buffer.handle(), 1, &copy_region);
3194 m_errorMonitor->VerifyFound();
3195 m_commandBuffer->EndCommandBuffer();
3196 }
3197}
3198
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003199TEST_F(VkLayerTest, BlitImageFormats) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003200 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003201
3202 VkImageObj src_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003203 src_image.Init(64, 64, 1, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003204 VkImageObj dst_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003205 dst_image.Init(64, 64, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003206 VkImageObj dst_image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003207 dst_image2.Init(64, 64, 1, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003208
3209 VkImageBlit blitRegion = {};
3210 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3211 blitRegion.srcSubresource.baseArrayLayer = 0;
3212 blitRegion.srcSubresource.layerCount = 1;
3213 blitRegion.srcSubresource.mipLevel = 0;
3214 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3215 blitRegion.dstSubresource.baseArrayLayer = 0;
3216 blitRegion.dstSubresource.layerCount = 1;
3217 blitRegion.dstSubresource.mipLevel = 0;
3218
Dave Houlton34df4cb2016-12-01 16:43:06 -07003219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3220
3221 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3222 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003223
3224 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003225 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003226 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image.image(), dst_image.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003227 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003228
3229 m_errorMonitor->VerifyFound();
3230
Dave Houlton34df4cb2016-12-01 16:43:06 -07003231 // Test should generate 2 VU failures
3232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003234
3235 // Unsigned int vs signed int
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003236 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image2.image(), dst_image2.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003237 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003238
Dave Houlton34df4cb2016-12-01 16:43:06 -07003239 // TODO: Note that this only verifies that at least one of the VU enums was found
3240 // Also, if any were not seen, they'll remain in the target list (Soln TBD, JIRA task: VL-72)
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003241 m_errorMonitor->VerifyFound();
3242
Tony Barbour552f6c02016-12-21 14:34:07 -07003243 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003244}
3245
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003246TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3247 VkResult err;
3248 bool pass;
3249
3250 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003251 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003252
3253 // If w/d/h granularity is 1, test is not meaningful
3254 // TODO: When virtual device limits are available, create a set of limits for this test that
3255 // will always have a granularity of > 1 for w, h, and d
3256 auto index = m_device->graphics_queue_node_index_;
3257 auto queue_family_properties = m_device->phy().queue_properties();
3258
3259 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3260 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3261 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3262 return;
3263 }
3264
3265 // Create two images of different types and try to copy between them
3266 VkImage srcImage;
3267 VkImage dstImage;
3268 VkDeviceMemory srcMem;
3269 VkDeviceMemory destMem;
3270 VkMemoryRequirements memReqs;
3271
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003272 VkImageCreateInfo image_create_info = {};
3273 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3274 image_create_info.pNext = NULL;
3275 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3276 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3277 image_create_info.extent.width = 32;
3278 image_create_info.extent.height = 32;
3279 image_create_info.extent.depth = 1;
3280 image_create_info.mipLevels = 1;
3281 image_create_info.arrayLayers = 4;
3282 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3283 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3284 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3285 image_create_info.flags = 0;
3286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003287 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003288 ASSERT_VK_SUCCESS(err);
3289
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003290 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003291 ASSERT_VK_SUCCESS(err);
3292
3293 // Allocate memory
3294 VkMemoryAllocateInfo memAlloc = {};
3295 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3296 memAlloc.pNext = NULL;
3297 memAlloc.allocationSize = 0;
3298 memAlloc.memoryTypeIndex = 0;
3299
3300 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3301 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003302 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003303 ASSERT_TRUE(pass);
3304 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3305 ASSERT_VK_SUCCESS(err);
3306
3307 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3308 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003309 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003310 ASSERT_VK_SUCCESS(err);
3311 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3312 ASSERT_VK_SUCCESS(err);
3313
3314 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3315 ASSERT_VK_SUCCESS(err);
3316 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3317 ASSERT_VK_SUCCESS(err);
3318
Tony Barbour552f6c02016-12-21 14:34:07 -07003319 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003320 VkImageCopy copyRegion;
3321 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3322 copyRegion.srcSubresource.mipLevel = 0;
3323 copyRegion.srcSubresource.baseArrayLayer = 0;
3324 copyRegion.srcSubresource.layerCount = 1;
3325 copyRegion.srcOffset.x = 0;
3326 copyRegion.srcOffset.y = 0;
3327 copyRegion.srcOffset.z = 0;
3328 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3329 copyRegion.dstSubresource.mipLevel = 0;
3330 copyRegion.dstSubresource.baseArrayLayer = 0;
3331 copyRegion.dstSubresource.layerCount = 1;
3332 copyRegion.dstOffset.x = 0;
3333 copyRegion.dstOffset.y = 0;
3334 copyRegion.dstOffset.z = 0;
3335 copyRegion.extent.width = 1;
3336 copyRegion.extent.height = 1;
3337 copyRegion.extent.depth = 1;
3338
3339 // Introduce failure by setting srcOffset to a bad granularity value
3340 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3342 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003343 m_errorMonitor->VerifyFound();
3344
3345 // Introduce failure by setting extent to a bad granularity value
3346 copyRegion.srcOffset.y = 0;
3347 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3349 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003350 m_errorMonitor->VerifyFound();
3351
3352 // Now do some buffer/image copies
3353 vk_testing::Buffer buffer;
3354 VkMemoryPropertyFlags reqs = 0;
3355 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3356 VkBufferImageCopy region = {};
3357 region.bufferOffset = 0;
3358 region.bufferRowLength = 3;
3359 region.bufferImageHeight = 128;
3360 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3361 region.imageSubresource.layerCount = 1;
3362 region.imageExtent.height = 16;
3363 region.imageExtent.width = 16;
3364 region.imageExtent.depth = 1;
3365 region.imageOffset.x = 0;
3366 region.imageOffset.y = 0;
3367 region.imageOffset.z = 0;
3368
3369 // Introduce failure by setting bufferRowLength to a bad granularity value
3370 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3372 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3373 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003374 m_errorMonitor->VerifyFound();
3375 region.bufferRowLength = 128;
3376
3377 // Introduce failure by setting bufferOffset to a bad granularity value
3378 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3380 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3381 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003382 m_errorMonitor->VerifyFound();
3383 region.bufferOffset = 0;
3384
3385 // Introduce failure by setting bufferImageHeight to a bad granularity value
3386 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3388 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3389 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003390 m_errorMonitor->VerifyFound();
3391 region.bufferImageHeight = 128;
3392
3393 // Introduce failure by setting imageExtent to a bad granularity value
3394 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3396 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3397 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003398 m_errorMonitor->VerifyFound();
3399 region.imageExtent.width = 16;
3400
3401 // Introduce failure by setting imageOffset to a bad granularity value
3402 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3404 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3405 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003406 m_errorMonitor->VerifyFound();
3407
Tony Barbour552f6c02016-12-21 14:34:07 -07003408 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003409
3410 vkDestroyImage(m_device->device(), srcImage, NULL);
3411 vkDestroyImage(m_device->device(), dstImage, NULL);
3412 vkFreeMemory(m_device->device(), srcMem, NULL);
3413 vkFreeMemory(m_device->device(), destMem, NULL);
3414}
3415
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003416TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003417 TEST_DESCRIPTION(
3418 "Submit command buffer created using one queue family and "
3419 "attempt to submit them on a queue created in a different "
3420 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003421
Tony Barbour1fa09702017-03-16 12:09:08 -06003422 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003423
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003424 // This test is meaningless unless we have multiple queue families
3425 auto queue_family_properties = m_device->phy().queue_properties();
3426 if (queue_family_properties.size() < 2) {
3427 return;
3428 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003430 // Get safe index of another queue family
3431 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003432 VkQueue other_queue;
3433 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3434
3435 // Record an empty cmd buffer
3436 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3437 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3438 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3439 vkEndCommandBuffer(m_commandBuffer->handle());
3440
3441 // And submit on the wrong queue
3442 VkSubmitInfo submit_info = {};
3443 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3444 submit_info.commandBufferCount = 1;
3445 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003446 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003447
3448 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003449}
3450
Chris Forbes4c24a922016-11-16 08:59:10 +13003451TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003452 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4c24a922016-11-16 08:59:10 +13003453
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003454 // There are no attachments, but refer to attachment 0.
3455 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003456 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003457 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003458 };
3459
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003460 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003461 VkRenderPass rp;
3462
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003463 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003465 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3466 m_errorMonitor->VerifyFound();
3467}
3468
Chris Forbesa58c4522016-09-28 15:19:39 +13003469TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3470 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
Tony Barbour1fa09702017-03-16 12:09:08 -06003471 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa58c4522016-09-28 15:19:39 +13003472
3473 // A renderpass with two subpasses, both writing the same attachment.
3474 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003475 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3476 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3477 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003478 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003479 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003480 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003481 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3482 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003483 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003484 VkSubpassDependency dep = {0,
3485 1,
3486 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3487 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3488 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3489 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3490 VK_DEPENDENCY_BY_REGION_BIT};
3491 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003492 VkRenderPass rp;
3493 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3494 ASSERT_VK_SUCCESS(err);
3495
3496 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003497 image.InitNoLayout(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbesa58c4522016-09-28 15:19:39 +13003498 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3499
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003500 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003501 VkFramebuffer fb;
3502 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3503 ASSERT_VK_SUCCESS(err);
3504
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003505 char const *vsSource =
3506 "#version 450\n"
3507 "void main() { gl_Position = vec4(1); }\n";
3508 char const *fsSource =
3509 "#version 450\n"
3510 "layout(location=0) out vec4 color;\n"
3511 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003512
3513 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3514 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3515 VkPipelineObj pipe(m_device);
3516 pipe.AddColorAttachment();
3517 pipe.AddShader(&vs);
3518 pipe.AddShader(&fs);
3519 VkViewport view_port = {};
3520 m_viewports.push_back(view_port);
3521 pipe.SetViewport(m_viewports);
3522 VkRect2D rect = {};
3523 m_scissors.push_back(rect);
3524 pipe.SetScissor(m_scissors);
3525
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003526 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003527 VkPipelineLayout pl;
3528 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3529 ASSERT_VK_SUCCESS(err);
3530 pipe.CreateVKPipeline(pl, rp);
3531
Tony Barbour552f6c02016-12-21 14:34:07 -07003532 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003533
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003534 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3535 nullptr,
3536 rp,
3537 fb,
3538 {{
3539 0, 0,
3540 },
3541 {32, 32}},
3542 0,
3543 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003544
3545 // subtest 1: bind in the wrong subpass
3546 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3547 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003549 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3550 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3551 m_errorMonitor->VerifyFound();
3552
3553 vkCmdEndRenderPass(m_commandBuffer->handle());
3554
3555 // subtest 2: bind in correct subpass, then transition to next subpass
3556 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3557 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3558 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003560 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3561 m_errorMonitor->VerifyFound();
3562
3563 vkCmdEndRenderPass(m_commandBuffer->handle());
3564
Tony Barbour552f6c02016-12-21 14:34:07 -07003565 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003566
3567 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3568 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3569 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3570}
3571
Tony Barbour4e919972016-08-09 13:27:40 -06003572TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003573 TEST_DESCRIPTION(
3574 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3575 "with extent outside of framebuffer");
Tony Barbour1fa09702017-03-16 12:09:08 -06003576 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour4e919972016-08-09 13:27:40 -06003577 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3578
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3580 "Cannot execute a render pass with renderArea "
3581 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003582
3583 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3584 m_renderPassBeginInfo.renderArea.extent.width = 257;
3585 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003586 m_commandBuffer->BeginCommandBuffer();
3587 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003588 m_errorMonitor->VerifyFound();
3589}
3590
3591TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003592 TEST_DESCRIPTION(
3593 "Generate INDEPENDENT_BLEND by disabling independent "
3594 "blend and then specifying different blend states for two "
3595 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003596 VkPhysicalDeviceFeatures features = {};
3597 features.independentBlend = VK_FALSE;
Tony Barbour1fa09702017-03-16 12:09:08 -06003598 ASSERT_NO_FATAL_FAILURE(Init(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003599
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3601 "Invalid Pipeline CreateInfo: If independent blend feature not "
3602 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003603
Cody Northropc31a84f2016-08-22 10:41:47 -06003604 VkDescriptorSetObj descriptorSet(m_device);
3605 descriptorSet.AppendDummy();
3606 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003607
Cody Northropc31a84f2016-08-22 10:41:47 -06003608 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003609 // Create a renderPass with two color attachments
3610 VkAttachmentReference attachments[2] = {};
3611 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003612 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003613 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3614
3615 VkSubpassDescription subpass = {};
3616 subpass.pColorAttachments = attachments;
3617 subpass.colorAttachmentCount = 2;
3618
3619 VkRenderPassCreateInfo rpci = {};
3620 rpci.subpassCount = 1;
3621 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003622 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003623
Tony Barbourffd60bd2017-03-09 12:04:55 -07003624 VkAttachmentDescription attach_desc[2] = {};
3625 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3626 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3627 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3628 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3629 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3630 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3631 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3632 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003633
Tony Barbourffd60bd2017-03-09 12:04:55 -07003634 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003635 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3636
3637 VkRenderPass renderpass;
3638 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003639 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003640 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003641
Cody Northropc31a84f2016-08-22 10:41:47 -06003642 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3643 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3644 att_state1.blendEnable = VK_TRUE;
3645 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3646 att_state2.blendEnable = VK_FALSE;
3647 pipeline.AddColorAttachment(0, &att_state1);
3648 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003649 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003650 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003651 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003652}
3653
Mike Weiblen40b160e2017-02-06 19:21:52 -07003654// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3655TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3656 TEST_DESCRIPTION(
3657 "Create a graphics pipeline that is incompatible with the requirements "
3658 "of its contained Renderpass/subpasses.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003659 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen40b160e2017-02-06 19:21:52 -07003660
3661 VkDescriptorSetObj ds_obj(m_device);
3662 ds_obj.AppendDummy();
3663 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3664
3665 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3666
3667 VkPipelineColorBlendAttachmentState att_state1 = {};
3668 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3669 att_state1.blendEnable = VK_TRUE;
3670
3671 VkRenderpassObj rp_obj(m_device);
3672
3673 {
3674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3675 VkPipelineObj pipeline(m_device);
3676 pipeline.AddShader(&vs_obj);
3677 pipeline.AddColorAttachment(0, &att_state1);
3678
3679 VkGraphicsPipelineCreateInfo info = {};
3680 pipeline.InitGraphicsPipelineCreateInfo(&info);
3681 info.pColorBlendState = nullptr;
3682
3683 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3684 m_errorMonitor->VerifyFound();
3685 }
3686}
3687
Chris Forbes26ec2122016-11-29 08:58:33 +13003688#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003689TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3690 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3691 "depth attachments in subpass");
Tony Barbour1fa09702017-03-16 12:09:08 -06003692 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour4e919972016-08-09 13:27:40 -06003693
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3695 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003696
3697 // Create a renderPass with a single color attachment
3698 VkAttachmentReference attach = {};
3699 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3700 VkSubpassDescription subpass = {};
3701 VkRenderPassCreateInfo rpci = {};
3702 rpci.subpassCount = 1;
3703 rpci.pSubpasses = &subpass;
3704 rpci.attachmentCount = 1;
3705 VkAttachmentDescription attach_desc = {};
3706 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3707 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3708 rpci.pAttachments = &attach_desc;
3709 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3710 VkRenderPass rp;
3711 subpass.pDepthStencilAttachment = &attach;
3712 subpass.pColorAttachments = NULL;
3713 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3714 m_errorMonitor->VerifyFound();
3715}
Chris Forbes26ec2122016-11-29 08:58:33 +13003716#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003717
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003718TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003719 TEST_DESCRIPTION(
3720 "Create a framebuffer where a subpass has a preserve "
3721 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003722
Tony Barbour1fa09702017-03-16 12:09:08 -06003723 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3725
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003727
3728 VkAttachmentReference color_attach = {};
3729 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3730 color_attach.attachment = 0;
3731 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3732 VkSubpassDescription subpass = {};
3733 subpass.colorAttachmentCount = 1;
3734 subpass.pColorAttachments = &color_attach;
3735 subpass.preserveAttachmentCount = 1;
3736 subpass.pPreserveAttachments = &preserve_attachment;
3737
3738 VkRenderPassCreateInfo rpci = {};
3739 rpci.subpassCount = 1;
3740 rpci.pSubpasses = &subpass;
3741 rpci.attachmentCount = 1;
3742 VkAttachmentDescription attach_desc = {};
3743 attach_desc.format = VK_FORMAT_UNDEFINED;
3744 rpci.pAttachments = &attach_desc;
3745 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3746 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003747 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003748
3749 m_errorMonitor->VerifyFound();
3750
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003751 if (result == VK_SUCCESS) {
3752 vkDestroyRenderPass(m_device->device(), rp, NULL);
3753 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003754}
3755
Chris Forbesc5389742016-06-29 11:49:23 +12003756TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003757 TEST_DESCRIPTION(
3758 "Ensure that CreateRenderPass produces a validation error "
3759 "when the source of a subpass multisample resolve "
3760 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003761
Tony Barbour1fa09702017-03-16 12:09:08 -06003762 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc5389742016-06-29 11:49:23 +12003763
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3765 "Subpass 0 requests multisample resolve from attachment 0 which has "
3766 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003767
3768 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003769 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3770 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3771 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3772 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3773 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3774 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003775 };
3776
3777 VkAttachmentReference color = {
3778 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3779 };
3780
3781 VkAttachmentReference resolve = {
3782 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3783 };
3784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003785 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003786
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003787 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003788
3789 VkRenderPass rp;
3790 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3791
3792 m_errorMonitor->VerifyFound();
3793
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003794 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003795}
3796
3797TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003798 TEST_DESCRIPTION(
3799 "Ensure CreateRenderPass produces a validation error "
3800 "when a subpass multisample resolve operation is "
3801 "requested, and the destination of that resolve has "
3802 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003803
Tony Barbour1fa09702017-03-16 12:09:08 -06003804 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc5389742016-06-29 11:49:23 +12003805
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3807 "Subpass 0 requests multisample resolve into attachment 1, which "
3808 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003809
3810 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003811 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3812 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3813 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3814 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3815 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3816 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003817 };
3818
3819 VkAttachmentReference color = {
3820 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3821 };
3822
3823 VkAttachmentReference resolve = {
3824 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3825 };
3826
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003827 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003828
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003829 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003830
3831 VkRenderPass rp;
3832 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3833
3834 m_errorMonitor->VerifyFound();
3835
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003836 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003837}
3838
Chris Forbes3f128ef2016-06-29 14:58:53 +12003839TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003840 TEST_DESCRIPTION(
3841 "Ensure CreateRenderPass produces a validation error "
3842 "when the color and depth attachments used by a subpass "
3843 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003844
Tony Barbour1fa09702017-03-16 12:09:08 -06003845 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3f128ef2016-06-29 14:58:53 +12003846
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3848 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003849
3850 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003851 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3852 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3853 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3854 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3855 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3856 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003857 };
3858
3859 VkAttachmentReference color[] = {
3860 {
3861 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3862 },
3863 {
3864 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3865 },
3866 };
3867
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003868 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003869
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003870 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003871
3872 VkRenderPass rp;
3873 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3874
3875 m_errorMonitor->VerifyFound();
3876
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003877 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
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();
6231 cmd_buf.BeginRenderPass(m_renderPassBeginInfo);
6232 // record layout different than actual descriptor layout of SHADER_RO
6233 image.SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
6234 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
Karl Schultz6addd812016-02-02 17:17:23 -07007588TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007589 // Cause error due to Begin while recording CB
7590 // Then cause 2 errors for attempting to reset CB w/o having
7591 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7592 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007594
Tony Barbour1fa09702017-03-16 12:09:08 -06007595 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007596
7597 // Calls AllocateCommandBuffers
7598 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7599
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007600 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007601 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007602 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7603 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007604 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7605 cmd_buf_info.pNext = NULL;
7606 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007607 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007608
7609 // Begin CB to transition to recording state
7610 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7611 // Can't re-begin. This should trigger error
7612 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007613 m_errorMonitor->VerifyFound();
7614
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007616 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007617 // Reset attempt will trigger error due to incorrect CommandPool state
7618 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007619 m_errorMonitor->VerifyFound();
7620
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007622 // Transition CB to RECORDED state
7623 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7624 // Now attempting to Begin will implicitly reset, which triggers error
7625 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007626 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007627}
7628
Karl Schultz6addd812016-02-02 17:17:23 -07007629TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007630 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007631 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007632
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7634 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007635
Tony Barbour1fa09702017-03-16 12:09:08 -06007636 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007638
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007639 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007640 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7641 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007642
7643 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007644 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7645 ds_pool_ci.pNext = NULL;
7646 ds_pool_ci.maxSets = 1;
7647 ds_pool_ci.poolSizeCount = 1;
7648 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007649
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007650 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007651 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007652 ASSERT_VK_SUCCESS(err);
7653
Tony Barboureb254902015-07-15 12:50:33 -06007654 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007655 dsl_binding.binding = 0;
7656 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7657 dsl_binding.descriptorCount = 1;
7658 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7659 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007660
Tony Barboureb254902015-07-15 12:50:33 -06007661 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007662 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7663 ds_layout_ci.pNext = NULL;
7664 ds_layout_ci.bindingCount = 1;
7665 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007666
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007667 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007668 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007669 ASSERT_VK_SUCCESS(err);
7670
7671 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007672 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007673 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007674 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007675 alloc_info.descriptorPool = ds_pool;
7676 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007677 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007678 ASSERT_VK_SUCCESS(err);
7679
Tony Barboureb254902015-07-15 12:50:33 -06007680 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007681 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7682 pipeline_layout_ci.setLayoutCount = 1;
7683 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007684
7685 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007686 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007687 ASSERT_VK_SUCCESS(err);
7688
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007689 VkViewport vp = {}; // Just need dummy vp to point to
7690 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007691
7692 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007693 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7694 vp_state_ci.scissorCount = 1;
7695 vp_state_ci.pScissors = &sc;
7696 vp_state_ci.viewportCount = 1;
7697 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007698
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007699 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7700 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7701 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7702 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7703 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7704 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007705 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007706 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007707 rs_state_ci.lineWidth = 1.0f;
7708
7709 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7710 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7711 vi_ci.pNext = nullptr;
7712 vi_ci.vertexBindingDescriptionCount = 0;
7713 vi_ci.pVertexBindingDescriptions = nullptr;
7714 vi_ci.vertexAttributeDescriptionCount = 0;
7715 vi_ci.pVertexAttributeDescriptions = nullptr;
7716
7717 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7718 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7719 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7720
7721 VkPipelineShaderStageCreateInfo shaderStages[2];
7722 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7723
7724 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7725 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007726 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007727 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007728
Tony Barboureb254902015-07-15 12:50:33 -06007729 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007730 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7731 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007732 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007733 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7734 gp_ci.layout = pipeline_layout;
7735 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007736 gp_ci.pVertexInputState = &vi_ci;
7737 gp_ci.pInputAssemblyState = &ia_ci;
7738
7739 gp_ci.stageCount = 1;
7740 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007741
7742 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007743 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7744 pc_ci.initialDataSize = 0;
7745 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007746
7747 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007748 VkPipelineCache pipelineCache;
7749
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007750 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007751 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007752 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007753 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007754
Chia-I Wuf7458c52015-10-26 21:10:41 +08007755 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7756 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7757 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7758 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007759}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007760
Tobin Ehlis912df022015-09-17 08:46:18 -06007761/*// TODO : This test should be good, but needs Tess support in compiler to run
7762TEST_F(VkLayerTest, InvalidPatchControlPoints)
7763{
7764 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007765 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007766
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007768 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7769primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007770
Tony Barbour1fa09702017-03-16 12:09:08 -06007771 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis912df022015-09-17 08:46:18 -06007772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007773
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007774 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007775 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007776 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007777
7778 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7779 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7780 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007781 ds_pool_ci.poolSizeCount = 1;
7782 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007783
7784 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007785 err = vkCreateDescriptorPool(m_device->device(),
7786VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007787 ASSERT_VK_SUCCESS(err);
7788
7789 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007790 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007791 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007792 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007793 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7794 dsl_binding.pImmutableSamplers = NULL;
7795
7796 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007797 ds_layout_ci.sType =
7798VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007799 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007800 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007801 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007802
7803 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007804 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7805&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007806 ASSERT_VK_SUCCESS(err);
7807
7808 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007809 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7810VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007811 ASSERT_VK_SUCCESS(err);
7812
7813 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007814 pipeline_layout_ci.sType =
7815VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007816 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007817 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007818 pipeline_layout_ci.pSetLayouts = &ds_layout;
7819
7820 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007821 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7822&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007823 ASSERT_VK_SUCCESS(err);
7824
7825 VkPipelineShaderStageCreateInfo shaderStages[3];
7826 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7827
Karl Schultz6addd812016-02-02 17:17:23 -07007828 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7829this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007830 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007831 VkShaderObj
7832tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7833this);
7834 VkShaderObj
7835te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7836this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007837
Karl Schultz6addd812016-02-02 17:17:23 -07007838 shaderStages[0].sType =
7839VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007840 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007841 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007842 shaderStages[1].sType =
7843VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007844 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007845 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007846 shaderStages[2].sType =
7847VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007848 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007849 shaderStages[2].shader = te.handle();
7850
7851 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007852 iaCI.sType =
7853VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007854 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007855
7856 VkPipelineTessellationStateCreateInfo tsCI = {};
7857 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7858 tsCI.patchControlPoints = 0; // This will cause an error
7859
7860 VkGraphicsPipelineCreateInfo gp_ci = {};
7861 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7862 gp_ci.pNext = NULL;
7863 gp_ci.stageCount = 3;
7864 gp_ci.pStages = shaderStages;
7865 gp_ci.pVertexInputState = NULL;
7866 gp_ci.pInputAssemblyState = &iaCI;
7867 gp_ci.pTessellationState = &tsCI;
7868 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007869 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007870 gp_ci.pMultisampleState = NULL;
7871 gp_ci.pDepthStencilState = NULL;
7872 gp_ci.pColorBlendState = NULL;
7873 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7874 gp_ci.layout = pipeline_layout;
7875 gp_ci.renderPass = renderPass();
7876
7877 VkPipelineCacheCreateInfo pc_ci = {};
7878 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7879 pc_ci.pNext = NULL;
7880 pc_ci.initialSize = 0;
7881 pc_ci.initialData = 0;
7882 pc_ci.maxSize = 0;
7883
7884 VkPipeline pipeline;
7885 VkPipelineCache pipelineCache;
7886
Karl Schultz6addd812016-02-02 17:17:23 -07007887 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7888&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007889 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007890 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7891&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007892
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007893 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007894
Chia-I Wuf7458c52015-10-26 21:10:41 +08007895 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7896 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7897 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7898 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007899}
7900*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007901
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007902TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007903 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007904
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007905 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007906
Tony Barbour1fa09702017-03-16 12:09:08 -06007907 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007908 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007909
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007910 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007911 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7912 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007913
7914 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007915 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7916 ds_pool_ci.maxSets = 1;
7917 ds_pool_ci.poolSizeCount = 1;
7918 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007919
7920 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007922 ASSERT_VK_SUCCESS(err);
7923
7924 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007925 dsl_binding.binding = 0;
7926 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7927 dsl_binding.descriptorCount = 1;
7928 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007929
7930 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007931 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7932 ds_layout_ci.bindingCount = 1;
7933 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007934
7935 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007936 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007937 ASSERT_VK_SUCCESS(err);
7938
7939 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007940 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007941 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007942 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007943 alloc_info.descriptorPool = ds_pool;
7944 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007945 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007946 ASSERT_VK_SUCCESS(err);
7947
7948 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007949 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7950 pipeline_layout_ci.setLayoutCount = 1;
7951 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007952
7953 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007954 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007955 ASSERT_VK_SUCCESS(err);
7956
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007957 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007958 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007959 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007960 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007961 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007962 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007963
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007964 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7965 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7966 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7967 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7968 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7969 rs_state_ci.depthClampEnable = VK_FALSE;
7970 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7971 rs_state_ci.depthBiasEnable = VK_FALSE;
7972
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007973 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7974 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7975 vi_ci.pNext = nullptr;
7976 vi_ci.vertexBindingDescriptionCount = 0;
7977 vi_ci.pVertexBindingDescriptions = nullptr;
7978 vi_ci.vertexAttributeDescriptionCount = 0;
7979 vi_ci.pVertexAttributeDescriptions = nullptr;
7980
7981 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7982 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7983 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7984
7985 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7986 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7987 pipe_ms_state_ci.pNext = NULL;
7988 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7989 pipe_ms_state_ci.sampleShadingEnable = 0;
7990 pipe_ms_state_ci.minSampleShading = 1.0;
7991 pipe_ms_state_ci.pSampleMask = NULL;
7992
Cody Northropeb3a6c12015-10-05 14:44:45 -06007993 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007994 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007995
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007996 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007997 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007998 shaderStages[0] = vs.GetStageCreateInfo();
7999 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008000
8001 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008002 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8003 gp_ci.stageCount = 2;
8004 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008005 gp_ci.pVertexInputState = &vi_ci;
8006 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008007 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008008 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008009 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008010 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8011 gp_ci.layout = pipeline_layout;
8012 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008013
8014 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008015 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008016
8017 VkPipeline pipeline;
8018 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008019 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008020 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008021
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008022 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008023 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008024
8025 // Check case where multiViewport is disabled and viewport count is not 1
8026 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
8028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
8029 vp_state_ci.scissorCount = 0;
8030 vp_state_ci.viewportCount = 0;
8031 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8032 m_errorMonitor->VerifyFound();
8033 } else {
8034 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008035 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008036 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008037 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008038
8039 // Check is that viewportcount and scissorcount match
8040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
8041 vp_state_ci.scissorCount = 1;
8042 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
8043 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8044 m_errorMonitor->VerifyFound();
8045
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008046 // Check case where multiViewport is enabled and viewport count is greater than max
8047 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
8049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
8050 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
8051 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
8052 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8053 m_errorMonitor->VerifyFound();
8054 }
8055 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06008056
Chia-I Wuf7458c52015-10-26 21:10:41 +08008057 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8058 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8059 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8060 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008061}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008062
8063// 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
8064// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07008065TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07008066 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008067
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008068 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
8069
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008071
Tony Barbour1fa09702017-03-16 12:09:08 -06008072 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008073 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008074
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008075 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008076 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8077 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008078
8079 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008080 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8081 ds_pool_ci.maxSets = 1;
8082 ds_pool_ci.poolSizeCount = 1;
8083 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008084
8085 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008086 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008087 ASSERT_VK_SUCCESS(err);
8088
8089 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008090 dsl_binding.binding = 0;
8091 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8092 dsl_binding.descriptorCount = 1;
8093 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008094
8095 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008096 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8097 ds_layout_ci.bindingCount = 1;
8098 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008099
8100 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008101 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008102 ASSERT_VK_SUCCESS(err);
8103
8104 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008105 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008106 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008107 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008108 alloc_info.descriptorPool = ds_pool;
8109 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008110 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008111 ASSERT_VK_SUCCESS(err);
8112
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008113 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8114 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8115 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8116
8117 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8118 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8119 vi_ci.pNext = nullptr;
8120 vi_ci.vertexBindingDescriptionCount = 0;
8121 vi_ci.pVertexBindingDescriptions = nullptr;
8122 vi_ci.vertexAttributeDescriptionCount = 0;
8123 vi_ci.pVertexAttributeDescriptions = nullptr;
8124
8125 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8126 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8127 pipe_ms_state_ci.pNext = NULL;
8128 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8129 pipe_ms_state_ci.sampleShadingEnable = 0;
8130 pipe_ms_state_ci.minSampleShading = 1.0;
8131 pipe_ms_state_ci.pSampleMask = NULL;
8132
Tobin Ehlise68360f2015-10-01 11:15:13 -06008133 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008134 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8135 pipeline_layout_ci.setLayoutCount = 1;
8136 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008137
8138 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008139 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008140 ASSERT_VK_SUCCESS(err);
8141
8142 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8143 // Set scissor as dynamic to avoid second error
8144 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008145 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8146 dyn_state_ci.dynamicStateCount = 1;
8147 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008148
Cody Northropeb3a6c12015-10-05 14:44:45 -06008149 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008150 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008151
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008152 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008153 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8154 // 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 +08008155 shaderStages[0] = vs.GetStageCreateInfo();
8156 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008157
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008158 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8159 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8160 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8161 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8162 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8163 rs_state_ci.depthClampEnable = VK_FALSE;
8164 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8165 rs_state_ci.depthBiasEnable = VK_FALSE;
8166
Tobin Ehlise68360f2015-10-01 11:15:13 -06008167 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008168 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8169 gp_ci.stageCount = 2;
8170 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008171 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008172 // Not setting VP state w/o dynamic vp state should cause validation error
8173 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008174 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008175 gp_ci.pVertexInputState = &vi_ci;
8176 gp_ci.pInputAssemblyState = &ia_ci;
8177 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008178 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8179 gp_ci.layout = pipeline_layout;
8180 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008181
8182 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008183 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008184
8185 VkPipeline pipeline;
8186 VkPipelineCache pipelineCache;
8187
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008188 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008189 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008190 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008191
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008192 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008193
Chia-I Wuf7458c52015-10-26 21:10:41 +08008194 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8195 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8196 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8197 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008198}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008199
8200// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
8201// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07008202TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
8203 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008204
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008206
Tony Barbour1fa09702017-03-16 12:09:08 -06008207 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008208
8209 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008210 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008211 return;
8212 }
8213
Tobin Ehlise68360f2015-10-01 11:15:13 -06008214 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008215
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008216 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008217 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8218 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008219
8220 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008221 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8222 ds_pool_ci.maxSets = 1;
8223 ds_pool_ci.poolSizeCount = 1;
8224 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008225
8226 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008227 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008228 ASSERT_VK_SUCCESS(err);
8229
8230 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008231 dsl_binding.binding = 0;
8232 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8233 dsl_binding.descriptorCount = 1;
8234 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008235
8236 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008237 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8238 ds_layout_ci.bindingCount = 1;
8239 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008240
8241 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008242 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008243 ASSERT_VK_SUCCESS(err);
8244
8245 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008246 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008247 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008248 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008249 alloc_info.descriptorPool = ds_pool;
8250 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008251 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008252 ASSERT_VK_SUCCESS(err);
8253
8254 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008255 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8256 pipeline_layout_ci.setLayoutCount = 1;
8257 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008258
8259 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008260 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008261 ASSERT_VK_SUCCESS(err);
8262
8263 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008264 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8265 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008266 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008267 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008268 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008269
8270 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8271 // Set scissor as dynamic to avoid that error
8272 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008273 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8274 dyn_state_ci.dynamicStateCount = 1;
8275 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008276
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008277 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8278 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8279 pipe_ms_state_ci.pNext = NULL;
8280 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8281 pipe_ms_state_ci.sampleShadingEnable = 0;
8282 pipe_ms_state_ci.minSampleShading = 1.0;
8283 pipe_ms_state_ci.pSampleMask = NULL;
8284
Cody Northropeb3a6c12015-10-05 14:44:45 -06008285 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008286 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008287
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008288 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008289 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8290 // 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 +08008291 shaderStages[0] = vs.GetStageCreateInfo();
8292 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008293
Cody Northropf6622dc2015-10-06 10:33:21 -06008294 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8295 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8296 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008297 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008298 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008299 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008300 vi_ci.pVertexAttributeDescriptions = nullptr;
8301
8302 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8303 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8304 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8305
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008306 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008307 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008308 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008309 rs_ci.pNext = nullptr;
8310
Mark Youngc89c6312016-03-31 16:03:20 -06008311 VkPipelineColorBlendAttachmentState att = {};
8312 att.blendEnable = VK_FALSE;
8313 att.colorWriteMask = 0xf;
8314
Cody Northropf6622dc2015-10-06 10:33:21 -06008315 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8316 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8317 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008318 cb_ci.attachmentCount = 1;
8319 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008320
Tobin Ehlise68360f2015-10-01 11:15:13 -06008321 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008322 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8323 gp_ci.stageCount = 2;
8324 gp_ci.pStages = shaderStages;
8325 gp_ci.pVertexInputState = &vi_ci;
8326 gp_ci.pInputAssemblyState = &ia_ci;
8327 gp_ci.pViewportState = &vp_state_ci;
8328 gp_ci.pRasterizationState = &rs_ci;
8329 gp_ci.pColorBlendState = &cb_ci;
8330 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008331 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008332 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8333 gp_ci.layout = pipeline_layout;
8334 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008335
8336 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008337 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008338
8339 VkPipeline pipeline;
8340 VkPipelineCache pipelineCache;
8341
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008342 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008343 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008344 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008345
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008346 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008347
Tobin Ehlisd332f282015-10-02 11:00:56 -06008348 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008349 // First need to successfully create the PSO from above by setting
8350 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008351 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 -07008352
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008353 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008354 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008355 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008356 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008357 m_commandBuffer->BeginCommandBuffer();
8358 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008359 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008360 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008361 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008362 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008363 Draw(1, 0, 0, 0);
8364
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008365 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008366
8367 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8368 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8369 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8370 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008371 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008372}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008373
8374// 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 -07008375// viewportCount
8376TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8377 VkResult err;
8378
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008380
Tony Barbour1fa09702017-03-16 12:09:08 -06008381 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008382
8383 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008384 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008385 return;
8386 }
8387
Karl Schultz6addd812016-02-02 17:17:23 -07008388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8389
8390 VkDescriptorPoolSize ds_type_count = {};
8391 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8392 ds_type_count.descriptorCount = 1;
8393
8394 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8395 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8396 ds_pool_ci.maxSets = 1;
8397 ds_pool_ci.poolSizeCount = 1;
8398 ds_pool_ci.pPoolSizes = &ds_type_count;
8399
8400 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008401 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008402 ASSERT_VK_SUCCESS(err);
8403
8404 VkDescriptorSetLayoutBinding dsl_binding = {};
8405 dsl_binding.binding = 0;
8406 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8407 dsl_binding.descriptorCount = 1;
8408 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8409
8410 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8411 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8412 ds_layout_ci.bindingCount = 1;
8413 ds_layout_ci.pBindings = &dsl_binding;
8414
8415 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008416 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008417 ASSERT_VK_SUCCESS(err);
8418
8419 VkDescriptorSet descriptorSet;
8420 VkDescriptorSetAllocateInfo alloc_info = {};
8421 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8422 alloc_info.descriptorSetCount = 1;
8423 alloc_info.descriptorPool = ds_pool;
8424 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008425 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008426 ASSERT_VK_SUCCESS(err);
8427
8428 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8429 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8430 pipeline_layout_ci.setLayoutCount = 1;
8431 pipeline_layout_ci.pSetLayouts = &ds_layout;
8432
8433 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008435 ASSERT_VK_SUCCESS(err);
8436
8437 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8438 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8439 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008440 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008441 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008442 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008443
8444 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8445 // Set scissor as dynamic to avoid that error
8446 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8447 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8448 dyn_state_ci.dynamicStateCount = 1;
8449 dyn_state_ci.pDynamicStates = &vp_state;
8450
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008451 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8452 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8453 pipe_ms_state_ci.pNext = NULL;
8454 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8455 pipe_ms_state_ci.sampleShadingEnable = 0;
8456 pipe_ms_state_ci.minSampleShading = 1.0;
8457 pipe_ms_state_ci.pSampleMask = NULL;
8458
Karl Schultz6addd812016-02-02 17:17:23 -07008459 VkPipelineShaderStageCreateInfo shaderStages[2];
8460 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8461
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008462 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008463 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8464 // 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 -07008465 shaderStages[0] = vs.GetStageCreateInfo();
8466 shaderStages[1] = fs.GetStageCreateInfo();
8467
8468 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8469 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8470 vi_ci.pNext = nullptr;
8471 vi_ci.vertexBindingDescriptionCount = 0;
8472 vi_ci.pVertexBindingDescriptions = nullptr;
8473 vi_ci.vertexAttributeDescriptionCount = 0;
8474 vi_ci.pVertexAttributeDescriptions = nullptr;
8475
8476 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8477 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8478 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8479
8480 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8481 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008482 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008483 rs_ci.pNext = nullptr;
8484
Mark Youngc89c6312016-03-31 16:03:20 -06008485 VkPipelineColorBlendAttachmentState att = {};
8486 att.blendEnable = VK_FALSE;
8487 att.colorWriteMask = 0xf;
8488
Karl Schultz6addd812016-02-02 17:17:23 -07008489 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8490 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8491 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008492 cb_ci.attachmentCount = 1;
8493 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008494
8495 VkGraphicsPipelineCreateInfo gp_ci = {};
8496 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8497 gp_ci.stageCount = 2;
8498 gp_ci.pStages = shaderStages;
8499 gp_ci.pVertexInputState = &vi_ci;
8500 gp_ci.pInputAssemblyState = &ia_ci;
8501 gp_ci.pViewportState = &vp_state_ci;
8502 gp_ci.pRasterizationState = &rs_ci;
8503 gp_ci.pColorBlendState = &cb_ci;
8504 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008505 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008506 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8507 gp_ci.layout = pipeline_layout;
8508 gp_ci.renderPass = renderPass();
8509
8510 VkPipelineCacheCreateInfo pc_ci = {};
8511 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8512
8513 VkPipeline pipeline;
8514 VkPipelineCache pipelineCache;
8515
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008516 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008517 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008518 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008519
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008520 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008521
8522 // Now hit second fail case where we set scissor w/ different count than PSO
8523 // First need to successfully create the PSO from above by setting
8524 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8526 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008527
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008528 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008529 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008530 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008531 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008532 m_commandBuffer->BeginCommandBuffer();
8533 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008534 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008535 VkViewport viewports[1] = {};
8536 viewports[0].width = 8;
8537 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008538 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008539 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008540 Draw(1, 0, 0, 0);
8541
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008542 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008543
Chia-I Wuf7458c52015-10-26 21:10:41 +08008544 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8545 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8546 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8547 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008548 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008549}
8550
Mark Young7394fdd2016-03-31 14:56:43 -06008551TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8552 VkResult err;
8553
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008555
Tony Barbour1fa09702017-03-16 12:09:08 -06008556 ASSERT_NO_FATAL_FAILURE(Init());
Mark Young7394fdd2016-03-31 14:56:43 -06008557 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8558
8559 VkDescriptorPoolSize ds_type_count = {};
8560 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8561 ds_type_count.descriptorCount = 1;
8562
8563 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8564 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8565 ds_pool_ci.maxSets = 1;
8566 ds_pool_ci.poolSizeCount = 1;
8567 ds_pool_ci.pPoolSizes = &ds_type_count;
8568
8569 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008570 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008571 ASSERT_VK_SUCCESS(err);
8572
8573 VkDescriptorSetLayoutBinding dsl_binding = {};
8574 dsl_binding.binding = 0;
8575 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8576 dsl_binding.descriptorCount = 1;
8577 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8578
8579 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8580 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8581 ds_layout_ci.bindingCount = 1;
8582 ds_layout_ci.pBindings = &dsl_binding;
8583
8584 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008585 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008586 ASSERT_VK_SUCCESS(err);
8587
8588 VkDescriptorSet descriptorSet;
8589 VkDescriptorSetAllocateInfo alloc_info = {};
8590 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8591 alloc_info.descriptorSetCount = 1;
8592 alloc_info.descriptorPool = ds_pool;
8593 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008594 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008595 ASSERT_VK_SUCCESS(err);
8596
8597 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8598 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8599 pipeline_layout_ci.setLayoutCount = 1;
8600 pipeline_layout_ci.pSetLayouts = &ds_layout;
8601
8602 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008603 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008604 ASSERT_VK_SUCCESS(err);
8605
8606 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8607 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8608 vp_state_ci.scissorCount = 1;
8609 vp_state_ci.pScissors = NULL;
8610 vp_state_ci.viewportCount = 1;
8611 vp_state_ci.pViewports = NULL;
8612
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008613 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008614 // Set scissor as dynamic to avoid that error
8615 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8616 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8617 dyn_state_ci.dynamicStateCount = 2;
8618 dyn_state_ci.pDynamicStates = dynamic_states;
8619
8620 VkPipelineShaderStageCreateInfo shaderStages[2];
8621 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8622
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008623 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8624 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008625 this); // TODO - We shouldn't need a fragment shader
8626 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008627 shaderStages[0] = vs.GetStageCreateInfo();
8628 shaderStages[1] = fs.GetStageCreateInfo();
8629
8630 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8631 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8632 vi_ci.pNext = nullptr;
8633 vi_ci.vertexBindingDescriptionCount = 0;
8634 vi_ci.pVertexBindingDescriptions = nullptr;
8635 vi_ci.vertexAttributeDescriptionCount = 0;
8636 vi_ci.pVertexAttributeDescriptions = nullptr;
8637
8638 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8639 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8640 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8641
8642 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8643 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8644 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008645 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008646
Mark Young47107952016-05-02 15:59:55 -06008647 // Check too low (line width of -1.0f).
8648 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008649
8650 VkPipelineColorBlendAttachmentState att = {};
8651 att.blendEnable = VK_FALSE;
8652 att.colorWriteMask = 0xf;
8653
8654 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8655 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8656 cb_ci.pNext = nullptr;
8657 cb_ci.attachmentCount = 1;
8658 cb_ci.pAttachments = &att;
8659
8660 VkGraphicsPipelineCreateInfo gp_ci = {};
8661 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8662 gp_ci.stageCount = 2;
8663 gp_ci.pStages = shaderStages;
8664 gp_ci.pVertexInputState = &vi_ci;
8665 gp_ci.pInputAssemblyState = &ia_ci;
8666 gp_ci.pViewportState = &vp_state_ci;
8667 gp_ci.pRasterizationState = &rs_ci;
8668 gp_ci.pColorBlendState = &cb_ci;
8669 gp_ci.pDynamicState = &dyn_state_ci;
8670 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8671 gp_ci.layout = pipeline_layout;
8672 gp_ci.renderPass = renderPass();
8673
8674 VkPipelineCacheCreateInfo pc_ci = {};
8675 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8676
8677 VkPipeline pipeline;
8678 VkPipelineCache pipelineCache;
8679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008680 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008681 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008682 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008683
8684 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008685 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008686
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008688
8689 // Check too high (line width of 65536.0f).
8690 rs_ci.lineWidth = 65536.0f;
8691
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008692 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008693 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008694 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008695
8696 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008697 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008698
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008700
8701 dyn_state_ci.dynamicStateCount = 3;
8702
8703 rs_ci.lineWidth = 1.0f;
8704
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008705 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008706 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008707 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008708 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008709 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008710
8711 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008712 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008713 m_errorMonitor->VerifyFound();
8714
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008716
8717 // Check too high with dynamic setting.
8718 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8719 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008720 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008721
8722 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8723 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8724 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8725 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008726 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008727}
8728
Jeremy Hayes37f0cdd2017-05-04 18:08:49 -06008729TEST_F(VkLayerTest, VALIDATION_ERROR_01407) {
8730 TEST_DESCRIPTION("Test VALIDATION_ERROR_01407: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
8731
8732 ASSERT_NO_FATAL_FAILURE(Init());
8733 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8734
8735 VkPipelineCache pipeline_cache;
8736 {
8737 VkPipelineCacheCreateInfo create_info{};
8738 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8739
8740 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8741 ASSERT_VK_SUCCESS(err);
8742 }
8743
8744 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8745 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8746
8747 VkPipelineShaderStageCreateInfo stages[2]{{}};
8748 stages[0] = vs.GetStageCreateInfo();
8749 stages[1] = fs.GetStageCreateInfo();
8750
8751 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
8752 VkVertexInputBindingDescription vertex_input_binding_description{};
8753 vertex_input_binding_description.binding = m_device->props.limits.maxVertexInputBindings;
8754
8755 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8756 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8757 vertex_input_state.pNext = nullptr;
8758 vertex_input_state.vertexBindingDescriptionCount = 1;
8759 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8760 vertex_input_state.vertexAttributeDescriptionCount = 0;
8761 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8762
8763 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8764 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8765 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8766
8767 VkViewport viewport{};
8768 VkPipelineViewportStateCreateInfo viewport_state{};
8769 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8770 viewport_state.scissorCount = 1;
8771 viewport_state.viewportCount = 1;
8772 viewport_state.pViewports = &viewport;
8773
8774 VkPipelineMultisampleStateCreateInfo multisample_state{};
8775 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8776 multisample_state.pNext = nullptr;
8777 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8778 multisample_state.sampleShadingEnable = 0;
8779 multisample_state.minSampleShading = 1.0;
8780 multisample_state.pSampleMask = nullptr;
8781
8782 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8783 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8784 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8785 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8786 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8787 rasterization_state.depthClampEnable = VK_FALSE;
8788 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8789 rasterization_state.depthBiasEnable = VK_FALSE;
8790
8791 VkPipelineLayout pipeline_layout;
8792 {
8793 VkPipelineLayoutCreateInfo create_info{};
8794 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8795 create_info.setLayoutCount = 0;
8796 create_info.pSetLayouts = nullptr;
8797
8798 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8799 ASSERT_VK_SUCCESS(err);
8800 }
8801
8802 {
8803 VkGraphicsPipelineCreateInfo create_info{};
8804 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8805 create_info.stageCount = 2;
8806 create_info.pStages = stages;
8807 create_info.pVertexInputState = &vertex_input_state;
8808 create_info.pInputAssemblyState = &input_assembly_state;
8809 create_info.pViewportState = &viewport_state;
8810 create_info.pMultisampleState = &multisample_state;
8811 create_info.pRasterizationState = &rasterization_state;
8812 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8813 create_info.layout = pipeline_layout;
8814 create_info.renderPass = renderPass();
8815
8816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01407);
8817 VkPipeline pipeline;
8818 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8819 m_errorMonitor->VerifyFound();
8820 }
8821
8822 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8823 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8824}
8825
8826TEST_F(VkLayerTest, VALIDATION_ERROR_01408) {
8827 TEST_DESCRIPTION(
8828 "Test VALIDATION_ERROR_01408: stride must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputBindingStride");
8829
8830 ASSERT_NO_FATAL_FAILURE(Init());
8831 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8832
8833 VkPipelineCache pipeline_cache;
8834 {
8835 VkPipelineCacheCreateInfo create_info{};
8836 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8837
8838 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8839 ASSERT_VK_SUCCESS(err);
8840 }
8841
8842 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8843 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8844
8845 VkPipelineShaderStageCreateInfo stages[2]{{}};
8846 stages[0] = vs.GetStageCreateInfo();
8847 stages[1] = fs.GetStageCreateInfo();
8848
8849 // Test when stride is greater than VkPhysicalDeviceLimits::maxVertexInputBindingStride.
8850 VkVertexInputBindingDescription vertex_input_binding_description{};
8851 vertex_input_binding_description.stride = m_device->props.limits.maxVertexInputBindingStride + 1;
8852
8853 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8854 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8855 vertex_input_state.pNext = nullptr;
8856 vertex_input_state.vertexBindingDescriptionCount = 1;
8857 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8858 vertex_input_state.vertexAttributeDescriptionCount = 0;
8859 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8860
8861 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8862 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8863 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8864
8865 VkViewport viewport{};
8866 VkPipelineViewportStateCreateInfo viewport_state{};
8867 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8868 viewport_state.scissorCount = 1;
8869 viewport_state.viewportCount = 1;
8870 viewport_state.pViewports = &viewport;
8871
8872 VkPipelineMultisampleStateCreateInfo multisample_state{};
8873 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8874 multisample_state.pNext = nullptr;
8875 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8876 multisample_state.sampleShadingEnable = 0;
8877 multisample_state.minSampleShading = 1.0;
8878 multisample_state.pSampleMask = nullptr;
8879
8880 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8881 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8882 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8883 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8884 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8885 rasterization_state.depthClampEnable = VK_FALSE;
8886 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8887 rasterization_state.depthBiasEnable = VK_FALSE;
8888
8889 VkPipelineLayout pipeline_layout;
8890 {
8891 VkPipelineLayoutCreateInfo create_info{};
8892 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8893 create_info.setLayoutCount = 0;
8894 create_info.pSetLayouts = nullptr;
8895
8896 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8897 ASSERT_VK_SUCCESS(err);
8898 }
8899
8900 {
8901 VkGraphicsPipelineCreateInfo create_info{};
8902 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8903 create_info.stageCount = 2;
8904 create_info.pStages = stages;
8905 create_info.pVertexInputState = &vertex_input_state;
8906 create_info.pInputAssemblyState = &input_assembly_state;
8907 create_info.pViewportState = &viewport_state;
8908 create_info.pMultisampleState = &multisample_state;
8909 create_info.pRasterizationState = &rasterization_state;
8910 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8911 create_info.layout = pipeline_layout;
8912 create_info.renderPass = renderPass();
8913
8914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01408);
8915 VkPipeline pipeline;
8916 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8917 m_errorMonitor->VerifyFound();
8918 }
8919
8920 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8921 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8922}
8923
Jeremy Hayes091e1ab2017-05-04 18:10:28 -06008924TEST_F(VkLayerTest, VALIDATION_ERROR_01410) {
8925 TEST_DESCRIPTION("Test VALIDATION_ERROR_01410: location must be less than VkPhysicalDeviceLimits::maxVertexInputAttributes");
8926
8927 ASSERT_NO_FATAL_FAILURE(Init());
8928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8929
8930 VkPipelineCache pipeline_cache;
8931 {
8932 VkPipelineCacheCreateInfo create_info{};
8933 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8934
8935 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8936 ASSERT_VK_SUCCESS(err);
8937 }
8938
8939 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8940 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8941
8942 VkPipelineShaderStageCreateInfo stages[2]{{}};
8943 stages[0] = vs.GetStageCreateInfo();
8944 stages[1] = fs.GetStageCreateInfo();
8945
8946 // Test when location is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes.
8947 VkVertexInputAttributeDescription vertex_input_attribute_description{};
8948 vertex_input_attribute_description.location = m_device->props.limits.maxVertexInputAttributes;
8949
8950 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8951 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8952 vertex_input_state.pNext = nullptr;
8953 vertex_input_state.vertexBindingDescriptionCount = 0;
8954 vertex_input_state.pVertexBindingDescriptions = nullptr;
8955 vertex_input_state.vertexAttributeDescriptionCount = 1;
8956 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
8957
8958 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8959 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8960 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8961
8962 VkViewport viewport{};
8963 VkPipelineViewportStateCreateInfo viewport_state{};
8964 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8965 viewport_state.scissorCount = 1;
8966 viewport_state.viewportCount = 1;
8967 viewport_state.pViewports = &viewport;
8968
8969 VkPipelineMultisampleStateCreateInfo multisample_state{};
8970 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8971 multisample_state.pNext = nullptr;
8972 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8973 multisample_state.sampleShadingEnable = 0;
8974 multisample_state.minSampleShading = 1.0;
8975 multisample_state.pSampleMask = nullptr;
8976
8977 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8978 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8979 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8980 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8981 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8982 rasterization_state.depthClampEnable = VK_FALSE;
8983 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8984 rasterization_state.depthBiasEnable = VK_FALSE;
8985
8986 VkPipelineLayout pipeline_layout;
8987 {
8988 VkPipelineLayoutCreateInfo create_info{};
8989 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8990 create_info.setLayoutCount = 0;
8991 create_info.pSetLayouts = nullptr;
8992
8993 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8994 ASSERT_VK_SUCCESS(err);
8995 }
8996
8997 {
8998 VkGraphicsPipelineCreateInfo create_info{};
8999 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9000 create_info.stageCount = 2;
9001 create_info.pStages = stages;
9002 create_info.pVertexInputState = &vertex_input_state;
9003 create_info.pInputAssemblyState = &input_assembly_state;
9004 create_info.pViewportState = &viewport_state;
9005 create_info.pMultisampleState = &multisample_state;
9006 create_info.pRasterizationState = &rasterization_state;
9007 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9008 create_info.layout = pipeline_layout;
9009 create_info.renderPass = renderPass();
9010
9011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01410);
9012 VkPipeline pipeline;
9013 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9014 m_errorMonitor->VerifyFound();
9015 }
9016
9017 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9018 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9019}
9020
9021TEST_F(VkLayerTest, VALIDATION_ERROR_01411) {
9022 TEST_DESCRIPTION("Test VALIDATION_ERROR_01411: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
9023
9024 ASSERT_NO_FATAL_FAILURE(Init());
9025 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9026
9027 VkPipelineCache pipeline_cache;
9028 {
9029 VkPipelineCacheCreateInfo create_info{};
9030 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9031
9032 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9033 ASSERT_VK_SUCCESS(err);
9034 }
9035
9036 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9037 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9038
9039 VkPipelineShaderStageCreateInfo stages[2]{{}};
9040 stages[0] = vs.GetStageCreateInfo();
9041 stages[1] = fs.GetStageCreateInfo();
9042
9043 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
9044 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9045 vertex_input_attribute_description.binding = m_device->props.limits.maxVertexInputBindings;
9046
9047 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9048 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9049 vertex_input_state.pNext = nullptr;
9050 vertex_input_state.vertexBindingDescriptionCount = 0;
9051 vertex_input_state.pVertexBindingDescriptions = nullptr;
9052 vertex_input_state.vertexAttributeDescriptionCount = 1;
9053 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9054
9055 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9056 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9057 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9058
9059 VkViewport viewport{};
9060 VkPipelineViewportStateCreateInfo viewport_state{};
9061 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9062 viewport_state.scissorCount = 1;
9063 viewport_state.viewportCount = 1;
9064 viewport_state.pViewports = &viewport;
9065
9066 VkPipelineMultisampleStateCreateInfo multisample_state{};
9067 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9068 multisample_state.pNext = nullptr;
9069 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9070 multisample_state.sampleShadingEnable = 0;
9071 multisample_state.minSampleShading = 1.0;
9072 multisample_state.pSampleMask = nullptr;
9073
9074 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9075 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9076 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9077 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9078 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9079 rasterization_state.depthClampEnable = VK_FALSE;
9080 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9081 rasterization_state.depthBiasEnable = VK_FALSE;
9082
9083 VkPipelineLayout pipeline_layout;
9084 {
9085 VkPipelineLayoutCreateInfo create_info{};
9086 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9087 create_info.setLayoutCount = 0;
9088 create_info.pSetLayouts = nullptr;
9089
9090 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9091 ASSERT_VK_SUCCESS(err);
9092 }
9093
9094 {
9095 VkGraphicsPipelineCreateInfo create_info{};
9096 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9097 create_info.stageCount = 2;
9098 create_info.pStages = stages;
9099 create_info.pVertexInputState = &vertex_input_state;
9100 create_info.pInputAssemblyState = &input_assembly_state;
9101 create_info.pViewportState = &viewport_state;
9102 create_info.pMultisampleState = &multisample_state;
9103 create_info.pRasterizationState = &rasterization_state;
9104 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9105 create_info.layout = pipeline_layout;
9106 create_info.renderPass = renderPass();
9107
9108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01411);
9109 VkPipeline pipeline;
9110 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9111 m_errorMonitor->VerifyFound();
9112 }
9113
9114 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9115 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9116}
9117
9118TEST_F(VkLayerTest, VALIDATION_ERROR_01412) {
9119 TEST_DESCRIPTION(
9120 "Test VALIDATION_ERROR_01412: offset must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributeOffset");
9121
9122 ASSERT_NO_FATAL_FAILURE(Init());
9123 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9124
9125 VkPipelineCache pipeline_cache;
9126 {
9127 VkPipelineCacheCreateInfo create_info{};
9128 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9129
9130 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9131 ASSERT_VK_SUCCESS(err);
9132 }
9133
9134 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9135 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9136
9137 VkPipelineShaderStageCreateInfo stages[2]{{}};
9138 stages[0] = vs.GetStageCreateInfo();
9139 stages[1] = fs.GetStageCreateInfo();
9140
9141 // Test when offset is greater than maximum.
9142 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9143 vertex_input_attribute_description.offset = m_device->props.limits.maxVertexInputAttributeOffset + 1;
9144
9145 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9146 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9147 vertex_input_state.pNext = nullptr;
9148 vertex_input_state.vertexBindingDescriptionCount = 0;
9149 vertex_input_state.pVertexBindingDescriptions = nullptr;
9150 vertex_input_state.vertexAttributeDescriptionCount = 1;
9151 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9152
9153 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9154 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9155 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9156
9157 VkViewport viewport{};
9158 VkPipelineViewportStateCreateInfo viewport_state{};
9159 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9160 viewport_state.scissorCount = 1;
9161 viewport_state.viewportCount = 1;
9162 viewport_state.pViewports = &viewport;
9163
9164 VkPipelineMultisampleStateCreateInfo multisample_state{};
9165 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9166 multisample_state.pNext = nullptr;
9167 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9168 multisample_state.sampleShadingEnable = 0;
9169 multisample_state.minSampleShading = 1.0;
9170 multisample_state.pSampleMask = nullptr;
9171
9172 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9173 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9174 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9175 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9176 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9177 rasterization_state.depthClampEnable = VK_FALSE;
9178 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9179 rasterization_state.depthBiasEnable = VK_FALSE;
9180
9181 VkPipelineLayout pipeline_layout;
9182 {
9183 VkPipelineLayoutCreateInfo create_info{};
9184 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9185 create_info.setLayoutCount = 0;
9186 create_info.pSetLayouts = nullptr;
9187
9188 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9189 ASSERT_VK_SUCCESS(err);
9190 }
9191
9192 {
9193 VkGraphicsPipelineCreateInfo create_info{};
9194 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9195 create_info.stageCount = 2;
9196 create_info.pStages = stages;
9197 create_info.pVertexInputState = &vertex_input_state;
9198 create_info.pInputAssemblyState = &input_assembly_state;
9199 create_info.pViewportState = &viewport_state;
9200 create_info.pMultisampleState = &multisample_state;
9201 create_info.pRasterizationState = &rasterization_state;
9202 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9203 create_info.layout = pipeline_layout;
9204 create_info.renderPass = renderPass();
9205
9206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01412);
9207 VkPipeline pipeline;
9208 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9209 m_errorMonitor->VerifyFound();
9210 }
9211
9212 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9213 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9214}
9215
Karl Schultz6addd812016-02-02 17:17:23 -07009216TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009217 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07009219 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009220
Tony Barbour1fa09702017-03-16 12:09:08 -06009221 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009223
Tony Barbour552f6c02016-12-21 14:34:07 -07009224 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009225 // Don't care about RenderPass handle b/c error should be flagged before
9226 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009227 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009228
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009229 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009230}
9231
Karl Schultz6addd812016-02-02 17:17:23 -07009232TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009233 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9235 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009236
Tony Barbour1fa09702017-03-16 12:09:08 -06009237 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009239
Tony Barbour552f6c02016-12-21 14:34:07 -07009240 m_commandBuffer->BeginCommandBuffer();
9241 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07009242 // Just create a dummy Renderpass that's non-NULL so we can get to the
9243 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009244 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009245
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009246 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009247}
9248
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009249TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009250 TEST_DESCRIPTION(
9251 "Begin a renderPass where clearValueCount is less than"
9252 "the number of renderPass attachments that use loadOp"
9253 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009254
Tony Barbour1fa09702017-03-16 12:09:08 -06009255 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9257
9258 // Create a renderPass with a single attachment that uses loadOp CLEAR
9259 VkAttachmentReference attach = {};
9260 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9261 VkSubpassDescription subpass = {};
9262 subpass.inputAttachmentCount = 1;
9263 subpass.pInputAttachments = &attach;
9264 VkRenderPassCreateInfo rpci = {};
9265 rpci.subpassCount = 1;
9266 rpci.pSubpasses = &subpass;
9267 rpci.attachmentCount = 1;
9268 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07009269 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009270 // Set loadOp to CLEAR
9271 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9272 rpci.pAttachments = &attach_desc;
9273 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9274 VkRenderPass rp;
9275 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9276
9277 VkCommandBufferInheritanceInfo hinfo = {};
9278 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9279 hinfo.renderPass = VK_NULL_HANDLE;
9280 hinfo.subpass = 0;
9281 hinfo.framebuffer = VK_NULL_HANDLE;
9282 hinfo.occlusionQueryEnable = VK_FALSE;
9283 hinfo.queryFlags = 0;
9284 hinfo.pipelineStatistics = 0;
9285 VkCommandBufferBeginInfo info = {};
9286 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9287 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9288 info.pInheritanceInfo = &hinfo;
9289
9290 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9291 VkRenderPassBeginInfo rp_begin = {};
9292 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9293 rp_begin.pNext = NULL;
9294 rp_begin.renderPass = renderPass();
9295 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009296 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009297
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009299
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009300 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009301
9302 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009303
9304 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009305}
9306
Slawomir Cygan0808f392016-11-28 17:53:23 +01009307TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009308 TEST_DESCRIPTION(
9309 "Begin a renderPass where clearValueCount is greater than"
9310 "the number of renderPass attachments that use loadOp"
9311 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01009312
Tony Barbour1fa09702017-03-16 12:09:08 -06009313 ASSERT_NO_FATAL_FAILURE(Init());
Slawomir Cygan0808f392016-11-28 17:53:23 +01009314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9315
9316 // Create a renderPass with a single attachment that uses loadOp CLEAR
9317 VkAttachmentReference attach = {};
9318 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9319 VkSubpassDescription subpass = {};
9320 subpass.inputAttachmentCount = 1;
9321 subpass.pInputAttachments = &attach;
9322 VkRenderPassCreateInfo rpci = {};
9323 rpci.subpassCount = 1;
9324 rpci.pSubpasses = &subpass;
9325 rpci.attachmentCount = 1;
9326 VkAttachmentDescription attach_desc = {};
9327 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
9328 // Set loadOp to CLEAR
9329 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9330 rpci.pAttachments = &attach_desc;
9331 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9332 VkRenderPass rp;
9333 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9334
9335 VkCommandBufferBeginInfo info = {};
9336 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9337 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9338
9339 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9340 VkRenderPassBeginInfo rp_begin = {};
9341 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9342 rp_begin.pNext = NULL;
9343 rp_begin.renderPass = renderPass();
9344 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009345 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01009346
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
9348 " has a clearValueCount of"
9349 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01009350
9351 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
9352
9353 m_errorMonitor->VerifyFound();
9354
9355 vkDestroyRenderPass(m_device->device(), rp, NULL);
9356}
9357
Cody Northrop3bb4d962016-05-09 16:15:57 -06009358TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06009359 TEST_DESCRIPTION("End a command buffer with an active render pass");
9360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9362 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009363
Tony Barbour1fa09702017-03-16 12:09:08 -06009364 ASSERT_NO_FATAL_FAILURE(Init());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009365 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9366
Tony Barbour552f6c02016-12-21 14:34:07 -07009367 m_commandBuffer->BeginCommandBuffer();
9368 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
9369 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009370
9371 m_errorMonitor->VerifyFound();
9372
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009373 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9374 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009375}
9376
Karl Schultz6addd812016-02-02 17:17:23 -07009377TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009378 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9380 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009381
Tony Barbour1fa09702017-03-16 12:09:08 -06009382 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009383 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009384
Tony Barbour552f6c02016-12-21 14:34:07 -07009385 m_commandBuffer->BeginCommandBuffer();
9386 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009387
9388 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009389 vk_testing::Buffer dstBuffer;
9390 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009391
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009392 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009393
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009394 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009395}
9396
Karl Schultz6addd812016-02-02 17:17:23 -07009397TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009398 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9400 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009401
Tony Barbour1fa09702017-03-16 12:09:08 -06009402 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009404
Tony Barbour552f6c02016-12-21 14:34:07 -07009405 m_commandBuffer->BeginCommandBuffer();
9406 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009407
9408 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009409 vk_testing::Buffer dstBuffer;
9410 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009411
Karl Schultz6addd812016-02-02 17:17:23 -07009412 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07009413 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
9414 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
9415 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009416
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009417 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009418}
9419
Karl Schultz6addd812016-02-02 17:17:23 -07009420TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009421 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9423 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009424
Tony Barbour1fa09702017-03-16 12:09:08 -06009425 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009426 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009427
Tony Barbour552f6c02016-12-21 14:34:07 -07009428 m_commandBuffer->BeginCommandBuffer();
9429 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009430
Michael Lentine0a369f62016-02-03 16:51:46 -06009431 VkClearColorValue clear_color;
9432 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009433 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9434 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9435 const int32_t tex_width = 32;
9436 const int32_t tex_height = 32;
9437 VkImageCreateInfo image_create_info = {};
9438 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9439 image_create_info.pNext = NULL;
9440 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9441 image_create_info.format = tex_format;
9442 image_create_info.extent.width = tex_width;
9443 image_create_info.extent.height = tex_height;
9444 image_create_info.extent.depth = 1;
9445 image_create_info.mipLevels = 1;
9446 image_create_info.arrayLayers = 1;
9447 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9448 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07009449 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009450
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009451 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009452 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009453
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009454 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009455
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009456 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009457
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009458 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009459}
9460
Karl Schultz6addd812016-02-02 17:17:23 -07009461TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009462 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9464 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009465
Tony Barbour1fa09702017-03-16 12:09:08 -06009466 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009467 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009468
Dave Houlton1d2022c2017-03-29 11:43:58 -06009469 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009470 if (!depth_format) {
9471 printf(" No Depth + Stencil format found. Skipped.\n");
9472 return;
9473 }
9474
Tony Barbour552f6c02016-12-21 14:34:07 -07009475 m_commandBuffer->BeginCommandBuffer();
9476 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009477
9478 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07009479 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009480 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
9481 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07009482 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07009483 image_create_info.extent.width = 64;
9484 image_create_info.extent.height = 64;
9485 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9486 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009487
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009488 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009489 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009490
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009491 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009492
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009493 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
9494 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009495
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009496 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009497}
9498
Karl Schultz6addd812016-02-02 17:17:23 -07009499TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009500 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009501 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009502
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9504 "vkCmdClearAttachments(): This call "
9505 "must be issued inside an active "
9506 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009507
Tony Barbour1fa09702017-03-16 12:09:08 -06009508 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009510
9511 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009512 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009513 ASSERT_VK_SUCCESS(err);
9514
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009515 VkClearAttachment color_attachment;
9516 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9517 color_attachment.clearValue.color.float32[0] = 0;
9518 color_attachment.clearValue.color.float32[1] = 0;
9519 color_attachment.clearValue.color.float32[2] = 0;
9520 color_attachment.clearValue.color.float32[3] = 0;
9521 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009522 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009523 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009524
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009525 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009526}
9527
Chris Forbes3b97e932016-09-07 11:29:24 +12009528TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009529 TEST_DESCRIPTION(
9530 "Test that an error is produced when CmdNextSubpass is "
9531 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12009532
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9534 "vkCmdNextSubpass(): Attempted to advance "
9535 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12009536
Tony Barbour1fa09702017-03-16 12:09:08 -06009537 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3b97e932016-09-07 11:29:24 +12009538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9539
Tony Barbour552f6c02016-12-21 14:34:07 -07009540 m_commandBuffer->BeginCommandBuffer();
9541 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12009542
9543 // error here.
9544 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
9545 m_errorMonitor->VerifyFound();
9546
Tony Barbour552f6c02016-12-21 14:34:07 -07009547 m_commandBuffer->EndRenderPass();
9548 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12009549}
9550
Chris Forbes6d624702016-09-07 13:57:05 +12009551TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009552 TEST_DESCRIPTION(
9553 "Test that an error is produced when CmdEndRenderPass is "
9554 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12009555
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9557 "vkCmdEndRenderPass(): Called before reaching "
9558 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12009559
Tony Barbour1fa09702017-03-16 12:09:08 -06009560 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009561 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
9562 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12009563
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009564 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12009565
9566 VkRenderPass rp;
9567 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
9568 ASSERT_VK_SUCCESS(err);
9569
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009570 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12009571
9572 VkFramebuffer fb;
9573 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
9574 ASSERT_VK_SUCCESS(err);
9575
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009576 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12009577
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009578 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 +12009579
9580 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9581
9582 // Error here.
9583 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9584 m_errorMonitor->VerifyFound();
9585
9586 // Clean up.
9587 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
9588 vkDestroyRenderPass(m_device->device(), rp, nullptr);
9589}
9590
Karl Schultz9e66a292016-04-21 15:57:51 -06009591TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
9592 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9594 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06009595
Tony Barbour1fa09702017-03-16 12:09:08 -06009596 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour552f6c02016-12-21 14:34:07 -07009597 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06009598
9599 VkBufferMemoryBarrier buf_barrier = {};
9600 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9601 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9602 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9603 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9604 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9605 buf_barrier.buffer = VK_NULL_HANDLE;
9606 buf_barrier.offset = 0;
9607 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009608 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9609 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06009610
9611 m_errorMonitor->VerifyFound();
9612}
9613
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009614TEST_F(VkLayerTest, InvalidBarriers) {
9615 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
9616
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009618
Tony Barbour1fa09702017-03-16 12:09:08 -06009619 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06009620 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009621 if (!depth_format) {
9622 printf(" No Depth + Stencil format found. Skipped.\n");
9623 return;
9624 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9626
9627 VkMemoryBarrier mem_barrier = {};
9628 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
9629 mem_barrier.pNext = NULL;
9630 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9631 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07009632 m_commandBuffer->BeginCommandBuffer();
9633 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009634 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009635 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009636 &mem_barrier, 0, nullptr, 0, nullptr);
9637 m_errorMonitor->VerifyFound();
9638
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009640 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009641 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 -06009642 ASSERT_TRUE(image.initialized());
9643 VkImageMemoryBarrier img_barrier = {};
9644 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9645 img_barrier.pNext = NULL;
9646 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9647 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9648 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9649 // New layout can't be UNDEFINED
9650 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
9651 img_barrier.image = image.handle();
9652 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9653 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9654 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9655 img_barrier.subresourceRange.baseArrayLayer = 0;
9656 img_barrier.subresourceRange.baseMipLevel = 0;
9657 img_barrier.subresourceRange.layerCount = 1;
9658 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009659 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9660 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009661 m_errorMonitor->VerifyFound();
9662 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9663
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9665 "Subresource must have the sum of the "
9666 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009667 // baseArrayLayer + layerCount must be <= image's arrayLayers
9668 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009669 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9670 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009671 m_errorMonitor->VerifyFound();
9672 img_barrier.subresourceRange.baseArrayLayer = 0;
9673
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009675 // baseMipLevel + levelCount must be <= image's mipLevels
9676 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009677 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9678 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009679 m_errorMonitor->VerifyFound();
9680 img_barrier.subresourceRange.baseMipLevel = 0;
9681
Mike Weiblen7053aa32017-01-25 15:21:10 -07009682 // levelCount must be non-zero.
9683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9684 img_barrier.subresourceRange.levelCount = 0;
9685 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9686 nullptr, 0, nullptr, 1, &img_barrier);
9687 m_errorMonitor->VerifyFound();
9688 img_barrier.subresourceRange.levelCount = 1;
9689
9690 // layerCount must be non-zero.
9691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
9692 img_barrier.subresourceRange.layerCount = 0;
9693 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9694 nullptr, 0, nullptr, 1, &img_barrier);
9695 m_errorMonitor->VerifyFound();
9696 img_barrier.subresourceRange.layerCount = 1;
9697
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009698 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 -06009699 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009700 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9701 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009702 VkBufferMemoryBarrier buf_barrier = {};
9703 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9704 buf_barrier.pNext = NULL;
9705 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9706 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9707 buf_barrier.buffer = buffer.handle();
9708 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9709 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9710 buf_barrier.offset = 0;
9711 buf_barrier.size = VK_WHOLE_SIZE;
9712 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009713 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9714 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009715 m_errorMonitor->VerifyFound();
9716 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9717
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009719 buf_barrier.offset = 257;
9720 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009721 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9722 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009723 m_errorMonitor->VerifyFound();
9724 buf_barrier.offset = 0;
9725
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009727 buf_barrier.size = 257;
9728 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009729 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9730 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009731 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009732
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009733 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
9735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009736 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009737 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009738 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009739 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9740 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009741 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009742
9743 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009744 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009745 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9746 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009747 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009748
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009749 // Having only one of depth or stencil set for DS image is an error
9750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
9751 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
9752 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9753 nullptr, 0, nullptr, 1, &img_barrier);
9754 m_errorMonitor->VerifyFound();
9755
9756 // Having anything other than DEPTH and STENCIL is an error
9757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Dave Houltonfbf52152017-01-06 12:55:29 -07009758 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9759 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9760 nullptr, 0, nullptr, 1, &img_barrier);
9761 m_errorMonitor->VerifyFound();
9762
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009763 // Now test depth-only
9764 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009765 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9766 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009767 VkDepthStencilObj d_image(m_device);
9768 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9769 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009770 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009771 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009772 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009773
9774 // DEPTH bit must be set
9775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9776 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009777 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009778 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9779 0, nullptr, 0, nullptr, 1, &img_barrier);
9780 m_errorMonitor->VerifyFound();
9781
9782 // No bits other than DEPTH may be set
9783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9784 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9785 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009786 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9787 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009788 m_errorMonitor->VerifyFound();
9789 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009790
9791 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009792 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9793 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009794 VkDepthStencilObj s_image(m_device);
9795 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9796 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009797 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009798 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009799 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009800 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9802 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009803 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009804 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9805 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009806 m_errorMonitor->VerifyFound();
9807 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009808
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009809 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009810 VkImageObj c_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009811 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 -06009812 ASSERT_TRUE(c_image.initialized());
9813 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9814 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9815 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009816
9817 // COLOR bit must be set
9818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9819 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009820 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009821 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9822 nullptr, 0, nullptr, 1, &img_barrier);
9823 m_errorMonitor->VerifyFound();
9824
9825 // No bits other than COLOR may be set
9826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9827 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9828 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009829 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9830 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009831 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009832
Mike Weiblene6e01172017-03-07 22:18:40 -07009833 // A barrier's new and old VkImageLayout must be compatible with an image's VkImageUsageFlags.
9834 {
9835 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009836 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 -07009837 ASSERT_TRUE(img_color.initialized());
9838
9839 VkImageObj img_ds(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009840 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 -07009841 ASSERT_TRUE(img_ds.initialized());
9842
9843 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009844 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 -07009845 ASSERT_TRUE(img_xfer_src.initialized());
9846
9847 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009848 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 -07009849 ASSERT_TRUE(img_xfer_dst.initialized());
9850
9851 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009852 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 -07009853 ASSERT_TRUE(img_sampled.initialized());
9854
9855 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009856 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 -07009857 ASSERT_TRUE(img_input.initialized());
9858
9859 const struct {
9860 VkImageObj &image_obj;
9861 VkImageLayout bad_layout;
9862 UNIQUE_VALIDATION_ERROR_CODE msg_code;
9863 } bad_buffer_layouts[] = {
9864 // clang-format off
9865 // images _without_ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
9866 {img_ds, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9867 {img_xfer_src, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9868 {img_xfer_dst, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9869 {img_sampled, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9870 {img_input, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9871 // images _without_ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
9872 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9873 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9874 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9875 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9876 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9877 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9878 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9879 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9880 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9881 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9882 // images _without_ VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
9883 {img_color, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9884 {img_ds, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9885 {img_xfer_src, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9886 {img_xfer_dst, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9887 // images _without_ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
9888 {img_color, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9889 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9890 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9891 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9892 {img_input, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9893 // images _without_ VK_IMAGE_USAGE_TRANSFER_DST_BIT
9894 {img_color, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9895 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9896 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9897 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9898 {img_input, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9899 // clang-format on
9900 };
9901 const uint32_t layout_count = sizeof(bad_buffer_layouts) / sizeof(bad_buffer_layouts[0]);
9902
9903 for (uint32_t i = 0; i < layout_count; ++i) {
9904 img_barrier.image = bad_buffer_layouts[i].image_obj.handle();
9905 const VkImageUsageFlags usage = bad_buffer_layouts[i].image_obj.usage();
9906 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
9907 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
9908 : VK_IMAGE_ASPECT_COLOR_BIT;
9909
9910 img_barrier.oldLayout = bad_buffer_layouts[i].bad_layout;
9911 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9913 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9914 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9915 m_errorMonitor->VerifyFound();
9916
9917 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9918 img_barrier.newLayout = bad_buffer_layouts[i].bad_layout;
9919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9920 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9921 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9922 m_errorMonitor->VerifyFound();
9923 }
9924
9925 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9926 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9927 }
9928
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009929 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9930
9931 // Create command pool with incompatible queueflags
9932 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mike Schuchardt06304c22017-03-01 17:09:09 -07009933 uint32_t queue_family_index = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_COMPUTE_BIT);
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009934 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009935 printf(" No non-compute queue found; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009936 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009937 }
9938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9939
9940 VkCommandPool command_pool;
9941 VkCommandPoolCreateInfo pool_create_info{};
9942 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9943 pool_create_info.queueFamilyIndex = queue_family_index;
9944 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9945 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9946
9947 // Allocate a command buffer
9948 VkCommandBuffer bad_command_buffer;
9949 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9950 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9951 command_buffer_allocate_info.commandPool = command_pool;
9952 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9953 command_buffer_allocate_info.commandBufferCount = 1;
9954 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9955
9956 VkCommandBufferBeginInfo cbbi = {};
9957 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9958 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9959 buf_barrier.offset = 0;
9960 buf_barrier.size = VK_WHOLE_SIZE;
9961 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9962 &buf_barrier, 0, nullptr);
9963 m_errorMonitor->VerifyFound();
9964
9965 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9966 vkEndCommandBuffer(bad_command_buffer);
9967 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009968 printf(" The non-compute queue does not support graphics; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009969 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009970 }
9971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9972 VkEvent event;
9973 VkEventCreateInfo event_create_info{};
9974 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9975 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9976 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9977 nullptr, 0, nullptr);
9978 m_errorMonitor->VerifyFound();
9979
9980 vkEndCommandBuffer(bad_command_buffer);
9981 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009982}
9983
Chris Forbes50223732017-05-01 09:43:35 -07009984TEST_F(VkPositiveLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9985 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ
9986 // in srcAccessMask.
Tony Barbour18ba25c2016-09-29 13:42:40 -06009987
Chris Forbes50223732017-05-01 09:43:35 -07009988 // The required behavior here was a bit unclear in earlier versions of the
9989 // spec, but there is no memory dependency required here, so this should
9990 // work without warnings.
9991
9992 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -06009993 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour18ba25c2016-09-29 13:42:40 -06009994 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009995 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 -07009996 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06009997 ASSERT_TRUE(image.initialized());
9998
9999 VkImageMemoryBarrier barrier = {};
10000 VkImageSubresourceRange range;
10001 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tony Barbour18ba25c2016-09-29 13:42:40 -060010002 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
Chris Forbes50223732017-05-01 09:43:35 -070010003 barrier.dstAccessMask = 0;
Tony Barbour18ba25c2016-09-29 13:42:40 -060010004 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10005 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
10006 barrier.image = image.handle();
10007 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10008 range.baseMipLevel = 0;
10009 range.levelCount = 1;
10010 range.baseArrayLayer = 0;
10011 range.layerCount = 1;
10012 barrier.subresourceRange = range;
10013 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
10014 cmdbuf.BeginCommandBuffer();
10015 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10016 &barrier);
10017 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
10018 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10019 barrier.srcAccessMask = 0;
10020 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10021 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10022 &barrier);
10023
Chris Forbes50223732017-05-01 09:43:35 -070010024 m_errorMonitor->VerifyNotFound();
Tony Barbour18ba25c2016-09-29 13:42:40 -060010025}
10026
Karl Schultz6addd812016-02-02 17:17:23 -070010027TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010028 // Bind a BeginRenderPass within an active RenderPass
Tony Barbour1fa09702017-03-16 12:09:08 -060010029 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010031
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010032 uint32_t const indices[] = {0};
10033 VkBufferCreateInfo buf_info = {};
10034 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10035 buf_info.size = 1024;
10036 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10037 buf_info.queueFamilyIndexCount = 1;
10038 buf_info.pQueueFamilyIndices = indices;
10039
10040 VkBuffer buffer;
10041 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
10042 ASSERT_VK_SUCCESS(err);
10043
10044 VkMemoryRequirements requirements;
10045 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
10046
10047 VkMemoryAllocateInfo alloc_info{};
10048 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10049 alloc_info.pNext = NULL;
10050 alloc_info.memoryTypeIndex = 0;
10051 alloc_info.allocationSize = requirements.size;
10052 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
10053 ASSERT_TRUE(pass);
10054
10055 VkDeviceMemory memory;
10056 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
10057 ASSERT_VK_SUCCESS(err);
10058
10059 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010060 ASSERT_VK_SUCCESS(err);
10061
Tony Barbour552f6c02016-12-21 14:34:07 -070010062 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010063 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010064
Karl Schultz6addd812016-02-02 17:17:23 -070010065 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10066 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010067 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
10069 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010070 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010071
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010072 vkFreeMemory(m_device->device(), memory, NULL);
10073 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010074}
10075
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010076TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10077 // Create an out-of-range queueFamilyIndex
Tony Barbour1fa09702017-03-16 12:09:08 -060010078 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010079 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10080 VkBufferCreateInfo buffCI = {};
10081 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10082 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010083 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010084 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010085 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010086 uint32_t qfi[2];
10087 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010088 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010089
10090 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010091 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010092
10093 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10095 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one of the indices "
10096 "specified when the device was created, via the VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010097 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010098 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010099
10100 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -070010101 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
10103
10104 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
10105 buffCI.queueFamilyIndexCount = 2;
10106 qfi[0] = 1;
10107 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -070010108 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010109 VkDeviceMemory mem;
10110 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -070010111 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010112
10113 VkMemoryAllocateInfo alloc_info = {};
10114 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10115 alloc_info.allocationSize = 1024;
10116 bool pass = false;
10117 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
10118 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -070010119 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010120 return;
10121 }
10122 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -070010123 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010124
10125 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -070010126 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010127 m_commandBuffer->end();
10128 QueueCommandBuffer(false);
10129 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -070010130 vkDestroyBuffer(m_device->device(), ib2, NULL);
10131 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010132 }
10133
Tony Barbourdf4c0042016-06-01 15:55:43 -060010134 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010135}
10136
Karl Schultz6addd812016-02-02 17:17:23 -070010137TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010138 TEST_DESCRIPTION(
10139 "Attempt vkCmdExecuteCommands with a primary command buffer"
10140 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010141
Tony Barbour1fa09702017-03-16 12:09:08 -060010142 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010144
Chris Forbesf29a84f2016-10-06 18:39:28 +130010145 // An empty primary command buffer
10146 VkCommandBufferObj cb(m_device, m_commandPool);
10147 cb.BeginCommandBuffer();
10148 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010149
Chris Forbesf29a84f2016-10-06 18:39:28 +130010150 m_commandBuffer->BeginCommandBuffer();
10151 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10152 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010153
Chris Forbesf29a84f2016-10-06 18:39:28 +130010154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
10155 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010156 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010157
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060010158 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be in the pending state");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010159}
10160
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010161TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010162 TEST_DESCRIPTION(
10163 "Attempt to update descriptor sets for images and buffers "
10164 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010165 VkResult err;
10166
Tony Barbour1fa09702017-03-16 12:09:08 -060010167 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010168 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10169 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10170 ds_type_count[i].type = VkDescriptorType(i);
10171 ds_type_count[i].descriptorCount = 1;
10172 }
10173 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10174 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10175 ds_pool_ci.pNext = NULL;
10176 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10177 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10178 ds_pool_ci.pPoolSizes = ds_type_count;
10179
10180 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010181 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010182 ASSERT_VK_SUCCESS(err);
10183
10184 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010185 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010186 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10187 dsl_binding[i].binding = 0;
10188 dsl_binding[i].descriptorType = VkDescriptorType(i);
10189 dsl_binding[i].descriptorCount = 1;
10190 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10191 dsl_binding[i].pImmutableSamplers = NULL;
10192 }
10193
10194 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10195 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10196 ds_layout_ci.pNext = NULL;
10197 ds_layout_ci.bindingCount = 1;
10198 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10199 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10200 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010201 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010202 ASSERT_VK_SUCCESS(err);
10203 }
10204 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10205 VkDescriptorSetAllocateInfo alloc_info = {};
10206 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10207 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10208 alloc_info.descriptorPool = ds_pool;
10209 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010210 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010211 ASSERT_VK_SUCCESS(err);
10212
10213 // Create a buffer & bufferView to be used for invalid updates
10214 VkBufferCreateInfo buff_ci = {};
10215 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -070010216 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010217 buff_ci.size = 256;
10218 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -070010219 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010220 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10221 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -070010222
10223 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
10224 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10225 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
10226 ASSERT_VK_SUCCESS(err);
10227
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010228 VkMemoryRequirements mem_reqs;
10229 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
10230 VkMemoryAllocateInfo mem_alloc_info = {};
10231 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10232 mem_alloc_info.pNext = NULL;
10233 mem_alloc_info.memoryTypeIndex = 0;
10234 mem_alloc_info.allocationSize = mem_reqs.size;
10235 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10236 if (!pass) {
10237 vkDestroyBuffer(m_device->device(), buffer, NULL);
10238 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10239 return;
10240 }
10241 VkDeviceMemory mem;
10242 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
10243 ASSERT_VK_SUCCESS(err);
10244 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10245 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010246
10247 VkBufferViewCreateInfo buff_view_ci = {};
10248 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10249 buff_view_ci.buffer = buffer;
10250 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10251 buff_view_ci.range = VK_WHOLE_SIZE;
10252 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010253 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010254 ASSERT_VK_SUCCESS(err);
10255
Tony Barbour415497c2017-01-24 10:06:09 -070010256 // Now get resources / view for storage_texel_buffer
10257 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
10258 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10259 if (!pass) {
10260 vkDestroyBuffer(m_device->device(), buffer, NULL);
10261 vkDestroyBufferView(m_device->device(), buff_view, NULL);
10262 vkFreeMemory(m_device->device(), mem, NULL);
10263 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
10264 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10265 return;
10266 }
10267 VkDeviceMemory storage_texel_buffer_mem;
10268 VkBufferView storage_texel_buffer_view;
10269 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
10270 ASSERT_VK_SUCCESS(err);
10271 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
10272 ASSERT_VK_SUCCESS(err);
10273 buff_view_ci.buffer = storage_texel_buffer;
10274 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
10275 ASSERT_VK_SUCCESS(err);
10276
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010277 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -070010278 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010279 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -070010280 image_ci.format = VK_FORMAT_UNDEFINED;
10281 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
10282 VkFormat format = static_cast<VkFormat>(f);
10283 VkFormatProperties fProps = m_device->format_properties(format);
10284 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10285 image_ci.format = format;
10286 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10287 break;
10288 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10289 image_ci.format = format;
10290 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
10291 break;
10292 }
10293 }
10294 if (image_ci.format == VK_FORMAT_UNDEFINED) {
10295 return;
10296 }
10297
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010298 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10299 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010300 image_ci.extent.width = 64;
10301 image_ci.extent.height = 64;
10302 image_ci.extent.depth = 1;
10303 image_ci.mipLevels = 1;
10304 image_ci.arrayLayers = 1;
10305 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010306 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010307 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010308 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10309 VkImage image;
10310 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10311 ASSERT_VK_SUCCESS(err);
10312 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010313 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010314
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010315 VkMemoryAllocateInfo mem_alloc = {};
10316 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10317 mem_alloc.pNext = NULL;
10318 mem_alloc.allocationSize = 0;
10319 mem_alloc.memoryTypeIndex = 0;
10320 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10321 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010322 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010323 ASSERT_TRUE(pass);
10324 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10325 ASSERT_VK_SUCCESS(err);
10326 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10327 ASSERT_VK_SUCCESS(err);
10328 // Now create view for image
10329 VkImageViewCreateInfo image_view_ci = {};
10330 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10331 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010332 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010333 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10334 image_view_ci.subresourceRange.layerCount = 1;
10335 image_view_ci.subresourceRange.baseArrayLayer = 0;
10336 image_view_ci.subresourceRange.levelCount = 1;
10337 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10338 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010339 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010340 ASSERT_VK_SUCCESS(err);
10341
10342 VkDescriptorBufferInfo buff_info = {};
10343 buff_info.buffer = buffer;
10344 VkDescriptorImageInfo img_info = {};
10345 img_info.imageView = image_view;
10346 VkWriteDescriptorSet descriptor_write = {};
10347 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10348 descriptor_write.dstBinding = 0;
10349 descriptor_write.descriptorCount = 1;
10350 descriptor_write.pTexelBufferView = &buff_view;
10351 descriptor_write.pBufferInfo = &buff_info;
10352 descriptor_write.pImageInfo = &img_info;
10353
10354 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010355 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010356 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
10357 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
10358 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
10359 VALIDATION_ERROR_00943, // STORAGE_IMAGE
10360 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
10361 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
10362 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
10363 VALIDATION_ERROR_00947, // STORAGE_BUFFER
10364 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
10365 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
10366 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010367 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010368 // Start loop at 1 as SAMPLER desc type has no usage bit error
10369 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -070010370 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10371 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
10372 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
10373 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010374 descriptor_write.descriptorType = VkDescriptorType(i);
10375 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010377
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010378 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010379
10380 m_errorMonitor->VerifyFound();
10381 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010382 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10383 descriptor_write.pTexelBufferView = &buff_view;
10384 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010385 }
Tony Barbour415497c2017-01-24 10:06:09 -070010386
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010387 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10388 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010389 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010390 vkDestroyImageView(m_device->device(), image_view, NULL);
10391 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010392 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010393 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010394 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010395 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010396 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010397 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10398}
10399
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010400TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010401 TEST_DESCRIPTION(
10402 "Attempt to update buffer descriptor set that has incorrect "
10403 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010404 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010405 "2. range value of 0\n"
10406 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010407 VkResult err;
10408
Tony Barbour1fa09702017-03-16 12:09:08 -060010409 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010410 VkDescriptorPoolSize ds_type_count = {};
10411 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10412 ds_type_count.descriptorCount = 1;
10413
10414 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10415 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10416 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010417 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010418 ds_pool_ci.maxSets = 1;
10419 ds_pool_ci.poolSizeCount = 1;
10420 ds_pool_ci.pPoolSizes = &ds_type_count;
10421
10422 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010423 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010424 ASSERT_VK_SUCCESS(err);
10425
10426 // Create layout with single uniform buffer descriptor
10427 VkDescriptorSetLayoutBinding dsl_binding = {};
10428 dsl_binding.binding = 0;
10429 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10430 dsl_binding.descriptorCount = 1;
10431 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10432 dsl_binding.pImmutableSamplers = NULL;
10433
10434 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10435 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10436 ds_layout_ci.pNext = NULL;
10437 ds_layout_ci.bindingCount = 1;
10438 ds_layout_ci.pBindings = &dsl_binding;
10439 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010440 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010441 ASSERT_VK_SUCCESS(err);
10442
10443 VkDescriptorSet descriptor_set = {};
10444 VkDescriptorSetAllocateInfo alloc_info = {};
10445 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10446 alloc_info.descriptorSetCount = 1;
10447 alloc_info.descriptorPool = ds_pool;
10448 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010449 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010450 ASSERT_VK_SUCCESS(err);
10451
10452 // Create a buffer to be used for invalid updates
10453 VkBufferCreateInfo buff_ci = {};
10454 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10455 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010456 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010457 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10458 VkBuffer buffer;
10459 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10460 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010461
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010462 // Have to bind memory to buffer before descriptor update
10463 VkMemoryAllocateInfo mem_alloc = {};
10464 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10465 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010466 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010467 mem_alloc.memoryTypeIndex = 0;
10468
10469 VkMemoryRequirements mem_reqs;
10470 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010471 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010472 if (!pass) {
10473 vkDestroyBuffer(m_device->device(), buffer, NULL);
10474 return;
10475 }
10476
10477 VkDeviceMemory mem;
10478 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10479 ASSERT_VK_SUCCESS(err);
10480 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10481 ASSERT_VK_SUCCESS(err);
10482
10483 VkDescriptorBufferInfo buff_info = {};
10484 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010485 // Cause error due to offset out of range
10486 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010487 buff_info.range = VK_WHOLE_SIZE;
10488 VkWriteDescriptorSet descriptor_write = {};
10489 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10490 descriptor_write.dstBinding = 0;
10491 descriptor_write.descriptorCount = 1;
10492 descriptor_write.pTexelBufferView = nullptr;
10493 descriptor_write.pBufferInfo = &buff_info;
10494 descriptor_write.pImageInfo = nullptr;
10495
10496 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10497 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010499
10500 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10501
10502 m_errorMonitor->VerifyFound();
10503 // Now cause error due to range of 0
10504 buff_info.offset = 0;
10505 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010507
10508 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10509
10510 m_errorMonitor->VerifyFound();
10511 // Now cause error due to range exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010512 buff_info.offset = 0;
10513 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010515
10516 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10517
10518 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010519 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010520 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10521 vkDestroyBuffer(m_device->device(), buffer, NULL);
10522 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10523 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10524}
10525
Tobin Ehlis845887e2017-02-02 19:01:44 -070010526TEST_F(VkLayerTest, DSBufferLimitErrors) {
10527 TEST_DESCRIPTION(
10528 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
10529 "Test cases include:\n"
10530 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
10531 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
10532 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
10533 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
10534 VkResult err;
10535
Tony Barbour1fa09702017-03-16 12:09:08 -060010536 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis845887e2017-02-02 19:01:44 -070010537 VkDescriptorPoolSize ds_type_count[2] = {};
10538 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10539 ds_type_count[0].descriptorCount = 1;
10540 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10541 ds_type_count[1].descriptorCount = 1;
10542
10543 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10544 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10545 ds_pool_ci.pNext = NULL;
10546 ds_pool_ci.maxSets = 1;
10547 ds_pool_ci.poolSizeCount = 2;
10548 ds_pool_ci.pPoolSizes = ds_type_count;
10549
10550 VkDescriptorPool ds_pool;
10551 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10552 ASSERT_VK_SUCCESS(err);
10553
10554 // Create layout with single uniform buffer & single storage buffer descriptor
10555 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
10556 dsl_binding[0].binding = 0;
10557 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10558 dsl_binding[0].descriptorCount = 1;
10559 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10560 dsl_binding[0].pImmutableSamplers = NULL;
10561 dsl_binding[1].binding = 1;
10562 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10563 dsl_binding[1].descriptorCount = 1;
10564 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10565 dsl_binding[1].pImmutableSamplers = NULL;
10566
10567 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10568 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10569 ds_layout_ci.pNext = NULL;
10570 ds_layout_ci.bindingCount = 2;
10571 ds_layout_ci.pBindings = dsl_binding;
10572 VkDescriptorSetLayout ds_layout;
10573 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10574 ASSERT_VK_SUCCESS(err);
10575
10576 VkDescriptorSet descriptor_set = {};
10577 VkDescriptorSetAllocateInfo alloc_info = {};
10578 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10579 alloc_info.descriptorSetCount = 1;
10580 alloc_info.descriptorPool = ds_pool;
10581 alloc_info.pSetLayouts = &ds_layout;
10582 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10583 ASSERT_VK_SUCCESS(err);
10584
10585 // Create a buffer to be used for invalid updates
10586 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
10587 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
10588 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
10589 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
10590 VkBufferCreateInfo ub_ci = {};
10591 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10592 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10593 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
10594 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10595 VkBuffer uniform_buffer;
10596 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
10597 ASSERT_VK_SUCCESS(err);
10598 VkBufferCreateInfo sb_ci = {};
10599 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10600 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
10601 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
10602 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10603 VkBuffer storage_buffer;
10604 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
10605 ASSERT_VK_SUCCESS(err);
10606 // Have to bind memory to buffer before descriptor update
10607 VkMemoryAllocateInfo mem_alloc = {};
10608 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10609 mem_alloc.pNext = NULL;
10610 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
10611 mem_alloc.memoryTypeIndex = 0;
10612
Cort Stratton77a0d592017-02-17 13:14:13 -080010613 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
10614 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
10615 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
10616 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
10617 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010618 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -070010619 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010620 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010621 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10622 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010623 return;
10624 }
10625
10626 VkDeviceMemory mem;
10627 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010628 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010629 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -070010630 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10631 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10632 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10633 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10634 return;
10635 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010636 ASSERT_VK_SUCCESS(err);
10637 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
10638 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -080010639 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010640 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
10641 ASSERT_VK_SUCCESS(err);
10642
10643 VkDescriptorBufferInfo buff_info = {};
10644 buff_info.buffer = uniform_buffer;
10645 buff_info.range = ub_ci.size; // This will exceed limit
10646 VkWriteDescriptorSet descriptor_write = {};
10647 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10648 descriptor_write.dstBinding = 0;
10649 descriptor_write.descriptorCount = 1;
10650 descriptor_write.pTexelBufferView = nullptr;
10651 descriptor_write.pBufferInfo = &buff_info;
10652 descriptor_write.pImageInfo = nullptr;
10653
10654 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10655 descriptor_write.dstSet = descriptor_set;
Tony Barbour02d08552017-03-24 16:36:01 -060010656 if (max_ub_range != UINT32_MAX) {
10657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
10658 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10659 m_errorMonitor->VerifyFound();
10660 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010661 // Reduce size of range to acceptable limit & cause offset error
10662 buff_info.range = max_ub_range;
10663 buff_info.offset = min_ub_align - 1;
10664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
10665 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10666 m_errorMonitor->VerifyFound();
10667
10668 // Now break storage updates
10669 buff_info.buffer = storage_buffer;
10670 buff_info.range = sb_ci.size; // This will exceed limit
10671 buff_info.offset = 0; // Reset offset for this update
10672
10673 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10674 descriptor_write.dstBinding = 1;
Tony Barbour02d08552017-03-24 16:36:01 -060010675 if (max_ub_range != UINT32_MAX) {
10676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
10677 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10678 m_errorMonitor->VerifyFound();
10679 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010680
10681 // Reduce size of range to acceptable limit & cause offset error
10682 buff_info.range = max_sb_range;
10683 buff_info.offset = min_sb_align - 1;
10684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
10685 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10686 m_errorMonitor->VerifyFound();
10687
10688 vkFreeMemory(m_device->device(), mem, NULL);
10689 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10690 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10691 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10692 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10693}
10694
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010695TEST_F(VkLayerTest, DSAspectBitsErrors) {
10696 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10697 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010698 TEST_DESCRIPTION(
10699 "Attempt to update descriptor sets for images "
10700 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010701 VkResult err;
10702
Tony Barbour1fa09702017-03-16 12:09:08 -060010703 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060010704 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070010705 if (!depth_format) {
10706 printf(" No Depth + Stencil format found. Skipped.\n");
10707 return;
10708 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010709 VkDescriptorPoolSize ds_type_count = {};
10710 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10711 ds_type_count.descriptorCount = 1;
10712
10713 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10714 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10715 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -070010716 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010717 ds_pool_ci.maxSets = 5;
10718 ds_pool_ci.poolSizeCount = 1;
10719 ds_pool_ci.pPoolSizes = &ds_type_count;
10720
10721 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010722 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010723 ASSERT_VK_SUCCESS(err);
10724
10725 VkDescriptorSetLayoutBinding dsl_binding = {};
10726 dsl_binding.binding = 0;
10727 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10728 dsl_binding.descriptorCount = 1;
10729 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10730 dsl_binding.pImmutableSamplers = NULL;
10731
10732 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10733 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10734 ds_layout_ci.pNext = NULL;
10735 ds_layout_ci.bindingCount = 1;
10736 ds_layout_ci.pBindings = &dsl_binding;
10737 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010738 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010739 ASSERT_VK_SUCCESS(err);
10740
10741 VkDescriptorSet descriptor_set = {};
10742 VkDescriptorSetAllocateInfo alloc_info = {};
10743 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10744 alloc_info.descriptorSetCount = 1;
10745 alloc_info.descriptorPool = ds_pool;
10746 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010747 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010748 ASSERT_VK_SUCCESS(err);
10749
10750 // Create an image to be used for invalid updates
10751 VkImageCreateInfo image_ci = {};
10752 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10753 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070010754 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010755 image_ci.extent.width = 64;
10756 image_ci.extent.height = 64;
10757 image_ci.extent.depth = 1;
10758 image_ci.mipLevels = 1;
10759 image_ci.arrayLayers = 1;
10760 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -070010761 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010762 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10763 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10764 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10765 VkImage image;
10766 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10767 ASSERT_VK_SUCCESS(err);
10768 // Bind memory to image
10769 VkMemoryRequirements mem_reqs;
10770 VkDeviceMemory image_mem;
10771 bool pass;
10772 VkMemoryAllocateInfo mem_alloc = {};
10773 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10774 mem_alloc.pNext = NULL;
10775 mem_alloc.allocationSize = 0;
10776 mem_alloc.memoryTypeIndex = 0;
10777 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10778 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010779 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010780 ASSERT_TRUE(pass);
10781 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10782 ASSERT_VK_SUCCESS(err);
10783 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10784 ASSERT_VK_SUCCESS(err);
10785 // Now create view for image
10786 VkImageViewCreateInfo image_view_ci = {};
10787 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10788 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -070010789 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010790 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10791 image_view_ci.subresourceRange.layerCount = 1;
10792 image_view_ci.subresourceRange.baseArrayLayer = 0;
10793 image_view_ci.subresourceRange.levelCount = 1;
10794 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010795 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010796
10797 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010798 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010799 ASSERT_VK_SUCCESS(err);
10800
10801 VkDescriptorImageInfo img_info = {};
10802 img_info.imageView = image_view;
10803 VkWriteDescriptorSet descriptor_write = {};
10804 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10805 descriptor_write.dstBinding = 0;
10806 descriptor_write.descriptorCount = 1;
10807 descriptor_write.pTexelBufferView = NULL;
10808 descriptor_write.pBufferInfo = NULL;
10809 descriptor_write.pImageInfo = &img_info;
10810 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10811 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010812 const char *error_msg =
10813 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10814 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010816
10817 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10818
10819 m_errorMonitor->VerifyFound();
10820 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10821 vkDestroyImage(m_device->device(), image, NULL);
10822 vkFreeMemory(m_device->device(), image_mem, NULL);
10823 vkDestroyImageView(m_device->device(), image_view, NULL);
10824 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10825 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10826}
10827
Karl Schultz6addd812016-02-02 17:17:23 -070010828TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010829 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010830 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010831
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10833 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10834 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010835
Tony Barbour1fa09702017-03-16 12:09:08 -060010836 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070010837 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010838 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010839 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10840 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010841
10842 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010843 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10844 ds_pool_ci.pNext = NULL;
10845 ds_pool_ci.maxSets = 1;
10846 ds_pool_ci.poolSizeCount = 1;
10847 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010848
Tobin Ehlis3b780662015-05-28 12:11:26 -060010849 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010850 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010851 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010852 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010853 dsl_binding.binding = 0;
10854 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10855 dsl_binding.descriptorCount = 1;
10856 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10857 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010858
Tony Barboureb254902015-07-15 12:50:33 -060010859 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010860 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10861 ds_layout_ci.pNext = NULL;
10862 ds_layout_ci.bindingCount = 1;
10863 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010864
Tobin Ehlis3b780662015-05-28 12:11:26 -060010865 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010866 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010867 ASSERT_VK_SUCCESS(err);
10868
10869 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010870 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010871 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010872 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010873 alloc_info.descriptorPool = ds_pool;
10874 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010875 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010876 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010877
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010878 VkSamplerCreateInfo sampler_ci = {};
10879 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10880 sampler_ci.pNext = NULL;
10881 sampler_ci.magFilter = VK_FILTER_NEAREST;
10882 sampler_ci.minFilter = VK_FILTER_NEAREST;
10883 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10884 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10885 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10886 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10887 sampler_ci.mipLodBias = 1.0;
10888 sampler_ci.anisotropyEnable = VK_FALSE;
10889 sampler_ci.maxAnisotropy = 1;
10890 sampler_ci.compareEnable = VK_FALSE;
10891 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10892 sampler_ci.minLod = 1.0;
10893 sampler_ci.maxLod = 1.0;
10894 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10895 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10896 VkSampler sampler;
10897 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10898 ASSERT_VK_SUCCESS(err);
10899
10900 VkDescriptorImageInfo info = {};
10901 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010902
10903 VkWriteDescriptorSet descriptor_write;
10904 memset(&descriptor_write, 0, sizeof(descriptor_write));
10905 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010906 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010907 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010908 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010909 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010910 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010911
10912 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10913
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010914 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010915
Chia-I Wuf7458c52015-10-26 21:10:41 +080010916 vkDestroySampler(m_device->device(), sampler, NULL);
10917 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10918 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010919}
10920
Karl Schultz6addd812016-02-02 17:17:23 -070010921TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010922 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010923 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010924
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010926
Tony Barbour1fa09702017-03-16 12:09:08 -060010927 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070010928 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010929 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010930 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10931 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010932
10933 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010934 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10935 ds_pool_ci.pNext = NULL;
10936 ds_pool_ci.maxSets = 1;
10937 ds_pool_ci.poolSizeCount = 1;
10938 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010939
Tobin Ehlis3b780662015-05-28 12:11:26 -060010940 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010941 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010942 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010943
Tony Barboureb254902015-07-15 12:50:33 -060010944 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010945 dsl_binding.binding = 0;
10946 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10947 dsl_binding.descriptorCount = 1;
10948 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10949 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010950
10951 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010952 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10953 ds_layout_ci.pNext = NULL;
10954 ds_layout_ci.bindingCount = 1;
10955 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010956
Tobin Ehlis3b780662015-05-28 12:11:26 -060010957 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010958 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010959 ASSERT_VK_SUCCESS(err);
10960
10961 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010962 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010963 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010964 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010965 alloc_info.descriptorPool = ds_pool;
10966 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010967 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010968 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010969
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010970 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10971
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010972 // Correctly update descriptor to avoid "NOT_UPDATED" error
10973 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010974 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010975 buff_info.offset = 0;
10976 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010977
10978 VkWriteDescriptorSet descriptor_write;
10979 memset(&descriptor_write, 0, sizeof(descriptor_write));
10980 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010981 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010982 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010983 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010984 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10985 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010986
10987 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10988
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010989 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010990
Chia-I Wuf7458c52015-10-26 21:10:41 +080010991 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10992 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010993}
10994
Karl Schultz6addd812016-02-02 17:17:23 -070010995TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010996 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010997 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010998
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011000
Tony Barbour1fa09702017-03-16 12:09:08 -060011001 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011002 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011003 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011004 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11005 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011006
11007 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011008 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11009 ds_pool_ci.pNext = NULL;
11010 ds_pool_ci.maxSets = 1;
11011 ds_pool_ci.poolSizeCount = 1;
11012 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011013
Tobin Ehlis3b780662015-05-28 12:11:26 -060011014 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011015 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011016 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011017
Tony Barboureb254902015-07-15 12:50:33 -060011018 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011019 dsl_binding.binding = 0;
11020 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11021 dsl_binding.descriptorCount = 1;
11022 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11023 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011024
11025 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011026 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11027 ds_layout_ci.pNext = NULL;
11028 ds_layout_ci.bindingCount = 1;
11029 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011030 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011031 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011032 ASSERT_VK_SUCCESS(err);
11033
11034 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011035 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011036 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011037 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011038 alloc_info.descriptorPool = ds_pool;
11039 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011040 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011041 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011042
Tony Barboureb254902015-07-15 12:50:33 -060011043 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011044 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11045 sampler_ci.pNext = NULL;
11046 sampler_ci.magFilter = VK_FILTER_NEAREST;
11047 sampler_ci.minFilter = VK_FILTER_NEAREST;
11048 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11049 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11050 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11051 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11052 sampler_ci.mipLodBias = 1.0;
11053 sampler_ci.anisotropyEnable = VK_FALSE;
11054 sampler_ci.maxAnisotropy = 1;
11055 sampler_ci.compareEnable = VK_FALSE;
11056 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11057 sampler_ci.minLod = 1.0;
11058 sampler_ci.maxLod = 1.0;
11059 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11060 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011061
Tobin Ehlis3b780662015-05-28 12:11:26 -060011062 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011063 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011064 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011065
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011066 VkDescriptorImageInfo info = {};
11067 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011068
11069 VkWriteDescriptorSet descriptor_write;
11070 memset(&descriptor_write, 0, sizeof(descriptor_write));
11071 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011072 descriptor_write.dstSet = descriptorSet;
11073 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011074 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011075 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011076 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011077 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011078
11079 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11080
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011081 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011082
Chia-I Wuf7458c52015-10-26 21:10:41 +080011083 vkDestroySampler(m_device->device(), sampler, NULL);
11084 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11085 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011086}
11087
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011088TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
11089 // Create layout w/ empty binding and attempt to update it
11090 VkResult err;
11091
Tony Barbour1fa09702017-03-16 12:09:08 -060011092 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011093
11094 VkDescriptorPoolSize ds_type_count = {};
11095 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11096 ds_type_count.descriptorCount = 1;
11097
11098 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11099 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11100 ds_pool_ci.pNext = NULL;
11101 ds_pool_ci.maxSets = 1;
11102 ds_pool_ci.poolSizeCount = 1;
11103 ds_pool_ci.pPoolSizes = &ds_type_count;
11104
11105 VkDescriptorPool ds_pool;
11106 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11107 ASSERT_VK_SUCCESS(err);
11108
11109 VkDescriptorSetLayoutBinding dsl_binding = {};
11110 dsl_binding.binding = 0;
11111 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11112 dsl_binding.descriptorCount = 0;
11113 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11114 dsl_binding.pImmutableSamplers = NULL;
11115
11116 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11117 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11118 ds_layout_ci.pNext = NULL;
11119 ds_layout_ci.bindingCount = 1;
11120 ds_layout_ci.pBindings = &dsl_binding;
11121 VkDescriptorSetLayout ds_layout;
11122 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11123 ASSERT_VK_SUCCESS(err);
11124
11125 VkDescriptorSet descriptor_set;
11126 VkDescriptorSetAllocateInfo alloc_info = {};
11127 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11128 alloc_info.descriptorSetCount = 1;
11129 alloc_info.descriptorPool = ds_pool;
11130 alloc_info.pSetLayouts = &ds_layout;
11131 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11132 ASSERT_VK_SUCCESS(err);
11133
11134 VkSamplerCreateInfo sampler_ci = {};
11135 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11136 sampler_ci.magFilter = VK_FILTER_NEAREST;
11137 sampler_ci.minFilter = VK_FILTER_NEAREST;
11138 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11139 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11140 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11141 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11142 sampler_ci.mipLodBias = 1.0;
11143 sampler_ci.maxAnisotropy = 1;
11144 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11145 sampler_ci.minLod = 1.0;
11146 sampler_ci.maxLod = 1.0;
11147 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11148
11149 VkSampler sampler;
11150 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11151 ASSERT_VK_SUCCESS(err);
11152
11153 VkDescriptorImageInfo info = {};
11154 info.sampler = sampler;
11155
11156 VkWriteDescriptorSet descriptor_write;
11157 memset(&descriptor_write, 0, sizeof(descriptor_write));
11158 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11159 descriptor_write.dstSet = descriptor_set;
11160 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011161 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011162 // This is the wrong type, but empty binding error will be flagged first
11163 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11164 descriptor_write.pImageInfo = &info;
11165
11166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
11167 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11168 m_errorMonitor->VerifyFound();
11169
11170 vkDestroySampler(m_device->device(), sampler, NULL);
11171 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11172 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11173}
11174
Karl Schultz6addd812016-02-02 17:17:23 -070011175TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11176 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11177 // types
11178 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011179
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011180 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 -060011181
Tony Barbour1fa09702017-03-16 12:09:08 -060011182 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011183
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011184 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011185 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11186 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011187
11188 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011189 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11190 ds_pool_ci.pNext = NULL;
11191 ds_pool_ci.maxSets = 1;
11192 ds_pool_ci.poolSizeCount = 1;
11193 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011194
Tobin Ehlis3b780662015-05-28 12:11:26 -060011195 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011196 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011197 ASSERT_VK_SUCCESS(err);
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;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011204
Tony Barboureb254902015-07-15 12:50:33 -060011205 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;
Tony Barboureb254902015-07-15 12:50:33 -060011210
Tobin Ehlis3b780662015-05-28 12:11:26 -060011211 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011212 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011213 ASSERT_VK_SUCCESS(err);
11214
11215 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011216 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011217 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011218 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011219 alloc_info.descriptorPool = ds_pool;
11220 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011221 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011222 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011223
Tony Barboureb254902015-07-15 12:50:33 -060011224 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011225 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11226 sampler_ci.pNext = NULL;
11227 sampler_ci.magFilter = VK_FILTER_NEAREST;
11228 sampler_ci.minFilter = VK_FILTER_NEAREST;
11229 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11230 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11231 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11232 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11233 sampler_ci.mipLodBias = 1.0;
11234 sampler_ci.anisotropyEnable = VK_FALSE;
11235 sampler_ci.maxAnisotropy = 1;
11236 sampler_ci.compareEnable = VK_FALSE;
11237 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11238 sampler_ci.minLod = 1.0;
11239 sampler_ci.maxLod = 1.0;
11240 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11241 sampler_ci.unnormalizedCoordinates = VK_FALSE;
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));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011251 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011252 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011253 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011254 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011255 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011256 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011257
11258 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11259
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011260 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011261
Chia-I Wuf7458c52015-10-26 21:10:41 +080011262 vkDestroySampler(m_device->device(), sampler, NULL);
11263 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11264 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011265}
11266
Karl Schultz6addd812016-02-02 17:17:23 -070011267TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011268 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011269 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011270
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011272
Tony Barbour1fa09702017-03-16 12:09:08 -060011273 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011274 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11275 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011276 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011277 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11278 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011279
11280 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011281 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11282 ds_pool_ci.pNext = NULL;
11283 ds_pool_ci.maxSets = 1;
11284 ds_pool_ci.poolSizeCount = 1;
11285 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011286
11287 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011288 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011289 ASSERT_VK_SUCCESS(err);
11290
11291 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011292 dsl_binding.binding = 0;
11293 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11294 dsl_binding.descriptorCount = 1;
11295 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11296 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011297
11298 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011299 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11300 ds_layout_ci.pNext = NULL;
11301 ds_layout_ci.bindingCount = 1;
11302 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011303 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011304 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011305 ASSERT_VK_SUCCESS(err);
11306
11307 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011308 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011309 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011310 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011311 alloc_info.descriptorPool = ds_pool;
11312 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011313 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011314 ASSERT_VK_SUCCESS(err);
11315
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011316 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011317
11318 VkDescriptorImageInfo descriptor_info;
11319 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11320 descriptor_info.sampler = sampler;
11321
11322 VkWriteDescriptorSet descriptor_write;
11323 memset(&descriptor_write, 0, sizeof(descriptor_write));
11324 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011325 descriptor_write.dstSet = descriptorSet;
11326 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011327 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011328 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11329 descriptor_write.pImageInfo = &descriptor_info;
11330
11331 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11332
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011333 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011334
Chia-I Wuf7458c52015-10-26 21:10:41 +080011335 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11336 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011337}
11338
Karl Schultz6addd812016-02-02 17:17:23 -070011339TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11340 // Create a single combined Image/Sampler descriptor and send it an invalid
11341 // imageView
11342 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011343
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011345
Tony Barbour1fa09702017-03-16 12:09:08 -060011346 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011347 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011348 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11349 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011350
11351 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011352 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11353 ds_pool_ci.pNext = NULL;
11354 ds_pool_ci.maxSets = 1;
11355 ds_pool_ci.poolSizeCount = 1;
11356 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011357
11358 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011359 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011360 ASSERT_VK_SUCCESS(err);
11361
11362 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011363 dsl_binding.binding = 0;
11364 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11365 dsl_binding.descriptorCount = 1;
11366 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11367 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011368
11369 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011370 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11371 ds_layout_ci.pNext = NULL;
11372 ds_layout_ci.bindingCount = 1;
11373 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011374 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011375 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011376 ASSERT_VK_SUCCESS(err);
11377
11378 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011379 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011380 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011381 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011382 alloc_info.descriptorPool = ds_pool;
11383 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011384 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011385 ASSERT_VK_SUCCESS(err);
11386
11387 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011388 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11389 sampler_ci.pNext = NULL;
11390 sampler_ci.magFilter = VK_FILTER_NEAREST;
11391 sampler_ci.minFilter = VK_FILTER_NEAREST;
11392 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11393 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11394 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11395 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11396 sampler_ci.mipLodBias = 1.0;
11397 sampler_ci.anisotropyEnable = VK_FALSE;
11398 sampler_ci.maxAnisotropy = 1;
11399 sampler_ci.compareEnable = VK_FALSE;
11400 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11401 sampler_ci.minLod = 1.0;
11402 sampler_ci.maxLod = 1.0;
11403 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11404 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011405
11406 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011407 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011408 ASSERT_VK_SUCCESS(err);
11409
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011410 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011411
11412 VkDescriptorImageInfo descriptor_info;
11413 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11414 descriptor_info.sampler = sampler;
11415 descriptor_info.imageView = view;
11416
11417 VkWriteDescriptorSet descriptor_write;
11418 memset(&descriptor_write, 0, sizeof(descriptor_write));
11419 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011420 descriptor_write.dstSet = descriptorSet;
11421 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011422 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011423 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11424 descriptor_write.pImageInfo = &descriptor_info;
11425
11426 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11427
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011428 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011429
Chia-I Wuf7458c52015-10-26 21:10:41 +080011430 vkDestroySampler(m_device->device(), sampler, NULL);
11431 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11432 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011433}
11434
Karl Schultz6addd812016-02-02 17:17:23 -070011435TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11436 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11437 // into the other
11438 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011439
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11441 " binding #1 with type "
11442 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11443 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011444
Tony Barbour1fa09702017-03-16 12:09:08 -060011445 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011446 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011447 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011448 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11449 ds_type_count[0].descriptorCount = 1;
11450 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11451 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011452
11453 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011454 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11455 ds_pool_ci.pNext = NULL;
11456 ds_pool_ci.maxSets = 1;
11457 ds_pool_ci.poolSizeCount = 2;
11458 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011459
11460 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011461 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011462 ASSERT_VK_SUCCESS(err);
11463 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011464 dsl_binding[0].binding = 0;
11465 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11466 dsl_binding[0].descriptorCount = 1;
11467 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11468 dsl_binding[0].pImmutableSamplers = NULL;
11469 dsl_binding[1].binding = 1;
11470 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11471 dsl_binding[1].descriptorCount = 1;
11472 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11473 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011474
11475 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011476 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11477 ds_layout_ci.pNext = NULL;
11478 ds_layout_ci.bindingCount = 2;
11479 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011480
11481 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011482 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011483 ASSERT_VK_SUCCESS(err);
11484
11485 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011486 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011487 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011488 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011489 alloc_info.descriptorPool = ds_pool;
11490 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011491 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011492 ASSERT_VK_SUCCESS(err);
11493
11494 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011495 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11496 sampler_ci.pNext = NULL;
11497 sampler_ci.magFilter = VK_FILTER_NEAREST;
11498 sampler_ci.minFilter = VK_FILTER_NEAREST;
11499 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11500 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11501 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11502 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11503 sampler_ci.mipLodBias = 1.0;
11504 sampler_ci.anisotropyEnable = VK_FALSE;
11505 sampler_ci.maxAnisotropy = 1;
11506 sampler_ci.compareEnable = VK_FALSE;
11507 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11508 sampler_ci.minLod = 1.0;
11509 sampler_ci.maxLod = 1.0;
11510 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11511 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011512
11513 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011514 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011515 ASSERT_VK_SUCCESS(err);
11516
11517 VkDescriptorImageInfo info = {};
11518 info.sampler = sampler;
11519
11520 VkWriteDescriptorSet descriptor_write;
11521 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11522 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011523 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011524 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011525 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011526 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11527 descriptor_write.pImageInfo = &info;
11528 // This write update should succeed
11529 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11530 // Now perform a copy update that fails due to type mismatch
11531 VkCopyDescriptorSet copy_ds_update;
11532 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11533 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11534 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011535 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011536 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011537 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
11538 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011539 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11540
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011541 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011542 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011543 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 -060011544 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11545 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11546 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011547 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011548 copy_ds_update.dstSet = descriptorSet;
11549 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011550 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011551 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11552
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011553 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011554
Tobin Ehlis04356f92015-10-27 16:35:27 -060011555 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11557 " binding#1 with offset index of 1 plus "
11558 "update array offset of 0 and update of "
11559 "5 descriptors oversteps total number "
11560 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011561
Tobin Ehlis04356f92015-10-27 16:35:27 -060011562 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11563 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11564 copy_ds_update.srcSet = descriptorSet;
11565 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011566 copy_ds_update.dstSet = descriptorSet;
11567 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011568 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011569 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11570
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011571 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011572
Chia-I Wuf7458c52015-10-26 21:10:41 +080011573 vkDestroySampler(m_device->device(), sampler, NULL);
11574 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11575 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011576}
11577
Karl Schultz6addd812016-02-02 17:17:23 -070011578TEST_F(VkLayerTest, NumSamplesMismatch) {
11579 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11580 // sampleCount
11581 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011582
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011584
Tony Barbour1fa09702017-03-16 12:09:08 -060011585 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011586 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011587 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011588 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011589 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011590
11591 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011592 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11593 ds_pool_ci.pNext = NULL;
11594 ds_pool_ci.maxSets = 1;
11595 ds_pool_ci.poolSizeCount = 1;
11596 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011597
Tobin Ehlis3b780662015-05-28 12:11:26 -060011598 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011599 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011600 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011601
Tony Barboureb254902015-07-15 12:50:33 -060011602 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011603 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011604 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011605 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011606 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11607 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011608
Tony Barboureb254902015-07-15 12:50:33 -060011609 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11610 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11611 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011612 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011613 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011614
Tobin Ehlis3b780662015-05-28 12:11:26 -060011615 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011616 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011617 ASSERT_VK_SUCCESS(err);
11618
11619 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011620 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011621 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011622 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011623 alloc_info.descriptorPool = ds_pool;
11624 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011625 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011626 ASSERT_VK_SUCCESS(err);
11627
Tony Barboureb254902015-07-15 12:50:33 -060011628 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011629 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011630 pipe_ms_state_ci.pNext = NULL;
11631 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11632 pipe_ms_state_ci.sampleShadingEnable = 0;
11633 pipe_ms_state_ci.minSampleShading = 1.0;
11634 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011635
Tony Barboureb254902015-07-15 12:50:33 -060011636 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011637 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11638 pipeline_layout_ci.pNext = NULL;
11639 pipeline_layout_ci.setLayoutCount = 1;
11640 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011641
11642 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011643 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011644 ASSERT_VK_SUCCESS(err);
11645
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011646 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011647 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 -060011648 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011649 VkPipelineObj pipe(m_device);
11650 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011651 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011652 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011653 pipe.SetMSAA(&pipe_ms_state_ci);
11654 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011655
Tony Barbour552f6c02016-12-21 14:34:07 -070011656 m_commandBuffer->BeginCommandBuffer();
11657 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011658 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011659
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070011660 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11661 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11662 VkRect2D scissor = {{0, 0}, {16, 16}};
11663 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11664
Mark Young29927482016-05-04 14:38:51 -060011665 // Render triangle (the error should trigger on the attempt to draw).
11666 Draw(3, 1, 0, 0);
11667
11668 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011669 m_commandBuffer->EndRenderPass();
11670 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060011671
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011672 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011673
Chia-I Wuf7458c52015-10-26 21:10:41 +080011674 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11675 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11676 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011677}
Mark Young29927482016-05-04 14:38:51 -060011678
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011679TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011680 TEST_DESCRIPTION(
11681 "Hit RenderPass incompatible cases. "
11682 "Initial case is drawing with an active renderpass that's "
11683 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011684 VkResult err;
11685
Tony Barbour1fa09702017-03-16 12:09:08 -060011686 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11688
11689 VkDescriptorSetLayoutBinding dsl_binding = {};
11690 dsl_binding.binding = 0;
11691 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11692 dsl_binding.descriptorCount = 1;
11693 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11694 dsl_binding.pImmutableSamplers = NULL;
11695
11696 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11697 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11698 ds_layout_ci.pNext = NULL;
11699 ds_layout_ci.bindingCount = 1;
11700 ds_layout_ci.pBindings = &dsl_binding;
11701
11702 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011703 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011704 ASSERT_VK_SUCCESS(err);
11705
11706 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11707 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11708 pipeline_layout_ci.pNext = NULL;
11709 pipeline_layout_ci.setLayoutCount = 1;
11710 pipeline_layout_ci.pSetLayouts = &ds_layout;
11711
11712 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011713 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011714 ASSERT_VK_SUCCESS(err);
11715
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011716 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011717 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 -060011718 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011719 // Create a renderpass that will be incompatible with default renderpass
11720 VkAttachmentReference attach = {};
11721 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11722 VkAttachmentReference color_att = {};
11723 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11724 VkSubpassDescription subpass = {};
11725 subpass.inputAttachmentCount = 1;
11726 subpass.pInputAttachments = &attach;
11727 subpass.colorAttachmentCount = 1;
11728 subpass.pColorAttachments = &color_att;
11729 VkRenderPassCreateInfo rpci = {};
11730 rpci.subpassCount = 1;
11731 rpci.pSubpasses = &subpass;
11732 rpci.attachmentCount = 1;
11733 VkAttachmentDescription attach_desc = {};
11734 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011735 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11736 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011737 rpci.pAttachments = &attach_desc;
11738 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11739 VkRenderPass rp;
11740 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11741 VkPipelineObj pipe(m_device);
11742 pipe.AddShader(&vs);
11743 pipe.AddShader(&fs);
11744 pipe.AddColorAttachment();
11745 VkViewport view_port = {};
11746 m_viewports.push_back(view_port);
11747 pipe.SetViewport(m_viewports);
11748 VkRect2D rect = {};
11749 m_scissors.push_back(rect);
11750 pipe.SetScissor(m_scissors);
11751 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11752
11753 VkCommandBufferInheritanceInfo cbii = {};
11754 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11755 cbii.renderPass = rp;
11756 cbii.subpass = 0;
11757 VkCommandBufferBeginInfo cbbi = {};
11758 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11759 cbbi.pInheritanceInfo = &cbii;
11760 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11761 VkRenderPassBeginInfo rpbi = {};
11762 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11763 rpbi.framebuffer = m_framebuffer;
11764 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011765 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11766 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011767
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011769 // Render triangle (the error should trigger on the attempt to draw).
11770 Draw(3, 1, 0, 0);
11771
11772 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011773 m_commandBuffer->EndRenderPass();
11774 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011775
11776 m_errorMonitor->VerifyFound();
11777
11778 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11779 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11780 vkDestroyRenderPass(m_device->device(), rp, NULL);
11781}
11782
Mark Youngc89c6312016-03-31 16:03:20 -060011783TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11784 // Create Pipeline where the number of blend attachments doesn't match the
11785 // number of color attachments. In this case, we don't add any color
11786 // blend attachments even though we have a color attachment.
11787 VkResult err;
11788
Tobin Ehlis974c0d92017-02-01 13:31:22 -070011789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060011790
Tony Barbour1fa09702017-03-16 12:09:08 -060011791 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc89c6312016-03-31 16:03:20 -060011792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11793 VkDescriptorPoolSize ds_type_count = {};
11794 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11795 ds_type_count.descriptorCount = 1;
11796
11797 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11798 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11799 ds_pool_ci.pNext = NULL;
11800 ds_pool_ci.maxSets = 1;
11801 ds_pool_ci.poolSizeCount = 1;
11802 ds_pool_ci.pPoolSizes = &ds_type_count;
11803
11804 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011805 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011806 ASSERT_VK_SUCCESS(err);
11807
11808 VkDescriptorSetLayoutBinding dsl_binding = {};
11809 dsl_binding.binding = 0;
11810 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11811 dsl_binding.descriptorCount = 1;
11812 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11813 dsl_binding.pImmutableSamplers = NULL;
11814
11815 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11816 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11817 ds_layout_ci.pNext = NULL;
11818 ds_layout_ci.bindingCount = 1;
11819 ds_layout_ci.pBindings = &dsl_binding;
11820
11821 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011822 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011823 ASSERT_VK_SUCCESS(err);
11824
11825 VkDescriptorSet descriptorSet;
11826 VkDescriptorSetAllocateInfo alloc_info = {};
11827 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11828 alloc_info.descriptorSetCount = 1;
11829 alloc_info.descriptorPool = ds_pool;
11830 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011831 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011832 ASSERT_VK_SUCCESS(err);
11833
11834 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011835 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011836 pipe_ms_state_ci.pNext = NULL;
11837 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11838 pipe_ms_state_ci.sampleShadingEnable = 0;
11839 pipe_ms_state_ci.minSampleShading = 1.0;
11840 pipe_ms_state_ci.pSampleMask = NULL;
11841
11842 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11843 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11844 pipeline_layout_ci.pNext = NULL;
11845 pipeline_layout_ci.setLayoutCount = 1;
11846 pipeline_layout_ci.pSetLayouts = &ds_layout;
11847
11848 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011849 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011850 ASSERT_VK_SUCCESS(err);
11851
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011852 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011853 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 -060011854 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011855 VkPipelineObj pipe(m_device);
11856 pipe.AddShader(&vs);
11857 pipe.AddShader(&fs);
11858 pipe.SetMSAA(&pipe_ms_state_ci);
11859 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011860 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011861
11862 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11863 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11864 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11865}
Mark Young29927482016-05-04 14:38:51 -060011866
Mark Muellerd4914412016-06-13 17:52:06 -060011867TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011868 TEST_DESCRIPTION(
11869 "Points to a wrong colorAttachment index in a VkClearAttachment "
11870 "structure passed to vkCmdClearAttachments");
Tony Barbour1fa09702017-03-16 12:09:08 -060011871 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011873
11874 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11875 m_errorMonitor->VerifyFound();
11876}
11877
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011878TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011879 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11880 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011881
Tony Barbour1fa09702017-03-16 12:09:08 -060011882 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011883 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011884
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011885 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011886 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11887 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011888
11889 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011890 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11891 ds_pool_ci.pNext = NULL;
11892 ds_pool_ci.maxSets = 1;
11893 ds_pool_ci.poolSizeCount = 1;
11894 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011895
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011896 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011897 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011898 ASSERT_VK_SUCCESS(err);
11899
Tony Barboureb254902015-07-15 12:50:33 -060011900 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011901 dsl_binding.binding = 0;
11902 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11903 dsl_binding.descriptorCount = 1;
11904 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11905 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011906
Tony Barboureb254902015-07-15 12:50:33 -060011907 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011908 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11909 ds_layout_ci.pNext = NULL;
11910 ds_layout_ci.bindingCount = 1;
11911 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011912
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011913 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011914 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011915 ASSERT_VK_SUCCESS(err);
11916
11917 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011918 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011919 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011920 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011921 alloc_info.descriptorPool = ds_pool;
11922 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011923 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011924 ASSERT_VK_SUCCESS(err);
11925
Tony Barboureb254902015-07-15 12:50:33 -060011926 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011927 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011928 pipe_ms_state_ci.pNext = NULL;
11929 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11930 pipe_ms_state_ci.sampleShadingEnable = 0;
11931 pipe_ms_state_ci.minSampleShading = 1.0;
11932 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011933
Tony Barboureb254902015-07-15 12:50:33 -060011934 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011935 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11936 pipeline_layout_ci.pNext = NULL;
11937 pipeline_layout_ci.setLayoutCount = 1;
11938 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011939
11940 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011941 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011942 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011944 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011945 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011946 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011947 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011948
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011949 VkPipelineObj pipe(m_device);
11950 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011951 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070011952 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011953 pipe.SetMSAA(&pipe_ms_state_ci);
11954 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011955
Tony Barbour552f6c02016-12-21 14:34:07 -070011956 m_commandBuffer->BeginCommandBuffer();
11957 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011958
Karl Schultz6addd812016-02-02 17:17:23 -070011959 // Main thing we care about for this test is that the VkImage obj we're
11960 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011961 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011962 VkClearAttachment color_attachment;
11963 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11964 color_attachment.clearValue.color.float32[0] = 1.0;
11965 color_attachment.clearValue.color.float32[1] = 1.0;
11966 color_attachment.clearValue.color.float32[2] = 1.0;
11967 color_attachment.clearValue.color.float32[3] = 1.0;
11968 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011969 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011970
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011971 // Call for full-sized FB Color attachment prior to issuing a Draw
11972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011973 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011974 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011975 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011976
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011977 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11978 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11980 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11981 m_errorMonitor->VerifyFound();
11982
11983 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11984 clear_rect.layerCount = 2;
11985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11986 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011987 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011988
Chia-I Wuf7458c52015-10-26 21:10:41 +080011989 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11990 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11991 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011992}
11993
Karl Schultz6addd812016-02-02 17:17:23 -070011994TEST_F(VkLayerTest, VtxBufferBadIndex) {
11995 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011996
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11998 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011999
Tony Barbour1fa09702017-03-16 12:09:08 -060012000 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisd332f282015-10-02 11:00:56 -060012001 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060012002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012003
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012004 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012005 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12006 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012007
12008 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012009 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12010 ds_pool_ci.pNext = NULL;
12011 ds_pool_ci.maxSets = 1;
12012 ds_pool_ci.poolSizeCount = 1;
12013 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012014
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060012015 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012016 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012017 ASSERT_VK_SUCCESS(err);
12018
Tony Barboureb254902015-07-15 12:50:33 -060012019 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012020 dsl_binding.binding = 0;
12021 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12022 dsl_binding.descriptorCount = 1;
12023 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12024 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012025
Tony Barboureb254902015-07-15 12:50:33 -060012026 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012027 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12028 ds_layout_ci.pNext = NULL;
12029 ds_layout_ci.bindingCount = 1;
12030 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060012031
Tobin Ehlis502480b2015-06-24 15:53:07 -060012032 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012033 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012034 ASSERT_VK_SUCCESS(err);
12035
12036 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012037 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012038 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012039 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012040 alloc_info.descriptorPool = ds_pool;
12041 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012042 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012043 ASSERT_VK_SUCCESS(err);
12044
Tony Barboureb254902015-07-15 12:50:33 -060012045 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012046 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012047 pipe_ms_state_ci.pNext = NULL;
12048 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12049 pipe_ms_state_ci.sampleShadingEnable = 0;
12050 pipe_ms_state_ci.minSampleShading = 1.0;
12051 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012052
Tony Barboureb254902015-07-15 12:50:33 -060012053 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012054 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12055 pipeline_layout_ci.pNext = NULL;
12056 pipeline_layout_ci.setLayoutCount = 1;
12057 pipeline_layout_ci.pSetLayouts = &ds_layout;
12058 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012060 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012061 ASSERT_VK_SUCCESS(err);
12062
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012063 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012064 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 -060012065 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012066 VkPipelineObj pipe(m_device);
12067 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012068 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012069 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012070 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012071 pipe.SetViewport(m_viewports);
12072 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012073 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012074
Tony Barbour552f6c02016-12-21 14:34:07 -070012075 m_commandBuffer->BeginCommandBuffer();
12076 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012077 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012078 // Don't care about actual data, just need to get to draw to flag error
12079 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012080 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012081 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012082 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012083
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012084 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012085
Chia-I Wuf7458c52015-10-26 21:10:41 +080012086 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12087 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12088 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012089}
Mark Muellerdfe37552016-07-07 14:47:42 -060012090
Mark Mueller2ee294f2016-08-04 12:59:48 -060012091TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012092 TEST_DESCRIPTION(
12093 "Use an invalid count in a vkEnumeratePhysicalDevices call."
12094 "Use invalid Queue Family Index in vkCreateDevice");
Tony Barbour1fa09702017-03-16 12:09:08 -060012095 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012096
Mark Mueller880fce52016-08-17 15:23:23 -060012097 // The following test fails with recent NVidia drivers.
12098 // By the time core_validation is reached, the NVidia
12099 // driver has sanitized the invalid condition and core_validation
12100 // is not introduced to the failure condition. This is not the case
12101 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012102 // uint32_t count = static_cast<uint32_t>(~0);
12103 // VkPhysicalDevice physical_device;
12104 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12105 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012106
Mark Mueller2ee294f2016-08-04 12:59:48 -060012107 float queue_priority = 0.0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012108 VkDeviceQueueCreateInfo queue_create_info = {};
12109 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12110 queue_create_info.queueCount = 1;
12111 queue_create_info.pQueuePriorities = &queue_priority;
12112 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12113
12114 VkPhysicalDeviceFeatures features = m_device->phy().features();
12115 VkDevice testDevice;
12116 VkDeviceCreateInfo device_create_info = {};
12117 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12118 device_create_info.queueCreateInfoCount = 1;
12119 device_create_info.pQueueCreateInfos = &queue_create_info;
12120 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012121
12122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12123 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex ");
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012124 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms that do
12125 // not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12126 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012127 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12128 m_errorMonitor->VerifyFound();
12129
12130 queue_create_info.queueFamilyIndex = 1;
12131
12132 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12133 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12134 for (unsigned i = 0; i < feature_count; i++) {
12135 if (VK_FALSE == feature_array[i]) {
12136 feature_array[i] = VK_TRUE;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012137 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12139 "While calling vkCreateDevice(), requesting feature #");
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012140 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms
12141 // that do not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12142 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12144 "You requested features that are unavailable on this device. You should first "
12145 "query feature availability by calling vkGetPhysicalDeviceFeatures().");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012146 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12147 m_errorMonitor->VerifyFound();
12148 break;
12149 }
12150 }
12151}
12152
Tobin Ehlis16edf082016-11-21 12:33:49 -070012153TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
12154 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
12155
Tony Barbour1fa09702017-03-16 12:09:08 -060012156 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis16edf082016-11-21 12:33:49 -070012157
12158 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
12159 std::vector<VkDeviceQueueCreateInfo> queue_info;
12160 queue_info.reserve(queue_props.size());
12161 std::vector<std::vector<float>> queue_priorities;
12162 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
12163 VkDeviceQueueCreateInfo qi{};
12164 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12165 qi.queueFamilyIndex = i;
12166 qi.queueCount = queue_props[i].queueCount;
12167 queue_priorities.emplace_back(qi.queueCount, 0.0f);
12168 qi.pQueuePriorities = queue_priorities[i].data();
12169 queue_info.push_back(qi);
12170 }
12171
12172 std::vector<const char *> device_extension_names;
12173
12174 VkDevice local_device;
12175 VkDeviceCreateInfo device_create_info = {};
12176 auto features = m_device->phy().features();
12177 // Intentionally disable pipeline stats
12178 features.pipelineStatisticsQuery = VK_FALSE;
12179 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12180 device_create_info.pNext = NULL;
12181 device_create_info.queueCreateInfoCount = queue_info.size();
12182 device_create_info.pQueueCreateInfos = queue_info.data();
12183 device_create_info.enabledLayerCount = 0;
12184 device_create_info.ppEnabledLayerNames = NULL;
12185 device_create_info.pEnabledFeatures = &features;
12186 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
12187 ASSERT_VK_SUCCESS(err);
12188
12189 VkQueryPoolCreateInfo qpci{};
12190 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12191 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
12192 qpci.queryCount = 1;
12193 VkQueryPool query_pool;
12194
12195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
12196 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
12197 m_errorMonitor->VerifyFound();
12198
12199 vkDestroyDevice(local_device, nullptr);
12200}
12201
Mark Mueller2ee294f2016-08-04 12:59:48 -060012202TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012203 TEST_DESCRIPTION(
12204 "Use an invalid queue index in a vkCmdWaitEvents call."
12205 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012206
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012207 const char *invalid_queue_index =
12208 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12209 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12210 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012212 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012215
Tony Barbour1fa09702017-03-16 12:09:08 -060012216 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012217
12218 VkEvent event;
12219 VkEventCreateInfo event_create_info{};
12220 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12221 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12222
Mark Mueller2ee294f2016-08-04 12:59:48 -060012223 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012224 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012225
Tony Barbour552f6c02016-12-21 14:34:07 -070012226 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012227
12228 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012229 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 -060012230 ASSERT_TRUE(image.initialized());
12231 VkImageMemoryBarrier img_barrier = {};
12232 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12233 img_barrier.pNext = NULL;
12234 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12235 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12236 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12237 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12238 img_barrier.image = image.handle();
12239 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012240
12241 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12242 // that layer validation catches the case when it is not.
12243 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012244 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12245 img_barrier.subresourceRange.baseArrayLayer = 0;
12246 img_barrier.subresourceRange.baseMipLevel = 0;
12247 img_barrier.subresourceRange.layerCount = 1;
12248 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012249 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12250 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012251 m_errorMonitor->VerifyFound();
12252
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012254
12255 VkQueryPool query_pool;
12256 VkQueryPoolCreateInfo query_pool_create_info = {};
12257 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12258 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12259 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012260 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012261
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012262 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012263 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12264
12265 vkEndCommandBuffer(m_commandBuffer->handle());
12266 m_errorMonitor->VerifyFound();
12267
12268 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12269 vkDestroyEvent(m_device->device(), event, nullptr);
12270}
12271
Mark Muellerdfe37552016-07-07 14:47:42 -060012272TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012273 TEST_DESCRIPTION(
12274 "Submit a command buffer using deleted vertex buffer, "
12275 "delete a buffer twice, use an invalid offset for each "
12276 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060012277
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012278 const char *deleted_buffer_in_command_buffer =
12279 "Cannot submit cmd buffer "
12280 "using deleted buffer ";
12281 const char *invalid_offset_message =
12282 "vkBindBufferMemory(): "
12283 "memoryOffset is 0x";
12284 const char *invalid_storage_buffer_offset_message =
12285 "vkBindBufferMemory(): "
12286 "storage memoryOffset "
12287 "is 0x";
12288 const char *invalid_texel_buffer_offset_message =
12289 "vkBindBufferMemory(): "
12290 "texel memoryOffset "
12291 "is 0x";
12292 const char *invalid_uniform_buffer_offset_message =
12293 "vkBindBufferMemory(): "
12294 "uniform memoryOffset "
12295 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060012296
Tony Barbour1fa09702017-03-16 12:09:08 -060012297 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerdfe37552016-07-07 14:47:42 -060012298 ASSERT_NO_FATAL_FAILURE(InitViewport());
12299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12300
12301 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012302 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012303 pipe_ms_state_ci.pNext = NULL;
12304 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12305 pipe_ms_state_ci.sampleShadingEnable = 0;
12306 pipe_ms_state_ci.minSampleShading = 1.0;
12307 pipe_ms_state_ci.pSampleMask = nullptr;
12308
12309 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12310 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12311 VkPipelineLayout pipeline_layout;
12312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012313 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012314 ASSERT_VK_SUCCESS(err);
12315
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012316 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12317 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012318 VkPipelineObj pipe(m_device);
12319 pipe.AddShader(&vs);
12320 pipe.AddShader(&fs);
12321 pipe.AddColorAttachment();
12322 pipe.SetMSAA(&pipe_ms_state_ci);
12323 pipe.SetViewport(m_viewports);
12324 pipe.SetScissor(m_scissors);
12325 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12326
Tony Barbour552f6c02016-12-21 14:34:07 -070012327 m_commandBuffer->BeginCommandBuffer();
12328 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012329 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012330
12331 {
12332 // Create and bind a vertex buffer in a reduced scope, which will cause
12333 // it to be deleted upon leaving this scope
12334 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012335 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012336 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12337 draw_verticies.AddVertexInputToPipe(pipe);
12338 }
12339
12340 Draw(1, 0, 0, 0);
12341
Tony Barbour552f6c02016-12-21 14:34:07 -070012342 m_commandBuffer->EndRenderPass();
12343 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060012344
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012346 QueueCommandBuffer(false);
12347 m_errorMonitor->VerifyFound();
12348
12349 {
12350 // Create and bind a vertex buffer in a reduced scope, and delete it
12351 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012352 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060012354 buffer_test.TestDoubleDestroy();
12355 }
12356 m_errorMonitor->VerifyFound();
12357
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012358 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012359 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012360 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012362 m_errorMonitor->SetUnexpectedError(
12363 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
12364 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012365 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12366 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012367 m_errorMonitor->VerifyFound();
12368 }
12369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012370 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12371 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012372 // Create and bind a memory buffer with an invalid offset again,
12373 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012375 m_errorMonitor->SetUnexpectedError(
12376 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12377 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012378 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12379 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012380 m_errorMonitor->VerifyFound();
12381 }
12382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012383 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012384 // Create and bind a memory buffer with an invalid offset again, but
12385 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012387 m_errorMonitor->SetUnexpectedError(
12388 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12389 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012390 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12391 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012392 m_errorMonitor->VerifyFound();
12393 }
12394
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012395 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012396 // Create and bind a memory buffer with an invalid offset again, but
12397 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012399 m_errorMonitor->SetUnexpectedError(
12400 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12401 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012402 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12403 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012404 m_errorMonitor->VerifyFound();
12405 }
12406
12407 {
12408 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012410 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
12411 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012412 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12413 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012414 m_errorMonitor->VerifyFound();
12415 }
12416
12417 {
12418 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012420 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12421 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012422 }
12423 m_errorMonitor->VerifyFound();
12424
12425 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12426}
12427
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012428// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12429TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012430 TEST_DESCRIPTION(
12431 "Hit all possible validation checks associated with the "
12432 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12433 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012434 // 3 in ValidateCmdBufImageLayouts
12435 // * -1 Attempt to submit cmd buf w/ deleted image
12436 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12437 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012438
Tony Barbour1fa09702017-03-16 12:09:08 -060012439 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060012440 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070012441 if (!depth_format) {
12442 printf(" No Depth + Stencil format found. Skipped.\n");
12443 return;
12444 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012445 // Create src & dst images to use for copy operations
12446 VkImage src_image;
12447 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080012448 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012449
12450 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12451 const int32_t tex_width = 32;
12452 const int32_t tex_height = 32;
12453
12454 VkImageCreateInfo image_create_info = {};
12455 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12456 image_create_info.pNext = NULL;
12457 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12458 image_create_info.format = tex_format;
12459 image_create_info.extent.width = tex_width;
12460 image_create_info.extent.height = tex_height;
12461 image_create_info.extent.depth = 1;
12462 image_create_info.mipLevels = 1;
12463 image_create_info.arrayLayers = 4;
12464 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12465 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12466 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080012467 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012468 image_create_info.flags = 0;
12469
12470 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12471 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012472 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012473 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12474 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012475 image_create_info.format = VK_FORMAT_D32_SFLOAT;
12476 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12477 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
12478 ASSERT_VK_SUCCESS(err);
12479
12480 // Allocate memory
12481 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080012482 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080012483 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080012484 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12485 mem_alloc.pNext = NULL;
12486 mem_alloc.allocationSize = 0;
12487 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080012488
12489 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012490 mem_alloc.allocationSize = img_mem_reqs.size;
12491 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012492 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080012493 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080012494 ASSERT_VK_SUCCESS(err);
12495
12496 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012497 mem_alloc.allocationSize = img_mem_reqs.size;
12498 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012499 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012500 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080012501 ASSERT_VK_SUCCESS(err);
12502
12503 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012504 mem_alloc.allocationSize = img_mem_reqs.size;
12505 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012506 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012507 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080012508 ASSERT_VK_SUCCESS(err);
12509
12510 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
12511 ASSERT_VK_SUCCESS(err);
12512 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
12513 ASSERT_VK_SUCCESS(err);
12514 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
12515 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012516
Tony Barbour552f6c02016-12-21 14:34:07 -070012517 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080012518 VkImageCopy copy_region;
12519 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12520 copy_region.srcSubresource.mipLevel = 0;
12521 copy_region.srcSubresource.baseArrayLayer = 0;
12522 copy_region.srcSubresource.layerCount = 1;
12523 copy_region.srcOffset.x = 0;
12524 copy_region.srcOffset.y = 0;
12525 copy_region.srcOffset.z = 0;
12526 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12527 copy_region.dstSubresource.mipLevel = 0;
12528 copy_region.dstSubresource.baseArrayLayer = 0;
12529 copy_region.dstSubresource.layerCount = 1;
12530 copy_region.dstOffset.x = 0;
12531 copy_region.dstOffset.y = 0;
12532 copy_region.dstOffset.z = 0;
12533 copy_region.extent.width = 1;
12534 copy_region.extent.height = 1;
12535 copy_region.extent.depth = 1;
12536
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12538 "layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12539 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012540
Cort530cf382016-12-08 09:59:47 -080012541 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 -060012542 m_errorMonitor->VerifyFound();
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012543 // The first call hits the expected WARNING and skips the call down the chain, so call a second time to call down chain and
12544 // update layer state
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012545 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12546 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012547 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 -060012548 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012550 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that "
12551 "doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060012552 m_errorMonitor->SetUnexpectedError("srcImageLayout must be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080012553 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 -060012554 m_errorMonitor->VerifyFound();
12555 // Final src error is due to bad layout type
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012557 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012558 "VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012559 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012560 "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 -080012561 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 -060012562 m_errorMonitor->VerifyFound();
12563 // Now verify same checks for dst
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12565 "layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
12566 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012567 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 -060012568 m_errorMonitor->VerifyFound();
12569 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012571 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012572 "the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012573 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012574 "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 -080012575 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 -060012576 m_errorMonitor->VerifyFound();
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012578 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL "
12579 "or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012580 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012581 "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 -080012582 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 -060012583 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012584
Cort3b021012016-12-07 12:00:57 -080012585 // Convert dst and depth images to TRANSFER_DST for subsequent tests
12586 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
12587 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12588 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
12589 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
12590 transfer_dst_image_barrier[0].srcAccessMask = 0;
12591 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
12592 transfer_dst_image_barrier[0].image = dst_image;
12593 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12594 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
12595 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12596 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12597 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12598 transfer_dst_image_barrier[0].image = depth_image;
12599 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
12600 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12601 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12602
12603 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080012604 VkClearColorValue color_clear_value = {};
12605 VkImageSubresourceRange clear_range;
12606 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12607 clear_range.baseMipLevel = 0;
12608 clear_range.baseArrayLayer = 0;
12609 clear_range.layerCount = 1;
12610 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012611
Cort3b021012016-12-07 12:00:57 -080012612 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
12613 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
12615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012616 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012617 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012618 // Fail due to provided layout not matching actual current layout for color clear.
12619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012620 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012621 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012622
Cort530cf382016-12-08 09:59:47 -080012623 VkClearDepthStencilValue depth_clear_value = {};
12624 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080012625
12626 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
12627 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
12629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012630 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012631 m_errorMonitor->VerifyFound();
12632 // Fail due to provided layout not matching actual current layout for depth clear.
12633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012634 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012635 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012636
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012637 // Now cause error due to bad image layout transition in PipelineBarrier
12638 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080012639 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012640 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080012641 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012642 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080012643 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12644 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012645 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012647 "you cannot transition the layout of aspect 1 from "
12648 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is "
12649 "VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070012650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012651 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12652 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012653 m_errorMonitor->VerifyFound();
12654
12655 // Finally some layout errors at RenderPass create time
12656 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12657 VkAttachmentReference attach = {};
12658 // perf warning for GENERAL layout w/ non-DS input attachment
12659 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12660 VkSubpassDescription subpass = {};
12661 subpass.inputAttachmentCount = 1;
12662 subpass.pInputAttachments = &attach;
12663 VkRenderPassCreateInfo rpci = {};
12664 rpci.subpassCount = 1;
12665 rpci.pSubpasses = &subpass;
12666 rpci.attachmentCount = 1;
12667 VkAttachmentDescription attach_desc = {};
12668 attach_desc.format = VK_FORMAT_UNDEFINED;
12669 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012670 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012671 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12673 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012674 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12675 m_errorMonitor->VerifyFound();
12676 // error w/ non-general layout
12677 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12678
12679 m_errorMonitor->SetDesiredFailureMsg(
12680 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12681 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12682 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12683 m_errorMonitor->VerifyFound();
12684 subpass.inputAttachmentCount = 0;
12685 subpass.colorAttachmentCount = 1;
12686 subpass.pColorAttachments = &attach;
12687 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12688 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12690 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012691 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12692 m_errorMonitor->VerifyFound();
12693 // error w/ non-color opt or GENERAL layout for color attachment
12694 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12695 m_errorMonitor->SetDesiredFailureMsg(
12696 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12697 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12698 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12699 m_errorMonitor->VerifyFound();
12700 subpass.colorAttachmentCount = 0;
12701 subpass.pDepthStencilAttachment = &attach;
12702 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12703 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12705 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012706 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12707 m_errorMonitor->VerifyFound();
12708 // error w/ non-ds opt or GENERAL layout for color attachment
12709 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12711 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12712 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012713 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12714 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012715 // For this error we need a valid renderpass so create default one
12716 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12717 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070012718 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012719 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12720 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12721 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12722 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12723 // Can't do a CLEAR load on READ_ONLY initialLayout
12724 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12725 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12726 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012728 "with invalid first layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012729 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12730 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012731
Cort3b021012016-12-07 12:00:57 -080012732 vkFreeMemory(m_device->device(), src_image_mem, NULL);
12733 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
12734 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012735 vkDestroyImage(m_device->device(), src_image, NULL);
12736 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080012737 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012738}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012739
Tobin Ehlise0936662016-10-11 08:10:51 -060012740TEST_F(VkLayerTest, InvalidStorageImageLayout) {
12741 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
12742 VkResult err;
12743
Tony Barbour1fa09702017-03-16 12:09:08 -060012744 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise0936662016-10-11 08:10:51 -060012745
12746 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
12747 VkImageTiling tiling;
12748 VkFormatProperties format_properties;
12749 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
12750 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12751 tiling = VK_IMAGE_TILING_LINEAR;
12752 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12753 tiling = VK_IMAGE_TILING_OPTIMAL;
12754 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070012755 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060012756 return;
12757 }
12758
12759 VkDescriptorPoolSize ds_type = {};
12760 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12761 ds_type.descriptorCount = 1;
12762
12763 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12764 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12765 ds_pool_ci.maxSets = 1;
12766 ds_pool_ci.poolSizeCount = 1;
12767 ds_pool_ci.pPoolSizes = &ds_type;
12768 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12769
12770 VkDescriptorPool ds_pool;
12771 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12772 ASSERT_VK_SUCCESS(err);
12773
12774 VkDescriptorSetLayoutBinding dsl_binding = {};
12775 dsl_binding.binding = 0;
12776 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12777 dsl_binding.descriptorCount = 1;
12778 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12779 dsl_binding.pImmutableSamplers = NULL;
12780
12781 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12782 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12783 ds_layout_ci.pNext = NULL;
12784 ds_layout_ci.bindingCount = 1;
12785 ds_layout_ci.pBindings = &dsl_binding;
12786
12787 VkDescriptorSetLayout ds_layout;
12788 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12789 ASSERT_VK_SUCCESS(err);
12790
12791 VkDescriptorSetAllocateInfo alloc_info = {};
12792 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12793 alloc_info.descriptorSetCount = 1;
12794 alloc_info.descriptorPool = ds_pool;
12795 alloc_info.pSetLayouts = &ds_layout;
12796 VkDescriptorSet descriptor_set;
12797 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12798 ASSERT_VK_SUCCESS(err);
12799
12800 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12801 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12802 pipeline_layout_ci.pNext = NULL;
12803 pipeline_layout_ci.setLayoutCount = 1;
12804 pipeline_layout_ci.pSetLayouts = &ds_layout;
12805 VkPipelineLayout pipeline_layout;
12806 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12807 ASSERT_VK_SUCCESS(err);
12808
12809 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012810 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
Tobin Ehlise0936662016-10-11 08:10:51 -060012811 ASSERT_TRUE(image.initialized());
12812 VkImageView view = image.targetView(tex_format);
12813
12814 VkDescriptorImageInfo image_info = {};
12815 image_info.imageView = view;
12816 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12817
12818 VkWriteDescriptorSet descriptor_write = {};
12819 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12820 descriptor_write.dstSet = descriptor_set;
12821 descriptor_write.dstBinding = 0;
12822 descriptor_write.descriptorCount = 1;
12823 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12824 descriptor_write.pImageInfo = &image_info;
12825
12826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12827 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12828 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12829 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12830 m_errorMonitor->VerifyFound();
12831
12832 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12833 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12834 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12835 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12836}
12837
Mark Mueller93b938f2016-08-18 10:27:40 -060012838TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012839 TEST_DESCRIPTION(
12840 "Use vkCmdExecuteCommands with invalid state "
12841 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012842
Tony Barbour1fa09702017-03-16 12:09:08 -060012843 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller93b938f2016-08-18 10:27:40 -060012844 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12845
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012846 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012847 const char *simultaneous_use_message2 =
12848 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12849 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012850
12851 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012852 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070012853 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012854 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12855 command_buffer_allocate_info.commandBufferCount = 1;
12856
12857 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012858 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012859 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12860 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012861 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012862 command_buffer_inheritance_info.renderPass = m_renderPass;
12863 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012864
Mark Mueller93b938f2016-08-18 10:27:40 -060012865 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012866 command_buffer_begin_info.flags =
12867 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012868 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12869
12870 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12871 vkEndCommandBuffer(secondary_command_buffer);
12872
Mark Mueller93b938f2016-08-18 10:27:40 -060012873 VkSubmitInfo submit_info = {};
12874 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12875 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012876 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012877
Mark Mueller4042b652016-09-05 22:52:21 -060012878 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012879 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12881 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012882 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012883 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012884 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12885 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012886
Dave Houltonfbf52152017-01-06 12:55:29 -070012887 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012888 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012889 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012890
Mark Mueller4042b652016-09-05 22:52:21 -060012891 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060012892 m_errorMonitor->SetUnexpectedError("commandBuffer must not be in the recording or pending state.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012893 m_errorMonitor->SetUnexpectedError(
12894 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12895 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012896 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012897 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12900 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012901 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012902 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12903 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012904
12905 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012906
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060012907 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be in the pending state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012908}
12909
Tony Barbour626994c2017-02-08 15:29:37 -070012910TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12911 TEST_DESCRIPTION(
12912 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12913 "errors");
12914 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12915 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 -060012916 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070012917
12918 VkCommandBuffer cmd_bufs[2];
12919 VkCommandBufferAllocateInfo alloc_info;
12920 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12921 alloc_info.pNext = NULL;
12922 alloc_info.commandBufferCount = 2;
Mike Schuchardt06304c22017-03-01 17:09:09 -070012923 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070012924 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12925 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12926
12927 VkCommandBufferBeginInfo cb_binfo;
12928 cb_binfo.pNext = NULL;
12929 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12930 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12931 cb_binfo.flags = 0;
12932 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12933 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12934 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12935 vkEndCommandBuffer(cmd_bufs[0]);
12936 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12937
12938 VkSubmitInfo submit_info = {};
12939 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12940 submit_info.commandBufferCount = 2;
12941 submit_info.pCommandBuffers = duplicates;
12942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12943 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12944 m_errorMonitor->VerifyFound();
12945 vkQueueWaitIdle(m_device->m_queue);
12946
12947 // Set one time use and now look for one time submit
12948 duplicates[0] = duplicates[1] = cmd_bufs[1];
12949 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12950 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12951 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12952 vkEndCommandBuffer(cmd_bufs[1]);
12953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12954 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12955 m_errorMonitor->VerifyFound();
12956 vkQueueWaitIdle(m_device->m_queue);
12957}
12958
Tobin Ehlisb093da82017-01-19 12:05:27 -070012959TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012960 TEST_DESCRIPTION(
12961 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12962 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012963
Tony Barbour1fa09702017-03-16 12:09:08 -060012964 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb093da82017-01-19 12:05:27 -070012965 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12966
12967 std::vector<const char *> device_extension_names;
12968 auto features = m_device->phy().features();
12969 // Make sure gs & ts are disabled
12970 features.geometryShader = false;
12971 features.tessellationShader = false;
12972 // The sacrificial device object
12973 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12974
12975 VkCommandPoolCreateInfo pool_create_info{};
12976 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12977 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12978
12979 VkCommandPool command_pool;
12980 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12981
12982 VkCommandBufferAllocateInfo cmd = {};
12983 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12984 cmd.pNext = NULL;
12985 cmd.commandPool = command_pool;
12986 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12987 cmd.commandBufferCount = 1;
12988
12989 VkCommandBuffer cmd_buffer;
12990 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12991 ASSERT_VK_SUCCESS(err);
12992
12993 VkEvent event;
12994 VkEventCreateInfo evci = {};
12995 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12996 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12997 ASSERT_VK_SUCCESS(result);
12998
12999 VkCommandBufferBeginInfo cbbi = {};
13000 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13001 vkBeginCommandBuffer(cmd_buffer, &cbbi);
13002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
13003 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
13004 m_errorMonitor->VerifyFound();
13005
13006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
13007 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
13008 m_errorMonitor->VerifyFound();
13009
13010 vkDestroyEvent(test_device.handle(), event, NULL);
13011 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
13012}
13013
Chris Forbesd70103a2017-04-13 11:34:09 -070013014TEST_F(VkLayerTest, EventInUseDestroyedSignaled) {
Tony Barbour1fa09702017-03-16 12:09:08 -060013015 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller917f6bc2016-08-30 10:57:19 -060013016 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13017
Tony Barbour552f6c02016-12-21 14:34:07 -070013018 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013019
13020 VkEvent event;
13021 VkEventCreateInfo event_create_info = {};
13022 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13023 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013024 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013025
Tony Barbour552f6c02016-12-21 14:34:07 -070013026 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013027 vkDestroyEvent(m_device->device(), event, nullptr);
13028
13029 VkSubmitInfo submit_info = {};
13030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13031 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013032 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070013033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013034 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13035 m_errorMonitor->VerifyFound();
Chris Forbesd70103a2017-04-13 11:34:09 -070013036}
Mark Muellerc8d441e2016-08-23 17:36:00 -060013037
Chris Forbesd70103a2017-04-13 11:34:09 -070013038TEST_F(VkLayerTest, InUseDestroyedSignaled) {
13039 TEST_DESCRIPTION(
13040 "Use vkCmdExecuteCommands with invalid state "
13041 "in primary and secondary command buffers. "
13042 "Delete objects that are inuse. Call VkQueueSubmit "
13043 "with an event that has been deleted.");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013044
Chris Forbesd70103a2017-04-13 11:34:09 -070013045 ASSERT_NO_FATAL_FAILURE(Init());
13046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13047
13048 m_errorMonitor->ExpectSuccess();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013049
Mark Mueller917f6bc2016-08-30 10:57:19 -060013050 VkSemaphoreCreateInfo semaphore_create_info = {};
13051 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13052 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013053 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013054 VkFenceCreateInfo fence_create_info = {};
13055 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13056 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013057 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013058
13059 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013060 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013061 descriptor_pool_type_count.descriptorCount = 1;
13062
13063 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13064 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13065 descriptor_pool_create_info.maxSets = 1;
13066 descriptor_pool_create_info.poolSizeCount = 1;
13067 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013068 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013069
13070 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013071 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013072
13073 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013074 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013075 descriptorset_layout_binding.descriptorCount = 1;
13076 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13077
13078 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013079 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013080 descriptorset_layout_create_info.bindingCount = 1;
13081 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13082
13083 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013084 ASSERT_VK_SUCCESS(
13085 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013086
13087 VkDescriptorSet descriptorset;
13088 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013089 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013090 descriptorset_allocate_info.descriptorSetCount = 1;
13091 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13092 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013093 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013094
Mark Mueller4042b652016-09-05 22:52:21 -060013095 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13096
13097 VkDescriptorBufferInfo buffer_info = {};
13098 buffer_info.buffer = buffer_test.GetBuffer();
13099 buffer_info.offset = 0;
13100 buffer_info.range = 1024;
13101
13102 VkWriteDescriptorSet write_descriptor_set = {};
13103 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13104 write_descriptor_set.dstSet = descriptorset;
13105 write_descriptor_set.descriptorCount = 1;
13106 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13107 write_descriptor_set.pBufferInfo = &buffer_info;
13108
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013109 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060013110
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013111 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13112 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013113
13114 VkPipelineObj pipe(m_device);
13115 pipe.AddColorAttachment();
13116 pipe.AddShader(&vs);
13117 pipe.AddShader(&fs);
13118
13119 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013120 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013121 pipeline_layout_create_info.setLayoutCount = 1;
13122 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13123
13124 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013125 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013126
13127 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
13128
Chris Forbesd70103a2017-04-13 11:34:09 -070013129 VkEvent event;
13130 VkEventCreateInfo event_create_info = {};
13131 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13132 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
13133
Tony Barbour552f6c02016-12-21 14:34:07 -070013134 m_commandBuffer->BeginCommandBuffer();
Chris Forbesd70103a2017-04-13 11:34:09 -070013135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013136 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060013137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013138 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13139 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13140 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013141
Tony Barbour552f6c02016-12-21 14:34:07 -070013142 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013143
Chris Forbesd70103a2017-04-13 11:34:09 -070013144 VkSubmitInfo submit_info = {};
13145 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13146 submit_info.commandBufferCount = 1;
13147 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013148 submit_info.signalSemaphoreCount = 1;
13149 submit_info.pSignalSemaphores = &semaphore;
13150 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013151 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060013152
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013154 vkDestroyEvent(m_device->device(), event, nullptr);
13155 m_errorMonitor->VerifyFound();
13156
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013158 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13159 m_errorMonitor->VerifyFound();
13160
Jeremy Hayes08369882017-02-02 10:31:06 -070013161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013162 vkDestroyFence(m_device->device(), fence, nullptr);
13163 m_errorMonitor->VerifyFound();
13164
Tobin Ehlis122207b2016-09-01 08:50:06 -070013165 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013166 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
13167 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013168 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013169 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
13170 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013171 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013172 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
13173 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013174 vkDestroyEvent(m_device->device(), event, nullptr);
13175 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013176 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013177 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13178}
13179
Tobin Ehlis2adda372016-09-01 08:51:06 -070013180TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
13181 TEST_DESCRIPTION("Delete in-use query pool.");
13182
Tony Barbour1fa09702017-03-16 12:09:08 -060013183 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis2adda372016-09-01 08:51:06 -070013184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13185
13186 VkQueryPool query_pool;
13187 VkQueryPoolCreateInfo query_pool_ci{};
13188 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
13189 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
13190 query_pool_ci.queryCount = 1;
13191 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070013192 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013193 // Reset query pool to create binding with cmd buffer
13194 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
13195
Tony Barbour552f6c02016-12-21 14:34:07 -070013196 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013197
13198 VkSubmitInfo submit_info = {};
13199 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13200 submit_info.commandBufferCount = 1;
13201 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13202 // Submit cmd buffer and then destroy query pool while in-flight
13203 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13204
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070013206 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13207 m_errorMonitor->VerifyFound();
13208
13209 vkQueueWaitIdle(m_device->m_queue);
13210 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013211 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013212 m_errorMonitor->SetUnexpectedError("Unable to remove QueryPool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070013213 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13214}
13215
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013216TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
13217 TEST_DESCRIPTION("Delete in-use pipeline.");
13218
Tony Barbour1fa09702017-03-16 12:09:08 -060013219 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13221
13222 // Empty pipeline layout used for binding PSO
13223 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13224 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13225 pipeline_layout_ci.setLayoutCount = 0;
13226 pipeline_layout_ci.pSetLayouts = NULL;
13227
13228 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013229 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013230 ASSERT_VK_SUCCESS(err);
13231
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013233 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013234 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13235 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013236 // Store pipeline handle so we can actually delete it before test finishes
13237 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013238 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013239 VkPipelineObj pipe(m_device);
13240 pipe.AddShader(&vs);
13241 pipe.AddShader(&fs);
13242 pipe.AddColorAttachment();
13243 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13244 delete_this_pipeline = pipe.handle();
13245
Tony Barbour552f6c02016-12-21 14:34:07 -070013246 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013247 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013248 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013249
Tony Barbour552f6c02016-12-21 14:34:07 -070013250 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013251
13252 VkSubmitInfo submit_info = {};
13253 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13254 submit_info.commandBufferCount = 1;
13255 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13256 // Submit cmd buffer and then pipeline destroyed while in-flight
13257 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013258 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013259 m_errorMonitor->VerifyFound();
13260 // Make sure queue finished and then actually delete pipeline
13261 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013262 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
13263 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013264 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
13265 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
13266}
13267
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013268TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
13269 TEST_DESCRIPTION("Delete in-use imageView.");
13270
Tony Barbour1fa09702017-03-16 12:09:08 -060013271 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13273
13274 VkDescriptorPoolSize ds_type_count;
13275 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13276 ds_type_count.descriptorCount = 1;
13277
13278 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13279 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13280 ds_pool_ci.maxSets = 1;
13281 ds_pool_ci.poolSizeCount = 1;
13282 ds_pool_ci.pPoolSizes = &ds_type_count;
13283
13284 VkDescriptorPool ds_pool;
13285 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13286 ASSERT_VK_SUCCESS(err);
13287
13288 VkSamplerCreateInfo sampler_ci = {};
13289 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13290 sampler_ci.pNext = NULL;
13291 sampler_ci.magFilter = VK_FILTER_NEAREST;
13292 sampler_ci.minFilter = VK_FILTER_NEAREST;
13293 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13294 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13295 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13296 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13297 sampler_ci.mipLodBias = 1.0;
13298 sampler_ci.anisotropyEnable = VK_FALSE;
13299 sampler_ci.maxAnisotropy = 1;
13300 sampler_ci.compareEnable = VK_FALSE;
13301 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13302 sampler_ci.minLod = 1.0;
13303 sampler_ci.maxLod = 1.0;
13304 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13305 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13306 VkSampler sampler;
13307
13308 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13309 ASSERT_VK_SUCCESS(err);
13310
13311 VkDescriptorSetLayoutBinding layout_binding;
13312 layout_binding.binding = 0;
13313 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13314 layout_binding.descriptorCount = 1;
13315 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13316 layout_binding.pImmutableSamplers = NULL;
13317
13318 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13319 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13320 ds_layout_ci.bindingCount = 1;
13321 ds_layout_ci.pBindings = &layout_binding;
13322 VkDescriptorSetLayout ds_layout;
13323 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13324 ASSERT_VK_SUCCESS(err);
13325
13326 VkDescriptorSetAllocateInfo alloc_info = {};
13327 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13328 alloc_info.descriptorSetCount = 1;
13329 alloc_info.descriptorPool = ds_pool;
13330 alloc_info.pSetLayouts = &ds_layout;
13331 VkDescriptorSet descriptor_set;
13332 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13333 ASSERT_VK_SUCCESS(err);
13334
13335 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13336 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13337 pipeline_layout_ci.pNext = NULL;
13338 pipeline_layout_ci.setLayoutCount = 1;
13339 pipeline_layout_ci.pSetLayouts = &ds_layout;
13340
13341 VkPipelineLayout pipeline_layout;
13342 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13343 ASSERT_VK_SUCCESS(err);
13344
13345 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013346 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 -060013347 ASSERT_TRUE(image.initialized());
13348
13349 VkImageView view;
13350 VkImageViewCreateInfo ivci = {};
13351 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13352 ivci.image = image.handle();
13353 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13354 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13355 ivci.subresourceRange.layerCount = 1;
13356 ivci.subresourceRange.baseMipLevel = 0;
13357 ivci.subresourceRange.levelCount = 1;
13358 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13359
13360 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13361 ASSERT_VK_SUCCESS(err);
13362
13363 VkDescriptorImageInfo image_info{};
13364 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13365 image_info.imageView = view;
13366 image_info.sampler = sampler;
13367
13368 VkWriteDescriptorSet descriptor_write = {};
13369 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13370 descriptor_write.dstSet = descriptor_set;
13371 descriptor_write.dstBinding = 0;
13372 descriptor_write.descriptorCount = 1;
13373 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13374 descriptor_write.pImageInfo = &image_info;
13375
13376 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13377
13378 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013379 char const *vsSource =
13380 "#version 450\n"
13381 "\n"
13382 "out gl_PerVertex { \n"
13383 " vec4 gl_Position;\n"
13384 "};\n"
13385 "void main(){\n"
13386 " gl_Position = vec4(1);\n"
13387 "}\n";
13388 char const *fsSource =
13389 "#version 450\n"
13390 "\n"
13391 "layout(set=0, binding=0) uniform sampler2D s;\n"
13392 "layout(location=0) out vec4 x;\n"
13393 "void main(){\n"
13394 " x = texture(s, vec2(1));\n"
13395 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013396 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13397 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13398 VkPipelineObj pipe(m_device);
13399 pipe.AddShader(&vs);
13400 pipe.AddShader(&fs);
13401 pipe.AddColorAttachment();
13402 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13403
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013405
Tony Barbour552f6c02016-12-21 14:34:07 -070013406 m_commandBuffer->BeginCommandBuffer();
13407 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013408 // Bind pipeline to cmd buffer
13409 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13410 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13411 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070013412
13413 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13414 VkRect2D scissor = {{0, 0}, {16, 16}};
13415 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13416 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13417
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013418 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013419 m_commandBuffer->EndRenderPass();
13420 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013421 // Submit cmd buffer then destroy sampler
13422 VkSubmitInfo submit_info = {};
13423 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13424 submit_info.commandBufferCount = 1;
13425 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13426 // Submit cmd buffer and then destroy imageView while in-flight
13427 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13428
13429 vkDestroyImageView(m_device->device(), view, nullptr);
13430 m_errorMonitor->VerifyFound();
13431 vkQueueWaitIdle(m_device->m_queue);
13432 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013433 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013434 m_errorMonitor->SetUnexpectedError("Unable to remove ImageView obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013435 vkDestroyImageView(m_device->device(), view, NULL);
13436 vkDestroySampler(m_device->device(), sampler, nullptr);
13437 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13438 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13439 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13440}
13441
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013442TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
13443 TEST_DESCRIPTION("Delete in-use bufferView.");
13444
Tony Barbour1fa09702017-03-16 12:09:08 -060013445 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13447
13448 VkDescriptorPoolSize ds_type_count;
13449 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13450 ds_type_count.descriptorCount = 1;
13451
13452 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13453 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13454 ds_pool_ci.maxSets = 1;
13455 ds_pool_ci.poolSizeCount = 1;
13456 ds_pool_ci.pPoolSizes = &ds_type_count;
13457
13458 VkDescriptorPool ds_pool;
13459 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13460 ASSERT_VK_SUCCESS(err);
13461
13462 VkDescriptorSetLayoutBinding layout_binding;
13463 layout_binding.binding = 0;
13464 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13465 layout_binding.descriptorCount = 1;
13466 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13467 layout_binding.pImmutableSamplers = NULL;
13468
13469 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13470 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13471 ds_layout_ci.bindingCount = 1;
13472 ds_layout_ci.pBindings = &layout_binding;
13473 VkDescriptorSetLayout ds_layout;
13474 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13475 ASSERT_VK_SUCCESS(err);
13476
13477 VkDescriptorSetAllocateInfo alloc_info = {};
13478 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13479 alloc_info.descriptorSetCount = 1;
13480 alloc_info.descriptorPool = ds_pool;
13481 alloc_info.pSetLayouts = &ds_layout;
13482 VkDescriptorSet descriptor_set;
13483 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13484 ASSERT_VK_SUCCESS(err);
13485
13486 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13487 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13488 pipeline_layout_ci.pNext = NULL;
13489 pipeline_layout_ci.setLayoutCount = 1;
13490 pipeline_layout_ci.pSetLayouts = &ds_layout;
13491
13492 VkPipelineLayout pipeline_layout;
13493 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13494 ASSERT_VK_SUCCESS(err);
13495
13496 VkBuffer buffer;
13497 uint32_t queue_family_index = 0;
13498 VkBufferCreateInfo buffer_create_info = {};
13499 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
13500 buffer_create_info.size = 1024;
13501 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
13502 buffer_create_info.queueFamilyIndexCount = 1;
13503 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
13504
13505 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
13506 ASSERT_VK_SUCCESS(err);
13507
13508 VkMemoryRequirements memory_reqs;
13509 VkDeviceMemory buffer_memory;
13510
13511 VkMemoryAllocateInfo memory_info = {};
13512 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13513 memory_info.allocationSize = 0;
13514 memory_info.memoryTypeIndex = 0;
13515
13516 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
13517 memory_info.allocationSize = memory_reqs.size;
13518 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
13519 ASSERT_TRUE(pass);
13520
13521 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
13522 ASSERT_VK_SUCCESS(err);
13523 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
13524 ASSERT_VK_SUCCESS(err);
13525
13526 VkBufferView view;
13527 VkBufferViewCreateInfo bvci = {};
13528 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
13529 bvci.buffer = buffer;
13530 bvci.format = VK_FORMAT_R8_UNORM;
13531 bvci.range = VK_WHOLE_SIZE;
13532
13533 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
13534 ASSERT_VK_SUCCESS(err);
13535
13536 VkWriteDescriptorSet descriptor_write = {};
13537 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13538 descriptor_write.dstSet = descriptor_set;
13539 descriptor_write.dstBinding = 0;
13540 descriptor_write.descriptorCount = 1;
13541 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13542 descriptor_write.pTexelBufferView = &view;
13543
13544 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13545
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013546 char const *vsSource =
13547 "#version 450\n"
13548 "\n"
13549 "out gl_PerVertex { \n"
13550 " vec4 gl_Position;\n"
13551 "};\n"
13552 "void main(){\n"
13553 " gl_Position = vec4(1);\n"
13554 "}\n";
13555 char const *fsSource =
13556 "#version 450\n"
13557 "\n"
13558 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
13559 "layout(location=0) out vec4 x;\n"
13560 "void main(){\n"
13561 " x = imageLoad(s, 0);\n"
13562 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013563 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13564 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13565 VkPipelineObj pipe(m_device);
13566 pipe.AddShader(&vs);
13567 pipe.AddShader(&fs);
13568 pipe.AddColorAttachment();
13569 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13570
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013572
Tony Barbour552f6c02016-12-21 14:34:07 -070013573 m_commandBuffer->BeginCommandBuffer();
13574 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013575 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13576 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13577 VkRect2D scissor = {{0, 0}, {16, 16}};
13578 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13579 // Bind pipeline to cmd buffer
13580 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13581 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13582 &descriptor_set, 0, nullptr);
13583 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013584 m_commandBuffer->EndRenderPass();
13585 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013586
13587 VkSubmitInfo submit_info = {};
13588 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13589 submit_info.commandBufferCount = 1;
13590 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13591 // Submit cmd buffer and then destroy bufferView while in-flight
13592 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13593
13594 vkDestroyBufferView(m_device->device(), view, nullptr);
13595 m_errorMonitor->VerifyFound();
13596 vkQueueWaitIdle(m_device->m_queue);
13597 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013598 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013599 m_errorMonitor->SetUnexpectedError("Unable to remove BufferView obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013600 vkDestroyBufferView(m_device->device(), view, NULL);
13601 vkDestroyBuffer(m_device->device(), buffer, NULL);
13602 vkFreeMemory(m_device->device(), buffer_memory, NULL);
13603 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13604 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13605 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13606}
13607
Tobin Ehlis209532e2016-09-07 13:52:18 -060013608TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
13609 TEST_DESCRIPTION("Delete in-use sampler.");
13610
Tony Barbour1fa09702017-03-16 12:09:08 -060013611 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis209532e2016-09-07 13:52:18 -060013612 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13613
13614 VkDescriptorPoolSize ds_type_count;
13615 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13616 ds_type_count.descriptorCount = 1;
13617
13618 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13619 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13620 ds_pool_ci.maxSets = 1;
13621 ds_pool_ci.poolSizeCount = 1;
13622 ds_pool_ci.pPoolSizes = &ds_type_count;
13623
13624 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013625 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013626 ASSERT_VK_SUCCESS(err);
13627
13628 VkSamplerCreateInfo sampler_ci = {};
13629 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13630 sampler_ci.pNext = NULL;
13631 sampler_ci.magFilter = VK_FILTER_NEAREST;
13632 sampler_ci.minFilter = VK_FILTER_NEAREST;
13633 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13634 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13635 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13636 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13637 sampler_ci.mipLodBias = 1.0;
13638 sampler_ci.anisotropyEnable = VK_FALSE;
13639 sampler_ci.maxAnisotropy = 1;
13640 sampler_ci.compareEnable = VK_FALSE;
13641 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13642 sampler_ci.minLod = 1.0;
13643 sampler_ci.maxLod = 1.0;
13644 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13645 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13646 VkSampler sampler;
13647
13648 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13649 ASSERT_VK_SUCCESS(err);
13650
13651 VkDescriptorSetLayoutBinding layout_binding;
13652 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013653 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013654 layout_binding.descriptorCount = 1;
13655 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13656 layout_binding.pImmutableSamplers = NULL;
13657
13658 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13659 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13660 ds_layout_ci.bindingCount = 1;
13661 ds_layout_ci.pBindings = &layout_binding;
13662 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013663 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013664 ASSERT_VK_SUCCESS(err);
13665
13666 VkDescriptorSetAllocateInfo alloc_info = {};
13667 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13668 alloc_info.descriptorSetCount = 1;
13669 alloc_info.descriptorPool = ds_pool;
13670 alloc_info.pSetLayouts = &ds_layout;
13671 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013672 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013673 ASSERT_VK_SUCCESS(err);
13674
13675 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13676 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13677 pipeline_layout_ci.pNext = NULL;
13678 pipeline_layout_ci.setLayoutCount = 1;
13679 pipeline_layout_ci.pSetLayouts = &ds_layout;
13680
13681 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013682 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013683 ASSERT_VK_SUCCESS(err);
13684
13685 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013686 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 -060013687 ASSERT_TRUE(image.initialized());
13688
13689 VkImageView view;
13690 VkImageViewCreateInfo ivci = {};
13691 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13692 ivci.image = image.handle();
13693 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13694 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13695 ivci.subresourceRange.layerCount = 1;
13696 ivci.subresourceRange.baseMipLevel = 0;
13697 ivci.subresourceRange.levelCount = 1;
13698 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13699
13700 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13701 ASSERT_VK_SUCCESS(err);
13702
13703 VkDescriptorImageInfo image_info{};
13704 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13705 image_info.imageView = view;
13706 image_info.sampler = sampler;
13707
13708 VkWriteDescriptorSet descriptor_write = {};
13709 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13710 descriptor_write.dstSet = descriptor_set;
13711 descriptor_write.dstBinding = 0;
13712 descriptor_write.descriptorCount = 1;
13713 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13714 descriptor_write.pImageInfo = &image_info;
13715
13716 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13717
13718 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013719 char const *vsSource =
13720 "#version 450\n"
13721 "\n"
13722 "out gl_PerVertex { \n"
13723 " vec4 gl_Position;\n"
13724 "};\n"
13725 "void main(){\n"
13726 " gl_Position = vec4(1);\n"
13727 "}\n";
13728 char const *fsSource =
13729 "#version 450\n"
13730 "\n"
13731 "layout(set=0, binding=0) uniform sampler2D s;\n"
13732 "layout(location=0) out vec4 x;\n"
13733 "void main(){\n"
13734 " x = texture(s, vec2(1));\n"
13735 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060013736 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13737 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13738 VkPipelineObj pipe(m_device);
13739 pipe.AddShader(&vs);
13740 pipe.AddShader(&fs);
13741 pipe.AddColorAttachment();
13742 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13743
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013745
Tony Barbour552f6c02016-12-21 14:34:07 -070013746 m_commandBuffer->BeginCommandBuffer();
13747 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013748 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013749 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13750 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13751 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070013752
13753 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13754 VkRect2D scissor = {{0, 0}, {16, 16}};
13755 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13756 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13757
Tobin Ehlis209532e2016-09-07 13:52:18 -060013758 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013759 m_commandBuffer->EndRenderPass();
13760 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060013761 // Submit cmd buffer then destroy sampler
13762 VkSubmitInfo submit_info = {};
13763 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13764 submit_info.commandBufferCount = 1;
13765 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13766 // Submit cmd buffer and then destroy sampler while in-flight
13767 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13768
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013769 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060013770 m_errorMonitor->VerifyFound();
13771 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070013772
Tobin Ehlis209532e2016-09-07 13:52:18 -060013773 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013774 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
13775 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013776 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060013777 vkDestroyImageView(m_device->device(), view, NULL);
13778 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13779 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13780 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13781}
13782
Mark Mueller1cd9f412016-08-25 13:23:52 -060013783TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013784 TEST_DESCRIPTION(
13785 "Call VkQueueSubmit with a semaphore that is already "
13786 "signaled but not waited on by the queue. Wait on a "
13787 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013788
Tony Barbour1fa09702017-03-16 12:09:08 -060013789 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller96a56d52016-08-24 10:28:05 -060013790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13791
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013792 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 -070013793 const char *invalid_fence_wait_message =
13794 " which has not been submitted on a Queue or during "
13795 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013796
Tony Barbour552f6c02016-12-21 14:34:07 -070013797 m_commandBuffer->BeginCommandBuffer();
13798 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060013799
13800 VkSemaphoreCreateInfo semaphore_create_info = {};
13801 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13802 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013803 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013804 VkSubmitInfo submit_info = {};
13805 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13806 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013807 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013808 submit_info.signalSemaphoreCount = 1;
13809 submit_info.pSignalSemaphores = &semaphore;
13810 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070013811 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060013812 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070013813 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070013814 m_commandBuffer->BeginCommandBuffer();
13815 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013817 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13818 m_errorMonitor->VerifyFound();
13819
Mark Mueller1cd9f412016-08-25 13:23:52 -060013820 VkFenceCreateInfo fence_create_info = {};
13821 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13822 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013823 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013824
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013826 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13827 m_errorMonitor->VerifyFound();
13828
Mark Mueller4042b652016-09-05 22:52:21 -060013829 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013830 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013831 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13832}
13833
Tobin Ehlis4af23302016-07-19 10:50:30 -060013834TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013835 TEST_DESCRIPTION(
13836 "Bind a secondary command buffer with with a framebuffer "
13837 "that does not match the framebuffer for the active "
13838 "renderpass.");
Tony Barbour1fa09702017-03-16 12:09:08 -060013839 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4af23302016-07-19 10:50:30 -060013840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13841
13842 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013843 VkAttachmentDescription attachment = {0,
13844 VK_FORMAT_B8G8R8A8_UNORM,
13845 VK_SAMPLE_COUNT_1_BIT,
13846 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13847 VK_ATTACHMENT_STORE_OP_STORE,
13848 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13849 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13850 VK_IMAGE_LAYOUT_UNDEFINED,
13851 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013853 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013854
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013855 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013856
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013857 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013858
13859 VkRenderPass rp;
13860 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13861 ASSERT_VK_SUCCESS(err);
13862
13863 // A compatible framebuffer.
13864 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013865 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 -060013866 ASSERT_TRUE(image.initialized());
13867
13868 VkImageViewCreateInfo ivci = {
13869 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13870 nullptr,
13871 0,
13872 image.handle(),
13873 VK_IMAGE_VIEW_TYPE_2D,
13874 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013875 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13876 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013877 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13878 };
13879 VkImageView view;
13880 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13881 ASSERT_VK_SUCCESS(err);
13882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013883 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013884 VkFramebuffer fb;
13885 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13886 ASSERT_VK_SUCCESS(err);
13887
13888 VkCommandBufferAllocateInfo cbai = {};
13889 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070013890 cbai.commandPool = m_commandPool->handle();
Tobin Ehlis4af23302016-07-19 10:50:30 -060013891 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13892 cbai.commandBufferCount = 1;
13893
13894 VkCommandBuffer sec_cb;
13895 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13896 ASSERT_VK_SUCCESS(err);
13897 VkCommandBufferBeginInfo cbbi = {};
13898 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013899 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013900 cbii.renderPass = renderPass();
13901 cbii.framebuffer = fb;
13902 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13903 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013904 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 -060013905 cbbi.pInheritanceInfo = &cbii;
13906 vkBeginCommandBuffer(sec_cb, &cbbi);
13907 vkEndCommandBuffer(sec_cb);
13908
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013909 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013910 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13911 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013912
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013914 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013915 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13916 m_errorMonitor->VerifyFound();
13917 // Cleanup
13918 vkDestroyImageView(m_device->device(), view, NULL);
13919 vkDestroyRenderPass(m_device->device(), rp, NULL);
13920 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13921}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013922
13923TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013924 TEST_DESCRIPTION(
13925 "If logicOp is available on the device, set it to an "
13926 "invalid value. If logicOp is not available, attempt to "
13927 "use it and verify that we see the correct error.");
Tony Barbour1fa09702017-03-16 12:09:08 -060013928 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013929 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13930
13931 auto features = m_device->phy().features();
13932 // Set the expected error depending on whether or not logicOp available
13933 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13935 "If logic operations feature not "
13936 "enabled, logicOpEnable must be "
13937 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013938 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013940 }
13941 // Create a pipeline using logicOp
13942 VkResult err;
13943
13944 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13945 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13946
13947 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013948 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013949 ASSERT_VK_SUCCESS(err);
13950
13951 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13952 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13953 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013954 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013955 vp_state_ci.pViewports = &vp;
13956 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013957 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013958 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013959
13960 VkPipelineShaderStageCreateInfo shaderStages[2];
13961 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013963 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13964 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013965 shaderStages[0] = vs.GetStageCreateInfo();
13966 shaderStages[1] = fs.GetStageCreateInfo();
13967
13968 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13969 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13970
13971 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13972 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13973 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13974
13975 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13976 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013977 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013978
13979 VkPipelineColorBlendAttachmentState att = {};
13980 att.blendEnable = VK_FALSE;
13981 att.colorWriteMask = 0xf;
13982
13983 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13984 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13985 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13986 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013987 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013988 cb_ci.attachmentCount = 1;
13989 cb_ci.pAttachments = &att;
13990
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013991 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13992 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13993 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13994
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013995 VkGraphicsPipelineCreateInfo gp_ci = {};
13996 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13997 gp_ci.stageCount = 2;
13998 gp_ci.pStages = shaderStages;
13999 gp_ci.pVertexInputState = &vi_ci;
14000 gp_ci.pInputAssemblyState = &ia_ci;
14001 gp_ci.pViewportState = &vp_state_ci;
14002 gp_ci.pRasterizationState = &rs_ci;
14003 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130014004 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014005 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14006 gp_ci.layout = pipeline_layout;
14007 gp_ci.renderPass = renderPass();
14008
14009 VkPipelineCacheCreateInfo pc_ci = {};
14010 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14011
14012 VkPipeline pipeline;
14013 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014014 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014015 ASSERT_VK_SUCCESS(err);
14016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014017 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014018 m_errorMonitor->VerifyFound();
14019 if (VK_SUCCESS == err) {
14020 vkDestroyPipeline(m_device->device(), pipeline, NULL);
14021 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014022 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
14023 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
14024}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014025
Mike Stroyanaccf7692015-05-12 16:00:45 -060014026#if GTEST_IS_THREADSAFE
14027struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014028 VkCommandBuffer commandBuffer;
Mike Stroyanca855662017-05-02 11:06:27 -060014029 VkDevice device;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014030 VkEvent event;
14031 bool bailout;
14032};
14033
Karl Schultz6addd812016-02-02 17:17:23 -070014034extern "C" void *AddToCommandBuffer(void *arg) {
14035 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014036
Mike Stroyana6d14942016-07-13 15:10:05 -060014037 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014038 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014039 if (data->bailout) {
14040 break;
14041 }
14042 }
14043 return NULL;
14044}
14045
Karl Schultz6addd812016-02-02 17:17:23 -070014046TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014047 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014048
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014050
Tony Barbour1fa09702017-03-16 12:09:08 -060014051 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanaccf7692015-05-12 16:00:45 -060014052 ASSERT_NO_FATAL_FAILURE(InitViewport());
14053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14054
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014055 // Calls AllocateCommandBuffers
14056 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014057
14058 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014059 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014060
14061 VkEventCreateInfo event_info;
14062 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014063 VkResult err;
14064
14065 memset(&event_info, 0, sizeof(event_info));
14066 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
14067
Chia-I Wuf7458c52015-10-26 21:10:41 +080014068 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014069 ASSERT_VK_SUCCESS(err);
14070
Mike Stroyanaccf7692015-05-12 16:00:45 -060014071 err = vkResetEvent(device(), event);
14072 ASSERT_VK_SUCCESS(err);
14073
14074 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014075 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014076 data.event = event;
14077 data.bailout = false;
14078 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060014079
14080 // First do some correct operations using multiple threads.
14081 // Add many entries to command buffer from another thread.
14082 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
14083 // Make non-conflicting calls from this thread at the same time.
14084 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060014085 uint32_t count;
14086 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060014087 }
14088 test_platform_thread_join(thread, NULL);
14089
14090 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060014091 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014092 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014093 // Add many entries to command buffer from this thread at the same time.
14094 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014095
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014096 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014097 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014098
Mike Stroyan10b8cb72016-01-22 15:22:03 -070014099 m_errorMonitor->SetBailout(NULL);
14100
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014101 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014102
Chia-I Wuf7458c52015-10-26 21:10:41 +080014103 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014104}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014105#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014106
Karl Schultz6addd812016-02-02 17:17:23 -070014107TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014108 TEST_DESCRIPTION(
14109 "Test that an error is produced for a spirv module "
14110 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120014111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014113
Tony Barbour1fa09702017-03-16 12:09:08 -060014114 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14116
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014117 VkShaderModule module;
14118 VkShaderModuleCreateInfo moduleCreateInfo;
14119 struct icd_spv_header spv;
14120
14121 spv.magic = ICD_SPV_MAGIC;
14122 spv.version = ICD_SPV_VERSION;
14123 spv.gen_magic = 0;
14124
14125 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14126 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014127 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014128 moduleCreateInfo.codeSize = 4;
14129 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014130 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014131
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014132 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014133}
14134
Karl Schultz6addd812016-02-02 17:17:23 -070014135TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014136 TEST_DESCRIPTION(
14137 "Test that an error is produced for a spirv module "
14138 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120014139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014141
Tony Barbour1fa09702017-03-16 12:09:08 -060014142 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14144
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014145 VkShaderModule module;
14146 VkShaderModuleCreateInfo moduleCreateInfo;
14147 struct icd_spv_header spv;
14148
14149 spv.magic = ~ICD_SPV_MAGIC;
14150 spv.version = ICD_SPV_VERSION;
14151 spv.gen_magic = 0;
14152
14153 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14154 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014155 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014156 moduleCreateInfo.codeSize = sizeof(spv) + 10;
14157 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014158 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014159
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014160 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014161}
14162
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014163#if 0
14164// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070014165TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070014166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014167 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014168
Tony Barbour1fa09702017-03-16 12:09:08 -060014169 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014170 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14171
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014172 VkShaderModule module;
14173 VkShaderModuleCreateInfo moduleCreateInfo;
14174 struct icd_spv_header spv;
14175
14176 spv.magic = ICD_SPV_MAGIC;
14177 spv.version = ~ICD_SPV_VERSION;
14178 spv.gen_magic = 0;
14179
14180 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14181 moduleCreateInfo.pNext = NULL;
14182
Karl Schultz6addd812016-02-02 17:17:23 -070014183 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014184 moduleCreateInfo.codeSize = sizeof(spv) + 10;
14185 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014186 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014187
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014188 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014189}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014190#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014191
Karl Schultz6addd812016-02-02 17:17:23 -070014192TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014193 TEST_DESCRIPTION(
14194 "Test that a warning is produced for a vertex output that "
14195 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014197
Tony Barbour1fa09702017-03-16 12:09:08 -060014198 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014199 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014200
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014201 char const *vsSource =
14202 "#version 450\n"
14203 "\n"
14204 "layout(location=0) out float x;\n"
14205 "out gl_PerVertex {\n"
14206 " vec4 gl_Position;\n"
14207 "};\n"
14208 "void main(){\n"
14209 " gl_Position = vec4(1);\n"
14210 " x = 0;\n"
14211 "}\n";
14212 char const *fsSource =
14213 "#version 450\n"
14214 "\n"
14215 "layout(location=0) out vec4 color;\n"
14216 "void main(){\n"
14217 " color = vec4(1);\n"
14218 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120014219
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014220 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14221 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014222
14223 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014224 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014225 pipe.AddShader(&vs);
14226 pipe.AddShader(&fs);
14227
Chris Forbes9f7ff632015-05-25 11:13:08 +120014228 VkDescriptorSetObj descriptorSet(m_device);
14229 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014230 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014231
Tony Barbour5781e8f2015-08-04 16:23:11 -060014232 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014233
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014234 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014235}
Chris Forbes9f7ff632015-05-25 11:13:08 +120014236
Mark Mueller098c9cb2016-09-08 09:01:57 -060014237TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
14238 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14239
Tony Barbour1fa09702017-03-16 12:09:08 -060014240 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014241 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14242
14243 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014244 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014245
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014246 char const *vsSource =
14247 "#version 450\n"
14248 "\n"
14249 "out gl_PerVertex {\n"
14250 " vec4 gl_Position;\n"
14251 "};\n"
14252 "void main(){\n"
14253 " gl_Position = vec4(1);\n"
14254 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014255
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014256 char const *fsSource =
14257 "#version 450\n"
14258 "\n"
14259 "layout (constant_id = 0) const float r = 0.0f;\n"
14260 "layout(location = 0) out vec4 uFragColor;\n"
14261 "void main(){\n"
14262 " uFragColor = vec4(r,1,0,1);\n"
14263 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014264
14265 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14266 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14267
14268 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14269 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14270
14271 VkPipelineLayout pipeline_layout;
14272 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14273
14274 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
14275 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
14276 vp_state_create_info.viewportCount = 1;
14277 VkViewport viewport = {};
14278 vp_state_create_info.pViewports = &viewport;
14279 vp_state_create_info.scissorCount = 1;
14280 VkRect2D scissors = {};
14281 vp_state_create_info.pScissors = &scissors;
14282
14283 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
14284
14285 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
14286 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
14287 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
14288 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
14289
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014290 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060014291
14292 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
14293 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14294
14295 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
14296 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14297 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14298
14299 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
14300 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
14301 rasterization_state_create_info.pNext = nullptr;
14302 rasterization_state_create_info.lineWidth = 1.0f;
14303 rasterization_state_create_info.rasterizerDiscardEnable = true;
14304
14305 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
14306 color_blend_attachment_state.blendEnable = VK_FALSE;
14307 color_blend_attachment_state.colorWriteMask = 0xf;
14308
14309 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
14310 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14311 color_blend_state_create_info.attachmentCount = 1;
14312 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
14313
14314 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
14315 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14316 graphicspipe_create_info.stageCount = 2;
14317 graphicspipe_create_info.pStages = shader_stage_create_info;
14318 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
14319 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
14320 graphicspipe_create_info.pViewportState = &vp_state_create_info;
14321 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
14322 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
14323 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
14324 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14325 graphicspipe_create_info.layout = pipeline_layout;
14326 graphicspipe_create_info.renderPass = renderPass();
14327
14328 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
14329 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14330
14331 VkPipelineCache pipelineCache;
14332 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
14333
14334 // This structure maps constant ids to data locations.
14335 const VkSpecializationMapEntry entry =
14336 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014337 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014338
14339 uint32_t data = 1;
14340
14341 // Set up the info describing spec map and data
14342 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014343 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060014344 };
14345 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
14346
14347 VkPipeline pipeline;
14348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
14349 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
14350 m_errorMonitor->VerifyFound();
14351
14352 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
14353 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14354}
14355
14356TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
14357 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14358
Tony Barbour1fa09702017-03-16 12:09:08 -060014359 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014360 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14361
14362 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
14363
14364 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
14365 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14366 descriptor_pool_type_count[0].descriptorCount = 1;
14367 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14368 descriptor_pool_type_count[1].descriptorCount = 1;
14369
14370 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14371 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14372 descriptor_pool_create_info.maxSets = 1;
14373 descriptor_pool_create_info.poolSizeCount = 2;
14374 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
14375 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14376
14377 VkDescriptorPool descriptorset_pool;
14378 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14379
14380 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14381 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14382 descriptorset_layout_binding.descriptorCount = 1;
14383 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070014384 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014385
14386 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14387 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14388 descriptorset_layout_create_info.bindingCount = 1;
14389 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14390
14391 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014392 ASSERT_VK_SUCCESS(
14393 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014394
14395 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14396 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14397 descriptorset_allocate_info.descriptorSetCount = 1;
14398 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14399 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14400 VkDescriptorSet descriptorset;
14401 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14402
14403 // Challenge core_validation with a non uniform buffer type.
14404 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
14405
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014406 char const *vsSource =
14407 "#version 450\n"
14408 "\n"
14409 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14410 " mat4 mvp;\n"
14411 "} ubuf;\n"
14412 "out gl_PerVertex {\n"
14413 " vec4 gl_Position;\n"
14414 "};\n"
14415 "void main(){\n"
14416 " gl_Position = ubuf.mvp * vec4(1);\n"
14417 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014418
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014419 char const *fsSource =
14420 "#version 450\n"
14421 "\n"
14422 "layout(location = 0) out vec4 uFragColor;\n"
14423 "void main(){\n"
14424 " uFragColor = vec4(0,1,0,1);\n"
14425 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014426
14427 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14428 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14429
14430 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14431 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14432 pipeline_layout_create_info.setLayoutCount = 1;
14433 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14434
14435 VkPipelineLayout pipeline_layout;
14436 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14437
14438 VkPipelineObj pipe(m_device);
14439 pipe.AddColorAttachment();
14440 pipe.AddShader(&vs);
14441 pipe.AddShader(&fs);
14442
14443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
14444 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14445 m_errorMonitor->VerifyFound();
14446
14447 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14448 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14449 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14450}
14451
14452TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
14453 TEST_DESCRIPTION(
14454 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
14455
Tony Barbour1fa09702017-03-16 12:09:08 -060014456 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14458
14459 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
14460
14461 VkDescriptorPoolSize descriptor_pool_type_count = {};
14462 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14463 descriptor_pool_type_count.descriptorCount = 1;
14464
14465 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14466 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14467 descriptor_pool_create_info.maxSets = 1;
14468 descriptor_pool_create_info.poolSizeCount = 1;
14469 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
14470 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14471
14472 VkDescriptorPool descriptorset_pool;
14473 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14474
14475 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14476 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14477 descriptorset_layout_binding.descriptorCount = 1;
14478 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
14479 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070014480 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014481
14482 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14483 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14484 descriptorset_layout_create_info.bindingCount = 1;
14485 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14486
14487 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014488 ASSERT_VK_SUCCESS(
14489 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014490
14491 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14492 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14493 descriptorset_allocate_info.descriptorSetCount = 1;
14494 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14495 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14496 VkDescriptorSet descriptorset;
14497 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14498
14499 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
14500
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014501 char const *vsSource =
14502 "#version 450\n"
14503 "\n"
14504 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14505 " mat4 mvp;\n"
14506 "} ubuf;\n"
14507 "out gl_PerVertex {\n"
14508 " vec4 gl_Position;\n"
14509 "};\n"
14510 "void main(){\n"
14511 " gl_Position = ubuf.mvp * vec4(1);\n"
14512 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014513
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014514 char const *fsSource =
14515 "#version 450\n"
14516 "\n"
14517 "layout(location = 0) out vec4 uFragColor;\n"
14518 "void main(){\n"
14519 " uFragColor = vec4(0,1,0,1);\n"
14520 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014521
14522 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14523 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14524
14525 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14526 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14527 pipeline_layout_create_info.setLayoutCount = 1;
14528 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14529
14530 VkPipelineLayout pipeline_layout;
14531 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14532
14533 VkPipelineObj pipe(m_device);
14534 pipe.AddColorAttachment();
14535 pipe.AddShader(&vs);
14536 pipe.AddShader(&fs);
14537
14538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
14539 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14540 m_errorMonitor->VerifyFound();
14541
14542 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14543 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14544 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14545}
14546
14547TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014548 TEST_DESCRIPTION(
14549 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
14550 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014551
Tony Barbour1fa09702017-03-16 12:09:08 -060014552 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014553 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14554
14555 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014556 "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 -060014557
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014558 char const *vsSource =
14559 "#version 450\n"
14560 "\n"
14561 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14562 "out gl_PerVertex {\n"
14563 " vec4 gl_Position;\n"
14564 "};\n"
14565 "void main(){\n"
14566 " gl_Position = vec4(consts.x);\n"
14567 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014568
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014569 char const *fsSource =
14570 "#version 450\n"
14571 "\n"
14572 "layout(location = 0) out vec4 uFragColor;\n"
14573 "void main(){\n"
14574 " uFragColor = vec4(0,1,0,1);\n"
14575 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014576
14577 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14578 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14579
14580 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14581 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14582
14583 // Set up a push constant range
14584 VkPushConstantRange push_constant_ranges = {};
14585 // Set to the wrong stage to challenge core_validation
14586 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
14587 push_constant_ranges.size = 4;
14588
14589 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
14590 pipeline_layout_create_info.pushConstantRangeCount = 1;
14591
14592 VkPipelineLayout pipeline_layout;
14593 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14594
14595 VkPipelineObj pipe(m_device);
14596 pipe.AddColorAttachment();
14597 pipe.AddShader(&vs);
14598 pipe.AddShader(&fs);
14599
14600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
14601 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14602 m_errorMonitor->VerifyFound();
14603
14604 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14605}
14606
14607TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
14608 TEST_DESCRIPTION(
14609 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
14610
Tony Barbour1fa09702017-03-16 12:09:08 -060014611 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014612 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14613
14614 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014615 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014616
14617 // Some awkward steps are required to test with custom device features.
14618 std::vector<const char *> device_extension_names;
14619 auto features = m_device->phy().features();
14620 // Disable support for 64 bit floats
14621 features.shaderFloat64 = false;
14622 // The sacrificial device object
14623 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
14624
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014625 char const *vsSource =
14626 "#version 450\n"
14627 "\n"
14628 "out gl_PerVertex {\n"
14629 " vec4 gl_Position;\n"
14630 "};\n"
14631 "void main(){\n"
14632 " gl_Position = vec4(1);\n"
14633 "}\n";
14634 char const *fsSource =
14635 "#version 450\n"
14636 "\n"
14637 "layout(location=0) out vec4 color;\n"
14638 "void main(){\n"
14639 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
14640 " color = vec4(green);\n"
14641 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014642
14643 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14644 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14645
14646 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014647
14648 VkPipelineObj pipe(&test_device);
14649 pipe.AddColorAttachment();
14650 pipe.AddShader(&vs);
14651 pipe.AddShader(&fs);
14652
14653 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14654 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14655 VkPipelineLayout pipeline_layout;
14656 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14657
14658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
14659 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
14660 m_errorMonitor->VerifyFound();
14661
14662 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
14663}
14664
Mark Lobodzinski20832822017-03-24 14:49:45 -060014665TEST_F(VkLayerTest, CreateShaderModuleCheckBadCapability) {
14666 TEST_DESCRIPTION("Create a shader in which a capability declared by the shader is not supported.");
14667 // Note that this failure message comes from spirv-tools, specifically the validator.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014668
Tony Barbour1fa09702017-03-16 12:09:08 -060014669 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14671
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014672 char const *vsSource =
14673 "#version 450\n"
14674 "\n"
14675 "out gl_PerVertex {\n"
14676 " vec4 gl_Position;\n"
14677 "};\n"
14678 "layout(xfb_buffer = 1) out;"
14679 "void main(){\n"
14680 " gl_Position = vec4(1);\n"
14681 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014682
Mark Lobodzinski20832822017-03-24 14:49:45 -060014683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Capability value 53 is not allowed by Vulkan");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014684
Mark Lobodzinski20832822017-03-24 14:49:45 -060014685 std::vector<unsigned int> spv;
14686 VkShaderModuleCreateInfo module_create_info;
14687 VkShaderModule shader_module;
14688 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14689 module_create_info.pNext = NULL;
14690 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, spv);
14691 module_create_info.pCode = spv.data();
14692 module_create_info.codeSize = spv.size() * sizeof(unsigned int);
14693 module_create_info.flags = 0;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014694
Mark Lobodzinski20832822017-03-24 14:49:45 -060014695 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014696
Mark Lobodzinski20832822017-03-24 14:49:45 -060014697 m_errorMonitor->VerifyFound();
Mark Mueller098c9cb2016-09-08 09:01:57 -060014698}
14699
Karl Schultz6addd812016-02-02 17:17:23 -070014700TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014701 TEST_DESCRIPTION(
14702 "Test that an error is produced for a fragment shader input "
14703 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120014704
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014706
Tony Barbour1fa09702017-03-16 12:09:08 -060014707 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014708 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014709
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014710 char const *vsSource =
14711 "#version 450\n"
14712 "\n"
14713 "out gl_PerVertex {\n"
14714 " vec4 gl_Position;\n"
14715 "};\n"
14716 "void main(){\n"
14717 " gl_Position = vec4(1);\n"
14718 "}\n";
14719 char const *fsSource =
14720 "#version 450\n"
14721 "\n"
14722 "layout(location=0) in float x;\n"
14723 "layout(location=0) out vec4 color;\n"
14724 "void main(){\n"
14725 " color = vec4(x);\n"
14726 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120014727
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014728 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14729 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014730
14731 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014732 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014733 pipe.AddShader(&vs);
14734 pipe.AddShader(&fs);
14735
Chris Forbes59cb88d2015-05-25 11:13:13 +120014736 VkDescriptorSetObj descriptorSet(m_device);
14737 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014738 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014739
Tony Barbour5781e8f2015-08-04 16:23:11 -060014740 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014741
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014742 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014743}
14744
Karl Schultz6addd812016-02-02 17:17:23 -070014745TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014746 TEST_DESCRIPTION(
14747 "Test that an error is produced for a fragment shader input "
14748 "within an interace block, which is not present in the outputs "
14749 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014751
Tony Barbour1fa09702017-03-16 12:09:08 -060014752 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14754
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014755 char const *vsSource =
14756 "#version 450\n"
14757 "\n"
14758 "out gl_PerVertex {\n"
14759 " vec4 gl_Position;\n"
14760 "};\n"
14761 "void main(){\n"
14762 " gl_Position = vec4(1);\n"
14763 "}\n";
14764 char const *fsSource =
14765 "#version 450\n"
14766 "\n"
14767 "in block { layout(location=0) float x; } ins;\n"
14768 "layout(location=0) out vec4 color;\n"
14769 "void main(){\n"
14770 " color = vec4(ins.x);\n"
14771 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014772
14773 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14774 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14775
14776 VkPipelineObj pipe(m_device);
14777 pipe.AddColorAttachment();
14778 pipe.AddShader(&vs);
14779 pipe.AddShader(&fs);
14780
14781 VkDescriptorSetObj descriptorSet(m_device);
14782 descriptorSet.AppendDummy();
14783 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14784
14785 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14786
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014787 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014788}
14789
Karl Schultz6addd812016-02-02 17:17:23 -070014790TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014791 TEST_DESCRIPTION(
14792 "Test that an error is produced for mismatched array sizes "
14793 "across the vertex->fragment shader interface");
14794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14795 "Type mismatch on location 0.0: 'ptr to "
14796 "output arr[2] of float32' vs 'ptr to "
14797 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130014798
Tony Barbour1fa09702017-03-16 12:09:08 -060014799 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes0036fd12016-01-26 14:19:49 +130014800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14801
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014802 char const *vsSource =
14803 "#version 450\n"
14804 "\n"
14805 "layout(location=0) out float x[2];\n"
14806 "out gl_PerVertex {\n"
14807 " vec4 gl_Position;\n"
14808 "};\n"
14809 "void main(){\n"
14810 " x[0] = 0; x[1] = 0;\n"
14811 " gl_Position = vec4(1);\n"
14812 "}\n";
14813 char const *fsSource =
14814 "#version 450\n"
14815 "\n"
14816 "layout(location=0) in float x[1];\n"
14817 "layout(location=0) out vec4 color;\n"
14818 "void main(){\n"
14819 " color = vec4(x[0]);\n"
14820 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014821
14822 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14823 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14824
14825 VkPipelineObj pipe(m_device);
14826 pipe.AddColorAttachment();
14827 pipe.AddShader(&vs);
14828 pipe.AddShader(&fs);
14829
14830 VkDescriptorSetObj descriptorSet(m_device);
14831 descriptorSet.AppendDummy();
14832 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14833
14834 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14835
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014836 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014837}
14838
Karl Schultz6addd812016-02-02 17:17:23 -070014839TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014840 TEST_DESCRIPTION(
14841 "Test that an error is produced for mismatched types across "
14842 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014844
Tony Barbour1fa09702017-03-16 12:09:08 -060014845 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014846 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014847
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014848 char const *vsSource =
14849 "#version 450\n"
14850 "\n"
14851 "layout(location=0) out int x;\n"
14852 "out gl_PerVertex {\n"
14853 " vec4 gl_Position;\n"
14854 "};\n"
14855 "void main(){\n"
14856 " x = 0;\n"
14857 " gl_Position = vec4(1);\n"
14858 "}\n";
14859 char const *fsSource =
14860 "#version 450\n"
14861 "\n"
14862 "layout(location=0) in float x;\n" /* VS writes int */
14863 "layout(location=0) out vec4 color;\n"
14864 "void main(){\n"
14865 " color = vec4(x);\n"
14866 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014867
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014868 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14869 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014870
14871 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014872 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014873 pipe.AddShader(&vs);
14874 pipe.AddShader(&fs);
14875
Chris Forbesb56af562015-05-25 11:13:17 +120014876 VkDescriptorSetObj descriptorSet(m_device);
14877 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014878 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014879
Tony Barbour5781e8f2015-08-04 16:23:11 -060014880 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014881
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014882 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014883}
14884
Karl Schultz6addd812016-02-02 17:17:23 -070014885TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014886 TEST_DESCRIPTION(
14887 "Test that an error is produced for mismatched types across "
14888 "the vertex->fragment shader interface, when the variable is contained within "
14889 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014891
Tony Barbour1fa09702017-03-16 12:09:08 -060014892 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14894
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014895 char const *vsSource =
14896 "#version 450\n"
14897 "\n"
14898 "out block { layout(location=0) int x; } outs;\n"
14899 "out gl_PerVertex {\n"
14900 " vec4 gl_Position;\n"
14901 "};\n"
14902 "void main(){\n"
14903 " outs.x = 0;\n"
14904 " gl_Position = vec4(1);\n"
14905 "}\n";
14906 char const *fsSource =
14907 "#version 450\n"
14908 "\n"
14909 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14910 "layout(location=0) out vec4 color;\n"
14911 "void main(){\n"
14912 " color = vec4(ins.x);\n"
14913 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014914
14915 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14916 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14917
14918 VkPipelineObj pipe(m_device);
14919 pipe.AddColorAttachment();
14920 pipe.AddShader(&vs);
14921 pipe.AddShader(&fs);
14922
14923 VkDescriptorSetObj descriptorSet(m_device);
14924 descriptorSet.AppendDummy();
14925 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14926
14927 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14928
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014929 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014930}
14931
14932TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014933 TEST_DESCRIPTION(
14934 "Test that an error is produced for location mismatches across "
14935 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14936 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014937 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 +130014938
Tony Barbour1fa09702017-03-16 12:09:08 -060014939 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130014940 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14941
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014942 char const *vsSource =
14943 "#version 450\n"
14944 "\n"
14945 "out block { layout(location=1) float x; } outs;\n"
14946 "out gl_PerVertex {\n"
14947 " vec4 gl_Position;\n"
14948 "};\n"
14949 "void main(){\n"
14950 " outs.x = 0;\n"
14951 " gl_Position = vec4(1);\n"
14952 "}\n";
14953 char const *fsSource =
14954 "#version 450\n"
14955 "\n"
14956 "in block { layout(location=0) float x; } ins;\n"
14957 "layout(location=0) out vec4 color;\n"
14958 "void main(){\n"
14959 " color = vec4(ins.x);\n"
14960 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014961
14962 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14963 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14964
14965 VkPipelineObj pipe(m_device);
14966 pipe.AddColorAttachment();
14967 pipe.AddShader(&vs);
14968 pipe.AddShader(&fs);
14969
14970 VkDescriptorSetObj descriptorSet(m_device);
14971 descriptorSet.AppendDummy();
14972 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14973
14974 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14975
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014976 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014977}
14978
14979TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014980 TEST_DESCRIPTION(
14981 "Test that an error is produced for component mismatches across the "
14982 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14983 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014984 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 +130014985
Tony Barbour1fa09702017-03-16 12:09:08 -060014986 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130014987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14988
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014989 char const *vsSource =
14990 "#version 450\n"
14991 "\n"
14992 "out block { layout(location=0, component=0) float x; } outs;\n"
14993 "out gl_PerVertex {\n"
14994 " vec4 gl_Position;\n"
14995 "};\n"
14996 "void main(){\n"
14997 " outs.x = 0;\n"
14998 " gl_Position = vec4(1);\n"
14999 "}\n";
15000 char const *fsSource =
15001 "#version 450\n"
15002 "\n"
15003 "in block { layout(location=0, component=1) float x; } ins;\n"
15004 "layout(location=0) out vec4 color;\n"
15005 "void main(){\n"
15006 " color = vec4(ins.x);\n"
15007 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015008
15009 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15010 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15011
15012 VkPipelineObj pipe(m_device);
15013 pipe.AddColorAttachment();
15014 pipe.AddShader(&vs);
15015 pipe.AddShader(&fs);
15016
15017 VkDescriptorSetObj descriptorSet(m_device);
15018 descriptorSet.AppendDummy();
15019 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15020
15021 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15022
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015023 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130015024}
15025
Chris Forbes1f3b0152016-11-30 12:48:40 +130015026TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
15027 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15028
Tony Barbour1fa09702017-03-16 12:09:08 -060015029 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes1f3b0152016-11-30 12:48:40 +130015030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15031
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015032 char const *vsSource =
15033 "#version 450\n"
15034 "layout(location=0) out mediump float x;\n"
15035 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15036 char const *fsSource =
15037 "#version 450\n"
15038 "layout(location=0) in highp float x;\n"
15039 "layout(location=0) out vec4 color;\n"
15040 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130015041
15042 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15043 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15044
15045 VkPipelineObj pipe(m_device);
15046 pipe.AddColorAttachment();
15047 pipe.AddShader(&vs);
15048 pipe.AddShader(&fs);
15049
15050 VkDescriptorSetObj descriptorSet(m_device);
15051 descriptorSet.AppendDummy();
15052 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15053
15054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15055
15056 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15057
15058 m_errorMonitor->VerifyFound();
15059}
15060
Chris Forbes870a39e2016-11-30 12:55:56 +130015061TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
15062 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15063
Tony Barbour1fa09702017-03-16 12:09:08 -060015064 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes870a39e2016-11-30 12:55:56 +130015065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15066
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015067 char const *vsSource =
15068 "#version 450\n"
15069 "out block { layout(location=0) mediump float x; };\n"
15070 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15071 char const *fsSource =
15072 "#version 450\n"
15073 "in block { layout(location=0) highp float x; };\n"
15074 "layout(location=0) out vec4 color;\n"
15075 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130015076
15077 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15078 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15079
15080 VkPipelineObj pipe(m_device);
15081 pipe.AddColorAttachment();
15082 pipe.AddShader(&vs);
15083 pipe.AddShader(&fs);
15084
15085 VkDescriptorSetObj descriptorSet(m_device);
15086 descriptorSet.AppendDummy();
15087 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15088
15089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15090
15091 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15092
15093 m_errorMonitor->VerifyFound();
15094}
15095
Karl Schultz6addd812016-02-02 17:17:23 -070015096TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015097 TEST_DESCRIPTION(
15098 "Test that a warning is produced for a vertex attribute which is "
15099 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015101
Tony Barbour1fa09702017-03-16 12:09:08 -060015102 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015103 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120015104
15105 VkVertexInputBindingDescription input_binding;
15106 memset(&input_binding, 0, sizeof(input_binding));
15107
15108 VkVertexInputAttributeDescription input_attrib;
15109 memset(&input_attrib, 0, sizeof(input_attrib));
15110 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15111
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015112 char const *vsSource =
15113 "#version 450\n"
15114 "\n"
15115 "out gl_PerVertex {\n"
15116 " vec4 gl_Position;\n"
15117 "};\n"
15118 "void main(){\n"
15119 " gl_Position = vec4(1);\n"
15120 "}\n";
15121 char const *fsSource =
15122 "#version 450\n"
15123 "\n"
15124 "layout(location=0) out vec4 color;\n"
15125 "void main(){\n"
15126 " color = vec4(1);\n"
15127 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120015128
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015129 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15130 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120015131
15132 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015133 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120015134 pipe.AddShader(&vs);
15135 pipe.AddShader(&fs);
15136
15137 pipe.AddVertexInputBindings(&input_binding, 1);
15138 pipe.AddVertexInputAttribs(&input_attrib, 1);
15139
Chris Forbesde136e02015-05-25 11:13:28 +120015140 VkDescriptorSetObj descriptorSet(m_device);
15141 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015142 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120015143
Tony Barbour5781e8f2015-08-04 16:23:11 -060015144 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120015145
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015146 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120015147}
15148
Karl Schultz6addd812016-02-02 17:17:23 -070015149TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015150 TEST_DESCRIPTION(
15151 "Test that a warning is produced for a location mismatch on "
15152 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015154
Tony Barbour1fa09702017-03-16 12:09:08 -060015155 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes7d83cd52016-01-15 11:32:03 +130015156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15157
15158 VkVertexInputBindingDescription input_binding;
15159 memset(&input_binding, 0, sizeof(input_binding));
15160
15161 VkVertexInputAttributeDescription input_attrib;
15162 memset(&input_attrib, 0, sizeof(input_attrib));
15163 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15164
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015165 char const *vsSource =
15166 "#version 450\n"
15167 "\n"
15168 "layout(location=1) in float x;\n"
15169 "out gl_PerVertex {\n"
15170 " vec4 gl_Position;\n"
15171 "};\n"
15172 "void main(){\n"
15173 " gl_Position = vec4(x);\n"
15174 "}\n";
15175 char const *fsSource =
15176 "#version 450\n"
15177 "\n"
15178 "layout(location=0) out vec4 color;\n"
15179 "void main(){\n"
15180 " color = vec4(1);\n"
15181 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130015182
15183 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15184 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15185
15186 VkPipelineObj pipe(m_device);
15187 pipe.AddColorAttachment();
15188 pipe.AddShader(&vs);
15189 pipe.AddShader(&fs);
15190
15191 pipe.AddVertexInputBindings(&input_binding, 1);
15192 pipe.AddVertexInputAttribs(&input_attrib, 1);
15193
15194 VkDescriptorSetObj descriptorSet(m_device);
15195 descriptorSet.AppendDummy();
15196 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15197
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015198 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015199 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15200
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015201 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130015202}
15203
Karl Schultz6addd812016-02-02 17:17:23 -070015204TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015205 TEST_DESCRIPTION(
15206 "Test that an error is produced for a vertex shader input which is not "
15207 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15209 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015210
Tony Barbour1fa09702017-03-16 12:09:08 -060015211 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120015213
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015214 char const *vsSource =
15215 "#version 450\n"
15216 "\n"
15217 "layout(location=0) in vec4 x;\n" /* not provided */
15218 "out gl_PerVertex {\n"
15219 " vec4 gl_Position;\n"
15220 "};\n"
15221 "void main(){\n"
15222 " gl_Position = x;\n"
15223 "}\n";
15224 char const *fsSource =
15225 "#version 450\n"
15226 "\n"
15227 "layout(location=0) out vec4 color;\n"
15228 "void main(){\n"
15229 " color = vec4(1);\n"
15230 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120015231
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015232 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15233 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120015234
15235 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015236 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120015237 pipe.AddShader(&vs);
15238 pipe.AddShader(&fs);
15239
Chris Forbes62e8e502015-05-25 11:13:29 +120015240 VkDescriptorSetObj descriptorSet(m_device);
15241 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015242 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120015243
Tony Barbour5781e8f2015-08-04 16:23:11 -060015244 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120015245
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015246 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120015247}
15248
Karl Schultz6addd812016-02-02 17:17:23 -070015249TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015250 TEST_DESCRIPTION(
15251 "Test that an error is produced for a mismatch between the "
15252 "fundamental type (float/int/uint) of an attribute and the "
15253 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060015254 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 -060015255
Tony Barbour1fa09702017-03-16 12:09:08 -060015256 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015258
15259 VkVertexInputBindingDescription input_binding;
15260 memset(&input_binding, 0, sizeof(input_binding));
15261
15262 VkVertexInputAttributeDescription input_attrib;
15263 memset(&input_attrib, 0, sizeof(input_attrib));
15264 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15265
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015266 char const *vsSource =
15267 "#version 450\n"
15268 "\n"
15269 "layout(location=0) in int x;\n" /* attrib provided float */
15270 "out gl_PerVertex {\n"
15271 " vec4 gl_Position;\n"
15272 "};\n"
15273 "void main(){\n"
15274 " gl_Position = vec4(x);\n"
15275 "}\n";
15276 char const *fsSource =
15277 "#version 450\n"
15278 "\n"
15279 "layout(location=0) out vec4 color;\n"
15280 "void main(){\n"
15281 " color = vec4(1);\n"
15282 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120015283
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015284 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15285 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015286
15287 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015288 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015289 pipe.AddShader(&vs);
15290 pipe.AddShader(&fs);
15291
15292 pipe.AddVertexInputBindings(&input_binding, 1);
15293 pipe.AddVertexInputAttribs(&input_attrib, 1);
15294
Chris Forbesc97d98e2015-05-25 11:13:31 +120015295 VkDescriptorSetObj descriptorSet(m_device);
15296 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015297 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015298
Tony Barbour5781e8f2015-08-04 16:23:11 -060015299 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015300
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015301 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015302}
15303
Chris Forbesc68b43c2016-04-06 11:18:47 +120015304TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015305 TEST_DESCRIPTION(
15306 "Test that an error is produced for a pipeline containing multiple "
15307 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15309 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120015310
Tony Barbour1fa09702017-03-16 12:09:08 -060015311 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc68b43c2016-04-06 11:18:47 +120015312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15313
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015314 char const *vsSource =
15315 "#version 450\n"
15316 "\n"
15317 "out gl_PerVertex {\n"
15318 " vec4 gl_Position;\n"
15319 "};\n"
15320 "void main(){\n"
15321 " gl_Position = vec4(1);\n"
15322 "}\n";
15323 char const *fsSource =
15324 "#version 450\n"
15325 "\n"
15326 "layout(location=0) out vec4 color;\n"
15327 "void main(){\n"
15328 " color = vec4(1);\n"
15329 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120015330
15331 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15332 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15333
15334 VkPipelineObj pipe(m_device);
15335 pipe.AddColorAttachment();
15336 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015337 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120015338 pipe.AddShader(&fs);
15339
15340 VkDescriptorSetObj descriptorSet(m_device);
15341 descriptorSet.AppendDummy();
15342 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15343
15344 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15345
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015346 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120015347}
15348
Chris Forbes82ff92a2016-09-09 10:50:24 +120015349TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120015351
Tony Barbour1fa09702017-03-16 12:09:08 -060015352 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes82ff92a2016-09-09 10:50:24 +120015353 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015355 char const *vsSource =
15356 "#version 450\n"
15357 "out gl_PerVertex {\n"
15358 " vec4 gl_Position;\n"
15359 "};\n"
15360 "void main(){\n"
15361 " gl_Position = vec4(0);\n"
15362 "}\n";
15363 char const *fsSource =
15364 "#version 450\n"
15365 "\n"
15366 "layout(location=0) out vec4 color;\n"
15367 "void main(){\n"
15368 " color = vec4(1);\n"
15369 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120015370
15371 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15372 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
15373
15374 VkPipelineObj pipe(m_device);
15375 pipe.AddColorAttachment();
15376 pipe.AddShader(&vs);
15377 pipe.AddShader(&fs);
15378
15379 VkDescriptorSetObj descriptorSet(m_device);
15380 descriptorSet.AppendDummy();
15381 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15382
15383 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15384
15385 m_errorMonitor->VerifyFound();
15386}
15387
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015388TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15390 "pDepthStencilState is NULL when rasterization is enabled and subpass "
15391 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015392
Tony Barbour1fa09702017-03-16 12:09:08 -060015393 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015394 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15395
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015396 char const *vsSource =
15397 "#version 450\n"
15398 "void main(){ gl_Position = vec4(0); }\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 Forbesae9d8cd2016-09-13 16:32:57 +120015406
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 VkDescriptorSetObj descriptorSet(m_device);
15416 descriptorSet.AppendDummy();
15417 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15418
15419 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015420 {
15421 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15422 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15423 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015424 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015425 {
15426 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15427 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15428 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015429 },
15430 };
15431 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015432 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015433 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015434 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
15435 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015436 VkRenderPass rp;
15437 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15438 ASSERT_VK_SUCCESS(err);
15439
15440 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
15441
15442 m_errorMonitor->VerifyFound();
15443
15444 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15445}
15446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015447TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015448 TEST_DESCRIPTION(
15449 "Test that an error is produced for a variable output from "
15450 "the TCS without the patch decoration, but consumed in the TES "
15451 "with the decoration.");
15452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15453 "is per-vertex in tessellation control shader stage "
15454 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120015455
Tony Barbour1fa09702017-03-16 12:09:08 -060015456 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa0193bc2016-04-04 19:19:47 +120015457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15458
Chris Forbesc1e852d2016-04-04 19:26:42 +120015459 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070015460 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120015461 return;
15462 }
15463
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015464 char const *vsSource =
15465 "#version 450\n"
15466 "void main(){}\n";
15467 char const *tcsSource =
15468 "#version 450\n"
15469 "layout(location=0) out int x[];\n"
15470 "layout(vertices=3) out;\n"
15471 "void main(){\n"
15472 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15473 " gl_TessLevelInner[0] = 1;\n"
15474 " x[gl_InvocationID] = gl_InvocationID;\n"
15475 "}\n";
15476 char const *tesSource =
15477 "#version 450\n"
15478 "layout(triangles, equal_spacing, cw) in;\n"
15479 "layout(location=0) patch in int x;\n"
15480 "out gl_PerVertex { vec4 gl_Position; };\n"
15481 "void main(){\n"
15482 " gl_Position.xyz = gl_TessCoord;\n"
15483 " gl_Position.w = x;\n"
15484 "}\n";
15485 char const *fsSource =
15486 "#version 450\n"
15487 "layout(location=0) out vec4 color;\n"
15488 "void main(){\n"
15489 " color = vec4(1);\n"
15490 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120015491
15492 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15493 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15494 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15495 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15496
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015497 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15498 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015500 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015501
15502 VkPipelineObj pipe(m_device);
15503 pipe.SetInputAssembly(&iasci);
15504 pipe.SetTessellation(&tsci);
15505 pipe.AddColorAttachment();
15506 pipe.AddShader(&vs);
15507 pipe.AddShader(&tcs);
15508 pipe.AddShader(&tes);
15509 pipe.AddShader(&fs);
15510
15511 VkDescriptorSetObj descriptorSet(m_device);
15512 descriptorSet.AppendDummy();
15513 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15514
15515 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15516
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015517 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120015518}
15519
Cort Stratton2bcca1b2017-05-05 16:02:35 -070015520TEST_F(VkLayerTest, CreatePipelineTessErrors) {
15521 TEST_DESCRIPTION("Test various errors when creating a graphics pipeline with tessellation stages active.");
15522
15523 ASSERT_NO_FATAL_FAILURE(Init());
15524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15525
15526 if (!m_device->phy().features().tessellationShader) {
15527 printf(" Device does not support tessellation shaders; skipped.\n");
15528 return;
15529 }
15530
15531 char const *vsSource =
15532 "#version 450\n"
15533 "void main(){}\n";
15534 char const *tcsSource =
15535 "#version 450\n"
15536 "layout(vertices=3) out;\n"
15537 "void main(){\n"
15538 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15539 " gl_TessLevelInner[0] = 1;\n"
15540 "}\n";
15541 char const *tesSource =
15542 "#version 450\n"
15543 "layout(triangles, equal_spacing, cw) in;\n"
15544 "out gl_PerVertex { vec4 gl_Position; };\n"
15545 "void main(){\n"
15546 " gl_Position.xyz = gl_TessCoord;\n"
15547 " gl_Position.w = 0;\n"
15548 "}\n";
15549 char const *fsSource =
15550 "#version 450\n"
15551 "layout(location=0) out vec4 color;\n"
15552 "void main(){\n"
15553 " color = vec4(1);\n"
15554 "}\n";
15555
15556 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15557 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15558 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15559 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15560
15561 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15562 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
15563
15564 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
15565
15566 VkDescriptorSetObj descriptorSet(m_device);
15567 descriptorSet.AppendDummy();
15568 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15569
15570 {
15571 VkPipelineObj pipe(m_device);
15572 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15573 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15574 pipe.SetInputAssembly(&iasci_bad);
15575 pipe.AddColorAttachment();
15576 pipe.AddShader(&vs);
15577 pipe.AddShader(&fs);
15578
15579 // Pass a tess control shader without a tess eval shader
15580 pipe.AddShader(&tcs);
15581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00534);
15582 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15583 m_errorMonitor->VerifyFound();
15584 }
15585
15586 {
15587 VkPipelineObj pipe(m_device);
15588 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15589 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15590 pipe.SetInputAssembly(&iasci_bad);
15591 pipe.AddColorAttachment();
15592 pipe.AddShader(&vs);
15593 pipe.AddShader(&fs);
15594
15595 // Pass a tess eval shader without a tess control shader
15596 pipe.AddShader(&tes);
15597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00535);
15598 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15599 m_errorMonitor->VerifyFound();
15600 }
15601
15602 {
15603 VkPipelineObj pipe(m_device);
15604 pipe.SetInputAssembly(&iasci);
15605 pipe.AddColorAttachment();
15606 pipe.AddShader(&vs);
15607 pipe.AddShader(&fs);
15608
15609 // Pass patch topology without tessellation shaders
15610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02100);
15611 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15612 m_errorMonitor->VerifyFound();
15613
15614 pipe.AddShader(&tcs);
15615 pipe.AddShader(&tes);
15616 // Pass a NULL pTessellationState (with active tessellation shader stages)
15617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00536);
15618 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15619 m_errorMonitor->VerifyFound();
15620
15621 // Pass an invalid pTessellationState (bad sType)
15622 VkPipelineTessellationStateCreateInfo tsci_bad = tsci;
15623 tsci_bad.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15624 pipe.SetTessellation(&tsci_bad);
15625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01427);
15626 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15627 m_errorMonitor->VerifyFound();
15628 // Pass out-of-range patchControlPoints
15629 tsci_bad = tsci;
15630 tsci_bad.patchControlPoints = 0;
15631 pipe.SetTessellation(&tsci);
15632 pipe.SetTessellation(&tsci_bad);
15633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15634 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15635 m_errorMonitor->VerifyFound();
15636 tsci_bad.patchControlPoints = m_device->props.limits.maxTessellationPatchSize + 1;
15637 pipe.SetTessellation(&tsci_bad);
15638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15639 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15640 m_errorMonitor->VerifyFound();
15641 pipe.SetTessellation(&tsci);
15642
15643 // Pass an invalid primitive topology
15644 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15645 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
15646 pipe.SetInputAssembly(&iasci_bad);
15647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02099);
15648 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15649 m_errorMonitor->VerifyFound();
15650 pipe.SetInputAssembly(&iasci);
15651 }
15652}
15653
Karl Schultz6addd812016-02-02 17:17:23 -070015654TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015655 TEST_DESCRIPTION(
15656 "Test that an error is produced for a vertex attribute setup where multiple "
15657 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15659 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015660
Tony Barbour1fa09702017-03-16 12:09:08 -060015661 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015663
15664 /* Two binding descriptions for binding 0 */
15665 VkVertexInputBindingDescription input_bindings[2];
15666 memset(input_bindings, 0, sizeof(input_bindings));
15667
15668 VkVertexInputAttributeDescription input_attrib;
15669 memset(&input_attrib, 0, sizeof(input_attrib));
15670 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15671
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015672 char const *vsSource =
15673 "#version 450\n"
15674 "\n"
15675 "layout(location=0) in float x;\n" /* attrib provided float */
15676 "out gl_PerVertex {\n"
15677 " vec4 gl_Position;\n"
15678 "};\n"
15679 "void main(){\n"
15680 " gl_Position = vec4(x);\n"
15681 "}\n";
15682 char const *fsSource =
15683 "#version 450\n"
15684 "\n"
15685 "layout(location=0) out vec4 color;\n"
15686 "void main(){\n"
15687 " color = vec4(1);\n"
15688 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120015689
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015690 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15691 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015692
15693 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015694 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015695 pipe.AddShader(&vs);
15696 pipe.AddShader(&fs);
15697
15698 pipe.AddVertexInputBindings(input_bindings, 2);
15699 pipe.AddVertexInputAttribs(&input_attrib, 1);
15700
Chris Forbes280ba2c2015-06-12 11:16:41 +120015701 VkDescriptorSetObj descriptorSet(m_device);
15702 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015703 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015704
Tony Barbour5781e8f2015-08-04 16:23:11 -060015705 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015706
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015707 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015708}
Chris Forbes8f68b562015-05-25 11:13:32 +120015709
Karl Schultz6addd812016-02-02 17:17:23 -070015710TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015711 TEST_DESCRIPTION(
15712 "Test that an error is produced for a fragment shader which does not "
15713 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015715
Tony Barbour1fa09702017-03-16 12:09:08 -060015716 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015717
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015718 char const *vsSource =
15719 "#version 450\n"
15720 "\n"
15721 "out gl_PerVertex {\n"
15722 " vec4 gl_Position;\n"
15723 "};\n"
15724 "void main(){\n"
15725 " gl_Position = vec4(1);\n"
15726 "}\n";
15727 char const *fsSource =
15728 "#version 450\n"
15729 "\n"
15730 "void main(){\n"
15731 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015732
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015733 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15734 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015735
15736 VkPipelineObj pipe(m_device);
15737 pipe.AddShader(&vs);
15738 pipe.AddShader(&fs);
15739
Chia-I Wu08accc62015-07-07 11:50:03 +080015740 /* set up CB 0, not written */
15741 pipe.AddColorAttachment();
15742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015743
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015744 VkDescriptorSetObj descriptorSet(m_device);
15745 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015746 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015747
Tony Barbour5781e8f2015-08-04 16:23:11 -060015748 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015749
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015750 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015751}
15752
Karl Schultz6addd812016-02-02 17:17:23 -070015753TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015754 TEST_DESCRIPTION(
15755 "Test that a warning is produced for a fragment shader which provides a spurious "
15756 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060015758 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015759
Tony Barbour1fa09702017-03-16 12:09:08 -060015760 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015761
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015762 char const *vsSource =
15763 "#version 450\n"
15764 "\n"
15765 "out gl_PerVertex {\n"
15766 " vec4 gl_Position;\n"
15767 "};\n"
15768 "void main(){\n"
15769 " gl_Position = vec4(1);\n"
15770 "}\n";
15771 char const *fsSource =
15772 "#version 450\n"
15773 "\n"
15774 "layout(location=0) out vec4 x;\n"
15775 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
15776 "void main(){\n"
15777 " x = vec4(1);\n"
15778 " y = vec4(1);\n"
15779 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015780
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015781 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15782 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015783
15784 VkPipelineObj pipe(m_device);
15785 pipe.AddShader(&vs);
15786 pipe.AddShader(&fs);
15787
Chia-I Wu08accc62015-07-07 11:50:03 +080015788 /* set up CB 0, not written */
15789 pipe.AddColorAttachment();
15790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015791 /* FS writes CB 1, but we don't configure it */
15792
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015793 VkDescriptorSetObj descriptorSet(m_device);
15794 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015795 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015796
Tony Barbour5781e8f2015-08-04 16:23:11 -060015797 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015798
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015799 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015800}
15801
Karl Schultz6addd812016-02-02 17:17:23 -070015802TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015803 TEST_DESCRIPTION(
15804 "Test that an error is produced for a mismatch between the fundamental "
15805 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015807
Tony Barbour1fa09702017-03-16 12:09:08 -060015808 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015809
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015810 char const *vsSource =
15811 "#version 450\n"
15812 "\n"
15813 "out gl_PerVertex {\n"
15814 " vec4 gl_Position;\n"
15815 "};\n"
15816 "void main(){\n"
15817 " gl_Position = vec4(1);\n"
15818 "}\n";
15819 char const *fsSource =
15820 "#version 450\n"
15821 "\n"
15822 "layout(location=0) out ivec4 x;\n" /* not UNORM */
15823 "void main(){\n"
15824 " x = ivec4(1);\n"
15825 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120015826
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015827 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15828 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015829
15830 VkPipelineObj pipe(m_device);
15831 pipe.AddShader(&vs);
15832 pipe.AddShader(&fs);
15833
Chia-I Wu08accc62015-07-07 11:50:03 +080015834 /* set up CB 0; type is UNORM by default */
15835 pipe.AddColorAttachment();
15836 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015837
Chris Forbesa36d69e2015-05-25 11:13:44 +120015838 VkDescriptorSetObj descriptorSet(m_device);
15839 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015840 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015841
Tony Barbour5781e8f2015-08-04 16:23:11 -060015842 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015843
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015844 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120015845}
Chris Forbes7b1b8932015-06-05 14:43:36 +120015846
Karl Schultz6addd812016-02-02 17:17:23 -070015847TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015848 TEST_DESCRIPTION(
15849 "Test that an error is produced for a shader consuming a uniform "
15850 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015852
Tony Barbour1fa09702017-03-16 12:09:08 -060015853 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes556c76c2015-08-14 12:04:59 +120015854
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015855 char const *vsSource =
15856 "#version 450\n"
15857 "\n"
15858 "out gl_PerVertex {\n"
15859 " vec4 gl_Position;\n"
15860 "};\n"
15861 "void main(){\n"
15862 " gl_Position = vec4(1);\n"
15863 "}\n";
15864 char const *fsSource =
15865 "#version 450\n"
15866 "\n"
15867 "layout(location=0) out vec4 x;\n"
15868 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
15869 "void main(){\n"
15870 " x = vec4(bar.y);\n"
15871 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120015872
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015873 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15874 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120015875
Chris Forbes556c76c2015-08-14 12:04:59 +120015876 VkPipelineObj pipe(m_device);
15877 pipe.AddShader(&vs);
15878 pipe.AddShader(&fs);
15879
15880 /* set up CB 0; type is UNORM by default */
15881 pipe.AddColorAttachment();
15882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15883
15884 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015885 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120015886
15887 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15888
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015889 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120015890}
15891
Chris Forbes5c59e902016-02-26 16:56:09 +130015892TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015893 TEST_DESCRIPTION(
15894 "Test that an error is produced for a shader consuming push constants "
15895 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130015897
Tony Barbour1fa09702017-03-16 12:09:08 -060015898 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5c59e902016-02-26 16:56:09 +130015899
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015900 char const *vsSource =
15901 "#version 450\n"
15902 "\n"
15903 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
15904 "out gl_PerVertex {\n"
15905 " vec4 gl_Position;\n"
15906 "};\n"
15907 "void main(){\n"
15908 " gl_Position = vec4(consts.x);\n"
15909 "}\n";
15910 char const *fsSource =
15911 "#version 450\n"
15912 "\n"
15913 "layout(location=0) out vec4 x;\n"
15914 "void main(){\n"
15915 " x = vec4(1);\n"
15916 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130015917
15918 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15919 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15920
15921 VkPipelineObj pipe(m_device);
15922 pipe.AddShader(&vs);
15923 pipe.AddShader(&fs);
15924
15925 /* set up CB 0; type is UNORM by default */
15926 pipe.AddColorAttachment();
15927 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15928
15929 VkDescriptorSetObj descriptorSet(m_device);
15930 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15931
15932 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15933
15934 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015935 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015936}
15937
Chris Forbes3fb17902016-08-22 14:57:55 +120015938TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015939 TEST_DESCRIPTION(
15940 "Test that an error is produced for a shader consuming an input attachment "
15941 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120015942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15943 "consumes input attachment index 0 but not provided in subpass");
15944
Tony Barbour1fa09702017-03-16 12:09:08 -060015945 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fb17902016-08-22 14:57:55 +120015946
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015947 char const *vsSource =
15948 "#version 450\n"
15949 "\n"
15950 "out gl_PerVertex {\n"
15951 " vec4 gl_Position;\n"
15952 "};\n"
15953 "void main(){\n"
15954 " gl_Position = vec4(1);\n"
15955 "}\n";
15956 char const *fsSource =
15957 "#version 450\n"
15958 "\n"
15959 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15960 "layout(location=0) out vec4 color;\n"
15961 "void main() {\n"
15962 " color = subpassLoad(x);\n"
15963 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015964
15965 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15966 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15967
15968 VkPipelineObj pipe(m_device);
15969 pipe.AddShader(&vs);
15970 pipe.AddShader(&fs);
15971 pipe.AddColorAttachment();
15972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15973
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015974 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15975 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015976 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015977 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015978 ASSERT_VK_SUCCESS(err);
15979
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015980 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015981 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015982 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015983 ASSERT_VK_SUCCESS(err);
15984
15985 // error here.
15986 pipe.CreateVKPipeline(pl, renderPass());
15987
15988 m_errorMonitor->VerifyFound();
15989
15990 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15991 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15992}
15993
Chris Forbes5a9a0472016-08-22 16:02:09 +120015994TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015995 TEST_DESCRIPTION(
15996 "Test that an error is produced for a shader consuming an input attachment "
15997 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15999 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
16000
Tony Barbour1fa09702017-03-16 12:09:08 -060016001 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5a9a0472016-08-22 16:02:09 +120016002
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016003 char const *vsSource =
16004 "#version 450\n"
16005 "\n"
16006 "out gl_PerVertex {\n"
16007 " vec4 gl_Position;\n"
16008 "};\n"
16009 "void main(){\n"
16010 " gl_Position = vec4(1);\n"
16011 "}\n";
16012 char const *fsSource =
16013 "#version 450\n"
16014 "\n"
16015 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16016 "layout(location=0) out vec4 color;\n"
16017 "void main() {\n"
16018 " color = subpassLoad(x);\n"
16019 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120016020
16021 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16022 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16023
16024 VkPipelineObj pipe(m_device);
16025 pipe.AddShader(&vs);
16026 pipe.AddShader(&fs);
16027 pipe.AddColorAttachment();
16028 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016030 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16031 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016032 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016033 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016034 ASSERT_VK_SUCCESS(err);
16035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016036 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016037 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016038 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016039 ASSERT_VK_SUCCESS(err);
16040
16041 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016042 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16043 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16044 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
16045 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16046 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 +120016047 };
16048 VkAttachmentReference color = {
16049 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16050 };
16051 VkAttachmentReference input = {
16052 1, VK_IMAGE_LAYOUT_GENERAL,
16053 };
16054
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016055 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016057 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016058 VkRenderPass rp;
16059 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16060 ASSERT_VK_SUCCESS(err);
16061
16062 // error here.
16063 pipe.CreateVKPipeline(pl, rp);
16064
16065 m_errorMonitor->VerifyFound();
16066
16067 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16068 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16069 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16070}
16071
Chris Forbes541f7b02016-08-22 15:30:27 +120016072TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016073 TEST_DESCRIPTION(
16074 "Test that an error is produced for a shader consuming an input attachment "
16075 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120016076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070016077 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120016078
Tony Barbour1fa09702017-03-16 12:09:08 -060016079 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes541f7b02016-08-22 15:30:27 +120016080
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016081 char const *vsSource =
16082 "#version 450\n"
16083 "\n"
16084 "out gl_PerVertex {\n"
16085 " vec4 gl_Position;\n"
16086 "};\n"
16087 "void main(){\n"
16088 " gl_Position = vec4(1);\n"
16089 "}\n";
16090 char const *fsSource =
16091 "#version 450\n"
16092 "\n"
16093 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
16094 "layout(location=0) out vec4 color;\n"
16095 "void main() {\n"
16096 " color = subpassLoad(xs[0]);\n"
16097 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120016098
16099 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16100 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16101
16102 VkPipelineObj pipe(m_device);
16103 pipe.AddShader(&vs);
16104 pipe.AddShader(&fs);
16105 pipe.AddColorAttachment();
16106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016108 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16109 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120016110 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016111 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016112 ASSERT_VK_SUCCESS(err);
16113
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016114 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120016115 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016116 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016117 ASSERT_VK_SUCCESS(err);
16118
16119 // error here.
16120 pipe.CreateVKPipeline(pl, renderPass());
16121
16122 m_errorMonitor->VerifyFound();
16123
16124 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16125 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16126}
16127
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016128TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016129 TEST_DESCRIPTION(
16130 "Test that an error is produced for a compute pipeline consuming a "
16131 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016133
Tony Barbour1fa09702017-03-16 12:09:08 -060016134 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016135
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016136 char const *csSource =
16137 "#version 450\n"
16138 "\n"
16139 "layout(local_size_x=1) in;\n"
16140 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16141 "void main(){\n"
16142 " x = vec4(1);\n"
16143 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016144
16145 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16146
16147 VkDescriptorSetObj descriptorSet(m_device);
16148 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016150 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16151 nullptr,
16152 0,
16153 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16154 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16155 descriptorSet.GetPipelineLayout(),
16156 VK_NULL_HANDLE,
16157 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016158
16159 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016160 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016161
16162 m_errorMonitor->VerifyFound();
16163
16164 if (err == VK_SUCCESS) {
16165 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16166 }
16167}
16168
Chris Forbes22a9b092016-07-19 14:34:05 +120016169TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016170 TEST_DESCRIPTION(
16171 "Test that an error is produced for a pipeline consuming a "
16172 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16174 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120016175
Tony Barbour1fa09702017-03-16 12:09:08 -060016176 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes22a9b092016-07-19 14:34:05 +120016177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016178 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
16179 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120016180 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016181 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016182 ASSERT_VK_SUCCESS(err);
16183
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016184 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120016185 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016186 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016187 ASSERT_VK_SUCCESS(err);
16188
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016189 char const *csSource =
16190 "#version 450\n"
16191 "\n"
16192 "layout(local_size_x=1) in;\n"
16193 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16194 "void main() {\n"
16195 " x.x = 1.0f;\n"
16196 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120016197 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16198
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016199 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16200 nullptr,
16201 0,
16202 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16203 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16204 pl,
16205 VK_NULL_HANDLE,
16206 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120016207
16208 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016209 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120016210
16211 m_errorMonitor->VerifyFound();
16212
16213 if (err == VK_SUCCESS) {
16214 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16215 }
16216
16217 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16218 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16219}
16220
Chris Forbes50020592016-07-27 13:52:41 +120016221TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016222 TEST_DESCRIPTION(
16223 "Test that an error is produced when an image view type "
16224 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120016225
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016226 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 +120016227
Tony Barbour1fa09702017-03-16 12:09:08 -060016228 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes50020592016-07-27 13:52:41 +120016229 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16230
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016231 char const *vsSource =
16232 "#version 450\n"
16233 "\n"
16234 "out gl_PerVertex { vec4 gl_Position; };\n"
16235 "void main() { gl_Position = vec4(0); }\n";
16236 char const *fsSource =
16237 "#version 450\n"
16238 "\n"
16239 "layout(set=0, binding=0) uniform sampler3D s;\n"
16240 "layout(location=0) out vec4 color;\n"
16241 "void main() {\n"
16242 " color = texture(s, vec3(0));\n"
16243 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120016244 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16245 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16246
16247 VkPipelineObj pipe(m_device);
16248 pipe.AddShader(&vs);
16249 pipe.AddShader(&fs);
16250 pipe.AddColorAttachment();
16251
16252 VkTextureObj texture(m_device, nullptr);
16253 VkSamplerObj sampler(m_device);
16254
16255 VkDescriptorSetObj descriptorSet(m_device);
16256 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16257 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16258
16259 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16260 ASSERT_VK_SUCCESS(err);
16261
Tony Barbour552f6c02016-12-21 14:34:07 -070016262 m_commandBuffer->BeginCommandBuffer();
16263 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120016264
16265 m_commandBuffer->BindPipeline(pipe);
16266 m_commandBuffer->BindDescriptorSet(descriptorSet);
16267
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016268 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120016269 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016270 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120016271 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16272
16273 // error produced here.
16274 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16275
16276 m_errorMonitor->VerifyFound();
16277
Tony Barbour552f6c02016-12-21 14:34:07 -070016278 m_commandBuffer->EndRenderPass();
16279 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120016280}
16281
Chris Forbes5533bfc2016-07-27 14:12:34 +120016282TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016283 TEST_DESCRIPTION(
16284 "Test that an error is produced when a multisampled images "
16285 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016288
Tony Barbour1fa09702017-03-16 12:09:08 -060016289 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5533bfc2016-07-27 14:12:34 +120016290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16291
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016292 char const *vsSource =
16293 "#version 450\n"
16294 "\n"
16295 "out gl_PerVertex { vec4 gl_Position; };\n"
16296 "void main() { gl_Position = vec4(0); }\n";
16297 char const *fsSource =
16298 "#version 450\n"
16299 "\n"
16300 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
16301 "layout(location=0) out vec4 color;\n"
16302 "void main() {\n"
16303 " color = texelFetch(s, ivec2(0), 0);\n"
16304 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120016305 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16306 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16307
16308 VkPipelineObj pipe(m_device);
16309 pipe.AddShader(&vs);
16310 pipe.AddShader(&fs);
16311 pipe.AddColorAttachment();
16312
16313 VkTextureObj texture(m_device, nullptr);
16314 VkSamplerObj sampler(m_device);
16315
16316 VkDescriptorSetObj descriptorSet(m_device);
16317 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16318 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16319
16320 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16321 ASSERT_VK_SUCCESS(err);
16322
Tony Barbour552f6c02016-12-21 14:34:07 -070016323 m_commandBuffer->BeginCommandBuffer();
16324 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120016325
16326 m_commandBuffer->BindPipeline(pipe);
16327 m_commandBuffer->BindDescriptorSet(descriptorSet);
16328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016329 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016330 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016331 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016332 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16333
16334 // error produced here.
16335 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16336
16337 m_errorMonitor->VerifyFound();
16338
Tony Barbour552f6c02016-12-21 14:34:07 -070016339 m_commandBuffer->EndRenderPass();
16340 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120016341}
16342
Mark Youngc48c4c12016-04-11 14:26:49 -060016343TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016344 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016345
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016346 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16347 {
16348 VkFormatProperties properties;
16349 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16350 if (properties.optimalTilingFeatures == 0) {
16351 printf(" Image format not supported; skipped.\n");
16352 return;
16353 }
16354 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016355
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016356 VkImageCreateInfo info = {};
16357 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16358 info.pNext = NULL;
16359 info.imageType = VK_IMAGE_TYPE_2D;
16360 info.format = format;
16361 info.extent.height = 32;
16362 info.extent.depth = 1;
16363 info.mipLevels = 1;
16364 info.arrayLayers = 1;
16365 info.samples = VK_SAMPLE_COUNT_1_BIT;
16366 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16367 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16368 info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016369
16370 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016371 {
16372 VkImageFormatProperties properties;
16373 auto const result = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), info.format, info.imageType,
16374 info.tiling, info.usage, info.flags, &properties);
16375 ASSERT_VK_SUCCESS(result);
16376 info.extent.width = properties.maxExtent.width + 1;
16377 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016378
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016379 VkImage image;
16380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
16381 vkCreateImage(m_device->device(), &info, NULL, &image);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016382 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016383}
16384
Mark Youngc48c4c12016-04-11 14:26:49 -060016385TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016386 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc48c4c12016-04-11 14:26:49 -060016387
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016388 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16389 {
16390 VkFormatProperties properties;
16391 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16392 if (properties.optimalTilingFeatures == 0) {
16393 printf(" Image format not supported; skipped.\n");
16394 return;
16395 }
16396 }
Mark Youngc48c4c12016-04-11 14:26:49 -060016397
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016398 VkImageCreateInfo info = {};
16399 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16400 info.pNext = NULL;
16401 info.imageType = VK_IMAGE_TYPE_2D;
16402 info.format = format;
16403 info.extent.height = 32;
16404 info.extent.depth = 1;
16405 info.mipLevels = 1;
16406 info.arrayLayers = 1;
16407 info.samples = VK_SAMPLE_COUNT_1_BIT;
16408 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16409 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16410 info.flags = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016411
16412 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016413 info.extent.width = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016414
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016415 VkImage image;
Tobin Ehlisa55b1d42017-04-04 12:23:48 -060016416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02917);
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016417 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
16418 vkCreateImage(m_device->device(), &info, NULL, &image);
Mark Youngc48c4c12016-04-11 14:26:49 -060016419 m_errorMonitor->VerifyFound();
16420}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070016421
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016422TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016423 TEST_DESCRIPTION(
16424 "Create a render pass with an attachment description "
16425 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016426
Tony Barbour1fa09702017-03-16 12:09:08 -060016427 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16429
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070016430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016431
16432 VkAttachmentReference color_attach = {};
16433 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
16434 color_attach.attachment = 0;
16435 VkSubpassDescription subpass = {};
16436 subpass.colorAttachmentCount = 1;
16437 subpass.pColorAttachments = &color_attach;
16438
16439 VkRenderPassCreateInfo rpci = {};
16440 rpci.subpassCount = 1;
16441 rpci.pSubpasses = &subpass;
16442 rpci.attachmentCount = 1;
16443 VkAttachmentDescription attach_desc = {};
16444 attach_desc.format = VK_FORMAT_UNDEFINED;
16445 rpci.pAttachments = &attach_desc;
16446 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16447 VkRenderPass rp;
16448 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
16449
16450 m_errorMonitor->VerifyFound();
16451
16452 if (result == VK_SUCCESS) {
16453 vkDestroyRenderPass(m_device->device(), rp, NULL);
16454 }
16455}
16456
Karl Schultz6addd812016-02-02 17:17:23 -070016457TEST_F(VkLayerTest, InvalidImageView) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016458 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehliscde08892015-09-22 10:11:37 -060016459
Mike Stroyana3082432015-09-25 13:39:21 -060016460 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070016461 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16462 const int32_t tex_width = 32;
16463 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060016464
16465 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016466 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16467 image_create_info.pNext = NULL;
16468 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16469 image_create_info.format = tex_format;
16470 image_create_info.extent.width = tex_width;
16471 image_create_info.extent.height = tex_height;
16472 image_create_info.extent.depth = 1;
16473 image_create_info.mipLevels = 1;
16474 image_create_info.arrayLayers = 1;
16475 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16476 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16477 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16478 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060016479
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016480 VkImage image;
16481 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060016482 ASSERT_VK_SUCCESS(err);
16483
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016484 VkMemoryRequirements requirements;
16485 vkGetImageMemoryRequirements(m_device->device(), image, &requirements);
16486
16487 VkMemoryAllocateInfo alloc_info{};
16488 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16489 alloc_info.pNext = NULL;
16490 alloc_info.memoryTypeIndex = 0;
16491 alloc_info.allocationSize = requirements.size;
16492 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
16493 ASSERT_TRUE(pass);
16494
16495 VkDeviceMemory memory;
16496 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
16497 ASSERT_VK_SUCCESS(err);
16498
16499 err = vkBindImageMemory(m_device->device(), image, memory, 0);
16500
Tobin Ehliscde08892015-09-22 10:11:37 -060016501 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016502 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016503 image_view_create_info.image = image;
16504 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16505 image_view_create_info.format = tex_format;
16506 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016507 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070016508 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016509 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060016510
16511 VkImageView view;
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016513 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016514 m_errorMonitor->VerifyFound();
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016515
16516 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060016517 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060016518}
Mike Stroyana3082432015-09-25 13:39:21 -060016519
Mark Youngd339ba32016-05-30 13:28:35 -060016520TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
16521 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060016522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060016523 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060016524
Tony Barbour1fa09702017-03-16 12:09:08 -060016525 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -060016526
16527 // Create an image and try to create a view with no memory backing the image
16528 VkImage image;
16529
16530 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16531 const int32_t tex_width = 32;
16532 const int32_t tex_height = 32;
16533
16534 VkImageCreateInfo image_create_info = {};
16535 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16536 image_create_info.pNext = NULL;
16537 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16538 image_create_info.format = tex_format;
16539 image_create_info.extent.width = tex_width;
16540 image_create_info.extent.height = tex_height;
16541 image_create_info.extent.depth = 1;
16542 image_create_info.mipLevels = 1;
16543 image_create_info.arrayLayers = 1;
16544 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16545 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16546 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16547 image_create_info.flags = 0;
16548
16549 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16550 ASSERT_VK_SUCCESS(err);
16551
16552 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016553 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060016554 image_view_create_info.image = image;
16555 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16556 image_view_create_info.format = tex_format;
16557 image_view_create_info.subresourceRange.layerCount = 1;
16558 image_view_create_info.subresourceRange.baseMipLevel = 0;
16559 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016560 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060016561
16562 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016563 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060016564
16565 m_errorMonitor->VerifyFound();
16566 vkDestroyImage(m_device->device(), image, NULL);
16567 // If last error is success, it still created the view, so delete it.
16568 if (err == VK_SUCCESS) {
16569 vkDestroyImageView(m_device->device(), view, NULL);
16570 }
Mark Youngd339ba32016-05-30 13:28:35 -060016571}
16572
Karl Schultz6addd812016-02-02 17:17:23 -070016573TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016574 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016576
Tony Barbour1fa09702017-03-16 12:09:08 -060016577 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016578
Karl Schultz6addd812016-02-02 17:17:23 -070016579 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016580 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016581 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016582 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016583
16584 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016585 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016586 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070016587 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16588 image_view_create_info.format = tex_format;
16589 image_view_create_info.subresourceRange.baseMipLevel = 0;
16590 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016591 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070016592 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016593 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016594
16595 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016596 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016597
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016598 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016599}
16600
Mike Weiblena1e13f42017-02-09 21:25:59 -070016601TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
16602 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
16603
Tony Barbour1fa09702017-03-16 12:09:08 -060016604 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblena1e13f42017-02-09 21:25:59 -070016605 VkSubresourceLayout subres_layout = {};
16606
16607 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
16608 {
16609 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
16610 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016611 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016612 ASSERT_TRUE(img.initialized());
16613
16614 VkImageSubresource subres = {};
16615 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16616 subres.mipLevel = 0;
16617 subres.arrayLayer = 0;
16618
16619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
16620 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16621 m_errorMonitor->VerifyFound();
16622 }
16623
16624 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
16625 {
16626 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016627 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016628 ASSERT_TRUE(img.initialized());
16629
16630 VkImageSubresource subres = {};
16631 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
16632 subres.mipLevel = 0;
16633 subres.arrayLayer = 0;
16634
16635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
16636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
16637 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16638 m_errorMonitor->VerifyFound();
16639 }
16640
16641 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
16642 {
16643 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016644 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016645 ASSERT_TRUE(img.initialized());
16646
16647 VkImageSubresource subres = {};
16648 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16649 subres.mipLevel = 1; // ERROR: triggers VU 00739
16650 subres.arrayLayer = 0;
16651
16652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
16653 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16654 m_errorMonitor->VerifyFound();
16655 }
16656
16657 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
16658 {
16659 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016660 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016661 ASSERT_TRUE(img.initialized());
16662
16663 VkImageSubresource subres = {};
16664 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16665 subres.mipLevel = 0;
16666 subres.arrayLayer = 1; // ERROR: triggers VU 00740
16667
16668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
16669 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16670 m_errorMonitor->VerifyFound();
16671 }
16672}
16673
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016674TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070016675 VkResult err;
16676 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016677
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016679
Tony Barbour1fa09702017-03-16 12:09:08 -060016680 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060016681
16682 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016683 VkImage srcImage;
16684 VkImage dstImage;
16685 VkDeviceMemory srcMem;
16686 VkDeviceMemory destMem;
16687 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016688
16689 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016690 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16691 image_create_info.pNext = NULL;
16692 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16693 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16694 image_create_info.extent.width = 32;
16695 image_create_info.extent.height = 32;
16696 image_create_info.extent.depth = 1;
16697 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016698 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070016699 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16700 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16701 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16702 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016703
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016704 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016705 ASSERT_VK_SUCCESS(err);
16706
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016707 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016708 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016709 ASSERT_VK_SUCCESS(err);
16710
16711 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016712 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016713 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16714 memAlloc.pNext = NULL;
16715 memAlloc.allocationSize = 0;
16716 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016717
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016718 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016719 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016720 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016721 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016722 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016723 ASSERT_VK_SUCCESS(err);
16724
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016725 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016726 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016727 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016728 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016729 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016730 ASSERT_VK_SUCCESS(err);
16731
16732 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16733 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016734 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016735 ASSERT_VK_SUCCESS(err);
16736
Tony Barbour552f6c02016-12-21 14:34:07 -070016737 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016738 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016739 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016740 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016741 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016742 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016743 copyRegion.srcOffset.x = 0;
16744 copyRegion.srcOffset.y = 0;
16745 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016746 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016747 copyRegion.dstSubresource.mipLevel = 0;
16748 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016749 // Introduce failure by forcing the dst layerCount to differ from src
16750 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016751 copyRegion.dstOffset.x = 0;
16752 copyRegion.dstOffset.y = 0;
16753 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016754 copyRegion.extent.width = 1;
16755 copyRegion.extent.height = 1;
16756 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016757 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016758 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016759
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016760 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016761
Chia-I Wuf7458c52015-10-26 21:10:41 +080016762 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016763 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016764 vkFreeMemory(m_device->device(), srcMem, NULL);
16765 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016766}
16767
Tony Barbourd6673642016-05-05 14:46:39 -060016768TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060016769 TEST_DESCRIPTION("Creating images with unsuported formats ");
16770
Tony Barbour1fa09702017-03-16 12:09:08 -060016771 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060016772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourd6673642016-05-05 14:46:39 -060016773
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016774 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130016775 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016776 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016777 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16778 image_create_info.format = VK_FORMAT_UNDEFINED;
16779 image_create_info.extent.width = 32;
16780 image_create_info.extent.height = 32;
16781 image_create_info.extent.depth = 1;
16782 image_create_info.mipLevels = 1;
16783 image_create_info.arrayLayers = 1;
16784 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16785 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16786 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16789 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016790
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016791 VkImage image;
16792 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016793 m_errorMonitor->VerifyFound();
16794
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016795 // Look for a format that is COMPLETELY unsupported with this hardware
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016796 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Tony Barbourd6673642016-05-05 14:46:39 -060016797 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16798 VkFormat format = static_cast<VkFormat>(f);
16799 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016800 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016801 unsupported = format;
16802 break;
16803 }
16804 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016805
Tony Barbourd6673642016-05-05 14:46:39 -060016806 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016807 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016809
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016810 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Tony Barbourd6673642016-05-05 14:46:39 -060016811 m_errorMonitor->VerifyFound();
16812 }
16813}
16814
16815TEST_F(VkLayerTest, ImageLayerViewTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060016816 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16817
Tony Barbour1fa09702017-03-16 12:09:08 -060016818 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060016819 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070016820 if (!depth_format) {
16821 return;
16822 }
Tony Barbourd6673642016-05-05 14:46:39 -060016823
16824 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016825 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 -060016826 VK_IMAGE_TILING_OPTIMAL, 0);
16827 ASSERT_TRUE(image.initialized());
16828
16829 VkImageView imgView;
16830 VkImageViewCreateInfo imgViewInfo = {};
16831 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16832 imgViewInfo.image = image.handle();
16833 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
16834 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16835 imgViewInfo.subresourceRange.layerCount = 1;
16836 imgViewInfo.subresourceRange.baseMipLevel = 0;
16837 imgViewInfo.subresourceRange.levelCount = 1;
16838 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16839
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016840 // View can't have baseMipLevel >= image's mipLevels - Expect VIEW_CREATE_ERROR
Tony Barbourd6673642016-05-05 14:46:39 -060016841 imgViewInfo.subresourceRange.baseMipLevel = 1;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060016843 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16844 m_errorMonitor->VerifyFound();
16845 imgViewInfo.subresourceRange.baseMipLevel = 0;
16846
Tony Barbourd6673642016-05-05 14:46:39 -060016847 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16848 imgViewInfo.subresourceRange.levelCount = 0;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060016850 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16851 m_errorMonitor->VerifyFound();
16852 imgViewInfo.subresourceRange.levelCount = 1;
16853
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016854 // View's levelCount can't be > image's mipLevels - Expect VIEW_CREATE_ERROR
16855 imgViewInfo.subresourceRange.levelCount = 2;
16856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
16857 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16858 m_errorMonitor->VerifyFound();
16859 imgViewInfo.subresourceRange.levelCount = 1;
16860
16861 // View can't have baseArrayLayer >= image's arraySize - Expect VIEW_CREATE_ERROR
16862 imgViewInfo.subresourceRange.baseArrayLayer = 1;
16863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
16864 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16865 m_errorMonitor->VerifyFound();
16866 imgViewInfo.subresourceRange.baseArrayLayer = 0;
16867
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016868 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16869 imgViewInfo.subresourceRange.layerCount = 0;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016870 m_errorMonitor->SetDesiredFailureMsg(
16871 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16872 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060016873 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16874 m_errorMonitor->VerifyFound();
16875 imgViewInfo.subresourceRange.layerCount = 1;
16876
Tony Barbourd6673642016-05-05 14:46:39 -060016877 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070016878 imgViewInfo.format = depth_format;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016879 m_errorMonitor->SetDesiredFailureMsg(
16880 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16881 "Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016882 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16883 m_errorMonitor->VerifyFound();
16884 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16885
Tony Barbourd6673642016-05-05 14:46:39 -060016886 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16887 // VIEW_CREATE_ERROR
16888 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060016890 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16891 m_errorMonitor->VerifyFound();
16892 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16893
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016894 // TODO: Update framework to easily passing mutable flag into ImageObj init
16895 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070016896 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
16897 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16898 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060016899 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16900 // VIEW_CREATE_ERROR
16901 VkImageCreateInfo mutImgInfo = image.create_info();
16902 VkImage mutImage;
16903 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016904 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016905 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16906 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016907 VkResult ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
Tony Barbourd6673642016-05-05 14:46:39 -060016908 ASSERT_VK_SUCCESS(ret);
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016909
16910 VkMemoryRequirements requirements;
16911 vkGetImageMemoryRequirements(m_device->device(), mutImage, &requirements);
16912
16913 VkMemoryAllocateInfo alloc_info{};
16914 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16915 alloc_info.pNext = NULL;
16916 alloc_info.memoryTypeIndex = 0;
16917 alloc_info.allocationSize = requirements.size;
16918 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
16919 ASSERT_TRUE(pass);
16920
16921 VkDeviceMemory memory;
16922 ret = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
16923 ASSERT_VK_SUCCESS(ret);
16924
16925 ret = vkBindImageMemory(m_device->device(), mutImage, memory, 0);
16926 ASSERT_VK_SUCCESS(ret);
16927
Tony Barbourd6673642016-05-05 14:46:39 -060016928 imgViewInfo.image = mutImage;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tony Barbourd6673642016-05-05 14:46:39 -060016930 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16931 m_errorMonitor->VerifyFound();
16932 imgViewInfo.image = image.handle();
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016933
16934 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourd6673642016-05-05 14:46:39 -060016935 vkDestroyImage(m_device->handle(), mutImage, NULL);
16936}
16937
Dave Houlton75967fc2017-03-06 17:21:16 -070016938TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
16939 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
16940
Tony Barbour1fa09702017-03-16 12:09:08 -060016941 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton75967fc2017-03-06 17:21:16 -070016942
Jamie Madill35127872017-03-15 16:17:46 -040016943 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton75967fc2017-03-06 17:21:16 -070016944 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
16945 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
16946 if (device_features.textureCompressionBC) {
16947 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
16948 } else if (device_features.textureCompressionETC2) {
16949 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
16950 } else if (device_features.textureCompressionASTC_LDR) {
16951 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
16952 } else {
16953 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
16954 return;
16955 }
16956
16957 VkImageCreateInfo ci;
16958 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16959 ci.pNext = NULL;
16960 ci.flags = 0;
16961 ci.imageType = VK_IMAGE_TYPE_2D;
16962 ci.format = compressed_format;
16963 ci.extent = {32, 32, 1};
16964 ci.mipLevels = 6;
16965 ci.arrayLayers = 1;
16966 ci.samples = VK_SAMPLE_COUNT_1_BIT;
16967 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
16968 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16969 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16970 ci.queueFamilyIndexCount = 0;
16971 ci.pQueueFamilyIndices = NULL;
16972 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16973
16974 VkImageObj image(m_device);
16975 image.init(&ci);
16976 ASSERT_TRUE(image.initialized());
16977
16978 VkImageObj odd_image(m_device);
16979 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
16980 odd_image.init(&ci);
16981 ASSERT_TRUE(odd_image.initialized());
16982
16983 // Allocate buffers
16984 VkMemoryPropertyFlags reqs = 0;
16985 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
16986 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
16987 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
16988 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
16989 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
16990
16991 VkBufferImageCopy region = {};
16992 region.bufferRowLength = 0;
16993 region.bufferImageHeight = 0;
16994 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16995 region.imageSubresource.layerCount = 1;
16996 region.imageOffset = {0, 0, 0};
16997 region.bufferOffset = 0;
16998
16999 // start recording
17000 m_commandBuffer->BeginCommandBuffer();
17001
17002 // Mip level copies that work - 5 levels
17003 m_errorMonitor->ExpectSuccess();
17004
17005 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
17006 region.imageExtent = {32, 32, 1};
17007 region.imageSubresource.mipLevel = 0;
17008 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
17009 &region);
17010 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17011 &region);
17012
17013 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
17014 region.imageExtent = {8, 8, 1};
17015 region.imageSubresource.mipLevel = 2;
17016 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
17017 &region);
17018 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17019 &region);
17020
17021 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
17022 region.imageExtent = {4, 4, 1};
17023 region.imageSubresource.mipLevel = 3;
17024 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17025 &region);
17026 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17027 &region);
17028
17029 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
17030 region.imageExtent = {2, 2, 1};
17031 region.imageSubresource.mipLevel = 4;
17032 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17033 &region);
17034 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17035 &region);
17036
17037 region.imageExtent = {1, 1, 1};
17038 region.imageSubresource.mipLevel = 5;
17039 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17040 &region);
17041 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17042 &region);
17043 m_errorMonitor->VerifyNotFound();
17044
17045 // Buffer must accomodate a full compressed block, regardless of texel count
17046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17047 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
17048 &region);
17049 m_errorMonitor->VerifyFound();
17050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
17051 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17052 &region);
17053 m_errorMonitor->VerifyFound();
17054
17055 // Copy width < compressed block size, but not the full mip width
17056 region.imageExtent = {1, 2, 1};
17057 region.imageSubresource.mipLevel = 4;
17058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17059 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17060 &region);
17061 m_errorMonitor->VerifyFound();
17062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17063 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17064 &region);
17065 m_errorMonitor->VerifyFound();
17066
17067 // Copy height < compressed block size but not the full mip height
17068 region.imageExtent = {2, 1, 1};
17069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17070 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17071 &region);
17072 m_errorMonitor->VerifyFound();
17073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17074 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17075 &region);
17076 m_errorMonitor->VerifyFound();
17077
17078 // Offsets must be multiple of compressed block size
17079 region.imageOffset = {1, 1, 0};
17080 region.imageExtent = {1, 1, 1};
17081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17082 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17083 &region);
17084 m_errorMonitor->VerifyFound();
17085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17086 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17087 &region);
17088 m_errorMonitor->VerifyFound();
17089
17090 // Offset + extent width = mip width - should succeed
17091 region.imageOffset = {4, 4, 0};
17092 region.imageExtent = {3, 4, 1};
17093 region.imageSubresource.mipLevel = 2;
17094 m_errorMonitor->ExpectSuccess();
17095 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17096 &region);
17097 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17098 &region);
17099 m_errorMonitor->VerifyNotFound();
17100
17101 // Offset + extent width > mip width, but still within the final compressed block - should succeed
17102 region.imageExtent = {4, 4, 1};
17103 m_errorMonitor->ExpectSuccess();
17104 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17105 &region);
17106 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17107 &region);
17108 m_errorMonitor->VerifyNotFound();
17109
17110 // Offset + extent width < mip width and not a multiple of block width - should fail
17111 region.imageExtent = {3, 3, 1};
17112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17113 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17114 &region);
17115 m_errorMonitor->VerifyFound();
17116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17117 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17118 &region);
17119 m_errorMonitor->VerifyFound();
17120}
17121
Dave Houlton59a20702017-02-02 17:26:23 -070017122TEST_F(VkLayerTest, ImageBufferCopyTests) {
17123 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
17124
Tony Barbour1fa09702017-03-16 12:09:08 -060017125 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourf887b162017-03-09 10:06:46 -070017126 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
17127 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
17128 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
17129 return;
17130 }
Dave Houlton584d51e2017-02-16 12:52:54 -070017131
17132 // Bail if any dimension of transfer granularity is 0.
17133 auto index = m_device->graphics_queue_node_index_;
17134 auto queue_family_properties = m_device->phy().queue_properties();
17135 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
17136 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
17137 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
17138 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
17139 return;
17140 }
17141
Dave Houlton59a20702017-02-02 17:26:23 -070017142 VkImageObj image_64k(m_device); // 128^2 texels, 64k
17143 VkImageObj image_16k(m_device); // 64^2 texels, 16k
17144 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070017145 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
17146 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
17147 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
17148 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
17149
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017150 image_64k.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017151 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17152 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017153 image_16k.Init(64, 64, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017154 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17155 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017156 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 -070017157 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070017158 ASSERT_TRUE(image_64k.initialized());
17159 ASSERT_TRUE(image_16k.initialized());
17160 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017161
Dave Houltonf3229d52017-02-21 15:59:08 -070017162 // Verify all needed Depth/Stencil formats are supported
17163 bool missing_ds_support = false;
17164 VkFormatProperties props = {0, 0, 0};
17165 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
17166 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17167 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
17168 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17169 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
17170 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17171 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
17172 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17173
17174 if (!missing_ds_support) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017175 ds_image_4D_1S.Init(
17176 256, 256, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017177 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17178 VK_IMAGE_TILING_OPTIMAL, 0);
17179 ASSERT_TRUE(ds_image_4D_1S.initialized());
17180
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017181 ds_image_3D_1S.Init(
17182 256, 256, 1, VK_FORMAT_D24_UNORM_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017183 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17184 VK_IMAGE_TILING_OPTIMAL, 0);
17185 ASSERT_TRUE(ds_image_3D_1S.initialized());
17186
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017187 ds_image_2D.Init(
17188 256, 256, 1, VK_FORMAT_D16_UNORM,
17189 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17190 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017191 ASSERT_TRUE(ds_image_2D.initialized());
17192
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017193 ds_image_1S.Init(
17194 256, 256, 1, VK_FORMAT_S8_UINT,
17195 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17196 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017197 ASSERT_TRUE(ds_image_1S.initialized());
17198 }
17199
17200 // Allocate buffers
17201 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070017202 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070017203 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
17204 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
17205 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
17206 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070017207
17208 VkBufferImageCopy region = {};
17209 region.bufferRowLength = 0;
17210 region.bufferImageHeight = 0;
17211 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17212 region.imageSubresource.layerCount = 1;
17213 region.imageOffset = {0, 0, 0};
17214 region.imageExtent = {64, 64, 1};
17215 region.bufferOffset = 0;
17216
17217 // attempt copies before putting command buffer in recording state
17218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
17219 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17220 &region);
17221 m_errorMonitor->VerifyFound();
17222
17223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
17224 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17225 &region);
17226 m_errorMonitor->VerifyFound();
17227
17228 // start recording
17229 m_commandBuffer->BeginCommandBuffer();
17230
17231 // successful copies
17232 m_errorMonitor->ExpectSuccess();
17233 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17234 &region);
17235 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17236 &region);
17237 region.imageOffset.x = 16; // 16k copy, offset requires larger image
17238 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17239 &region);
17240 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
17241 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17242 &region);
17243 region.imageOffset.x = 0;
17244 region.imageExtent.height = 64;
17245 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
17246 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17247 &region);
17248 m_errorMonitor->VerifyNotFound();
17249
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017250 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070017251 region.imageExtent = {65, 64, 1};
17252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17253 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17254 &region);
17255 m_errorMonitor->VerifyFound();
17256
17257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17258 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17259 &region);
17260 m_errorMonitor->VerifyFound();
17261
17262 // image/buffer too small (offset) on copy to image
17263 region.imageExtent = {64, 64, 1};
17264 region.imageOffset = {0, 4, 0};
17265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17266 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17267 &region);
17268 m_errorMonitor->VerifyFound();
17269
17270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17271 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17272 &region);
17273 m_errorMonitor->VerifyFound();
17274
17275 // image/buffer too small on copy to buffer
17276 region.imageExtent = {64, 64, 1};
17277 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070017278 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
17280 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17281 &region);
17282 m_errorMonitor->VerifyFound();
17283
17284 region.imageExtent = {64, 65, 1};
17285 region.bufferOffset = 0;
17286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
17287 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17288 &region);
17289 m_errorMonitor->VerifyFound();
17290
17291 // buffer size ok but rowlength causes loose packing
17292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17293 region.imageExtent = {64, 64, 1};
17294 region.bufferRowLength = 68;
17295 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17296 &region);
17297 m_errorMonitor->VerifyFound();
17298
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017299 // An extent with zero area should produce a warning, but no error
17300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
17301 region.imageExtent.width = 0;
17302 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17303 &region);
17304 m_errorMonitor->VerifyFound();
17305
Dave Houlton59a20702017-02-02 17:26:23 -070017306 // aspect bits
17307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
17308 region.imageExtent = {64, 64, 1};
17309 region.bufferRowLength = 0;
17310 region.bufferImageHeight = 0;
17311 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17312 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17313 buffer_16k.handle(), 1, &region);
17314 m_errorMonitor->VerifyFound();
17315
17316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
17317 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17318 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17319 &region);
17320 m_errorMonitor->VerifyFound();
17321
17322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
17323 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17324 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17325 buffer_16k.handle(), 1, &region);
17326 m_errorMonitor->VerifyFound();
17327
Dave Houltonf3229d52017-02-21 15:59:08 -070017328 // Test Depth/Stencil copies
17329 if (missing_ds_support) {
17330 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
17331 } else {
17332 VkBufferImageCopy ds_region = {};
17333 ds_region.bufferOffset = 0;
17334 ds_region.bufferRowLength = 0;
17335 ds_region.bufferImageHeight = 0;
17336 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17337 ds_region.imageSubresource.mipLevel = 0;
17338 ds_region.imageSubresource.baseArrayLayer = 0;
17339 ds_region.imageSubresource.layerCount = 1;
17340 ds_region.imageOffset = {0, 0, 0};
17341 ds_region.imageExtent = {256, 256, 1};
17342
17343 // Depth copies that should succeed
17344 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
17345 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17346 buffer_256k.handle(), 1, &ds_region);
17347 m_errorMonitor->VerifyNotFound();
17348
17349 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
17350 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17351 buffer_256k.handle(), 1, &ds_region);
17352 m_errorMonitor->VerifyNotFound();
17353
17354 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
17355 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17356 buffer_128k.handle(), 1, &ds_region);
17357 m_errorMonitor->VerifyNotFound();
17358
17359 // Depth copies that should fail
17360 ds_region.bufferOffset = 4;
17361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17362 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
17363 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17364 buffer_256k.handle(), 1, &ds_region);
17365 m_errorMonitor->VerifyFound();
17366
17367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17368 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
17369 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17370 buffer_256k.handle(), 1, &ds_region);
17371 m_errorMonitor->VerifyFound();
17372
17373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17374 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
17375 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17376 buffer_128k.handle(), 1, &ds_region);
17377 m_errorMonitor->VerifyFound();
17378
17379 // Stencil copies that should succeed
17380 ds_region.bufferOffset = 0;
17381 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
17382 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17383 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17384 buffer_64k.handle(), 1, &ds_region);
17385 m_errorMonitor->VerifyNotFound();
17386
17387 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17388 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17389 buffer_64k.handle(), 1, &ds_region);
17390 m_errorMonitor->VerifyNotFound();
17391
17392 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
17393 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17394 buffer_64k.handle(), 1, &ds_region);
17395 m_errorMonitor->VerifyNotFound();
17396
17397 // Stencil copies that should fail
17398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17399 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17400 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17401 buffer_16k.handle(), 1, &ds_region);
17402 m_errorMonitor->VerifyFound();
17403
17404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17405 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17406 ds_region.bufferRowLength = 260;
17407 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17408 buffer_64k.handle(), 1, &ds_region);
17409 m_errorMonitor->VerifyFound();
17410
17411 ds_region.bufferRowLength = 0;
17412 ds_region.bufferOffset = 4;
17413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17414 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
17415 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17416 buffer_64k.handle(), 1, &ds_region);
17417 m_errorMonitor->VerifyFound();
17418 }
17419
Dave Houlton584d51e2017-02-16 12:52:54 -070017420 // Test compressed formats, if supported
Jamie Madill35127872017-03-15 16:17:46 -040017421 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton584d51e2017-02-16 12:52:54 -070017422 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070017423 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
17424 device_features.textureCompressionASTC_LDR)) {
17425 printf(" No compressed formats supported - block compression tests skipped.\n");
17426 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070017427 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
17428 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070017429 if (device_features.textureCompressionBC) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017430 image_16k_4x4comp.Init(128, 128, 1, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
17431 0);
17432 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 -070017433 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017434 } else if (device_features.textureCompressionETC2) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017435 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 -070017436 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017437 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 -070017438 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017439 } else {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017440 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 -070017441 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017442 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 -070017443 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017444 }
17445 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017446
Dave Houlton584d51e2017-02-16 12:52:54 -070017447 // Just fits
17448 m_errorMonitor->ExpectSuccess();
17449 region.imageExtent = {128, 128, 1};
17450 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17451 buffer_16k.handle(), 1, &region);
17452 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017453
Dave Houlton584d51e2017-02-16 12:52:54 -070017454 // with offset, too big for buffer
17455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17456 region.bufferOffset = 16;
17457 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17458 buffer_16k.handle(), 1, &region);
17459 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017460 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017461
Dave Houlton67e9b532017-03-02 17:00:10 -070017462 // extents that are not a multiple of compressed block size
17463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17464 region.imageExtent.width = 66;
17465 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17466 buffer_16k.handle(), 1, &region);
17467 m_errorMonitor->VerifyFound();
17468 region.imageExtent.width = 128;
17469
17470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017471 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070017472 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17473 buffer_16k.handle(), 1, &region);
17474 m_errorMonitor->VerifyFound();
17475 region.imageExtent.height = 128;
17476
17477 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
17478
17479 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
17480 m_errorMonitor->ExpectSuccess();
17481 region.imageExtent.width = 66;
17482 region.imageOffset.x = 64;
17483 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17484 buffer_16k.handle(), 1, &region);
17485 region.imageExtent.width = 16;
17486 region.imageOffset.x = 0;
17487 region.imageExtent.height = 2;
17488 region.imageOffset.y = 128;
17489 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017490 buffer_16k.handle(), 1, &region);
17491 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017492 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017493
Dave Houlton584d51e2017-02-16 12:52:54 -070017494 // buffer offset must be a multiple of texel block size (16)
17495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
17496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
17497 region.imageExtent = {64, 64, 1};
17498 region.bufferOffset = 24;
17499 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17500 buffer_16k.handle(), 1, &region);
17501 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017502
Dave Houlton584d51e2017-02-16 12:52:54 -070017503 // rowlength not a multiple of block width (4)
17504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
17505 region.bufferOffset = 0;
17506 region.bufferRowLength = 130;
17507 region.bufferImageHeight = 0;
17508 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17509 buffer_64k.handle(), 1, &region);
17510 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017511
Dave Houlton584d51e2017-02-16 12:52:54 -070017512 // imageheight not a multiple of block height (4)
17513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
17514 region.bufferRowLength = 0;
17515 region.bufferImageHeight = 130;
17516 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17517 buffer_64k.handle(), 1, &region);
17518 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070017519 }
Dave Houlton59a20702017-02-02 17:26:23 -070017520}
17521
Tony Barbourd6673642016-05-05 14:46:39 -060017522TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070017523 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060017524
Tony Barbour1fa09702017-03-16 12:09:08 -060017525 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060017526
Rene Lindsay135204f2016-12-22 17:11:09 -070017527 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060017528 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017529 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 -070017530 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060017531 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060017532 vk_testing::Buffer buffer;
17533 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070017534 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060017535 VkBufferImageCopy region = {};
17536 region.bufferRowLength = 128;
17537 region.bufferImageHeight = 128;
17538 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17539 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070017540 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017541 region.imageExtent.height = 4;
17542 region.imageExtent.width = 4;
17543 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070017544
17545 VkImageObj image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017546 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 -070017547 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070017548 ASSERT_TRUE(image2.initialized());
17549 vk_testing::Buffer buffer2;
17550 VkMemoryPropertyFlags reqs2 = 0;
17551 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
17552 VkBufferImageCopy region2 = {};
17553 region2.bufferRowLength = 128;
17554 region2.bufferImageHeight = 128;
17555 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17556 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
17557 region2.imageSubresource.layerCount = 1;
17558 region2.imageExtent.height = 4;
17559 region2.imageExtent.width = 4;
17560 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017561 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060017562
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017563 // Image must have offset.z of 0 and extent.depth of 1
17564 // Introduce failure by setting imageExtent.depth to 0
17565 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017567 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017568 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017569 m_errorMonitor->VerifyFound();
17570
17571 region.imageExtent.depth = 1;
17572
17573 // Image must have offset.z of 0 and extent.depth of 1
17574 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017575 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017576 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017579 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017580 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017581 m_errorMonitor->VerifyFound();
17582
17583 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017584 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
17585 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070017586 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017588 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17589 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017590 m_errorMonitor->VerifyFound();
17591
17592 // BufferOffset must be a multiple of 4
17593 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070017594 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070017596 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
17597 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017598 m_errorMonitor->VerifyFound();
17599
17600 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
17601 region.bufferOffset = 0;
17602 region.imageExtent.height = 128;
17603 region.imageExtent.width = 128;
17604 // Introduce failure by setting bufferRowLength > 0 but less than width
17605 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017607 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17608 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017609 m_errorMonitor->VerifyFound();
17610
17611 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
17612 region.bufferRowLength = 128;
17613 // Introduce failure by setting bufferRowHeight > 0 but less than height
17614 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017616 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17617 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017618 m_errorMonitor->VerifyFound();
17619
17620 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060017621 VkImageObj intImage1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017622 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 -070017623 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017624 VkImageObj intImage2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017625 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 -070017626 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017627 VkImageBlit blitRegion = {};
17628 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17629 blitRegion.srcSubresource.baseArrayLayer = 0;
17630 blitRegion.srcSubresource.layerCount = 1;
17631 blitRegion.srcSubresource.mipLevel = 0;
17632 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17633 blitRegion.dstSubresource.baseArrayLayer = 0;
17634 blitRegion.dstSubresource.layerCount = 1;
17635 blitRegion.dstSubresource.mipLevel = 0;
17636
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017637 // Look for NULL-blit warning
Jeremy Hayesf8e749f2017-03-15 09:40:27 -060017638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17639 "vkCmdBlitImage: pRegions[0].srcOffsets specify a zero-volume area.");
17640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17641 "vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017642 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.Layout(), intImage2.handle(),
17643 intImage2.Layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017644 m_errorMonitor->VerifyFound();
17645
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070017646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060017647 VkImageMemoryBarrier img_barrier;
17648 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17649 img_barrier.pNext = NULL;
17650 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17651 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17652 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17653 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17654 img_barrier.image = image.handle();
17655 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17656 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17657 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17658 img_barrier.subresourceRange.baseArrayLayer = 0;
17659 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060017660 img_barrier.subresourceRange.layerCount = 0;
17661 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017662 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
17663 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060017664 m_errorMonitor->VerifyFound();
17665 img_barrier.subresourceRange.layerCount = 1;
17666}
17667
17668TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060017669 TEST_DESCRIPTION("Exceed the limits of image format ");
17670
Tony Barbour1fa09702017-03-16 12:09:08 -060017671 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017672
17673 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
17674 {
17675 VkFormatProperties properties;
17676 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
17677 if (properties.linearTilingFeatures == 0) {
17678 printf(" Image format not supported; skipped.\n");
17679 return;
17680 }
17681 }
17682
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060017684 VkImageCreateInfo image_create_info = {};
17685 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17686 image_create_info.pNext = NULL;
17687 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017688 image_create_info.format = format;
Tony Barbourd6673642016-05-05 14:46:39 -060017689 image_create_info.extent.width = 32;
17690 image_create_info.extent.height = 32;
17691 image_create_info.extent.depth = 1;
17692 image_create_info.mipLevels = 1;
17693 image_create_info.arrayLayers = 1;
17694 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17695 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17696 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17697 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17698 image_create_info.flags = 0;
17699
17700 VkImage nullImg;
17701 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017702 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
17703 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070017704 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017705 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17706 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17707 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070017708 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017709
Tony Barbour0907e362017-03-09 15:05:30 -070017710 uint32_t maxDim =
17711 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
17712 // If max mip levels exceeds image extents, skip the max mip levels test
17713 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
17714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
17715 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
17716 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17717 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17718 m_errorMonitor->VerifyFound();
17719 image_create_info.mipLevels = 1;
17720 }
Tony Barbourd6673642016-05-05 14:46:39 -060017721
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060017723 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
17724 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17725 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17726 m_errorMonitor->VerifyFound();
17727 image_create_info.arrayLayers = 1;
17728
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060017730 int samples = imgFmtProps.sampleCounts >> 1;
17731 image_create_info.samples = (VkSampleCountFlagBits)samples;
17732 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17733 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17734 m_errorMonitor->VerifyFound();
17735 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17736
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17738 "pCreateInfo->initialLayout, must be "
17739 "VK_IMAGE_LAYOUT_UNDEFINED or "
17740 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060017741 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17742 // Expect INVALID_LAYOUT
17743 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17744 m_errorMonitor->VerifyFound();
17745 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17746}
17747
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017748TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017749 // Image copy with source region specified greater than src image size
Tony Barbour1fa09702017-03-16 12:09:08 -060017750 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017751
Dave Houltonfc1a4052017-04-27 14:32:45 -060017752 // Create images with full mip chain
17753 VkImageCreateInfo ci;
17754 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17755 ci.pNext = NULL;
17756 ci.flags = 0;
17757 ci.imageType = VK_IMAGE_TYPE_3D;
17758 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
17759 ci.extent = {32, 32, 8};
17760 ci.mipLevels = 6;
17761 ci.arrayLayers = 1;
17762 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17763 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17764 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17765 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17766 ci.queueFamilyIndexCount = 0;
17767 ci.pQueueFamilyIndices = NULL;
17768 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17769
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017770 VkImageObj src_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017771 src_image.init(&ci);
17772 ASSERT_TRUE(src_image.initialized());
17773
17774 // Dest image with one more mip level
17775 ci.extent = {64, 64, 16};
17776 ci.mipLevels = 7;
17777 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017778 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017779 dst_image.init(&ci);
17780 ASSERT_TRUE(dst_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017781
Tony Barbour552f6c02016-12-21 14:34:07 -070017782 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017783
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017784 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017785 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017786 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017787 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060017788 copy_region.srcSubresource.mipLevel = 0;
17789 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017790 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017791 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017792 copy_region.srcSubresource.layerCount = 1;
17793 copy_region.dstSubresource.layerCount = 1;
17794 copy_region.srcOffset = {0, 0, 0};
17795 copy_region.dstOffset = {0, 0, 0};
17796
17797 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017798 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17799 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017800 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017801
Dave Houltonfc1a4052017-04-27 14:32:45 -060017802 // Source exceeded in x-dim, VU 01202
17803 copy_region.srcOffset.x = 4;
17804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175); // General "contained within" VU
17805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01202);
17806 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17807 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017808 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017809
17810 // Source exceeded in y-dim, VU 01203
17811 copy_region.srcOffset.x = 0;
17812 copy_region.extent.height = 48;
17813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
17814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01203);
17815 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17816 &copy_region);
17817 m_errorMonitor->VerifyFound();
17818
17819 // Source exceeded in z-dim, VU 01204
17820 copy_region.extent = {4, 4, 4};
17821 copy_region.srcSubresource.mipLevel = 2;
17822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
17823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01204);
17824 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17825 &copy_region);
17826 m_errorMonitor->VerifyFound();
17827
17828 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017829}
17830
17831TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017832 // Image copy with dest region specified greater than dest image size
Tony Barbour1fa09702017-03-16 12:09:08 -060017833 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017834
Dave Houltonfc1a4052017-04-27 14:32:45 -060017835 // Create images with full mip chain
17836 VkImageCreateInfo ci;
17837 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17838 ci.pNext = NULL;
17839 ci.flags = 0;
17840 ci.imageType = VK_IMAGE_TYPE_3D;
17841 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
17842 ci.extent = {32, 32, 8};
17843 ci.mipLevels = 6;
17844 ci.arrayLayers = 1;
17845 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17846 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17847 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17848 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17849 ci.queueFamilyIndexCount = 0;
17850 ci.pQueueFamilyIndices = NULL;
17851 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17852
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017853 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017854 dst_image.init(&ci);
17855 ASSERT_TRUE(dst_image.initialized());
17856
17857 // Src image with one more mip level
17858 ci.extent = {64, 64, 16};
17859 ci.mipLevels = 7;
17860 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17861 VkImageObj src_image(m_device);
17862 src_image.init(&ci);
17863 ASSERT_TRUE(src_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017864
Tony Barbour552f6c02016-12-21 14:34:07 -070017865 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017866
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017867 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017868 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017869 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017870 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060017871 copy_region.srcSubresource.mipLevel = 0;
17872 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017873 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017874 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017875 copy_region.srcSubresource.layerCount = 1;
17876 copy_region.dstSubresource.layerCount = 1;
17877 copy_region.srcOffset = {0, 0, 0};
17878 copy_region.dstOffset = {0, 0, 0};
17879
17880 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017881 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17882 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017883 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017884
Dave Houltonfc1a4052017-04-27 14:32:45 -060017885 // Dest exceeded in x-dim, VU 01205
17886 copy_region.dstOffset.x = 4;
17887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176); // General "contained within" VU
17888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01205);
17889 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17890 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017891 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017892
17893 // Dest exceeded in y-dim, VU 01206
17894 copy_region.dstOffset.x = 0;
17895 copy_region.extent.height = 48;
17896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
17897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01206);
17898 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17899 &copy_region);
17900 m_errorMonitor->VerifyFound();
17901
17902 // Dest exceeded in z-dim, VU 01207
17903 copy_region.extent = {4, 4, 4};
17904 copy_region.dstSubresource.mipLevel = 2;
17905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
17906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01207);
17907 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17908 &copy_region);
17909 m_errorMonitor->VerifyFound();
17910
17911 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017912}
17913
Karl Schultz6addd812016-02-02 17:17:23 -070017914TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060017915 VkResult err;
17916 bool pass;
17917
17918 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070017919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060017920
Tony Barbour1fa09702017-03-16 12:09:08 -060017921 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -060017922
17923 // Create two images of different types and try to copy between them
17924 VkImage srcImage;
17925 VkImage dstImage;
17926 VkDeviceMemory srcMem;
17927 VkDeviceMemory destMem;
17928 VkMemoryRequirements memReqs;
17929
17930 VkImageCreateInfo image_create_info = {};
17931 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17932 image_create_info.pNext = NULL;
17933 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17934 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17935 image_create_info.extent.width = 32;
17936 image_create_info.extent.height = 32;
17937 image_create_info.extent.depth = 1;
17938 image_create_info.mipLevels = 1;
17939 image_create_info.arrayLayers = 1;
17940 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17941 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17942 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17943 image_create_info.flags = 0;
17944
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017945 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060017946 ASSERT_VK_SUCCESS(err);
17947
17948 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17949 // Introduce failure by creating second image with a different-sized format.
17950 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060017951 VkFormatProperties properties;
17952 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
17953 if (properties.optimalTilingFeatures == 0) {
17954 printf(" Image format not supported; skipped.\n");
17955 return;
17956 }
Karl Schultzbdb75952016-04-19 11:36:49 -060017957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017958 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060017959 ASSERT_VK_SUCCESS(err);
17960
17961 // Allocate memory
17962 VkMemoryAllocateInfo memAlloc = {};
17963 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17964 memAlloc.pNext = NULL;
17965 memAlloc.allocationSize = 0;
17966 memAlloc.memoryTypeIndex = 0;
17967
17968 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
17969 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017970 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060017971 ASSERT_TRUE(pass);
17972 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
17973 ASSERT_VK_SUCCESS(err);
17974
17975 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
17976 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017977 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060017978 ASSERT_TRUE(pass);
17979 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
17980 ASSERT_VK_SUCCESS(err);
17981
17982 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17983 ASSERT_VK_SUCCESS(err);
17984 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
17985 ASSERT_VK_SUCCESS(err);
17986
Tony Barbour552f6c02016-12-21 14:34:07 -070017987 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060017988 VkImageCopy copyRegion;
17989 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17990 copyRegion.srcSubresource.mipLevel = 0;
17991 copyRegion.srcSubresource.baseArrayLayer = 0;
17992 copyRegion.srcSubresource.layerCount = 0;
17993 copyRegion.srcOffset.x = 0;
17994 copyRegion.srcOffset.y = 0;
17995 copyRegion.srcOffset.z = 0;
17996 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17997 copyRegion.dstSubresource.mipLevel = 0;
17998 copyRegion.dstSubresource.baseArrayLayer = 0;
17999 copyRegion.dstSubresource.layerCount = 0;
18000 copyRegion.dstOffset.x = 0;
18001 copyRegion.dstOffset.y = 0;
18002 copyRegion.dstOffset.z = 0;
18003 copyRegion.extent.width = 1;
18004 copyRegion.extent.height = 1;
18005 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018006 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018007 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018008
18009 m_errorMonitor->VerifyFound();
18010
18011 vkDestroyImage(m_device->device(), srcImage, NULL);
18012 vkDestroyImage(m_device->device(), dstImage, NULL);
18013 vkFreeMemory(m_device->device(), srcMem, NULL);
18014 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018015}
18016
Karl Schultz6addd812016-02-02 17:17:23 -070018017TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
18018 VkResult err;
18019 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018020
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018021 // Create a depth image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18023 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018024
Tony Barbour1fa09702017-03-16 12:09:08 -060018025 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018026 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018027 if (!depth_format) {
18028 return;
18029 }
Mike Stroyana3082432015-09-25 13:39:21 -060018030
18031 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018032 VkImage srcImage;
18033 VkImage dstImage;
18034 VkDeviceMemory srcMem;
18035 VkDeviceMemory destMem;
18036 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018037
18038 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018039 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18040 image_create_info.pNext = NULL;
18041 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018042 image_create_info.format = VK_FORMAT_D32_SFLOAT;
Karl Schultz6addd812016-02-02 17:17:23 -070018043 image_create_info.extent.width = 32;
18044 image_create_info.extent.height = 32;
18045 image_create_info.extent.depth = 1;
18046 image_create_info.mipLevels = 1;
18047 image_create_info.arrayLayers = 1;
18048 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Youngad61f4b2017-04-07 08:59:56 -060018049 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -070018050 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18051 image_create_info.flags = 0;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018052 VkFormatProperties properties;
18053 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18054 if (properties.optimalTilingFeatures == 0) {
18055 printf(" Image format not supported; skipped.\n");
18056 return;
18057 }
Mike Stroyana3082432015-09-25 13:39:21 -060018058
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018059 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018060 ASSERT_VK_SUCCESS(err);
18061
Karl Schultzbdb75952016-04-19 11:36:49 -060018062 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18063
Mark Lobodzinskidb117632016-03-31 10:45:56 -060018064 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070018065 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070018066 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060018067 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018068
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018069 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018070 ASSERT_VK_SUCCESS(err);
18071
18072 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018073 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018074 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18075 memAlloc.pNext = NULL;
18076 memAlloc.allocationSize = 0;
18077 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018078
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018079 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018080 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018081 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018082 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018083 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018084 ASSERT_VK_SUCCESS(err);
18085
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018086 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018087 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018088 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018089 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018090 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018091 ASSERT_VK_SUCCESS(err);
18092
18093 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18094 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018095 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018096 ASSERT_VK_SUCCESS(err);
18097
Tony Barbour552f6c02016-12-21 14:34:07 -070018098 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018099 VkImageCopy copyRegion;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018100 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018101 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018102 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018103 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018104 copyRegion.srcOffset.x = 0;
18105 copyRegion.srcOffset.y = 0;
18106 copyRegion.srcOffset.z = 0;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018107 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018108 copyRegion.dstSubresource.mipLevel = 0;
18109 copyRegion.dstSubresource.baseArrayLayer = 0;
18110 copyRegion.dstSubresource.layerCount = 0;
18111 copyRegion.dstOffset.x = 0;
18112 copyRegion.dstOffset.y = 0;
18113 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018114 copyRegion.extent.width = 1;
18115 copyRegion.extent.height = 1;
18116 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018117 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018118 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018119
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018120 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018121
Chia-I Wuf7458c52015-10-26 21:10:41 +080018122 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018123 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018124 vkFreeMemory(m_device->device(), srcMem, NULL);
18125 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018126}
18127
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018128TEST_F(VkLayerTest, CopyImageSampleCountMismatch) {
18129 TEST_DESCRIPTION("Image copies with sample count mis-matches");
Dave Houlton33c22b72017-02-28 13:16:02 -070018130
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018131 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton33c22b72017-02-28 13:16:02 -070018132
18133 VkImageFormatProperties image_format_properties;
18134 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
18135 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
18136 &image_format_properties);
18137
18138 if ((0 == (VK_SAMPLE_COUNT_2_BIT & image_format_properties.sampleCounts)) ||
18139 (0 == (VK_SAMPLE_COUNT_4_BIT & image_format_properties.sampleCounts))) {
18140 printf(" Image multi-sample support not found; skipped.\n");
18141 return;
18142 }
18143
18144 VkImageCreateInfo ci;
18145 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18146 ci.pNext = NULL;
18147 ci.flags = 0;
18148 ci.imageType = VK_IMAGE_TYPE_2D;
18149 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18150 ci.extent = {128, 128, 1};
18151 ci.mipLevels = 1;
18152 ci.arrayLayers = 1;
18153 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18154 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18155 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18156 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18157 ci.queueFamilyIndexCount = 0;
18158 ci.pQueueFamilyIndices = NULL;
18159 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18160
18161 VkImageObj image1(m_device);
18162 image1.init(&ci);
18163 ASSERT_TRUE(image1.initialized());
18164
18165 ci.samples = VK_SAMPLE_COUNT_2_BIT;
18166 VkImageObj image2(m_device);
18167 image2.init(&ci);
18168 ASSERT_TRUE(image2.initialized());
18169
18170 ci.samples = VK_SAMPLE_COUNT_4_BIT;
18171 VkImageObj image4(m_device);
18172 image4.init(&ci);
18173 ASSERT_TRUE(image4.initialized());
18174
18175 m_commandBuffer->BeginCommandBuffer();
18176
18177 VkImageCopy copyRegion;
18178 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18179 copyRegion.srcSubresource.mipLevel = 0;
18180 copyRegion.srcSubresource.baseArrayLayer = 0;
18181 copyRegion.srcSubresource.layerCount = 1;
18182 copyRegion.srcOffset = {0, 0, 0};
18183 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18184 copyRegion.dstSubresource.mipLevel = 0;
18185 copyRegion.dstSubresource.baseArrayLayer = 0;
18186 copyRegion.dstSubresource.layerCount = 1;
18187 copyRegion.dstOffset = {0, 0, 0};
18188 copyRegion.extent = {128, 128, 1};
18189
18190 // Copy a single sample image to/from a multi-sample image
18191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18192 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image1.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18193 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18194 m_errorMonitor->VerifyFound();
18195
18196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18197 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image1.handle(),
18198 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18199 m_errorMonitor->VerifyFound();
18200
18201 // Copy between multi-sample images with different sample counts
18202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18203 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18204 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18205 m_errorMonitor->VerifyFound();
18206
18207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18208 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image4.handle(), VK_IMAGE_LAYOUT_GENERAL, image2.handle(),
18209 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18210 m_errorMonitor->VerifyFound();
18211
18212 m_commandBuffer->EndCommandBuffer();
18213}
18214
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018215TEST_F(VkLayerTest, CopyImageAspectMismatch) {
18216 TEST_DESCRIPTION("Image copies with aspect mask errors");
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018217 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018218 auto ds_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060018219 if (!ds_format) {
18220 return;
18221 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018222
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018223 VkFormatProperties properties;
18224 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT, &properties);
18225 if (properties.optimalTilingFeatures == 0) {
18226 printf(" Image format VK_FORMAT_D32_SFLOAT not supported; skipped.\n");
18227 return;
18228 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018229 VkImageObj color_image(m_device), ds_image(m_device), depth_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018230 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 -060018231 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 -060018232 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018233 ds_image.Init(128, 128, 1, ds_format, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
18234 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018235 ASSERT_TRUE(color_image.initialized());
18236 ASSERT_TRUE(depth_image.initialized());
18237 ASSERT_TRUE(ds_image.initialized());
18238
18239 VkImageCopy copyRegion;
18240 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18241 copyRegion.srcSubresource.mipLevel = 0;
18242 copyRegion.srcSubresource.baseArrayLayer = 0;
18243 copyRegion.srcSubresource.layerCount = 1;
18244 copyRegion.srcOffset = {0, 0, 0};
18245 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18246 copyRegion.dstSubresource.mipLevel = 0;
18247 copyRegion.dstSubresource.baseArrayLayer = 0;
18248 copyRegion.dstSubresource.layerCount = 1;
18249 copyRegion.dstOffset = {64, 0, 0};
18250 copyRegion.extent = {64, 128, 1};
18251
18252 // Submitting command before command buffer is in recording state
Dave Houlton3c9fca72017-03-27 17:25:54 -060018253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18254 "You must call vkBeginCommandBuffer"); // VALIDATION_ERROR_01192);
18255 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), depth_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18256 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018257 m_errorMonitor->VerifyFound();
18258
18259 m_commandBuffer->BeginCommandBuffer();
18260
18261 // Src and dest aspect masks don't match
18262 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
18263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01197);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018264 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, ds_image.handle(),
18265 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018266 m_errorMonitor->VerifyFound();
18267 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18268
18269 // Illegal combinations of aspect bits - VU 01221
Dave Houlton3c9fca72017-03-27 17:25:54 -060018270 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; // color must be alone
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018271 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
18272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01221);
18273 // These aspect/format mismatches are redundant but unavoidable here
18274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018276 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18277 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018278 m_errorMonitor->VerifyFound();
18279 // Metadata aspect is illegal - VU 01222
18280 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18281 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01222);
18283 // These aspect/format mismatches are redundant but unavoidable here
Dave Houlton3c9fca72017-03-27 17:25:54 -060018284 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18285 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018286 m_errorMonitor->VerifyFound();
18287
18288 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18289 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18290
18291 // Aspect mask doesn't match source image format - VU 01200
18292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18293 // Again redundant but unavoidable when provoking vu01200 w/o vu01201
18294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18295 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18296 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18297 m_errorMonitor->VerifyFound();
18298
18299 // Aspect mask doesn't match dest image format - VU 01201
18300 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18301 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
18303 // Again redundant but unavoidable when provoking vu01201 w/o vu01200
18304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18305 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18306 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18307 m_errorMonitor->VerifyFound();
18308
18309 m_commandBuffer->EndCommandBuffer();
18310}
18311
Karl Schultz6addd812016-02-02 17:17:23 -070018312TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
18313 VkResult err;
18314 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018315
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18317 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018318
Tony Barbour1fa09702017-03-16 12:09:08 -060018319 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018320
18321 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018322 VkImage srcImage;
18323 VkImage dstImage;
18324 VkDeviceMemory srcMem;
18325 VkDeviceMemory destMem;
18326 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018327
18328 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018329 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18330 image_create_info.pNext = NULL;
18331 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18332 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18333 image_create_info.extent.width = 32;
18334 image_create_info.extent.height = 1;
18335 image_create_info.extent.depth = 1;
18336 image_create_info.mipLevels = 1;
18337 image_create_info.arrayLayers = 1;
18338 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18339 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18340 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18341 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018342
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018343 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018344 ASSERT_VK_SUCCESS(err);
18345
Karl Schultz6addd812016-02-02 17:17:23 -070018346 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018347
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018348 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018349 ASSERT_VK_SUCCESS(err);
18350
18351 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018352 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018353 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18354 memAlloc.pNext = NULL;
18355 memAlloc.allocationSize = 0;
18356 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018357
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018358 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018359 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018360 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018361 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018362 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018363 ASSERT_VK_SUCCESS(err);
18364
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018365 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018366 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018367 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018368 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018369 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018370 ASSERT_VK_SUCCESS(err);
18371
18372 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18373 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018374 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018375 ASSERT_VK_SUCCESS(err);
18376
Tony Barbour552f6c02016-12-21 14:34:07 -070018377 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018378 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018379 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18380 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018381 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018382 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018383 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018384 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018385 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018386 resolveRegion.srcOffset.x = 0;
18387 resolveRegion.srcOffset.y = 0;
18388 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018389 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018390 resolveRegion.dstSubresource.mipLevel = 0;
18391 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018392 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018393 resolveRegion.dstOffset.x = 0;
18394 resolveRegion.dstOffset.y = 0;
18395 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018396 resolveRegion.extent.width = 1;
18397 resolveRegion.extent.height = 1;
18398 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018399 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018400 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018401
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018402 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018403
Chia-I Wuf7458c52015-10-26 21:10:41 +080018404 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018405 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018406 vkFreeMemory(m_device->device(), srcMem, NULL);
18407 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018408}
18409
Karl Schultz6addd812016-02-02 17:17:23 -070018410TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
18411 VkResult err;
18412 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18415 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018416
Tony Barbour1fa09702017-03-16 12:09:08 -060018417 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018418
Chris Forbesa7530692016-05-08 12:35:39 +120018419 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018420 VkImage srcImage;
18421 VkImage dstImage;
18422 VkDeviceMemory srcMem;
18423 VkDeviceMemory destMem;
18424 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018425
18426 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018427 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18428 image_create_info.pNext = NULL;
18429 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18430 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18431 image_create_info.extent.width = 32;
18432 image_create_info.extent.height = 1;
18433 image_create_info.extent.depth = 1;
18434 image_create_info.mipLevels = 1;
18435 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120018436 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018437 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18438 // Note: Some implementations expect color attachment usage for any
18439 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018440 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018441 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018443 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018444 ASSERT_VK_SUCCESS(err);
18445
Karl Schultz6addd812016-02-02 17:17:23 -070018446 // Note: Some implementations expect color attachment usage for any
18447 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018448 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018450 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018451 ASSERT_VK_SUCCESS(err);
18452
18453 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018454 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018455 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18456 memAlloc.pNext = NULL;
18457 memAlloc.allocationSize = 0;
18458 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018459
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018460 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018461 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018462 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018463 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018464 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018465 ASSERT_VK_SUCCESS(err);
18466
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018467 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018468 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018469 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018470 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018471 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018472 ASSERT_VK_SUCCESS(err);
18473
18474 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18475 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018476 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018477 ASSERT_VK_SUCCESS(err);
18478
Tony Barbour552f6c02016-12-21 14:34:07 -070018479 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018480 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018481 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18482 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018483 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018484 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018485 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018486 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018487 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018488 resolveRegion.srcOffset.x = 0;
18489 resolveRegion.srcOffset.y = 0;
18490 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018491 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018492 resolveRegion.dstSubresource.mipLevel = 0;
18493 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018494 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018495 resolveRegion.dstOffset.x = 0;
18496 resolveRegion.dstOffset.y = 0;
18497 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018498 resolveRegion.extent.width = 1;
18499 resolveRegion.extent.height = 1;
18500 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018501 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018502 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018503
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018504 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018505
Chia-I Wuf7458c52015-10-26 21:10:41 +080018506 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018507 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018508 vkFreeMemory(m_device->device(), srcMem, NULL);
18509 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018510}
18511
Karl Schultz6addd812016-02-02 17:17:23 -070018512TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
18513 VkResult err;
18514 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018515
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018517 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018518
Tony Barbour1fa09702017-03-16 12:09:08 -060018519 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018520
18521 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018522 VkImage srcImage;
18523 VkImage dstImage;
18524 VkDeviceMemory srcMem;
18525 VkDeviceMemory destMem;
18526 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018527
18528 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018529 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18530 image_create_info.pNext = NULL;
18531 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18532 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18533 image_create_info.extent.width = 32;
18534 image_create_info.extent.height = 1;
18535 image_create_info.extent.depth = 1;
18536 image_create_info.mipLevels = 1;
18537 image_create_info.arrayLayers = 1;
18538 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18539 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18540 // Note: Some implementations expect color attachment usage for any
18541 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018542 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018543 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018544
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018545 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018546 ASSERT_VK_SUCCESS(err);
18547
Karl Schultz6addd812016-02-02 17:17:23 -070018548 // Set format to something other than source image
18549 image_create_info.format = VK_FORMAT_R32_SFLOAT;
18550 // Note: Some implementations expect color attachment usage for any
18551 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018552 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018553 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018554
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018555 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018556 ASSERT_VK_SUCCESS(err);
18557
18558 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018559 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018560 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18561 memAlloc.pNext = NULL;
18562 memAlloc.allocationSize = 0;
18563 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018564
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018565 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018566 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018567 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018568 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018569 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018570 ASSERT_VK_SUCCESS(err);
18571
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018572 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018573 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018574 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018575 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018576 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018577 ASSERT_VK_SUCCESS(err);
18578
18579 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18580 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018581 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018582 ASSERT_VK_SUCCESS(err);
18583
Tony Barbour552f6c02016-12-21 14:34:07 -070018584 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018585 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018586 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18587 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018588 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018589 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018590 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018591 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018592 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018593 resolveRegion.srcOffset.x = 0;
18594 resolveRegion.srcOffset.y = 0;
18595 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018596 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018597 resolveRegion.dstSubresource.mipLevel = 0;
18598 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018599 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018600 resolveRegion.dstOffset.x = 0;
18601 resolveRegion.dstOffset.y = 0;
18602 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018603 resolveRegion.extent.width = 1;
18604 resolveRegion.extent.height = 1;
18605 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018606 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018607 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018608
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018609 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018610
Chia-I Wuf7458c52015-10-26 21:10:41 +080018611 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018612 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018613 vkFreeMemory(m_device->device(), srcMem, NULL);
18614 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018615}
18616
Karl Schultz6addd812016-02-02 17:17:23 -070018617TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
18618 VkResult err;
18619 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018620
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018622 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018623
Tony Barbour1fa09702017-03-16 12:09:08 -060018624 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018625
18626 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018627 VkImage srcImage;
18628 VkImage dstImage;
18629 VkDeviceMemory srcMem;
18630 VkDeviceMemory destMem;
18631 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018632
18633 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018634 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18635 image_create_info.pNext = NULL;
18636 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18637 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18638 image_create_info.extent.width = 32;
18639 image_create_info.extent.height = 1;
18640 image_create_info.extent.depth = 1;
18641 image_create_info.mipLevels = 1;
18642 image_create_info.arrayLayers = 1;
18643 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18644 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18645 // Note: Some implementations expect color attachment usage for any
18646 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018647 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018648 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018649
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018650 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018651 ASSERT_VK_SUCCESS(err);
18652
Karl Schultz6addd812016-02-02 17:17:23 -070018653 image_create_info.imageType = VK_IMAGE_TYPE_1D;
18654 // Note: Some implementations expect color attachment usage for any
18655 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018656 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018657 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018658
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018659 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018660 ASSERT_VK_SUCCESS(err);
18661
18662 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018663 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018664 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18665 memAlloc.pNext = NULL;
18666 memAlloc.allocationSize = 0;
18667 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018668
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018669 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018670 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018671 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018672 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018673 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018674 ASSERT_VK_SUCCESS(err);
18675
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018676 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018677 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018678 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018679 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018680 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018681 ASSERT_VK_SUCCESS(err);
18682
18683 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18684 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018685 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018686 ASSERT_VK_SUCCESS(err);
18687
Tony Barbour552f6c02016-12-21 14:34:07 -070018688 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018689 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018690 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18691 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018692 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018693 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018694 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018695 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018696 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018697 resolveRegion.srcOffset.x = 0;
18698 resolveRegion.srcOffset.y = 0;
18699 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018700 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018701 resolveRegion.dstSubresource.mipLevel = 0;
18702 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018703 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018704 resolveRegion.dstOffset.x = 0;
18705 resolveRegion.dstOffset.y = 0;
18706 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018707 resolveRegion.extent.width = 1;
18708 resolveRegion.extent.height = 1;
18709 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018710 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018711 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018712
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018713 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018714
Chia-I Wuf7458c52015-10-26 21:10:41 +080018715 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018716 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018717 vkFreeMemory(m_device->device(), srcMem, NULL);
18718 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018719}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018720
Karl Schultz6addd812016-02-02 17:17:23 -070018721TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018722 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070018723 // to using a DS format, then cause it to hit error due to COLOR_BIT not
18724 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018725 // The image format check comes 2nd in validation so we trigger it first,
18726 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070018727 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018728
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18730 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018731
Tony Barbour1fa09702017-03-16 12:09:08 -060018732 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018733 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018734 if (!depth_format) {
18735 return;
18736 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018737
Chia-I Wu1b99bb22015-10-27 19:25:11 +080018738 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018739 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18740 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018741
18742 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018743 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18744 ds_pool_ci.pNext = NULL;
18745 ds_pool_ci.maxSets = 1;
18746 ds_pool_ci.poolSizeCount = 1;
18747 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018748
18749 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018750 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018751 ASSERT_VK_SUCCESS(err);
18752
18753 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018754 dsl_binding.binding = 0;
18755 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18756 dsl_binding.descriptorCount = 1;
18757 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18758 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018759
18760 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018761 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18762 ds_layout_ci.pNext = NULL;
18763 ds_layout_ci.bindingCount = 1;
18764 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018765 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018766 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018767 ASSERT_VK_SUCCESS(err);
18768
18769 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018770 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080018771 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070018772 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018773 alloc_info.descriptorPool = ds_pool;
18774 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018775 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018776 ASSERT_VK_SUCCESS(err);
18777
Karl Schultz6addd812016-02-02 17:17:23 -070018778 VkImage image_bad;
18779 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018780 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070018781 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018782 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070018783 const int32_t tex_width = 32;
18784 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018785
18786 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018787 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18788 image_create_info.pNext = NULL;
18789 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18790 image_create_info.format = tex_format_bad;
18791 image_create_info.extent.width = tex_width;
18792 image_create_info.extent.height = tex_height;
18793 image_create_info.extent.depth = 1;
18794 image_create_info.mipLevels = 1;
18795 image_create_info.arrayLayers = 1;
18796 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18797 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018798 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018799 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018800
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018801 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018802 ASSERT_VK_SUCCESS(err);
18803 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018804 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
18805 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018806 ASSERT_VK_SUCCESS(err);
18807
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018808 // ---Bind image memory---
18809 VkMemoryRequirements img_mem_reqs;
18810 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
18811 VkMemoryAllocateInfo image_alloc_info = {};
18812 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18813 image_alloc_info.pNext = NULL;
18814 image_alloc_info.memoryTypeIndex = 0;
18815 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018816 bool pass =
18817 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 -070018818 ASSERT_TRUE(pass);
18819 VkDeviceMemory mem;
18820 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
18821 ASSERT_VK_SUCCESS(err);
18822 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
18823 ASSERT_VK_SUCCESS(err);
18824 // -----------------------
18825
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018826 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130018827 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070018828 image_view_create_info.image = image_bad;
18829 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18830 image_view_create_info.format = tex_format_bad;
18831 image_view_create_info.subresourceRange.baseArrayLayer = 0;
18832 image_view_create_info.subresourceRange.baseMipLevel = 0;
18833 image_view_create_info.subresourceRange.layerCount = 1;
18834 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018835 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018836
18837 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018838 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018839
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018840 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018841
Chia-I Wuf7458c52015-10-26 21:10:41 +080018842 vkDestroyImage(m_device->device(), image_bad, NULL);
18843 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018844 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18845 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018846
18847 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018848}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018849
18850TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018851 TEST_DESCRIPTION(
18852 "Call ClearColorImage w/ a depth|stencil image and "
18853 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018854
Tony Barbour1fa09702017-03-16 12:09:08 -060018855 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018856 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018857 if (!depth_format) {
18858 return;
18859 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18861
Tony Barbour552f6c02016-12-21 14:34:07 -070018862 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018863
18864 // Color image
18865 VkClearColorValue clear_color;
18866 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
18867 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
18868 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
18869 const int32_t img_width = 32;
18870 const int32_t img_height = 32;
18871 VkImageCreateInfo image_create_info = {};
18872 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18873 image_create_info.pNext = NULL;
18874 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18875 image_create_info.format = color_format;
18876 image_create_info.extent.width = img_width;
18877 image_create_info.extent.height = img_height;
18878 image_create_info.extent.depth = 1;
18879 image_create_info.mipLevels = 1;
18880 image_create_info.arrayLayers = 1;
18881 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18882 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
18883 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18884
18885 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018886 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018887
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018888 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018889
18890 // Depth/Stencil image
18891 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018892 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018893 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
18894 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070018895 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018896 ds_image_create_info.extent.width = 64;
18897 ds_image_create_info.extent.height = 64;
18898 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070018899 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 -060018900
18901 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018902 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018903
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018904 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 -060018905
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018907
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018908 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018909 &color_range);
18910
18911 m_errorMonitor->VerifyFound();
18912
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18914 "vkCmdClearColorImage called with "
18915 "image created without "
18916 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060018917
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070018918 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060018919 &color_range);
18920
18921 m_errorMonitor->VerifyFound();
18922
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018923 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18925 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018926
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018927 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
18928 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018929
18930 m_errorMonitor->VerifyFound();
18931}
Tobin Ehliscde08892015-09-22 10:11:37 -060018932
Mike Schuchardt35fece12017-03-07 14:40:28 -070018933TEST_F(VkLayerTest, CommandQueueFlags) {
18934 TEST_DESCRIPTION(
18935 "Allocate a command buffer on a queue that does not support graphics and try to issue a "
18936 "graphics-only command");
18937
18938 ASSERT_NO_FATAL_FAILURE(Init());
18939
18940 uint32_t queueFamilyIndex = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_GRAPHICS_BIT);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018941 if (queueFamilyIndex == UINT32_MAX) {
Mike Schuchardt35fece12017-03-07 14:40:28 -070018942 printf(" Non-graphics queue family not found; skipped.\n");
18943 return;
18944 } else {
18945 // Create command pool on a non-graphics queue
18946 VkCommandPoolObj command_pool(m_device, queueFamilyIndex);
18947
18948 // Setup command buffer on pool
18949 VkCommandBufferObj command_buffer(m_device, &command_pool);
18950 command_buffer.BeginCommandBuffer();
18951
18952 // Issue a graphics only command
18953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01446);
18954 VkViewport viewport = {0, 0, 16, 16, 0, 1};
18955 command_buffer.SetViewport(0, 1, &viewport);
18956 m_errorMonitor->VerifyFound();
18957 }
18958}
18959
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018960// WSI Enabled Tests
18961//
Chris Forbes09368e42016-10-13 11:59:22 +130018962#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018963TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
18964
18965#if defined(VK_USE_PLATFORM_XCB_KHR)
18966 VkSurfaceKHR surface = VK_NULL_HANDLE;
18967
18968 VkResult err;
18969 bool pass;
18970 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
18971 VkSwapchainCreateInfoKHR swapchain_create_info = {};
18972 // uint32_t swapchain_image_count = 0;
18973 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
18974 // uint32_t image_index = 0;
18975 // VkPresentInfoKHR present_info = {};
18976
Tony Barbour1fa09702017-03-16 12:09:08 -060018977 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018978
18979 // Use the create function from one of the VK_KHR_*_surface extension in
18980 // order to create a surface, testing all known errors in the process,
18981 // before successfully creating a surface:
18982 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
18983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
18984 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
18985 pass = (err != VK_SUCCESS);
18986 ASSERT_TRUE(pass);
18987 m_errorMonitor->VerifyFound();
18988
18989 // Next, try to create a surface with the wrong
18990 // VkXcbSurfaceCreateInfoKHR::sType:
18991 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
18992 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
18993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
18994 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
18995 pass = (err != VK_SUCCESS);
18996 ASSERT_TRUE(pass);
18997 m_errorMonitor->VerifyFound();
18998
18999 // Create a native window, and then correctly create a surface:
19000 xcb_connection_t *connection;
19001 xcb_screen_t *screen;
19002 xcb_window_t xcb_window;
19003 xcb_intern_atom_reply_t *atom_wm_delete_window;
19004
19005 const xcb_setup_t *setup;
19006 xcb_screen_iterator_t iter;
19007 int scr;
19008 uint32_t value_mask, value_list[32];
19009 int width = 1;
19010 int height = 1;
19011
19012 connection = xcb_connect(NULL, &scr);
19013 ASSERT_TRUE(connection != NULL);
19014 setup = xcb_get_setup(connection);
19015 iter = xcb_setup_roots_iterator(setup);
19016 while (scr-- > 0)
19017 xcb_screen_next(&iter);
19018 screen = iter.data;
19019
19020 xcb_window = xcb_generate_id(connection);
19021
19022 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
19023 value_list[0] = screen->black_pixel;
19024 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
19025
19026 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
19027 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
19028
19029 /* Magic code that will send notification when window is destroyed */
19030 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
19031 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
19032
19033 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
19034 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
19035 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
19036 free(reply);
19037
19038 xcb_map_window(connection, xcb_window);
19039
19040 // Force the x/y coordinates to 100,100 results are identical in consecutive
19041 // runs
19042 const uint32_t coords[] = { 100, 100 };
19043 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
19044
19045 // Finally, try to correctly create a surface:
19046 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
19047 xcb_create_info.pNext = NULL;
19048 xcb_create_info.flags = 0;
19049 xcb_create_info.connection = connection;
19050 xcb_create_info.window = xcb_window;
19051 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19052 pass = (err == VK_SUCCESS);
19053 ASSERT_TRUE(pass);
19054
19055 // Check if surface supports presentation:
19056
19057 // 1st, do so without having queried the queue families:
19058 VkBool32 supported = false;
19059 // TODO: Get the following error to come out:
19060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19061 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
19062 "function");
19063 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19064 pass = (err != VK_SUCCESS);
19065 // ASSERT_TRUE(pass);
19066 // m_errorMonitor->VerifyFound();
19067
19068 // Next, query a queue family index that's too large:
19069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19070 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
19071 pass = (err != VK_SUCCESS);
19072 ASSERT_TRUE(pass);
19073 m_errorMonitor->VerifyFound();
19074
19075 // Finally, do so correctly:
19076 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19077 // SUPPORTED
19078 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19079 pass = (err == VK_SUCCESS);
19080 ASSERT_TRUE(pass);
19081
19082 // Before proceeding, try to create a swapchain without having called
19083 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
19084 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19085 swapchain_create_info.pNext = NULL;
19086 swapchain_create_info.flags = 0;
19087 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
19088 swapchain_create_info.surface = surface;
19089 swapchain_create_info.imageArrayLayers = 1;
19090 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
19091 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
19092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19093 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
19094 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19095 pass = (err != VK_SUCCESS);
19096 ASSERT_TRUE(pass);
19097 m_errorMonitor->VerifyFound();
19098
19099 // Get the surface capabilities:
19100 VkSurfaceCapabilitiesKHR surface_capabilities;
19101
19102 // Do so correctly (only error logged by this entrypoint is if the
19103 // extension isn't enabled):
19104 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
19105 pass = (err == VK_SUCCESS);
19106 ASSERT_TRUE(pass);
19107
19108 // Get the surface formats:
19109 uint32_t surface_format_count;
19110
19111 // First, try without a pointer to surface_format_count:
19112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
19113 "specified as NULL");
19114 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
19115 pass = (err == VK_SUCCESS);
19116 ASSERT_TRUE(pass);
19117 m_errorMonitor->VerifyFound();
19118
19119 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
19120 // correctly done a 1st try (to get the count):
19121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19122 surface_format_count = 0;
19123 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
19124 pass = (err == VK_SUCCESS);
19125 ASSERT_TRUE(pass);
19126 m_errorMonitor->VerifyFound();
19127
19128 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19129 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19130 pass = (err == VK_SUCCESS);
19131 ASSERT_TRUE(pass);
19132
19133 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19134 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
19135
19136 // Next, do a 2nd try with surface_format_count being set too high:
19137 surface_format_count += 5;
19138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19139 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19140 pass = (err == VK_SUCCESS);
19141 ASSERT_TRUE(pass);
19142 m_errorMonitor->VerifyFound();
19143
19144 // Finally, do a correct 1st and 2nd try:
19145 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19146 pass = (err == VK_SUCCESS);
19147 ASSERT_TRUE(pass);
19148 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19149 pass = (err == VK_SUCCESS);
19150 ASSERT_TRUE(pass);
19151
19152 // Get the surface present modes:
19153 uint32_t surface_present_mode_count;
19154
19155 // First, try without a pointer to surface_format_count:
19156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
19157 "specified as NULL");
19158
19159 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
19160 pass = (err == VK_SUCCESS);
19161 ASSERT_TRUE(pass);
19162 m_errorMonitor->VerifyFound();
19163
19164 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
19165 // correctly done a 1st try (to get the count):
19166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19167 surface_present_mode_count = 0;
19168 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
19169 (VkPresentModeKHR *)&surface_present_mode_count);
19170 pass = (err == VK_SUCCESS);
19171 ASSERT_TRUE(pass);
19172 m_errorMonitor->VerifyFound();
19173
19174 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19175 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19176 pass = (err == VK_SUCCESS);
19177 ASSERT_TRUE(pass);
19178
19179 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19180 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
19181
19182 // Next, do a 2nd try with surface_format_count being set too high:
19183 surface_present_mode_count += 5;
19184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19185 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19186 pass = (err == VK_SUCCESS);
19187 ASSERT_TRUE(pass);
19188 m_errorMonitor->VerifyFound();
19189
19190 // Finally, do a correct 1st and 2nd try:
19191 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19192 pass = (err == VK_SUCCESS);
19193 ASSERT_TRUE(pass);
19194 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19195 pass = (err == VK_SUCCESS);
19196 ASSERT_TRUE(pass);
19197
19198 // Create a swapchain:
19199
19200 // First, try without a pointer to swapchain_create_info:
19201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
19202 "specified as NULL");
19203
19204 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
19205 pass = (err != VK_SUCCESS);
19206 ASSERT_TRUE(pass);
19207 m_errorMonitor->VerifyFound();
19208
19209 // Next, call with a non-NULL swapchain_create_info, that has the wrong
19210 // sType:
19211 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19213
19214 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19215 pass = (err != VK_SUCCESS);
19216 ASSERT_TRUE(pass);
19217 m_errorMonitor->VerifyFound();
19218
19219 // Next, call with a NULL swapchain pointer:
19220 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19221 swapchain_create_info.pNext = NULL;
19222 swapchain_create_info.flags = 0;
19223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
19224 "specified as NULL");
19225
19226 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
19227 pass = (err != VK_SUCCESS);
19228 ASSERT_TRUE(pass);
19229 m_errorMonitor->VerifyFound();
19230
19231 // TODO: Enhance swapchain layer so that
19232 // swapchain_create_info.queueFamilyIndexCount is checked against something?
19233
19234 // Next, call with a queue family index that's too large:
19235 uint32_t queueFamilyIndex[2] = { 100000, 0 };
19236 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19237 swapchain_create_info.queueFamilyIndexCount = 2;
19238 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
19239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19240 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19241 pass = (err != VK_SUCCESS);
19242 ASSERT_TRUE(pass);
19243 m_errorMonitor->VerifyFound();
19244
19245 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
19246 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19247 swapchain_create_info.queueFamilyIndexCount = 1;
19248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19249 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
19250 "pCreateInfo->pQueueFamilyIndices).");
19251 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19252 pass = (err != VK_SUCCESS);
19253 ASSERT_TRUE(pass);
19254 m_errorMonitor->VerifyFound();
19255
19256 // Next, call with an invalid imageSharingMode:
19257 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
19258 swapchain_create_info.queueFamilyIndexCount = 1;
19259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19260 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
19261 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19262 pass = (err != VK_SUCCESS);
19263 ASSERT_TRUE(pass);
19264 m_errorMonitor->VerifyFound();
19265 // Fix for the future:
19266 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19267 // SUPPORTED
19268 swapchain_create_info.queueFamilyIndexCount = 0;
19269 queueFamilyIndex[0] = 0;
19270 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
19271
19272 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
19273 // Get the images from a swapchain:
19274 // Acquire an image from a swapchain:
19275 // Present an image to a swapchain:
19276 // Destroy the swapchain:
19277
19278 // TODOs:
19279 //
19280 // - Try destroying the device without first destroying the swapchain
19281 //
19282 // - Try destroying the device without first destroying the surface
19283 //
19284 // - Try destroying the surface without first destroying the swapchain
19285
19286 // Destroy the surface:
19287 vkDestroySurfaceKHR(instance(), surface, NULL);
19288
19289 // Tear down the window:
19290 xcb_destroy_window(connection, xcb_window);
19291 xcb_disconnect(connection);
19292
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019293#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019294 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019295#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019296}
Chris Forbes09368e42016-10-13 11:59:22 +130019297#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019298
19299//
19300// POSITIVE VALIDATION TESTS
19301//
19302// These tests do not expect to encounter ANY validation errors pass only if this is true
19303
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019304TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
19305 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
Tony Barbour1fa09702017-03-16 12:09:08 -060019306 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19308
19309 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19310 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019311 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019312 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19313 command_buffer_allocate_info.commandBufferCount = 1;
19314
19315 VkCommandBuffer secondary_command_buffer;
19316 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19317 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19318 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19319 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19320 command_buffer_inheritance_info.renderPass = m_renderPass;
19321 command_buffer_inheritance_info.framebuffer = m_framebuffer;
19322
19323 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19324 command_buffer_begin_info.flags =
19325 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19326 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19327
19328 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19329 VkClearAttachment color_attachment;
19330 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19331 color_attachment.clearValue.color.float32[0] = 0;
19332 color_attachment.clearValue.color.float32[1] = 0;
19333 color_attachment.clearValue.color.float32[2] = 0;
19334 color_attachment.clearValue.color.float32[3] = 0;
19335 color_attachment.colorAttachment = 0;
19336 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
19337 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
19338}
19339
Tobin Ehlise0006882016-11-03 10:14:28 -060019340TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019341 TEST_DESCRIPTION(
19342 "Perform an image layout transition in a secondary command buffer followed "
19343 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060019344 VkResult err;
19345 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060019346 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019347 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019348 if (!depth_format) {
19349 return;
19350 }
Tobin Ehlise0006882016-11-03 10:14:28 -060019351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19352 // Allocate a secondary and primary cmd buffer
19353 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19354 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019355 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Tobin Ehlise0006882016-11-03 10:14:28 -060019356 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19357 command_buffer_allocate_info.commandBufferCount = 1;
19358
19359 VkCommandBuffer secondary_command_buffer;
19360 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19361 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19362 VkCommandBuffer primary_command_buffer;
19363 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19364 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19365 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19366 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19367 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19368 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
19369 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19370
19371 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19372 ASSERT_VK_SUCCESS(err);
19373 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060019374 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 -060019375 ASSERT_TRUE(image.initialized());
19376 VkImageMemoryBarrier img_barrier = {};
19377 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19378 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19379 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19380 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19381 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19382 img_barrier.image = image.handle();
19383 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19384 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19385 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19386 img_barrier.subresourceRange.baseArrayLayer = 0;
19387 img_barrier.subresourceRange.baseMipLevel = 0;
19388 img_barrier.subresourceRange.layerCount = 1;
19389 img_barrier.subresourceRange.levelCount = 1;
19390 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
19391 0, nullptr, 1, &img_barrier);
19392 err = vkEndCommandBuffer(secondary_command_buffer);
19393 ASSERT_VK_SUCCESS(err);
19394
19395 // Now update primary cmd buffer to execute secondary and transitions image
19396 command_buffer_begin_info.pInheritanceInfo = nullptr;
19397 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
19398 ASSERT_VK_SUCCESS(err);
19399 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
19400 VkImageMemoryBarrier img_barrier2 = {};
19401 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19402 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19403 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19404 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19405 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19406 img_barrier2.image = image.handle();
19407 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19408 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19409 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19410 img_barrier2.subresourceRange.baseArrayLayer = 0;
19411 img_barrier2.subresourceRange.baseMipLevel = 0;
19412 img_barrier2.subresourceRange.layerCount = 1;
19413 img_barrier2.subresourceRange.levelCount = 1;
19414 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
19415 nullptr, 1, &img_barrier2);
19416 err = vkEndCommandBuffer(primary_command_buffer);
19417 ASSERT_VK_SUCCESS(err);
19418 VkSubmitInfo submit_info = {};
19419 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19420 submit_info.commandBufferCount = 1;
19421 submit_info.pCommandBuffers = &primary_command_buffer;
19422 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19423 ASSERT_VK_SUCCESS(err);
19424 m_errorMonitor->VerifyNotFound();
19425 err = vkDeviceWaitIdle(m_device->device());
19426 ASSERT_VK_SUCCESS(err);
Mike Schuchardt06304c22017-03-01 17:09:09 -070019427 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &secondary_command_buffer);
19428 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &primary_command_buffer);
Tobin Ehlise0006882016-11-03 10:14:28 -060019429}
19430
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019431// This is a positive test. No failures are expected.
19432TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019433 TEST_DESCRIPTION(
19434 "Ensure that the vkUpdateDescriptorSets validation code "
19435 "is ignoring VkWriteDescriptorSet members that are not "
19436 "related to the descriptor type specified by "
19437 "VkWriteDescriptorSet::descriptorType. Correct "
19438 "validation behavior will result in the test running to "
19439 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019440
19441 const uintptr_t invalid_ptr = 0xcdcdcdcd;
19442
Tony Barbour1fa09702017-03-16 12:09:08 -060019443 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019444
19445 // Image Case
19446 {
19447 m_errorMonitor->ExpectSuccess();
19448
19449 VkImage image;
19450 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
19451 const int32_t tex_width = 32;
19452 const int32_t tex_height = 32;
19453 VkImageCreateInfo image_create_info = {};
19454 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19455 image_create_info.pNext = NULL;
19456 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19457 image_create_info.format = tex_format;
19458 image_create_info.extent.width = tex_width;
19459 image_create_info.extent.height = tex_height;
19460 image_create_info.extent.depth = 1;
19461 image_create_info.mipLevels = 1;
19462 image_create_info.arrayLayers = 1;
19463 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19464 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19465 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
19466 image_create_info.flags = 0;
19467 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19468 ASSERT_VK_SUCCESS(err);
19469
19470 VkMemoryRequirements memory_reqs;
19471 VkDeviceMemory image_memory;
19472 bool pass;
19473 VkMemoryAllocateInfo memory_info = {};
19474 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19475 memory_info.pNext = NULL;
19476 memory_info.allocationSize = 0;
19477 memory_info.memoryTypeIndex = 0;
19478 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19479 memory_info.allocationSize = memory_reqs.size;
19480 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19481 ASSERT_TRUE(pass);
19482 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
19483 ASSERT_VK_SUCCESS(err);
19484 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
19485 ASSERT_VK_SUCCESS(err);
19486
19487 VkImageViewCreateInfo image_view_create_info = {};
19488 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19489 image_view_create_info.image = image;
19490 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
19491 image_view_create_info.format = tex_format;
19492 image_view_create_info.subresourceRange.layerCount = 1;
19493 image_view_create_info.subresourceRange.baseMipLevel = 0;
19494 image_view_create_info.subresourceRange.levelCount = 1;
19495 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19496
19497 VkImageView view;
19498 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
19499 ASSERT_VK_SUCCESS(err);
19500
19501 VkDescriptorPoolSize ds_type_count = {};
19502 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19503 ds_type_count.descriptorCount = 1;
19504
19505 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19506 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19507 ds_pool_ci.pNext = NULL;
19508 ds_pool_ci.maxSets = 1;
19509 ds_pool_ci.poolSizeCount = 1;
19510 ds_pool_ci.pPoolSizes = &ds_type_count;
19511
19512 VkDescriptorPool ds_pool;
19513 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19514 ASSERT_VK_SUCCESS(err);
19515
19516 VkDescriptorSetLayoutBinding dsl_binding = {};
19517 dsl_binding.binding = 0;
19518 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19519 dsl_binding.descriptorCount = 1;
19520 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19521 dsl_binding.pImmutableSamplers = NULL;
19522
19523 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19524 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19525 ds_layout_ci.pNext = NULL;
19526 ds_layout_ci.bindingCount = 1;
19527 ds_layout_ci.pBindings = &dsl_binding;
19528 VkDescriptorSetLayout ds_layout;
19529 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19530 ASSERT_VK_SUCCESS(err);
19531
19532 VkDescriptorSet descriptor_set;
19533 VkDescriptorSetAllocateInfo alloc_info = {};
19534 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19535 alloc_info.descriptorSetCount = 1;
19536 alloc_info.descriptorPool = ds_pool;
19537 alloc_info.pSetLayouts = &ds_layout;
19538 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19539 ASSERT_VK_SUCCESS(err);
19540
19541 VkDescriptorImageInfo image_info = {};
19542 image_info.imageView = view;
19543 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19544
19545 VkWriteDescriptorSet descriptor_write;
19546 memset(&descriptor_write, 0, sizeof(descriptor_write));
19547 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19548 descriptor_write.dstSet = descriptor_set;
19549 descriptor_write.dstBinding = 0;
19550 descriptor_write.descriptorCount = 1;
19551 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19552 descriptor_write.pImageInfo = &image_info;
19553
19554 // Set pBufferInfo and pTexelBufferView to invalid values, which should
19555 // be
19556 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
19557 // This will most likely produce a crash if the parameter_validation
19558 // layer
19559 // does not correctly ignore pBufferInfo.
19560 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
19561 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19562
19563 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19564
19565 m_errorMonitor->VerifyNotFound();
19566
19567 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19568 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19569 vkDestroyImageView(m_device->device(), view, NULL);
19570 vkDestroyImage(m_device->device(), image, NULL);
19571 vkFreeMemory(m_device->device(), image_memory, NULL);
19572 }
19573
19574 // Buffer Case
19575 {
19576 m_errorMonitor->ExpectSuccess();
19577
19578 VkBuffer buffer;
19579 uint32_t queue_family_index = 0;
19580 VkBufferCreateInfo buffer_create_info = {};
19581 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19582 buffer_create_info.size = 1024;
19583 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19584 buffer_create_info.queueFamilyIndexCount = 1;
19585 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19586
19587 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19588 ASSERT_VK_SUCCESS(err);
19589
19590 VkMemoryRequirements memory_reqs;
19591 VkDeviceMemory buffer_memory;
19592 bool pass;
19593 VkMemoryAllocateInfo memory_info = {};
19594 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19595 memory_info.pNext = NULL;
19596 memory_info.allocationSize = 0;
19597 memory_info.memoryTypeIndex = 0;
19598
19599 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19600 memory_info.allocationSize = memory_reqs.size;
19601 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19602 ASSERT_TRUE(pass);
19603
19604 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19605 ASSERT_VK_SUCCESS(err);
19606 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19607 ASSERT_VK_SUCCESS(err);
19608
19609 VkDescriptorPoolSize ds_type_count = {};
19610 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19611 ds_type_count.descriptorCount = 1;
19612
19613 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19614 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19615 ds_pool_ci.pNext = NULL;
19616 ds_pool_ci.maxSets = 1;
19617 ds_pool_ci.poolSizeCount = 1;
19618 ds_pool_ci.pPoolSizes = &ds_type_count;
19619
19620 VkDescriptorPool ds_pool;
19621 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19622 ASSERT_VK_SUCCESS(err);
19623
19624 VkDescriptorSetLayoutBinding dsl_binding = {};
19625 dsl_binding.binding = 0;
19626 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19627 dsl_binding.descriptorCount = 1;
19628 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19629 dsl_binding.pImmutableSamplers = NULL;
19630
19631 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19632 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19633 ds_layout_ci.pNext = NULL;
19634 ds_layout_ci.bindingCount = 1;
19635 ds_layout_ci.pBindings = &dsl_binding;
19636 VkDescriptorSetLayout ds_layout;
19637 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19638 ASSERT_VK_SUCCESS(err);
19639
19640 VkDescriptorSet descriptor_set;
19641 VkDescriptorSetAllocateInfo alloc_info = {};
19642 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19643 alloc_info.descriptorSetCount = 1;
19644 alloc_info.descriptorPool = ds_pool;
19645 alloc_info.pSetLayouts = &ds_layout;
19646 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19647 ASSERT_VK_SUCCESS(err);
19648
19649 VkDescriptorBufferInfo buffer_info = {};
19650 buffer_info.buffer = buffer;
19651 buffer_info.offset = 0;
19652 buffer_info.range = 1024;
19653
19654 VkWriteDescriptorSet descriptor_write;
19655 memset(&descriptor_write, 0, sizeof(descriptor_write));
19656 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19657 descriptor_write.dstSet = descriptor_set;
19658 descriptor_write.dstBinding = 0;
19659 descriptor_write.descriptorCount = 1;
19660 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19661 descriptor_write.pBufferInfo = &buffer_info;
19662
19663 // Set pImageInfo and pTexelBufferView to invalid values, which should
19664 // be
19665 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
19666 // This will most likely produce a crash if the parameter_validation
19667 // layer
19668 // does not correctly ignore pImageInfo.
19669 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
19670 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19671
19672 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19673
19674 m_errorMonitor->VerifyNotFound();
19675
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019676 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19677 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19678 vkDestroyBuffer(m_device->device(), buffer, NULL);
19679 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19680 }
19681
19682 // Texel Buffer Case
19683 {
19684 m_errorMonitor->ExpectSuccess();
19685
19686 VkBuffer buffer;
19687 uint32_t queue_family_index = 0;
19688 VkBufferCreateInfo buffer_create_info = {};
19689 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19690 buffer_create_info.size = 1024;
19691 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
19692 buffer_create_info.queueFamilyIndexCount = 1;
19693 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19694
19695 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19696 ASSERT_VK_SUCCESS(err);
19697
19698 VkMemoryRequirements memory_reqs;
19699 VkDeviceMemory buffer_memory;
19700 bool pass;
19701 VkMemoryAllocateInfo memory_info = {};
19702 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19703 memory_info.pNext = NULL;
19704 memory_info.allocationSize = 0;
19705 memory_info.memoryTypeIndex = 0;
19706
19707 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19708 memory_info.allocationSize = memory_reqs.size;
19709 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19710 ASSERT_TRUE(pass);
19711
19712 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19713 ASSERT_VK_SUCCESS(err);
19714 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19715 ASSERT_VK_SUCCESS(err);
19716
19717 VkBufferViewCreateInfo buff_view_ci = {};
19718 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
19719 buff_view_ci.buffer = buffer;
19720 buff_view_ci.format = VK_FORMAT_R8_UNORM;
19721 buff_view_ci.range = VK_WHOLE_SIZE;
19722 VkBufferView buffer_view;
19723 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
19724
19725 VkDescriptorPoolSize ds_type_count = {};
19726 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19727 ds_type_count.descriptorCount = 1;
19728
19729 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19730 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19731 ds_pool_ci.pNext = NULL;
19732 ds_pool_ci.maxSets = 1;
19733 ds_pool_ci.poolSizeCount = 1;
19734 ds_pool_ci.pPoolSizes = &ds_type_count;
19735
19736 VkDescriptorPool ds_pool;
19737 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19738 ASSERT_VK_SUCCESS(err);
19739
19740 VkDescriptorSetLayoutBinding dsl_binding = {};
19741 dsl_binding.binding = 0;
19742 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19743 dsl_binding.descriptorCount = 1;
19744 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19745 dsl_binding.pImmutableSamplers = NULL;
19746
19747 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19748 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19749 ds_layout_ci.pNext = NULL;
19750 ds_layout_ci.bindingCount = 1;
19751 ds_layout_ci.pBindings = &dsl_binding;
19752 VkDescriptorSetLayout ds_layout;
19753 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19754 ASSERT_VK_SUCCESS(err);
19755
19756 VkDescriptorSet descriptor_set;
19757 VkDescriptorSetAllocateInfo alloc_info = {};
19758 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19759 alloc_info.descriptorSetCount = 1;
19760 alloc_info.descriptorPool = ds_pool;
19761 alloc_info.pSetLayouts = &ds_layout;
19762 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19763 ASSERT_VK_SUCCESS(err);
19764
19765 VkWriteDescriptorSet descriptor_write;
19766 memset(&descriptor_write, 0, sizeof(descriptor_write));
19767 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19768 descriptor_write.dstSet = descriptor_set;
19769 descriptor_write.dstBinding = 0;
19770 descriptor_write.descriptorCount = 1;
19771 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19772 descriptor_write.pTexelBufferView = &buffer_view;
19773
19774 // Set pImageInfo and pBufferInfo to invalid values, which should be
19775 // ignored for descriptorType ==
19776 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
19777 // This will most likely produce a crash if the parameter_validation
19778 // layer
19779 // does not correctly ignore pImageInfo and pBufferInfo.
19780 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
19781 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
19782
19783 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19784
19785 m_errorMonitor->VerifyNotFound();
19786
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019787 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19788 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19789 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
19790 vkDestroyBuffer(m_device->device(), buffer, NULL);
19791 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19792 }
19793}
19794
Tobin Ehlisf7428442016-10-25 07:58:24 -060019795TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
19796 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
19797
Tony Barbour1fa09702017-03-16 12:09:08 -060019798 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf7428442016-10-25 07:58:24 -060019799 // Create layout where two binding #s are "1"
19800 static const uint32_t NUM_BINDINGS = 3;
19801 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
19802 dsl_binding[0].binding = 1;
19803 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19804 dsl_binding[0].descriptorCount = 1;
19805 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19806 dsl_binding[0].pImmutableSamplers = NULL;
19807 dsl_binding[1].binding = 0;
19808 dsl_binding[1].descriptorCount = 1;
19809 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19810 dsl_binding[1].descriptorCount = 1;
19811 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19812 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019813 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060019814 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19815 dsl_binding[2].descriptorCount = 1;
19816 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19817 dsl_binding[2].pImmutableSamplers = NULL;
19818
19819 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19820 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19821 ds_layout_ci.pNext = NULL;
19822 ds_layout_ci.bindingCount = NUM_BINDINGS;
19823 ds_layout_ci.pBindings = dsl_binding;
19824 VkDescriptorSetLayout ds_layout;
19825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
19826 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19827 m_errorMonitor->VerifyFound();
19828}
19829
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060019830TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019831 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
19832
Tony Barbour1fa09702017-03-16 12:09:08 -060019833 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019834
Tony Barbour552f6c02016-12-21 14:34:07 -070019835 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019836
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060019837 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
19838
19839 {
19840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
19841 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
19842 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19843 m_errorMonitor->VerifyFound();
19844 }
19845
19846 {
19847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
19848 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
19849 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19850 m_errorMonitor->VerifyFound();
19851 }
19852
19853 {
19854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
19855 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
19856 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19857 m_errorMonitor->VerifyFound();
19858 }
19859
19860 {
19861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
19862 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
19863 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19864 m_errorMonitor->VerifyFound();
19865 }
19866
19867 {
19868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
19869 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
19870 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19871 m_errorMonitor->VerifyFound();
19872 }
19873
19874 {
19875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
19876 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
19877 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
19878 m_errorMonitor->VerifyFound();
19879 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019880
19881 {
19882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
19883 VkRect2D scissor = {{-1, 0}, {16, 16}};
19884 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
19885 m_errorMonitor->VerifyFound();
19886 }
19887
19888 {
19889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
19890 VkRect2D scissor = {{0, -2}, {16, 16}};
19891 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
19892 m_errorMonitor->VerifyFound();
19893 }
19894
19895 {
19896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
19897 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
19898 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
19899 m_errorMonitor->VerifyFound();
19900 }
19901
19902 {
19903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
19904 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
19905 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
19906 m_errorMonitor->VerifyFound();
19907 }
19908
Tony Barbour552f6c02016-12-21 14:34:07 -070019909 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060019910}
19911
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019912// This is a positive test. No failures are expected.
19913TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
19914 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
19915 VkResult err;
19916
Tony Barbour1fa09702017-03-16 12:09:08 -060019917 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019918 m_errorMonitor->ExpectSuccess();
19919 VkDescriptorPoolSize ds_type_count = {};
19920 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19921 ds_type_count.descriptorCount = 2;
19922
19923 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19924 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19925 ds_pool_ci.pNext = NULL;
19926 ds_pool_ci.maxSets = 1;
19927 ds_pool_ci.poolSizeCount = 1;
19928 ds_pool_ci.pPoolSizes = &ds_type_count;
19929
19930 VkDescriptorPool ds_pool;
19931 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19932 ASSERT_VK_SUCCESS(err);
19933
19934 // Create layout with two uniform buffer descriptors w/ empty binding between them
19935 static const uint32_t NUM_BINDINGS = 3;
19936 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
19937 dsl_binding[0].binding = 0;
19938 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19939 dsl_binding[0].descriptorCount = 1;
19940 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
19941 dsl_binding[0].pImmutableSamplers = NULL;
19942 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019943 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019944 dsl_binding[2].binding = 2;
19945 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19946 dsl_binding[2].descriptorCount = 1;
19947 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
19948 dsl_binding[2].pImmutableSamplers = NULL;
19949
19950 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19951 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19952 ds_layout_ci.pNext = NULL;
19953 ds_layout_ci.bindingCount = NUM_BINDINGS;
19954 ds_layout_ci.pBindings = dsl_binding;
19955 VkDescriptorSetLayout ds_layout;
19956 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19957 ASSERT_VK_SUCCESS(err);
19958
19959 VkDescriptorSet descriptor_set = {};
19960 VkDescriptorSetAllocateInfo alloc_info = {};
19961 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19962 alloc_info.descriptorSetCount = 1;
19963 alloc_info.descriptorPool = ds_pool;
19964 alloc_info.pSetLayouts = &ds_layout;
19965 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19966 ASSERT_VK_SUCCESS(err);
19967
19968 // Create a buffer to be used for update
19969 VkBufferCreateInfo buff_ci = {};
19970 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19971 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19972 buff_ci.size = 256;
19973 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
19974 VkBuffer buffer;
19975 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
19976 ASSERT_VK_SUCCESS(err);
19977 // Have to bind memory to buffer before descriptor update
19978 VkMemoryAllocateInfo mem_alloc = {};
19979 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19980 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019981 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019982 mem_alloc.memoryTypeIndex = 0;
19983
19984 VkMemoryRequirements mem_reqs;
19985 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
19986 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
19987 if (!pass) {
19988 vkDestroyBuffer(m_device->device(), buffer, NULL);
19989 return;
19990 }
19991
19992 VkDeviceMemory mem;
19993 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19994 ASSERT_VK_SUCCESS(err);
19995 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19996 ASSERT_VK_SUCCESS(err);
19997
19998 // Only update the descriptor at binding 2
19999 VkDescriptorBufferInfo buff_info = {};
20000 buff_info.buffer = buffer;
20001 buff_info.offset = 0;
20002 buff_info.range = VK_WHOLE_SIZE;
20003 VkWriteDescriptorSet descriptor_write = {};
20004 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20005 descriptor_write.dstBinding = 2;
20006 descriptor_write.descriptorCount = 1;
20007 descriptor_write.pTexelBufferView = nullptr;
20008 descriptor_write.pBufferInfo = &buff_info;
20009 descriptor_write.pImageInfo = nullptr;
20010 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20011 descriptor_write.dstSet = descriptor_set;
20012
20013 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20014
20015 m_errorMonitor->VerifyNotFound();
20016 // Cleanup
20017 vkFreeMemory(m_device->device(), mem, NULL);
20018 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20019 vkDestroyBuffer(m_device->device(), buffer, NULL);
20020 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20021}
20022
20023// This is a positive test. No failures are expected.
20024TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
20025 VkResult err;
20026 bool pass;
20027
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020028 TEST_DESCRIPTION(
20029 "Create a buffer, allocate memory, bind memory, destroy "
20030 "the buffer, create an image, and bind the same memory to "
20031 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020032
20033 m_errorMonitor->ExpectSuccess();
20034
Tony Barbour1fa09702017-03-16 12:09:08 -060020035 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020036
20037 VkBuffer buffer;
20038 VkImage image;
20039 VkDeviceMemory mem;
20040 VkMemoryRequirements mem_reqs;
20041
20042 VkBufferCreateInfo buf_info = {};
20043 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20044 buf_info.pNext = NULL;
20045 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20046 buf_info.size = 256;
20047 buf_info.queueFamilyIndexCount = 0;
20048 buf_info.pQueueFamilyIndices = NULL;
20049 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20050 buf_info.flags = 0;
20051 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
20052 ASSERT_VK_SUCCESS(err);
20053
20054 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20055
20056 VkMemoryAllocateInfo alloc_info = {};
20057 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20058 alloc_info.pNext = NULL;
20059 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020060
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020061 // Ensure memory is big enough for both bindings
20062 alloc_info.allocationSize = 0x10000;
20063
20064 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20065 if (!pass) {
20066 vkDestroyBuffer(m_device->device(), buffer, NULL);
20067 return;
20068 }
20069
20070 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20071 ASSERT_VK_SUCCESS(err);
20072
20073 uint8_t *pData;
20074 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
20075 ASSERT_VK_SUCCESS(err);
20076
20077 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
20078
20079 vkUnmapMemory(m_device->device(), mem);
20080
20081 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20082 ASSERT_VK_SUCCESS(err);
20083
20084 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
20085 // memory. In fact, it was never used by the GPU.
20086 // Just be be sure, wait for idle.
20087 vkDestroyBuffer(m_device->device(), buffer, NULL);
20088 vkDeviceWaitIdle(m_device->device());
20089
Tobin Ehlis6a005702016-12-28 15:25:56 -070020090 // Use optimal as some platforms report linear support but then fail image creation
20091 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
20092 VkImageFormatProperties image_format_properties;
20093 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
20094 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
20095 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020096 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070020097 vkFreeMemory(m_device->device(), mem, NULL);
20098 return;
20099 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020100 VkImageCreateInfo image_create_info = {};
20101 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20102 image_create_info.pNext = NULL;
20103 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20104 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
20105 image_create_info.extent.width = 64;
20106 image_create_info.extent.height = 64;
20107 image_create_info.extent.depth = 1;
20108 image_create_info.mipLevels = 1;
20109 image_create_info.arrayLayers = 1;
20110 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070020111 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020112 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
20113 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
20114 image_create_info.queueFamilyIndexCount = 0;
20115 image_create_info.pQueueFamilyIndices = NULL;
20116 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20117 image_create_info.flags = 0;
20118
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020119 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020120 * to be textures or it will be the staging image if they are not.
20121 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020122 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20123 ASSERT_VK_SUCCESS(err);
20124
20125 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
20126
Tobin Ehlis6a005702016-12-28 15:25:56 -070020127 VkMemoryAllocateInfo mem_alloc = {};
20128 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20129 mem_alloc.pNext = NULL;
20130 mem_alloc.allocationSize = 0;
20131 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020132 mem_alloc.allocationSize = mem_reqs.size;
20133
20134 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20135 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070020136 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020137 vkDestroyImage(m_device->device(), image, NULL);
20138 return;
20139 }
20140
20141 // VALIDATION FAILURE:
20142 err = vkBindImageMemory(m_device->device(), image, mem, 0);
20143 ASSERT_VK_SUCCESS(err);
20144
20145 m_errorMonitor->VerifyNotFound();
20146
20147 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020148 vkDestroyImage(m_device->device(), image, NULL);
20149}
20150
Tony Barbourab713912017-02-02 14:17:35 -070020151// This is a positive test. No failures are expected.
20152TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
20153 VkResult err;
20154
20155 TEST_DESCRIPTION(
20156 "Call all applicable destroy and free routines with NULL"
20157 "handles, expecting no validation errors");
20158
20159 m_errorMonitor->ExpectSuccess();
20160
Tony Barbour1fa09702017-03-16 12:09:08 -060020161 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourab713912017-02-02 14:17:35 -070020162 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20163 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
20164 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
20165 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
20166 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20167 vkDestroyDevice(VK_NULL_HANDLE, NULL);
20168 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
20169 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
20170 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20171 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
20172 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
20173 vkDestroyInstance(VK_NULL_HANDLE, NULL);
20174 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
20175 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
20176 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20177 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
20178 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
20179 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
20180 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
20181 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
20182
20183 VkCommandPool command_pool;
20184 VkCommandPoolCreateInfo pool_create_info{};
20185 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20186 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20187 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20188 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20189 VkCommandBuffer command_buffers[3] = {};
20190 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20191 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20192 command_buffer_allocate_info.commandPool = command_pool;
20193 command_buffer_allocate_info.commandBufferCount = 1;
20194 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20195 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
20196 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
20197 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20198
20199 VkDescriptorPoolSize ds_type_count = {};
20200 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20201 ds_type_count.descriptorCount = 1;
20202
20203 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20204 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20205 ds_pool_ci.pNext = NULL;
20206 ds_pool_ci.maxSets = 1;
20207 ds_pool_ci.poolSizeCount = 1;
20208 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
20209 ds_pool_ci.pPoolSizes = &ds_type_count;
20210
20211 VkDescriptorPool ds_pool;
20212 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20213 ASSERT_VK_SUCCESS(err);
20214
20215 VkDescriptorSetLayoutBinding dsl_binding = {};
20216 dsl_binding.binding = 2;
20217 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20218 dsl_binding.descriptorCount = 1;
20219 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20220 dsl_binding.pImmutableSamplers = NULL;
20221 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20222 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20223 ds_layout_ci.pNext = NULL;
20224 ds_layout_ci.bindingCount = 1;
20225 ds_layout_ci.pBindings = &dsl_binding;
20226 VkDescriptorSetLayout ds_layout;
20227 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20228 ASSERT_VK_SUCCESS(err);
20229
20230 VkDescriptorSet descriptor_sets[3] = {};
20231 VkDescriptorSetAllocateInfo alloc_info = {};
20232 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20233 alloc_info.descriptorSetCount = 1;
20234 alloc_info.descriptorPool = ds_pool;
20235 alloc_info.pSetLayouts = &ds_layout;
20236 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
20237 ASSERT_VK_SUCCESS(err);
20238 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
20239 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20240 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20241
20242 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
20243
20244 m_errorMonitor->VerifyNotFound();
20245}
20246
Tony Barbour626994c2017-02-08 15:29:37 -070020247TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070020248 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070020249
20250 m_errorMonitor->ExpectSuccess();
20251
Tony Barbour1fa09702017-03-16 12:09:08 -060020252 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070020253 VkCommandBuffer cmd_bufs[4];
20254 VkCommandBufferAllocateInfo alloc_info;
20255 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20256 alloc_info.pNext = NULL;
20257 alloc_info.commandBufferCount = 4;
Mike Schuchardt06304c22017-03-01 17:09:09 -070020258 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070020259 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20260 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
20261 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020262 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM,
Mike Weiblen62d08a32017-03-07 22:18:27 -070020263 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
20264 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070020265 ASSERT_TRUE(image.initialized());
20266 VkCommandBufferBeginInfo cb_binfo;
20267 cb_binfo.pNext = NULL;
20268 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20269 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
20270 cb_binfo.flags = 0;
20271 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
20272 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
20273 VkImageMemoryBarrier img_barrier = {};
20274 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20275 img_barrier.pNext = NULL;
20276 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20277 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20278 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20279 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
20280 img_barrier.image = image.handle();
20281 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20282 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20283 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20284 img_barrier.subresourceRange.baseArrayLayer = 0;
20285 img_barrier.subresourceRange.baseMipLevel = 0;
20286 img_barrier.subresourceRange.layerCount = 1;
20287 img_barrier.subresourceRange.levelCount = 1;
20288 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20289 &img_barrier);
20290 vkEndCommandBuffer(cmd_bufs[0]);
20291 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
20292 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
20293 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20294 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20295 &img_barrier);
20296 vkEndCommandBuffer(cmd_bufs[1]);
20297 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
20298 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20299 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20300 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20301 &img_barrier);
20302 vkEndCommandBuffer(cmd_bufs[2]);
20303 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
20304 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20305 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20306 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20307 &img_barrier);
20308 vkEndCommandBuffer(cmd_bufs[3]);
20309
20310 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
20311 VkSemaphore semaphore1, semaphore2;
20312 VkSemaphoreCreateInfo semaphore_create_info{};
20313 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20314 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
20315 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
20316 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
20317 VkSubmitInfo submit_info[3];
20318 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20319 submit_info[0].pNext = nullptr;
20320 submit_info[0].commandBufferCount = 1;
20321 submit_info[0].pCommandBuffers = &cmd_bufs[0];
20322 submit_info[0].signalSemaphoreCount = 1;
20323 submit_info[0].pSignalSemaphores = &semaphore1;
20324 submit_info[0].waitSemaphoreCount = 0;
20325 submit_info[0].pWaitDstStageMask = nullptr;
20326 submit_info[0].pWaitDstStageMask = flags;
20327 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20328 submit_info[1].pNext = nullptr;
20329 submit_info[1].commandBufferCount = 1;
20330 submit_info[1].pCommandBuffers = &cmd_bufs[1];
20331 submit_info[1].waitSemaphoreCount = 1;
20332 submit_info[1].pWaitSemaphores = &semaphore1;
20333 submit_info[1].signalSemaphoreCount = 1;
20334 submit_info[1].pSignalSemaphores = &semaphore2;
20335 submit_info[1].pWaitDstStageMask = flags;
20336 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20337 submit_info[2].pNext = nullptr;
20338 submit_info[2].commandBufferCount = 2;
20339 submit_info[2].pCommandBuffers = &cmd_bufs[2];
20340 submit_info[2].waitSemaphoreCount = 1;
20341 submit_info[2].pWaitSemaphores = &semaphore2;
20342 submit_info[2].signalSemaphoreCount = 0;
20343 submit_info[2].pSignalSemaphores = nullptr;
20344 submit_info[2].pWaitDstStageMask = flags;
20345 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
20346 vkQueueWaitIdle(m_device->m_queue);
20347
20348 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
20349 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
20350 m_errorMonitor->VerifyNotFound();
20351}
20352
Tobin Ehlis953e8392016-11-17 10:54:13 -070020353TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
20354 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
20355 // We previously had a bug where dynamic offset of inactive bindings was still being used
20356 VkResult err;
20357 m_errorMonitor->ExpectSuccess();
20358
Tony Barbour1fa09702017-03-16 12:09:08 -060020359 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis953e8392016-11-17 10:54:13 -070020360 ASSERT_NO_FATAL_FAILURE(InitViewport());
20361 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20362
20363 VkDescriptorPoolSize ds_type_count = {};
20364 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20365 ds_type_count.descriptorCount = 3;
20366
20367 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20368 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20369 ds_pool_ci.pNext = NULL;
20370 ds_pool_ci.maxSets = 1;
20371 ds_pool_ci.poolSizeCount = 1;
20372 ds_pool_ci.pPoolSizes = &ds_type_count;
20373
20374 VkDescriptorPool ds_pool;
20375 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20376 ASSERT_VK_SUCCESS(err);
20377
20378 const uint32_t BINDING_COUNT = 3;
20379 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020380 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020381 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20382 dsl_binding[0].descriptorCount = 1;
20383 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20384 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020385 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020386 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20387 dsl_binding[1].descriptorCount = 1;
20388 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20389 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020390 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020391 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20392 dsl_binding[2].descriptorCount = 1;
20393 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20394 dsl_binding[2].pImmutableSamplers = NULL;
20395
20396 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20397 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20398 ds_layout_ci.pNext = NULL;
20399 ds_layout_ci.bindingCount = BINDING_COUNT;
20400 ds_layout_ci.pBindings = dsl_binding;
20401 VkDescriptorSetLayout ds_layout;
20402 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20403 ASSERT_VK_SUCCESS(err);
20404
20405 VkDescriptorSet descriptor_set;
20406 VkDescriptorSetAllocateInfo alloc_info = {};
20407 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20408 alloc_info.descriptorSetCount = 1;
20409 alloc_info.descriptorPool = ds_pool;
20410 alloc_info.pSetLayouts = &ds_layout;
20411 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20412 ASSERT_VK_SUCCESS(err);
20413
20414 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20415 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20416 pipeline_layout_ci.pNext = NULL;
20417 pipeline_layout_ci.setLayoutCount = 1;
20418 pipeline_layout_ci.pSetLayouts = &ds_layout;
20419
20420 VkPipelineLayout pipeline_layout;
20421 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20422 ASSERT_VK_SUCCESS(err);
20423
20424 // Create two buffers to update the descriptors with
20425 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
20426 uint32_t qfi = 0;
20427 VkBufferCreateInfo buffCI = {};
20428 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20429 buffCI.size = 2048;
20430 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20431 buffCI.queueFamilyIndexCount = 1;
20432 buffCI.pQueueFamilyIndices = &qfi;
20433
20434 VkBuffer dyub1;
20435 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
20436 ASSERT_VK_SUCCESS(err);
20437 // buffer2
20438 buffCI.size = 1024;
20439 VkBuffer dyub2;
20440 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
20441 ASSERT_VK_SUCCESS(err);
20442 // Allocate memory and bind to buffers
20443 VkMemoryAllocateInfo mem_alloc[2] = {};
20444 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20445 mem_alloc[0].pNext = NULL;
20446 mem_alloc[0].memoryTypeIndex = 0;
20447 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20448 mem_alloc[1].pNext = NULL;
20449 mem_alloc[1].memoryTypeIndex = 0;
20450
20451 VkMemoryRequirements mem_reqs1;
20452 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
20453 VkMemoryRequirements mem_reqs2;
20454 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
20455 mem_alloc[0].allocationSize = mem_reqs1.size;
20456 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
20457 mem_alloc[1].allocationSize = mem_reqs2.size;
20458 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
20459 if (!pass) {
20460 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20461 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20462 return;
20463 }
20464
20465 VkDeviceMemory mem1;
20466 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
20467 ASSERT_VK_SUCCESS(err);
20468 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
20469 ASSERT_VK_SUCCESS(err);
20470 VkDeviceMemory mem2;
20471 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
20472 ASSERT_VK_SUCCESS(err);
20473 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
20474 ASSERT_VK_SUCCESS(err);
20475 // Update descriptors
20476 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
20477 buff_info[0].buffer = dyub1;
20478 buff_info[0].offset = 0;
20479 buff_info[0].range = 256;
20480 buff_info[1].buffer = dyub1;
20481 buff_info[1].offset = 256;
20482 buff_info[1].range = 512;
20483 buff_info[2].buffer = dyub2;
20484 buff_info[2].offset = 0;
20485 buff_info[2].range = 512;
20486
20487 VkWriteDescriptorSet descriptor_write;
20488 memset(&descriptor_write, 0, sizeof(descriptor_write));
20489 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20490 descriptor_write.dstSet = descriptor_set;
20491 descriptor_write.dstBinding = 0;
20492 descriptor_write.descriptorCount = BINDING_COUNT;
20493 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20494 descriptor_write.pBufferInfo = buff_info;
20495
20496 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20497
Tony Barbour552f6c02016-12-21 14:34:07 -070020498 m_commandBuffer->BeginCommandBuffer();
20499 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070020500
20501 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020502 char const *vsSource =
20503 "#version 450\n"
20504 "\n"
20505 "out gl_PerVertex { \n"
20506 " vec4 gl_Position;\n"
20507 "};\n"
20508 "void main(){\n"
20509 " gl_Position = vec4(1);\n"
20510 "}\n";
20511 char const *fsSource =
20512 "#version 450\n"
20513 "\n"
20514 "layout(location=0) out vec4 x;\n"
20515 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
20516 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
20517 "void main(){\n"
20518 " x = vec4(bar1.y) + vec4(bar2.y);\n"
20519 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070020520 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20521 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20522 VkPipelineObj pipe(m_device);
20523 pipe.SetViewport(m_viewports);
20524 pipe.SetScissor(m_scissors);
20525 pipe.AddShader(&vs);
20526 pipe.AddShader(&fs);
20527 pipe.AddColorAttachment();
20528 pipe.CreateVKPipeline(pipeline_layout, renderPass());
20529
20530 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
20531 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
20532 // we used to have a bug in this case.
20533 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
20534 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
20535 &descriptor_set, BINDING_COUNT, dyn_off);
20536 Draw(1, 0, 0, 0);
20537 m_errorMonitor->VerifyNotFound();
20538
20539 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20540 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20541 vkFreeMemory(m_device->device(), mem1, NULL);
20542 vkFreeMemory(m_device->device(), mem2, NULL);
20543
20544 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20545 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20546 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20547}
20548
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020549TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020550 TEST_DESCRIPTION(
20551 "Ensure that validations handling of non-coherent memory "
20552 "mapping while using VK_WHOLE_SIZE does not cause access "
20553 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020554 VkResult err;
20555 uint8_t *pData;
Tony Barbour1fa09702017-03-16 12:09:08 -060020556 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020557
20558 VkDeviceMemory mem;
20559 VkMemoryRequirements mem_reqs;
20560 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020561 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020562 VkMemoryAllocateInfo alloc_info = {};
20563 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20564 alloc_info.pNext = NULL;
20565 alloc_info.memoryTypeIndex = 0;
20566
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020567 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020568 alloc_info.allocationSize = allocation_size;
20569
20570 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
20571 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 -070020572 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020573 if (!pass) {
20574 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020575 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
20576 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020577 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020578 pass = m_device->phy().set_memory_type(
20579 mem_reqs.memoryTypeBits, &alloc_info,
20580 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
20581 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020582 if (!pass) {
20583 return;
20584 }
20585 }
20586 }
20587
20588 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20589 ASSERT_VK_SUCCESS(err);
20590
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020591 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020592 m_errorMonitor->ExpectSuccess();
20593 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
20594 ASSERT_VK_SUCCESS(err);
20595 VkMappedMemoryRange mmr = {};
20596 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20597 mmr.memory = mem;
20598 mmr.offset = 0;
20599 mmr.size = VK_WHOLE_SIZE;
20600 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20601 ASSERT_VK_SUCCESS(err);
20602 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20603 ASSERT_VK_SUCCESS(err);
20604 m_errorMonitor->VerifyNotFound();
20605 vkUnmapMemory(m_device->device(), mem);
20606
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020607 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020608 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020609 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020610 ASSERT_VK_SUCCESS(err);
20611 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20612 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020613 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020614 mmr.size = VK_WHOLE_SIZE;
20615 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20616 ASSERT_VK_SUCCESS(err);
20617 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20618 ASSERT_VK_SUCCESS(err);
20619 m_errorMonitor->VerifyNotFound();
20620 vkUnmapMemory(m_device->device(), mem);
20621
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020622 // Map with offset and size
20623 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020624 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020625 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020626 ASSERT_VK_SUCCESS(err);
20627 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20628 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020629 mmr.offset = 4 * atom_size;
20630 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020631 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20632 ASSERT_VK_SUCCESS(err);
20633 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20634 ASSERT_VK_SUCCESS(err);
20635 m_errorMonitor->VerifyNotFound();
20636 vkUnmapMemory(m_device->device(), mem);
20637
20638 // Map without offset and flush WHOLE_SIZE with two separate offsets
20639 m_errorMonitor->ExpectSuccess();
20640 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
20641 ASSERT_VK_SUCCESS(err);
20642 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20643 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020644 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020645 mmr.size = VK_WHOLE_SIZE;
20646 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20647 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020648 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020649 mmr.size = VK_WHOLE_SIZE;
20650 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20651 ASSERT_VK_SUCCESS(err);
20652 m_errorMonitor->VerifyNotFound();
20653 vkUnmapMemory(m_device->device(), mem);
20654
20655 vkFreeMemory(m_device->device(), mem, NULL);
20656}
20657
20658// This is a positive test. We used to expect error in this case but spec now allows it
20659TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
20660 m_errorMonitor->ExpectSuccess();
20661 vk_testing::Fence testFence;
20662 VkFenceCreateInfo fenceInfo = {};
20663 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20664 fenceInfo.pNext = NULL;
20665
Tony Barbour1fa09702017-03-16 12:09:08 -060020666 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020667 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020668 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020669 VkResult result = vkResetFences(m_device->device(), 1, fences);
20670 ASSERT_VK_SUCCESS(result);
20671
20672 m_errorMonitor->VerifyNotFound();
20673}
20674
20675TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
20676 m_errorMonitor->ExpectSuccess();
20677
Tony Barbour1fa09702017-03-16 12:09:08 -060020678 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020679 VkResult err;
20680
20681 // Record (empty!) command buffer that can be submitted multiple times
20682 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020683 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
20684 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020685 m_commandBuffer->BeginCommandBuffer(&cbbi);
20686 m_commandBuffer->EndCommandBuffer();
20687
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020688 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020689 VkFence fence;
20690 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20691 ASSERT_VK_SUCCESS(err);
20692
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020693 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020694 VkSemaphore s1, s2;
20695 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
20696 ASSERT_VK_SUCCESS(err);
20697 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
20698 ASSERT_VK_SUCCESS(err);
20699
20700 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020701 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020702 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20703 ASSERT_VK_SUCCESS(err);
20704
20705 // Submit CB again, signaling s2.
20706 si.pSignalSemaphores = &s2;
20707 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
20708 ASSERT_VK_SUCCESS(err);
20709
20710 // Wait for fence.
20711 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20712 ASSERT_VK_SUCCESS(err);
20713
20714 // CB is still in flight from second submission, but semaphore s1 is no
20715 // longer in flight. delete it.
20716 vkDestroySemaphore(m_device->device(), s1, nullptr);
20717
20718 m_errorMonitor->VerifyNotFound();
20719
20720 // Force device idle and clean up remaining objects
20721 vkDeviceWaitIdle(m_device->device());
20722 vkDestroySemaphore(m_device->device(), s2, nullptr);
20723 vkDestroyFence(m_device->device(), fence, nullptr);
20724}
20725
20726TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
20727 m_errorMonitor->ExpectSuccess();
20728
Tony Barbour1fa09702017-03-16 12:09:08 -060020729 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020730 VkResult err;
20731
20732 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020733 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020734 VkFence f1;
20735 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
20736 ASSERT_VK_SUCCESS(err);
20737
20738 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020739 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020740 VkFence f2;
20741 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
20742 ASSERT_VK_SUCCESS(err);
20743
20744 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020745 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020746 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
20747
20748 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020749 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020750 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
20751
20752 // Should have both retired!
20753 vkDestroyFence(m_device->device(), f1, nullptr);
20754 vkDestroyFence(m_device->device(), f2, nullptr);
20755
20756 m_errorMonitor->VerifyNotFound();
20757}
20758
20759TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020760 TEST_DESCRIPTION(
20761 "Verify that creating an image view from an image with valid usage "
20762 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020763
Tony Barbour1fa09702017-03-16 12:09:08 -060020764 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020765
20766 m_errorMonitor->ExpectSuccess();
20767 // Verify that we can create a view with usage INPUT_ATTACHMENT
20768 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020769 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 -060020770 ASSERT_TRUE(image.initialized());
20771 VkImageView imageView;
20772 VkImageViewCreateInfo ivci = {};
20773 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
20774 ivci.image = image.handle();
20775 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
20776 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
20777 ivci.subresourceRange.layerCount = 1;
20778 ivci.subresourceRange.baseMipLevel = 0;
20779 ivci.subresourceRange.levelCount = 1;
20780 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20781
20782 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
20783 m_errorMonitor->VerifyNotFound();
20784 vkDestroyImageView(m_device->device(), imageView, NULL);
20785}
20786
20787// This is a positive test. No failures are expected.
20788TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020789 TEST_DESCRIPTION(
20790 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
20791 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020792
Tony Barbour1fa09702017-03-16 12:09:08 -060020793 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020794
20795 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020796 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Tony Barbour623721f2017-03-24 15:00:21 -060020797 if (!m_device->phy().features().sparseBinding) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020798
20799 m_errorMonitor->ExpectSuccess();
20800
20801 VkImage image;
20802 VkImageCreateInfo image_create_info = {};
20803 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20804 image_create_info.pNext = NULL;
20805 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20806 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
20807 image_create_info.extent.width = 64;
20808 image_create_info.extent.height = 64;
20809 image_create_info.extent.depth = 1;
20810 image_create_info.mipLevels = 1;
20811 image_create_info.arrayLayers = 1;
20812 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
20813 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
20814 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
20815 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
20816 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20817 ASSERT_VK_SUCCESS(err);
20818
20819 VkMemoryRequirements memory_reqs;
20820 VkDeviceMemory memory_one, memory_two;
20821 bool pass;
20822 VkMemoryAllocateInfo memory_info = {};
20823 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20824 memory_info.pNext = NULL;
20825 memory_info.allocationSize = 0;
20826 memory_info.memoryTypeIndex = 0;
20827 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
20828 // Find an image big enough to allow sparse mapping of 2 memory regions
20829 // Increase the image size until it is at least twice the
20830 // size of the required alignment, to ensure we can bind both
20831 // allocated memory blocks to the image on aligned offsets.
20832 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
20833 vkDestroyImage(m_device->device(), image, nullptr);
20834 image_create_info.extent.width *= 2;
20835 image_create_info.extent.height *= 2;
20836 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
20837 ASSERT_VK_SUCCESS(err);
20838 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
20839 }
20840 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
20841 // at the end of the first
20842 memory_info.allocationSize = memory_reqs.alignment;
20843 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20844 ASSERT_TRUE(pass);
20845 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
20846 ASSERT_VK_SUCCESS(err);
20847 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
20848 ASSERT_VK_SUCCESS(err);
20849 VkSparseMemoryBind binds[2];
20850 binds[0].flags = 0;
20851 binds[0].memory = memory_one;
20852 binds[0].memoryOffset = 0;
20853 binds[0].resourceOffset = 0;
20854 binds[0].size = memory_info.allocationSize;
20855 binds[1].flags = 0;
20856 binds[1].memory = memory_two;
20857 binds[1].memoryOffset = 0;
20858 binds[1].resourceOffset = memory_info.allocationSize;
20859 binds[1].size = memory_info.allocationSize;
20860
20861 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
20862 opaqueBindInfo.image = image;
20863 opaqueBindInfo.bindCount = 2;
20864 opaqueBindInfo.pBinds = binds;
20865
20866 VkFence fence = VK_NULL_HANDLE;
20867 VkBindSparseInfo bindSparseInfo = {};
20868 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
20869 bindSparseInfo.imageOpaqueBindCount = 1;
20870 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
20871
20872 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
20873 vkQueueWaitIdle(m_device->m_queue);
20874 vkDestroyImage(m_device->device(), image, NULL);
20875 vkFreeMemory(m_device->device(), memory_one, NULL);
20876 vkFreeMemory(m_device->device(), memory_two, NULL);
20877 m_errorMonitor->VerifyNotFound();
20878}
20879
20880TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020881 TEST_DESCRIPTION(
20882 "Ensure that CmdBeginRenderPass with an attachment's "
20883 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
20884 "the command buffer has prior knowledge of that "
20885 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020886
20887 m_errorMonitor->ExpectSuccess();
20888
Tony Barbour1fa09702017-03-16 12:09:08 -060020889 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020890
20891 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020892 VkAttachmentDescription attachment = {0,
20893 VK_FORMAT_R8G8B8A8_UNORM,
20894 VK_SAMPLE_COUNT_1_BIT,
20895 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
20896 VK_ATTACHMENT_STORE_OP_STORE,
20897 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
20898 VK_ATTACHMENT_STORE_OP_DONT_CARE,
20899 VK_IMAGE_LAYOUT_UNDEFINED,
20900 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020901
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020902 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020903
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020904 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020905
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020906 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020907
20908 VkRenderPass rp;
20909 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20910 ASSERT_VK_SUCCESS(err);
20911
20912 // A compatible framebuffer.
20913 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020914 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 -060020915 ASSERT_TRUE(image.initialized());
20916
20917 VkImageViewCreateInfo ivci = {
20918 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
20919 nullptr,
20920 0,
20921 image.handle(),
20922 VK_IMAGE_VIEW_TYPE_2D,
20923 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020924 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
20925 VK_COMPONENT_SWIZZLE_IDENTITY},
20926 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020927 };
20928 VkImageView view;
20929 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
20930 ASSERT_VK_SUCCESS(err);
20931
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020932 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020933 VkFramebuffer fb;
20934 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
20935 ASSERT_VK_SUCCESS(err);
20936
20937 // Record a single command buffer which uses this renderpass twice. The
20938 // bug is triggered at the beginning of the second renderpass, when the
20939 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020940 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 -070020941 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020942 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
20943 vkCmdEndRenderPass(m_commandBuffer->handle());
20944 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
20945
20946 m_errorMonitor->VerifyNotFound();
20947
20948 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070020949 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020950
20951 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20952 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20953 vkDestroyImageView(m_device->device(), view, nullptr);
20954}
20955
20956TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020957 TEST_DESCRIPTION(
20958 "This test should pass. Create a Framebuffer and "
20959 "command buffer, bind them together, then destroy "
20960 "command pool and framebuffer and verify there are no "
20961 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020962
20963 m_errorMonitor->ExpectSuccess();
20964
Tony Barbour1fa09702017-03-16 12:09:08 -060020965 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020966
20967 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020968 VkAttachmentDescription attachment = {0,
20969 VK_FORMAT_R8G8B8A8_UNORM,
20970 VK_SAMPLE_COUNT_1_BIT,
20971 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
20972 VK_ATTACHMENT_STORE_OP_STORE,
20973 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
20974 VK_ATTACHMENT_STORE_OP_DONT_CARE,
20975 VK_IMAGE_LAYOUT_UNDEFINED,
20976 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020977
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020978 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020979
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020980 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020981
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020982 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020983
20984 VkRenderPass rp;
20985 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20986 ASSERT_VK_SUCCESS(err);
20987
20988 // A compatible framebuffer.
20989 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020990 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 -060020991 ASSERT_TRUE(image.initialized());
20992
20993 VkImageViewCreateInfo ivci = {
20994 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
20995 nullptr,
20996 0,
20997 image.handle(),
20998 VK_IMAGE_VIEW_TYPE_2D,
20999 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021000 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21001 VK_COMPONENT_SWIZZLE_IDENTITY},
21002 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021003 };
21004 VkImageView view;
21005 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21006 ASSERT_VK_SUCCESS(err);
21007
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021008 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021009 VkFramebuffer fb;
21010 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21011 ASSERT_VK_SUCCESS(err);
21012
21013 // Explicitly create a command buffer to bind the FB to so that we can then
21014 // destroy the command pool in order to implicitly free command buffer
21015 VkCommandPool command_pool;
21016 VkCommandPoolCreateInfo pool_create_info{};
21017 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21018 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21019 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21020 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21021
21022 VkCommandBuffer command_buffer;
21023 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21024 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21025 command_buffer_allocate_info.commandPool = command_pool;
21026 command_buffer_allocate_info.commandBufferCount = 1;
21027 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21028 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21029
21030 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021031 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 -060021032 VkCommandBufferBeginInfo begin_info{};
21033 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21034 vkBeginCommandBuffer(command_buffer, &begin_info);
21035
21036 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21037 vkCmdEndRenderPass(command_buffer);
21038 vkEndCommandBuffer(command_buffer);
21039 vkDestroyImageView(m_device->device(), view, nullptr);
21040 // Destroy command pool to implicitly free command buffer
21041 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21042 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21043 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21044 m_errorMonitor->VerifyNotFound();
21045}
21046
21047TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021048 TEST_DESCRIPTION(
21049 "Ensure that CmdBeginRenderPass applies the layout "
21050 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021051
21052 m_errorMonitor->ExpectSuccess();
21053
Tony Barbour1fa09702017-03-16 12:09:08 -060021054 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021055
21056 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021057 VkAttachmentDescription attachment = {0,
21058 VK_FORMAT_R8G8B8A8_UNORM,
21059 VK_SAMPLE_COUNT_1_BIT,
21060 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21061 VK_ATTACHMENT_STORE_OP_STORE,
21062 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21063 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21064 VK_IMAGE_LAYOUT_UNDEFINED,
21065 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021066
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021067 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021068
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021069 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021070
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021071 VkSubpassDependency dep = {0,
21072 0,
21073 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21074 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21075 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21076 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21077 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021078
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021079 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021080
21081 VkResult err;
21082 VkRenderPass rp;
21083 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21084 ASSERT_VK_SUCCESS(err);
21085
21086 // A compatible framebuffer.
21087 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021088 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 -060021089 ASSERT_TRUE(image.initialized());
21090
21091 VkImageViewCreateInfo ivci = {
21092 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21093 nullptr,
21094 0,
21095 image.handle(),
21096 VK_IMAGE_VIEW_TYPE_2D,
21097 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021098 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21099 VK_COMPONENT_SWIZZLE_IDENTITY},
21100 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021101 };
21102 VkImageView view;
21103 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21104 ASSERT_VK_SUCCESS(err);
21105
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021106 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021107 VkFramebuffer fb;
21108 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21109 ASSERT_VK_SUCCESS(err);
21110
21111 // Record a single command buffer which issues a pipeline barrier w/
21112 // image memory barrier for the attachment. This detects the previously
21113 // missing tracking of the subpass layout by throwing a validation error
21114 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021115 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 -070021116 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021117 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21118
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021119 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
21120 nullptr,
21121 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21122 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21123 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21124 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21125 VK_QUEUE_FAMILY_IGNORED,
21126 VK_QUEUE_FAMILY_IGNORED,
21127 image.handle(),
21128 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021129 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021130 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21131 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021132
21133 vkCmdEndRenderPass(m_commandBuffer->handle());
21134 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021135 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021136
21137 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21138 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21139 vkDestroyImageView(m_device->device(), view, nullptr);
21140}
21141
21142TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021143 TEST_DESCRIPTION(
21144 "Validate that when an imageView of a depth/stencil image "
21145 "is used as a depth/stencil framebuffer attachment, the "
21146 "aspectMask is ignored and both depth and stencil image "
21147 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021148
Tony Barbour1fa09702017-03-16 12:09:08 -060021149 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021150 VkFormatProperties format_properties;
21151 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
21152 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
21153 return;
21154 }
21155
21156 m_errorMonitor->ExpectSuccess();
21157
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021158 VkAttachmentDescription attachment = {0,
21159 VK_FORMAT_D32_SFLOAT_S8_UINT,
21160 VK_SAMPLE_COUNT_1_BIT,
21161 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21162 VK_ATTACHMENT_STORE_OP_STORE,
21163 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21164 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21165 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
21166 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021167
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021168 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021169
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021170 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021171
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021172 VkSubpassDependency dep = {0,
21173 0,
21174 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21175 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21176 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21177 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21178 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021179
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021180 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021181
21182 VkResult err;
21183 VkRenderPass rp;
21184 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21185 ASSERT_VK_SUCCESS(err);
21186
21187 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021188 image.InitNoLayout(32, 32, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
21189 0x26, // usage
21190 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021191 ASSERT_TRUE(image.initialized());
21192 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
21193
21194 VkImageViewCreateInfo ivci = {
21195 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21196 nullptr,
21197 0,
21198 image.handle(),
21199 VK_IMAGE_VIEW_TYPE_2D,
21200 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021201 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
21202 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021203 };
21204 VkImageView view;
21205 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21206 ASSERT_VK_SUCCESS(err);
21207
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021208 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021209 VkFramebuffer fb;
21210 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21211 ASSERT_VK_SUCCESS(err);
21212
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021213 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 -070021214 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021215 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21216
21217 VkImageMemoryBarrier imb = {};
21218 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21219 imb.pNext = nullptr;
21220 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21221 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21222 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21223 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
21224 imb.srcQueueFamilyIndex = 0;
21225 imb.dstQueueFamilyIndex = 0;
21226 imb.image = image.handle();
21227 imb.subresourceRange.aspectMask = 0x6;
21228 imb.subresourceRange.baseMipLevel = 0;
21229 imb.subresourceRange.levelCount = 0x1;
21230 imb.subresourceRange.baseArrayLayer = 0;
21231 imb.subresourceRange.layerCount = 0x1;
21232
21233 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021234 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21235 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021236
21237 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070021238 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021239 QueueCommandBuffer(false);
21240 m_errorMonitor->VerifyNotFound();
21241
21242 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21243 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21244 vkDestroyImageView(m_device->device(), view, nullptr);
21245}
21246
21247TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021248 TEST_DESCRIPTION(
21249 "Ensure that layout transitions work correctly without "
21250 "errors, when an attachment reference is "
21251 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021252
21253 m_errorMonitor->ExpectSuccess();
21254
Tony Barbour1fa09702017-03-16 12:09:08 -060021255 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021256
21257 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021258 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021259
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021260 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021261
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021262 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021263
21264 VkRenderPass rp;
21265 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21266 ASSERT_VK_SUCCESS(err);
21267
21268 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021269 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021270 VkFramebuffer fb;
21271 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21272 ASSERT_VK_SUCCESS(err);
21273
21274 // Record a command buffer which just begins and ends the renderpass. The
21275 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021276 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 -070021277 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021278 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21279 vkCmdEndRenderPass(m_commandBuffer->handle());
21280 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021281 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021282
21283 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21284 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21285}
21286
21287// This is a positive test. No errors are expected.
21288TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021289 TEST_DESCRIPTION(
21290 "Create a stencil-only attachment with a LOAD_OP set to "
21291 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021292 VkResult result = VK_SUCCESS;
Tony Barbour1fa09702017-03-16 12:09:08 -060021293 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021294 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070021295 if (!depth_format) {
21296 printf(" No Depth + Stencil format found. Skipped.\n");
21297 return;
21298 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021299 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070021300 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021301 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
21302 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021303 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
21304 return;
21305 }
21306
Tony Barbourf887b162017-03-09 10:06:46 -070021307 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021308 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021309 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021310 VkAttachmentDescription att = {};
21311 VkAttachmentReference ref = {};
21312 att.format = depth_stencil_fmt;
21313 att.samples = VK_SAMPLE_COUNT_1_BIT;
21314 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
21315 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21316 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21317 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
21318 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21319 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21320
21321 VkClearValue clear;
21322 clear.depthStencil.depth = 1.0;
21323 clear.depthStencil.stencil = 0;
21324 ref.attachment = 0;
21325 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21326
21327 VkSubpassDescription subpass = {};
21328 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
21329 subpass.flags = 0;
21330 subpass.inputAttachmentCount = 0;
21331 subpass.pInputAttachments = NULL;
21332 subpass.colorAttachmentCount = 0;
21333 subpass.pColorAttachments = NULL;
21334 subpass.pResolveAttachments = NULL;
21335 subpass.pDepthStencilAttachment = &ref;
21336 subpass.preserveAttachmentCount = 0;
21337 subpass.pPreserveAttachments = NULL;
21338
21339 VkRenderPass rp;
21340 VkRenderPassCreateInfo rp_info = {};
21341 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21342 rp_info.attachmentCount = 1;
21343 rp_info.pAttachments = &att;
21344 rp_info.subpassCount = 1;
21345 rp_info.pSubpasses = &subpass;
21346 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
21347 ASSERT_VK_SUCCESS(result);
21348
21349 VkImageView *depthView = m_depthStencil->BindInfo();
21350 VkFramebufferCreateInfo fb_info = {};
21351 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
21352 fb_info.pNext = NULL;
21353 fb_info.renderPass = rp;
21354 fb_info.attachmentCount = 1;
21355 fb_info.pAttachments = depthView;
21356 fb_info.width = 100;
21357 fb_info.height = 100;
21358 fb_info.layers = 1;
21359 VkFramebuffer fb;
21360 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
21361 ASSERT_VK_SUCCESS(result);
21362
21363 VkRenderPassBeginInfo rpbinfo = {};
21364 rpbinfo.clearValueCount = 1;
21365 rpbinfo.pClearValues = &clear;
21366 rpbinfo.pNext = NULL;
21367 rpbinfo.renderPass = rp;
21368 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
21369 rpbinfo.renderArea.extent.width = 100;
21370 rpbinfo.renderArea.extent.height = 100;
21371 rpbinfo.renderArea.offset.x = 0;
21372 rpbinfo.renderArea.offset.y = 0;
21373 rpbinfo.framebuffer = fb;
21374
21375 VkFence fence = {};
21376 VkFenceCreateInfo fence_ci = {};
21377 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21378 fence_ci.pNext = nullptr;
21379 fence_ci.flags = 0;
21380 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
21381 ASSERT_VK_SUCCESS(result);
21382
21383 m_commandBuffer->BeginCommandBuffer();
21384 m_commandBuffer->BeginRenderPass(rpbinfo);
21385 m_commandBuffer->EndRenderPass();
21386 m_commandBuffer->EndCommandBuffer();
21387 m_commandBuffer->QueueCommandBuffer(fence);
21388
21389 VkImageObj destImage(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021390 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 -070021391 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021392 VkImageMemoryBarrier barrier = {};
21393 VkImageSubresourceRange range;
21394 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21395 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21396 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
21397 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21398 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
21399 barrier.image = m_depthStencil->handle();
21400 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21401 range.baseMipLevel = 0;
21402 range.levelCount = 1;
21403 range.baseArrayLayer = 0;
21404 range.layerCount = 1;
21405 barrier.subresourceRange = range;
21406 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21407 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
21408 cmdbuf.BeginCommandBuffer();
21409 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 -070021410 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021411 barrier.srcAccessMask = 0;
21412 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
21413 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
21414 barrier.image = destImage.handle();
21415 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21416 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 -070021417 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021418 VkImageCopy cregion;
21419 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21420 cregion.srcSubresource.mipLevel = 0;
21421 cregion.srcSubresource.baseArrayLayer = 0;
21422 cregion.srcSubresource.layerCount = 1;
21423 cregion.srcOffset.x = 0;
21424 cregion.srcOffset.y = 0;
21425 cregion.srcOffset.z = 0;
21426 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21427 cregion.dstSubresource.mipLevel = 0;
21428 cregion.dstSubresource.baseArrayLayer = 0;
21429 cregion.dstSubresource.layerCount = 1;
21430 cregion.dstOffset.x = 0;
21431 cregion.dstOffset.y = 0;
21432 cregion.dstOffset.z = 0;
21433 cregion.extent.width = 100;
21434 cregion.extent.height = 100;
21435 cregion.extent.depth = 1;
21436 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021437 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021438 cmdbuf.EndCommandBuffer();
21439
21440 VkSubmitInfo submit_info;
21441 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21442 submit_info.pNext = NULL;
21443 submit_info.waitSemaphoreCount = 0;
21444 submit_info.pWaitSemaphores = NULL;
21445 submit_info.pWaitDstStageMask = NULL;
21446 submit_info.commandBufferCount = 1;
21447 submit_info.pCommandBuffers = &cmdbuf.handle();
21448 submit_info.signalSemaphoreCount = 0;
21449 submit_info.pSignalSemaphores = NULL;
21450
21451 m_errorMonitor->ExpectSuccess();
21452 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21453 m_errorMonitor->VerifyNotFound();
21454
21455 vkQueueWaitIdle(m_device->m_queue);
21456 vkDestroyFence(m_device->device(), fence, nullptr);
21457 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21458 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21459}
21460
21461// This is a positive test. No errors should be generated.
Mike Weiblene4e225d2017-03-07 23:15:43 -070021462TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) {
21463 TEST_DESCRIPTION("Ensure barriers' new and old VkImageLayout are compatible with their images' VkImageUsageFlags");
21464
21465 m_errorMonitor->ExpectSuccess();
21466
Tony Barbour1fa09702017-03-16 12:09:08 -060021467 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021468 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060021469 if (!depth_format) {
21470 printf(" No Depth + Stencil format found. Skipped.\n");
21471 return;
21472 }
Mike Weiblene4e225d2017-03-07 23:15:43 -070021473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21474
21475 VkImageMemoryBarrier img_barrier = {};
21476 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21477 img_barrier.pNext = NULL;
21478 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
21479 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21480 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21481 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21482 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21483 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21484 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
21485 img_barrier.subresourceRange.baseArrayLayer = 0;
21486 img_barrier.subresourceRange.baseMipLevel = 0;
21487 img_barrier.subresourceRange.layerCount = 1;
21488 img_barrier.subresourceRange.levelCount = 1;
21489
21490 {
21491 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021492 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 -070021493 ASSERT_TRUE(img_color.initialized());
21494
21495 VkImageObj img_ds1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021496 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 -070021497 ASSERT_TRUE(img_ds1.initialized());
21498
21499 VkImageObj img_ds2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021500 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 -070021501 ASSERT_TRUE(img_ds2.initialized());
21502
21503 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021504 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 -070021505 ASSERT_TRUE(img_xfer_src.initialized());
21506
21507 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021508 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 -070021509 ASSERT_TRUE(img_xfer_dst.initialized());
21510
21511 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021512 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 -070021513 ASSERT_TRUE(img_sampled.initialized());
21514
21515 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021516 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 -070021517 ASSERT_TRUE(img_input.initialized());
21518
21519 const struct {
21520 VkImageObj &image_obj;
21521 VkImageLayout old_layout;
21522 VkImageLayout new_layout;
21523 } buffer_layouts[] = {
21524 // clang-format off
21525 {img_color, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21526 {img_ds1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21527 {img_ds2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21528 {img_sampled, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21529 {img_input, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21530 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21531 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21532 // clang-format on
21533 };
21534 const uint32_t layout_count = sizeof(buffer_layouts) / sizeof(buffer_layouts[0]);
21535
21536 m_commandBuffer->BeginCommandBuffer();
21537 for (uint32_t i = 0; i < layout_count; ++i) {
21538 img_barrier.image = buffer_layouts[i].image_obj.handle();
21539 const VkImageUsageFlags usage = buffer_layouts[i].image_obj.usage();
21540 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
21541 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
21542 : VK_IMAGE_ASPECT_COLOR_BIT;
21543
21544 img_barrier.oldLayout = buffer_layouts[i].old_layout;
21545 img_barrier.newLayout = buffer_layouts[i].new_layout;
21546 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21547 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21548
21549 img_barrier.oldLayout = buffer_layouts[i].new_layout;
21550 img_barrier.newLayout = buffer_layouts[i].old_layout;
21551 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21552 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21553 }
21554 m_commandBuffer->EndCommandBuffer();
21555
21556 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
21557 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
21558 }
21559 m_errorMonitor->VerifyNotFound();
21560}
21561
21562// This is a positive test. No errors should be generated.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021563TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
21564 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
21565
21566 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060021567 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021568
21569 VkEvent event;
21570 VkEventCreateInfo event_create_info{};
21571 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
21572 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
21573
21574 VkCommandPool command_pool;
21575 VkCommandPoolCreateInfo pool_create_info{};
21576 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21577 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21578 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21579 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21580
21581 VkCommandBuffer command_buffer;
21582 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21583 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21584 command_buffer_allocate_info.commandPool = command_pool;
21585 command_buffer_allocate_info.commandBufferCount = 1;
21586 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21587 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21588
21589 VkQueue queue = VK_NULL_HANDLE;
21590 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
21591
21592 {
21593 VkCommandBufferBeginInfo begin_info{};
21594 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21595 vkBeginCommandBuffer(command_buffer, &begin_info);
21596
21597 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 -070021598 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021599 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
21600 vkEndCommandBuffer(command_buffer);
21601 }
21602 {
21603 VkSubmitInfo submit_info{};
21604 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21605 submit_info.commandBufferCount = 1;
21606 submit_info.pCommandBuffers = &command_buffer;
21607 submit_info.signalSemaphoreCount = 0;
21608 submit_info.pSignalSemaphores = nullptr;
21609 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21610 }
21611 { vkSetEvent(m_device->device(), event); }
21612
21613 vkQueueWaitIdle(queue);
21614
21615 vkDestroyEvent(m_device->device(), event, nullptr);
21616 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21617 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21618
21619 m_errorMonitor->VerifyNotFound();
21620}
21621// This is a positive test. No errors should be generated.
21622TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
21623 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
21624
Tony Barbour1fa09702017-03-16 12:09:08 -060021625 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021626 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021627
21628 m_errorMonitor->ExpectSuccess();
21629
21630 VkQueryPool query_pool;
21631 VkQueryPoolCreateInfo query_pool_create_info{};
21632 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
21633 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
21634 query_pool_create_info.queryCount = 1;
21635 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
21636
21637 VkCommandPool command_pool;
21638 VkCommandPoolCreateInfo pool_create_info{};
21639 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21640 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21641 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21642 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21643
21644 VkCommandBuffer command_buffer;
21645 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21646 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21647 command_buffer_allocate_info.commandPool = command_pool;
21648 command_buffer_allocate_info.commandBufferCount = 1;
21649 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21650 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21651
21652 VkCommandBuffer secondary_command_buffer;
21653 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
21654 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
21655
21656 VkQueue queue = VK_NULL_HANDLE;
21657 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21658
21659 uint32_t qfi = 0;
21660 VkBufferCreateInfo buff_create_info = {};
21661 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21662 buff_create_info.size = 1024;
21663 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
21664 buff_create_info.queueFamilyIndexCount = 1;
21665 buff_create_info.pQueueFamilyIndices = &qfi;
21666
21667 VkResult err;
21668 VkBuffer buffer;
21669 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
21670 ASSERT_VK_SUCCESS(err);
21671 VkMemoryAllocateInfo mem_alloc = {};
21672 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21673 mem_alloc.pNext = NULL;
21674 mem_alloc.allocationSize = 1024;
21675 mem_alloc.memoryTypeIndex = 0;
21676
21677 VkMemoryRequirements memReqs;
21678 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
21679 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
21680 if (!pass) {
21681 vkDestroyBuffer(m_device->device(), buffer, NULL);
21682 return;
21683 }
21684
21685 VkDeviceMemory mem;
21686 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
21687 ASSERT_VK_SUCCESS(err);
21688 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
21689 ASSERT_VK_SUCCESS(err);
21690
21691 VkCommandBufferInheritanceInfo hinfo = {};
21692 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
21693 hinfo.renderPass = VK_NULL_HANDLE;
21694 hinfo.subpass = 0;
21695 hinfo.framebuffer = VK_NULL_HANDLE;
21696 hinfo.occlusionQueryEnable = VK_FALSE;
21697 hinfo.queryFlags = 0;
21698 hinfo.pipelineStatistics = 0;
21699
21700 {
21701 VkCommandBufferBeginInfo begin_info{};
21702 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21703 begin_info.pInheritanceInfo = &hinfo;
21704 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
21705
21706 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
21707 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
21708
21709 vkEndCommandBuffer(secondary_command_buffer);
21710
21711 begin_info.pInheritanceInfo = nullptr;
21712 vkBeginCommandBuffer(command_buffer, &begin_info);
21713
21714 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
21715 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
21716
21717 vkEndCommandBuffer(command_buffer);
21718 }
21719 {
21720 VkSubmitInfo submit_info{};
21721 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21722 submit_info.commandBufferCount = 1;
21723 submit_info.pCommandBuffers = &command_buffer;
21724 submit_info.signalSemaphoreCount = 0;
21725 submit_info.pSignalSemaphores = nullptr;
21726 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21727 }
21728
21729 vkQueueWaitIdle(queue);
21730
21731 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
21732 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21733 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
21734 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21735 vkDestroyBuffer(m_device->device(), buffer, NULL);
21736 vkFreeMemory(m_device->device(), mem, NULL);
21737
21738 m_errorMonitor->VerifyNotFound();
21739}
21740
21741// This is a positive test. No errors should be generated.
21742TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
21743 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
21744
Tony Barbour1fa09702017-03-16 12:09:08 -060021745 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021746 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021747
21748 m_errorMonitor->ExpectSuccess();
21749
21750 VkQueryPool query_pool;
21751 VkQueryPoolCreateInfo query_pool_create_info{};
21752 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
21753 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
21754 query_pool_create_info.queryCount = 1;
21755 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
21756
21757 VkCommandPool command_pool;
21758 VkCommandPoolCreateInfo pool_create_info{};
21759 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21760 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21761 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21762 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21763
21764 VkCommandBuffer command_buffer[2];
21765 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21766 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21767 command_buffer_allocate_info.commandPool = command_pool;
21768 command_buffer_allocate_info.commandBufferCount = 2;
21769 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21770 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21771
21772 VkQueue queue = VK_NULL_HANDLE;
21773 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21774
21775 uint32_t qfi = 0;
21776 VkBufferCreateInfo buff_create_info = {};
21777 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21778 buff_create_info.size = 1024;
21779 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
21780 buff_create_info.queueFamilyIndexCount = 1;
21781 buff_create_info.pQueueFamilyIndices = &qfi;
21782
21783 VkResult err;
21784 VkBuffer buffer;
21785 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
21786 ASSERT_VK_SUCCESS(err);
21787 VkMemoryAllocateInfo mem_alloc = {};
21788 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21789 mem_alloc.pNext = NULL;
21790 mem_alloc.allocationSize = 1024;
21791 mem_alloc.memoryTypeIndex = 0;
21792
21793 VkMemoryRequirements memReqs;
21794 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
21795 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
21796 if (!pass) {
21797 vkDestroyBuffer(m_device->device(), buffer, NULL);
21798 return;
21799 }
21800
21801 VkDeviceMemory mem;
21802 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
21803 ASSERT_VK_SUCCESS(err);
21804 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
21805 ASSERT_VK_SUCCESS(err);
21806
21807 {
21808 VkCommandBufferBeginInfo begin_info{};
21809 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21810 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21811
21812 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
21813 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
21814
21815 vkEndCommandBuffer(command_buffer[0]);
21816
21817 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21818
21819 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
21820
21821 vkEndCommandBuffer(command_buffer[1]);
21822 }
21823 {
21824 VkSubmitInfo submit_info{};
21825 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21826 submit_info.commandBufferCount = 2;
21827 submit_info.pCommandBuffers = command_buffer;
21828 submit_info.signalSemaphoreCount = 0;
21829 submit_info.pSignalSemaphores = nullptr;
21830 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21831 }
21832
21833 vkQueueWaitIdle(queue);
21834
21835 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
21836 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
21837 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21838 vkDestroyBuffer(m_device->device(), buffer, NULL);
21839 vkFreeMemory(m_device->device(), mem, NULL);
21840
21841 m_errorMonitor->VerifyNotFound();
21842}
21843
Tony Barbourc46924f2016-11-04 11:49:52 -060021844TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021845 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
21846
Tony Barbour1fa09702017-03-16 12:09:08 -060021847 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021848 VkEvent event;
21849 VkEventCreateInfo event_create_info{};
21850 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
21851 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
21852
21853 VkCommandPool command_pool;
21854 VkCommandPoolCreateInfo pool_create_info{};
21855 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21856 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21857 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21858 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21859
21860 VkCommandBuffer command_buffer;
21861 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21862 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21863 command_buffer_allocate_info.commandPool = command_pool;
21864 command_buffer_allocate_info.commandBufferCount = 1;
21865 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21866 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21867
21868 VkQueue queue = VK_NULL_HANDLE;
21869 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
21870
21871 {
21872 VkCommandBufferBeginInfo begin_info{};
21873 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21874 vkBeginCommandBuffer(command_buffer, &begin_info);
21875
21876 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021877 vkEndCommandBuffer(command_buffer);
21878 }
21879 {
21880 VkSubmitInfo submit_info{};
21881 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21882 submit_info.commandBufferCount = 1;
21883 submit_info.pCommandBuffers = &command_buffer;
21884 submit_info.signalSemaphoreCount = 0;
21885 submit_info.pSignalSemaphores = nullptr;
21886 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21887 }
21888 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
21890 "that is already in use by a "
21891 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021892 vkSetEvent(m_device->device(), event);
21893 m_errorMonitor->VerifyFound();
21894 }
21895
21896 vkQueueWaitIdle(queue);
21897
21898 vkDestroyEvent(m_device->device(), event, nullptr);
21899 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21900 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21901}
21902
21903// This is a positive test. No errors should be generated.
21904TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021905 TEST_DESCRIPTION(
21906 "Two command buffers with two separate fences are each "
21907 "run through a Submit & WaitForFences cycle 3 times. This "
21908 "previously revealed a bug so running this positive test "
21909 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021910 m_errorMonitor->ExpectSuccess();
21911
Tony Barbour1fa09702017-03-16 12:09:08 -060021912 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021913 VkQueue queue = VK_NULL_HANDLE;
21914 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
21915
21916 static const uint32_t NUM_OBJECTS = 2;
21917 static const uint32_t NUM_FRAMES = 3;
21918 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
21919 VkFence fences[NUM_OBJECTS] = {};
21920
21921 VkCommandPool cmd_pool;
21922 VkCommandPoolCreateInfo cmd_pool_ci = {};
21923 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21924 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
21925 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21926 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
21927 ASSERT_VK_SUCCESS(err);
21928
21929 VkCommandBufferAllocateInfo cmd_buf_info = {};
21930 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21931 cmd_buf_info.commandPool = cmd_pool;
21932 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21933 cmd_buf_info.commandBufferCount = 1;
21934
21935 VkFenceCreateInfo fence_ci = {};
21936 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21937 fence_ci.pNext = nullptr;
21938 fence_ci.flags = 0;
21939
21940 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
21941 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
21942 ASSERT_VK_SUCCESS(err);
21943 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
21944 ASSERT_VK_SUCCESS(err);
21945 }
21946
21947 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
21948 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
21949 // Create empty cmd buffer
21950 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
21951 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21952
21953 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
21954 ASSERT_VK_SUCCESS(err);
21955 err = vkEndCommandBuffer(cmd_buffers[obj]);
21956 ASSERT_VK_SUCCESS(err);
21957
21958 VkSubmitInfo submit_info = {};
21959 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21960 submit_info.commandBufferCount = 1;
21961 submit_info.pCommandBuffers = &cmd_buffers[obj];
21962 // Submit cmd buffer and wait for fence
21963 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
21964 ASSERT_VK_SUCCESS(err);
21965 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
21966 ASSERT_VK_SUCCESS(err);
21967 err = vkResetFences(m_device->device(), 1, &fences[obj]);
21968 ASSERT_VK_SUCCESS(err);
21969 }
21970 }
21971 m_errorMonitor->VerifyNotFound();
21972 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
21973 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
21974 vkDestroyFence(m_device->device(), fences[i], nullptr);
21975 }
21976}
21977// This is a positive test. No errors should be generated.
21978TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021979 TEST_DESCRIPTION(
21980 "Two command buffers, each in a separate QueueSubmit call "
21981 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021982
Tony Barbour1fa09702017-03-16 12:09:08 -060021983 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021984 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021985
21986 m_errorMonitor->ExpectSuccess();
21987
21988 VkSemaphore semaphore;
21989 VkSemaphoreCreateInfo semaphore_create_info{};
21990 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21991 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21992
21993 VkCommandPool command_pool;
21994 VkCommandPoolCreateInfo pool_create_info{};
21995 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21996 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21997 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21998 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21999
22000 VkCommandBuffer command_buffer[2];
22001 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22002 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22003 command_buffer_allocate_info.commandPool = command_pool;
22004 command_buffer_allocate_info.commandBufferCount = 2;
22005 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22006 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22007
22008 VkQueue queue = VK_NULL_HANDLE;
22009 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22010
22011 {
22012 VkCommandBufferBeginInfo begin_info{};
22013 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22014 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22015
22016 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 -070022017 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022018
22019 VkViewport viewport{};
22020 viewport.maxDepth = 1.0f;
22021 viewport.minDepth = 0.0f;
22022 viewport.width = 512;
22023 viewport.height = 512;
22024 viewport.x = 0;
22025 viewport.y = 0;
22026 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22027 vkEndCommandBuffer(command_buffer[0]);
22028 }
22029 {
22030 VkCommandBufferBeginInfo begin_info{};
22031 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22032 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22033
22034 VkViewport viewport{};
22035 viewport.maxDepth = 1.0f;
22036 viewport.minDepth = 0.0f;
22037 viewport.width = 512;
22038 viewport.height = 512;
22039 viewport.x = 0;
22040 viewport.y = 0;
22041 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22042 vkEndCommandBuffer(command_buffer[1]);
22043 }
22044 {
22045 VkSubmitInfo submit_info{};
22046 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22047 submit_info.commandBufferCount = 1;
22048 submit_info.pCommandBuffers = &command_buffer[0];
22049 submit_info.signalSemaphoreCount = 1;
22050 submit_info.pSignalSemaphores = &semaphore;
22051 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22052 }
22053 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022054 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022055 VkSubmitInfo submit_info{};
22056 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22057 submit_info.commandBufferCount = 1;
22058 submit_info.pCommandBuffers = &command_buffer[1];
22059 submit_info.waitSemaphoreCount = 1;
22060 submit_info.pWaitSemaphores = &semaphore;
22061 submit_info.pWaitDstStageMask = flags;
22062 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22063 }
22064
22065 vkQueueWaitIdle(m_device->m_queue);
22066
22067 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22068 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22069 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22070
22071 m_errorMonitor->VerifyNotFound();
22072}
22073
22074// This is a positive test. No errors should be generated.
22075TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022076 TEST_DESCRIPTION(
22077 "Two command buffers, each in a separate QueueSubmit call "
22078 "submitted on separate queues, the second having a fence"
22079 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022080
Tony Barbour1fa09702017-03-16 12:09:08 -060022081 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022082 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022083
22084 m_errorMonitor->ExpectSuccess();
22085
22086 VkFence fence;
22087 VkFenceCreateInfo fence_create_info{};
22088 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22089 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22090
22091 VkSemaphore semaphore;
22092 VkSemaphoreCreateInfo semaphore_create_info{};
22093 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22094 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22095
22096 VkCommandPool command_pool;
22097 VkCommandPoolCreateInfo pool_create_info{};
22098 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22099 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22100 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22101 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22102
22103 VkCommandBuffer command_buffer[2];
22104 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22105 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22106 command_buffer_allocate_info.commandPool = command_pool;
22107 command_buffer_allocate_info.commandBufferCount = 2;
22108 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22109 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22110
22111 VkQueue queue = VK_NULL_HANDLE;
22112 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22113
22114 {
22115 VkCommandBufferBeginInfo begin_info{};
22116 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22117 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22118
22119 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 -070022120 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022121
22122 VkViewport viewport{};
22123 viewport.maxDepth = 1.0f;
22124 viewport.minDepth = 0.0f;
22125 viewport.width = 512;
22126 viewport.height = 512;
22127 viewport.x = 0;
22128 viewport.y = 0;
22129 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22130 vkEndCommandBuffer(command_buffer[0]);
22131 }
22132 {
22133 VkCommandBufferBeginInfo begin_info{};
22134 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22135 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22136
22137 VkViewport viewport{};
22138 viewport.maxDepth = 1.0f;
22139 viewport.minDepth = 0.0f;
22140 viewport.width = 512;
22141 viewport.height = 512;
22142 viewport.x = 0;
22143 viewport.y = 0;
22144 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22145 vkEndCommandBuffer(command_buffer[1]);
22146 }
22147 {
22148 VkSubmitInfo submit_info{};
22149 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22150 submit_info.commandBufferCount = 1;
22151 submit_info.pCommandBuffers = &command_buffer[0];
22152 submit_info.signalSemaphoreCount = 1;
22153 submit_info.pSignalSemaphores = &semaphore;
22154 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22155 }
22156 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022157 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022158 VkSubmitInfo submit_info{};
22159 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22160 submit_info.commandBufferCount = 1;
22161 submit_info.pCommandBuffers = &command_buffer[1];
22162 submit_info.waitSemaphoreCount = 1;
22163 submit_info.pWaitSemaphores = &semaphore;
22164 submit_info.pWaitDstStageMask = flags;
22165 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22166 }
22167
22168 vkQueueWaitIdle(m_device->m_queue);
22169
22170 vkDestroyFence(m_device->device(), fence, nullptr);
22171 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22172 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22173 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22174
22175 m_errorMonitor->VerifyNotFound();
22176}
22177
22178// This is a positive test. No errors should be generated.
22179TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022180 TEST_DESCRIPTION(
22181 "Two command buffers, each in a separate QueueSubmit call "
22182 "submitted on separate queues, the second having a fence"
22183 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022184
Tony Barbour1fa09702017-03-16 12:09:08 -060022185 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022186 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022187
22188 m_errorMonitor->ExpectSuccess();
22189
22190 VkFence fence;
22191 VkFenceCreateInfo fence_create_info{};
22192 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22193 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22194
22195 VkSemaphore semaphore;
22196 VkSemaphoreCreateInfo semaphore_create_info{};
22197 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22198 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22199
22200 VkCommandPool command_pool;
22201 VkCommandPoolCreateInfo pool_create_info{};
22202 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22203 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22204 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22205 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22206
22207 VkCommandBuffer command_buffer[2];
22208 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22209 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22210 command_buffer_allocate_info.commandPool = command_pool;
22211 command_buffer_allocate_info.commandBufferCount = 2;
22212 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22213 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22214
22215 VkQueue queue = VK_NULL_HANDLE;
22216 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22217
22218 {
22219 VkCommandBufferBeginInfo begin_info{};
22220 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22221 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22222
22223 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 -070022224 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022225
22226 VkViewport viewport{};
22227 viewport.maxDepth = 1.0f;
22228 viewport.minDepth = 0.0f;
22229 viewport.width = 512;
22230 viewport.height = 512;
22231 viewport.x = 0;
22232 viewport.y = 0;
22233 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22234 vkEndCommandBuffer(command_buffer[0]);
22235 }
22236 {
22237 VkCommandBufferBeginInfo begin_info{};
22238 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22239 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22240
22241 VkViewport viewport{};
22242 viewport.maxDepth = 1.0f;
22243 viewport.minDepth = 0.0f;
22244 viewport.width = 512;
22245 viewport.height = 512;
22246 viewport.x = 0;
22247 viewport.y = 0;
22248 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22249 vkEndCommandBuffer(command_buffer[1]);
22250 }
22251 {
22252 VkSubmitInfo submit_info{};
22253 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22254 submit_info.commandBufferCount = 1;
22255 submit_info.pCommandBuffers = &command_buffer[0];
22256 submit_info.signalSemaphoreCount = 1;
22257 submit_info.pSignalSemaphores = &semaphore;
22258 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22259 }
22260 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022261 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022262 VkSubmitInfo submit_info{};
22263 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22264 submit_info.commandBufferCount = 1;
22265 submit_info.pCommandBuffers = &command_buffer[1];
22266 submit_info.waitSemaphoreCount = 1;
22267 submit_info.pWaitSemaphores = &semaphore;
22268 submit_info.pWaitDstStageMask = flags;
22269 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22270 }
22271
22272 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22273 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22274
22275 vkDestroyFence(m_device->device(), fence, nullptr);
22276 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22277 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22278 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22279
22280 m_errorMonitor->VerifyNotFound();
22281}
22282
22283TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Tony Barbour1fa09702017-03-16 12:09:08 -060022284 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022285 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022286 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022287 return;
22288 }
22289
22290 VkResult err;
22291
22292 m_errorMonitor->ExpectSuccess();
22293
22294 VkQueue q0 = m_device->m_queue;
22295 VkQueue q1 = nullptr;
22296 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
22297 ASSERT_NE(q1, nullptr);
22298
22299 // An (empty) command buffer. We must have work in the first submission --
22300 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022301 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022302 VkCommandPool pool;
22303 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
22304 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022305 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
22306 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022307 VkCommandBuffer cb;
22308 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
22309 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022310 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022311 err = vkBeginCommandBuffer(cb, &cbbi);
22312 ASSERT_VK_SUCCESS(err);
22313 err = vkEndCommandBuffer(cb);
22314 ASSERT_VK_SUCCESS(err);
22315
22316 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022317 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022318 VkSemaphore s;
22319 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
22320 ASSERT_VK_SUCCESS(err);
22321
22322 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022323 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022324
22325 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
22326 ASSERT_VK_SUCCESS(err);
22327
22328 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022329 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022330 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022331
22332 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
22333 ASSERT_VK_SUCCESS(err);
22334
22335 // Wait for q0 idle
22336 err = vkQueueWaitIdle(q0);
22337 ASSERT_VK_SUCCESS(err);
22338
22339 // Command buffer should have been completed (it was on q0); reset the pool.
22340 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
22341
22342 m_errorMonitor->VerifyNotFound();
22343
22344 // Force device completely idle and clean up resources
22345 vkDeviceWaitIdle(m_device->device());
22346 vkDestroyCommandPool(m_device->device(), pool, nullptr);
22347 vkDestroySemaphore(m_device->device(), s, nullptr);
22348}
22349
22350// This is a positive test. No errors should be generated.
22351TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022352 TEST_DESCRIPTION(
22353 "Two command buffers, each in a separate QueueSubmit call "
22354 "submitted on separate queues, the second having a fence, "
22355 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022356
Tony Barbour1fa09702017-03-16 12:09:08 -060022357 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022358 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022359
22360 m_errorMonitor->ExpectSuccess();
22361
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022362 VkFence fence;
22363 VkFenceCreateInfo fence_create_info{};
22364 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22365 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22366
22367 VkSemaphore semaphore;
22368 VkSemaphoreCreateInfo semaphore_create_info{};
22369 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22370 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22371
22372 VkCommandPool command_pool;
22373 VkCommandPoolCreateInfo pool_create_info{};
22374 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22375 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22376 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22377 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22378
22379 VkCommandBuffer command_buffer[2];
22380 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22381 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22382 command_buffer_allocate_info.commandPool = command_pool;
22383 command_buffer_allocate_info.commandBufferCount = 2;
22384 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22385 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22386
22387 VkQueue queue = VK_NULL_HANDLE;
22388 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22389
22390 {
22391 VkCommandBufferBeginInfo begin_info{};
22392 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22393 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22394
22395 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 -070022396 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022397
22398 VkViewport viewport{};
22399 viewport.maxDepth = 1.0f;
22400 viewport.minDepth = 0.0f;
22401 viewport.width = 512;
22402 viewport.height = 512;
22403 viewport.x = 0;
22404 viewport.y = 0;
22405 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22406 vkEndCommandBuffer(command_buffer[0]);
22407 }
22408 {
22409 VkCommandBufferBeginInfo begin_info{};
22410 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22411 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22412
22413 VkViewport viewport{};
22414 viewport.maxDepth = 1.0f;
22415 viewport.minDepth = 0.0f;
22416 viewport.width = 512;
22417 viewport.height = 512;
22418 viewport.x = 0;
22419 viewport.y = 0;
22420 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22421 vkEndCommandBuffer(command_buffer[1]);
22422 }
22423 {
22424 VkSubmitInfo submit_info{};
22425 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22426 submit_info.commandBufferCount = 1;
22427 submit_info.pCommandBuffers = &command_buffer[0];
22428 submit_info.signalSemaphoreCount = 1;
22429 submit_info.pSignalSemaphores = &semaphore;
22430 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22431 }
22432 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022433 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022434 VkSubmitInfo submit_info{};
22435 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22436 submit_info.commandBufferCount = 1;
22437 submit_info.pCommandBuffers = &command_buffer[1];
22438 submit_info.waitSemaphoreCount = 1;
22439 submit_info.pWaitSemaphores = &semaphore;
22440 submit_info.pWaitDstStageMask = flags;
22441 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22442 }
22443
22444 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22445
22446 vkDestroyFence(m_device->device(), fence, nullptr);
22447 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22448 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22449 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22450
22451 m_errorMonitor->VerifyNotFound();
22452}
22453
22454// This is a positive test. No errors should be generated.
22455TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022456 TEST_DESCRIPTION(
22457 "Two command buffers, each in a separate QueueSubmit call "
22458 "on the same queue, sharing a signal/wait semaphore, the "
22459 "second having a fence, "
22460 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022461
22462 m_errorMonitor->ExpectSuccess();
22463
Tony Barbour1fa09702017-03-16 12:09:08 -060022464 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022465 VkFence fence;
22466 VkFenceCreateInfo fence_create_info{};
22467 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22468 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22469
22470 VkSemaphore semaphore;
22471 VkSemaphoreCreateInfo semaphore_create_info{};
22472 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22473 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22474
22475 VkCommandPool command_pool;
22476 VkCommandPoolCreateInfo pool_create_info{};
22477 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22478 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22479 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22480 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22481
22482 VkCommandBuffer command_buffer[2];
22483 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22484 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22485 command_buffer_allocate_info.commandPool = command_pool;
22486 command_buffer_allocate_info.commandBufferCount = 2;
22487 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22488 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22489
22490 {
22491 VkCommandBufferBeginInfo begin_info{};
22492 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22493 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22494
22495 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 -070022496 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022497
22498 VkViewport viewport{};
22499 viewport.maxDepth = 1.0f;
22500 viewport.minDepth = 0.0f;
22501 viewport.width = 512;
22502 viewport.height = 512;
22503 viewport.x = 0;
22504 viewport.y = 0;
22505 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22506 vkEndCommandBuffer(command_buffer[0]);
22507 }
22508 {
22509 VkCommandBufferBeginInfo begin_info{};
22510 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22511 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22512
22513 VkViewport viewport{};
22514 viewport.maxDepth = 1.0f;
22515 viewport.minDepth = 0.0f;
22516 viewport.width = 512;
22517 viewport.height = 512;
22518 viewport.x = 0;
22519 viewport.y = 0;
22520 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22521 vkEndCommandBuffer(command_buffer[1]);
22522 }
22523 {
22524 VkSubmitInfo submit_info{};
22525 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22526 submit_info.commandBufferCount = 1;
22527 submit_info.pCommandBuffers = &command_buffer[0];
22528 submit_info.signalSemaphoreCount = 1;
22529 submit_info.pSignalSemaphores = &semaphore;
22530 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22531 }
22532 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022533 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022534 VkSubmitInfo submit_info{};
22535 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22536 submit_info.commandBufferCount = 1;
22537 submit_info.pCommandBuffers = &command_buffer[1];
22538 submit_info.waitSemaphoreCount = 1;
22539 submit_info.pWaitSemaphores = &semaphore;
22540 submit_info.pWaitDstStageMask = flags;
22541 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22542 }
22543
22544 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22545
22546 vkDestroyFence(m_device->device(), fence, nullptr);
22547 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22548 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22549 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22550
22551 m_errorMonitor->VerifyNotFound();
22552}
22553
22554// This is a positive test. No errors should be generated.
22555TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022556 TEST_DESCRIPTION(
22557 "Two command buffers, each in a separate QueueSubmit call "
22558 "on the same queue, no fences, followed by a third QueueSubmit with NO "
22559 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022560
22561 m_errorMonitor->ExpectSuccess();
22562
Tony Barbour1fa09702017-03-16 12:09:08 -060022563 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022564 VkFence fence;
22565 VkFenceCreateInfo fence_create_info{};
22566 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22567 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22568
22569 VkCommandPool command_pool;
22570 VkCommandPoolCreateInfo pool_create_info{};
22571 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22572 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22573 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22574 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22575
22576 VkCommandBuffer command_buffer[2];
22577 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22578 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22579 command_buffer_allocate_info.commandPool = command_pool;
22580 command_buffer_allocate_info.commandBufferCount = 2;
22581 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22582 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22583
22584 {
22585 VkCommandBufferBeginInfo begin_info{};
22586 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22587 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22588
22589 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 -070022590 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022591
22592 VkViewport viewport{};
22593 viewport.maxDepth = 1.0f;
22594 viewport.minDepth = 0.0f;
22595 viewport.width = 512;
22596 viewport.height = 512;
22597 viewport.x = 0;
22598 viewport.y = 0;
22599 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22600 vkEndCommandBuffer(command_buffer[0]);
22601 }
22602 {
22603 VkCommandBufferBeginInfo begin_info{};
22604 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22605 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22606
22607 VkViewport viewport{};
22608 viewport.maxDepth = 1.0f;
22609 viewport.minDepth = 0.0f;
22610 viewport.width = 512;
22611 viewport.height = 512;
22612 viewport.x = 0;
22613 viewport.y = 0;
22614 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22615 vkEndCommandBuffer(command_buffer[1]);
22616 }
22617 {
22618 VkSubmitInfo submit_info{};
22619 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22620 submit_info.commandBufferCount = 1;
22621 submit_info.pCommandBuffers = &command_buffer[0];
22622 submit_info.signalSemaphoreCount = 0;
22623 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
22624 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22625 }
22626 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022627 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022628 VkSubmitInfo submit_info{};
22629 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22630 submit_info.commandBufferCount = 1;
22631 submit_info.pCommandBuffers = &command_buffer[1];
22632 submit_info.waitSemaphoreCount = 0;
22633 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
22634 submit_info.pWaitDstStageMask = flags;
22635 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22636 }
22637
22638 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
22639
22640 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22641 ASSERT_VK_SUCCESS(err);
22642
22643 vkDestroyFence(m_device->device(), fence, nullptr);
22644 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22645 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22646
22647 m_errorMonitor->VerifyNotFound();
22648}
22649
22650// This is a positive test. No errors should be generated.
22651TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022652 TEST_DESCRIPTION(
22653 "Two command buffers, each in a separate QueueSubmit call "
22654 "on the same queue, the second having a fence, followed "
22655 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022656
22657 m_errorMonitor->ExpectSuccess();
22658
Tony Barbour1fa09702017-03-16 12:09:08 -060022659 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022660 VkFence fence;
22661 VkFenceCreateInfo fence_create_info{};
22662 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22663 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22664
22665 VkCommandPool command_pool;
22666 VkCommandPoolCreateInfo pool_create_info{};
22667 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22668 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22669 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22670 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22671
22672 VkCommandBuffer command_buffer[2];
22673 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22674 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22675 command_buffer_allocate_info.commandPool = command_pool;
22676 command_buffer_allocate_info.commandBufferCount = 2;
22677 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22678 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22679
22680 {
22681 VkCommandBufferBeginInfo begin_info{};
22682 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22683 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22684
22685 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 -070022686 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022687
22688 VkViewport viewport{};
22689 viewport.maxDepth = 1.0f;
22690 viewport.minDepth = 0.0f;
22691 viewport.width = 512;
22692 viewport.height = 512;
22693 viewport.x = 0;
22694 viewport.y = 0;
22695 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22696 vkEndCommandBuffer(command_buffer[0]);
22697 }
22698 {
22699 VkCommandBufferBeginInfo begin_info{};
22700 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22701 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22702
22703 VkViewport viewport{};
22704 viewport.maxDepth = 1.0f;
22705 viewport.minDepth = 0.0f;
22706 viewport.width = 512;
22707 viewport.height = 512;
22708 viewport.x = 0;
22709 viewport.y = 0;
22710 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22711 vkEndCommandBuffer(command_buffer[1]);
22712 }
22713 {
22714 VkSubmitInfo submit_info{};
22715 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22716 submit_info.commandBufferCount = 1;
22717 submit_info.pCommandBuffers = &command_buffer[0];
22718 submit_info.signalSemaphoreCount = 0;
22719 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
22720 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22721 }
22722 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022723 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022724 VkSubmitInfo submit_info{};
22725 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22726 submit_info.commandBufferCount = 1;
22727 submit_info.pCommandBuffers = &command_buffer[1];
22728 submit_info.waitSemaphoreCount = 0;
22729 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
22730 submit_info.pWaitDstStageMask = flags;
22731 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22732 }
22733
22734 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22735
22736 vkDestroyFence(m_device->device(), fence, nullptr);
22737 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22738 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22739
22740 m_errorMonitor->VerifyNotFound();
22741}
22742
22743// This is a positive test. No errors should be generated.
22744TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022745 TEST_DESCRIPTION(
22746 "Two command buffers each in a separate SubmitInfo sent in a single "
22747 "QueueSubmit call followed by a WaitForFences call.");
Tony Barbour1fa09702017-03-16 12:09:08 -060022748 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022749
22750 m_errorMonitor->ExpectSuccess();
22751
22752 VkFence fence;
22753 VkFenceCreateInfo fence_create_info{};
22754 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22755 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22756
22757 VkSemaphore semaphore;
22758 VkSemaphoreCreateInfo semaphore_create_info{};
22759 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22760 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22761
22762 VkCommandPool command_pool;
22763 VkCommandPoolCreateInfo pool_create_info{};
22764 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22765 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22766 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22767 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22768
22769 VkCommandBuffer command_buffer[2];
22770 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22771 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22772 command_buffer_allocate_info.commandPool = command_pool;
22773 command_buffer_allocate_info.commandBufferCount = 2;
22774 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22775 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22776
22777 {
22778 VkCommandBufferBeginInfo begin_info{};
22779 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22780 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22781
22782 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 -070022783 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022784
22785 VkViewport viewport{};
22786 viewport.maxDepth = 1.0f;
22787 viewport.minDepth = 0.0f;
22788 viewport.width = 512;
22789 viewport.height = 512;
22790 viewport.x = 0;
22791 viewport.y = 0;
22792 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22793 vkEndCommandBuffer(command_buffer[0]);
22794 }
22795 {
22796 VkCommandBufferBeginInfo begin_info{};
22797 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22798 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22799
22800 VkViewport viewport{};
22801 viewport.maxDepth = 1.0f;
22802 viewport.minDepth = 0.0f;
22803 viewport.width = 512;
22804 viewport.height = 512;
22805 viewport.x = 0;
22806 viewport.y = 0;
22807 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22808 vkEndCommandBuffer(command_buffer[1]);
22809 }
22810 {
22811 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022812 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022813
22814 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22815 submit_info[0].pNext = NULL;
22816 submit_info[0].commandBufferCount = 1;
22817 submit_info[0].pCommandBuffers = &command_buffer[0];
22818 submit_info[0].signalSemaphoreCount = 1;
22819 submit_info[0].pSignalSemaphores = &semaphore;
22820 submit_info[0].waitSemaphoreCount = 0;
22821 submit_info[0].pWaitSemaphores = NULL;
22822 submit_info[0].pWaitDstStageMask = 0;
22823
22824 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22825 submit_info[1].pNext = NULL;
22826 submit_info[1].commandBufferCount = 1;
22827 submit_info[1].pCommandBuffers = &command_buffer[1];
22828 submit_info[1].waitSemaphoreCount = 1;
22829 submit_info[1].pWaitSemaphores = &semaphore;
22830 submit_info[1].pWaitDstStageMask = flags;
22831 submit_info[1].signalSemaphoreCount = 0;
22832 submit_info[1].pSignalSemaphores = NULL;
22833 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
22834 }
22835
22836 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22837
22838 vkDestroyFence(m_device->device(), fence, nullptr);
22839 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22840 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22841 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22842
22843 m_errorMonitor->VerifyNotFound();
22844}
22845
22846TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
22847 m_errorMonitor->ExpectSuccess();
22848
Tony Barbour1fa09702017-03-16 12:09:08 -060022849 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022850 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22851
Tony Barbour552f6c02016-12-21 14:34:07 -070022852 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022853
22854 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
22855 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
22856 m_errorMonitor->VerifyNotFound();
22857 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
22858 m_errorMonitor->VerifyNotFound();
22859 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
22860 m_errorMonitor->VerifyNotFound();
22861
22862 m_commandBuffer->EndCommandBuffer();
22863 m_errorMonitor->VerifyNotFound();
22864}
22865
22866TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022867 TEST_DESCRIPTION(
22868 "Positive test where we create a renderpass with an "
22869 "attachment that uses LOAD_OP_CLEAR, the first subpass "
22870 "has a valid layout, and a second subpass then uses a "
22871 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022872 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060022873 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060022874 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070022875 if (!depth_format) {
22876 printf(" No Depth + Stencil format found. Skipped.\n");
22877 return;
22878 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022879
22880 VkAttachmentReference attach[2] = {};
22881 attach[0].attachment = 0;
22882 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
22883 attach[1].attachment = 0;
22884 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
22885 VkSubpassDescription subpasses[2] = {};
22886 // First subpass clears DS attach on load
22887 subpasses[0].pDepthStencilAttachment = &attach[0];
22888 // 2nd subpass reads in DS as input attachment
22889 subpasses[1].inputAttachmentCount = 1;
22890 subpasses[1].pInputAttachments = &attach[1];
22891 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070022892 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022893 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
22894 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
22895 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
22896 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
22897 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
22898 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
22899 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
22900 VkRenderPassCreateInfo rpci = {};
22901 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
22902 rpci.attachmentCount = 1;
22903 rpci.pAttachments = &attach_desc;
22904 rpci.subpassCount = 2;
22905 rpci.pSubpasses = subpasses;
22906
22907 // Now create RenderPass and verify no errors
22908 VkRenderPass rp;
22909 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
22910 m_errorMonitor->VerifyNotFound();
22911
22912 vkDestroyRenderPass(m_device->device(), rp, NULL);
22913}
22914
Tobin Ehlis01103de2017-02-16 13:22:47 -070022915TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
22916 TEST_DESCRIPTION(
22917 "Create a render pass with depth-stencil attachment where layout transition "
22918 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
22919 "transition has correctly occurred at queue submit time with no validation errors.");
22920
Tony Barbour1fa09702017-03-16 12:09:08 -060022921 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060022922 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070022923 if (!depth_format) {
22924 printf(" No Depth + Stencil format found. Skipped.\n");
22925 return;
22926 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070022927 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070022928 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070022929 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
22930 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070022931 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070022932 return;
22933 }
22934
22935 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070022936 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22937
22938 // A renderpass with one depth/stencil attachment.
22939 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070022940 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070022941 VK_SAMPLE_COUNT_1_BIT,
22942 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
22943 VK_ATTACHMENT_STORE_OP_DONT_CARE,
22944 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
22945 VK_ATTACHMENT_STORE_OP_DONT_CARE,
22946 VK_IMAGE_LAYOUT_UNDEFINED,
22947 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
22948
22949 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
22950
22951 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
22952
22953 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
22954
22955 VkRenderPass rp;
22956 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
22957 ASSERT_VK_SUCCESS(err);
22958 // A compatible ds image.
22959 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060022960 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 -070022961 ASSERT_TRUE(image.initialized());
22962
22963 VkImageViewCreateInfo ivci = {
22964 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
22965 nullptr,
22966 0,
22967 image.handle(),
22968 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070022969 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070022970 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
22971 VK_COMPONENT_SWIZZLE_IDENTITY},
22972 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
22973 };
22974 VkImageView view;
22975 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
22976 ASSERT_VK_SUCCESS(err);
22977
22978 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
22979 VkFramebuffer fb;
22980 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
22981 ASSERT_VK_SUCCESS(err);
22982
22983 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
22984 m_commandBuffer->BeginCommandBuffer();
22985 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
22986 vkCmdEndRenderPass(m_commandBuffer->handle());
22987 m_commandBuffer->EndCommandBuffer();
22988 QueueCommandBuffer(false);
22989 m_errorMonitor->VerifyNotFound();
22990
22991 // Cleanup
22992 vkDestroyImageView(m_device->device(), view, NULL);
22993 vkDestroyRenderPass(m_device->device(), rp, NULL);
22994 vkDestroyFramebuffer(m_device->device(), fb, NULL);
22995}
22996
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022997TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022998 TEST_DESCRIPTION(
22999 "Test that pipeline validation accepts matrices passed "
23000 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023001 m_errorMonitor->ExpectSuccess();
23002
Tony Barbour1fa09702017-03-16 12:09:08 -060023003 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23005
23006 VkVertexInputBindingDescription input_binding;
23007 memset(&input_binding, 0, sizeof(input_binding));
23008
23009 VkVertexInputAttributeDescription input_attribs[2];
23010 memset(input_attribs, 0, sizeof(input_attribs));
23011
23012 for (int i = 0; i < 2; i++) {
23013 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23014 input_attribs[i].location = i;
23015 }
23016
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023017 char const *vsSource =
23018 "#version 450\n"
23019 "\n"
23020 "layout(location=0) in mat2x4 x;\n"
23021 "out gl_PerVertex {\n"
23022 " vec4 gl_Position;\n"
23023 "};\n"
23024 "void main(){\n"
23025 " gl_Position = x[0] + x[1];\n"
23026 "}\n";
23027 char const *fsSource =
23028 "#version 450\n"
23029 "\n"
23030 "layout(location=0) out vec4 color;\n"
23031 "void main(){\n"
23032 " color = vec4(1);\n"
23033 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023034
23035 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23036 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23037
23038 VkPipelineObj pipe(m_device);
23039 pipe.AddColorAttachment();
23040 pipe.AddShader(&vs);
23041 pipe.AddShader(&fs);
23042
23043 pipe.AddVertexInputBindings(&input_binding, 1);
23044 pipe.AddVertexInputAttribs(input_attribs, 2);
23045
23046 VkDescriptorSetObj descriptorSet(m_device);
23047 descriptorSet.AppendDummy();
23048 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23049
23050 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23051
23052 /* expect success */
23053 m_errorMonitor->VerifyNotFound();
23054}
23055
23056TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
23057 m_errorMonitor->ExpectSuccess();
23058
Tony Barbour1fa09702017-03-16 12:09:08 -060023059 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23061
23062 VkVertexInputBindingDescription input_binding;
23063 memset(&input_binding, 0, sizeof(input_binding));
23064
23065 VkVertexInputAttributeDescription input_attribs[2];
23066 memset(input_attribs, 0, sizeof(input_attribs));
23067
23068 for (int i = 0; i < 2; i++) {
23069 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23070 input_attribs[i].location = i;
23071 }
23072
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023073 char const *vsSource =
23074 "#version 450\n"
23075 "\n"
23076 "layout(location=0) in vec4 x[2];\n"
23077 "out gl_PerVertex {\n"
23078 " vec4 gl_Position;\n"
23079 "};\n"
23080 "void main(){\n"
23081 " gl_Position = x[0] + x[1];\n"
23082 "}\n";
23083 char const *fsSource =
23084 "#version 450\n"
23085 "\n"
23086 "layout(location=0) out vec4 color;\n"
23087 "void main(){\n"
23088 " color = vec4(1);\n"
23089 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023090
23091 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23092 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23093
23094 VkPipelineObj pipe(m_device);
23095 pipe.AddColorAttachment();
23096 pipe.AddShader(&vs);
23097 pipe.AddShader(&fs);
23098
23099 pipe.AddVertexInputBindings(&input_binding, 1);
23100 pipe.AddVertexInputAttribs(input_attribs, 2);
23101
23102 VkDescriptorSetObj descriptorSet(m_device);
23103 descriptorSet.AppendDummy();
23104 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23105
23106 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23107
23108 m_errorMonitor->VerifyNotFound();
23109}
23110
23111TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023112 TEST_DESCRIPTION(
23113 "Test that pipeline validation accepts consuming a vertex attribute "
23114 "through multiple vertex shader inputs, each consuming a different "
23115 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023116 m_errorMonitor->ExpectSuccess();
23117
Tony Barbour1fa09702017-03-16 12:09:08 -060023118 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23120
23121 VkVertexInputBindingDescription input_binding;
23122 memset(&input_binding, 0, sizeof(input_binding));
23123
23124 VkVertexInputAttributeDescription input_attribs[3];
23125 memset(input_attribs, 0, sizeof(input_attribs));
23126
23127 for (int i = 0; i < 3; i++) {
23128 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23129 input_attribs[i].location = i;
23130 }
23131
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023132 char const *vsSource =
23133 "#version 450\n"
23134 "\n"
23135 "layout(location=0) in vec4 x;\n"
23136 "layout(location=1) in vec3 y1;\n"
23137 "layout(location=1, component=3) in float y2;\n"
23138 "layout(location=2) in vec4 z;\n"
23139 "out gl_PerVertex {\n"
23140 " vec4 gl_Position;\n"
23141 "};\n"
23142 "void main(){\n"
23143 " gl_Position = x + vec4(y1, y2) + z;\n"
23144 "}\n";
23145 char const *fsSource =
23146 "#version 450\n"
23147 "\n"
23148 "layout(location=0) out vec4 color;\n"
23149 "void main(){\n"
23150 " color = vec4(1);\n"
23151 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023152
23153 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23154 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23155
23156 VkPipelineObj pipe(m_device);
23157 pipe.AddColorAttachment();
23158 pipe.AddShader(&vs);
23159 pipe.AddShader(&fs);
23160
23161 pipe.AddVertexInputBindings(&input_binding, 1);
23162 pipe.AddVertexInputAttribs(input_attribs, 3);
23163
23164 VkDescriptorSetObj descriptorSet(m_device);
23165 descriptorSet.AppendDummy();
23166 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23167
23168 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23169
23170 m_errorMonitor->VerifyNotFound();
23171}
23172
23173TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
23174 m_errorMonitor->ExpectSuccess();
23175
Tony Barbour1fa09702017-03-16 12:09:08 -060023176 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23178
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023179 char const *vsSource =
23180 "#version 450\n"
23181 "out gl_PerVertex {\n"
23182 " vec4 gl_Position;\n"
23183 "};\n"
23184 "void main(){\n"
23185 " gl_Position = vec4(0);\n"
23186 "}\n";
23187 char const *fsSource =
23188 "#version 450\n"
23189 "\n"
23190 "layout(location=0) out vec4 color;\n"
23191 "void main(){\n"
23192 " color = vec4(1);\n"
23193 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023194
23195 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23196 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23197
23198 VkPipelineObj pipe(m_device);
23199 pipe.AddColorAttachment();
23200 pipe.AddShader(&vs);
23201 pipe.AddShader(&fs);
23202
23203 VkDescriptorSetObj descriptorSet(m_device);
23204 descriptorSet.AppendDummy();
23205 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23206
23207 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23208
23209 m_errorMonitor->VerifyNotFound();
23210}
23211
23212TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023213 TEST_DESCRIPTION(
23214 "Test that pipeline validation accepts the relaxed type matching rules "
23215 "set out in 14.1.3: fundamental type must match, and producer side must "
23216 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023217 m_errorMonitor->ExpectSuccess();
23218
23219 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
23220
Tony Barbour1fa09702017-03-16 12:09:08 -060023221 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23223
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023224 char const *vsSource =
23225 "#version 450\n"
23226 "out gl_PerVertex {\n"
23227 " vec4 gl_Position;\n"
23228 "};\n"
23229 "layout(location=0) out vec3 x;\n"
23230 "layout(location=1) out ivec3 y;\n"
23231 "layout(location=2) out vec3 z;\n"
23232 "void main(){\n"
23233 " gl_Position = vec4(0);\n"
23234 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
23235 "}\n";
23236 char const *fsSource =
23237 "#version 450\n"
23238 "\n"
23239 "layout(location=0) out vec4 color;\n"
23240 "layout(location=0) in float x;\n"
23241 "layout(location=1) flat in int y;\n"
23242 "layout(location=2) in vec2 z;\n"
23243 "void main(){\n"
23244 " color = vec4(1 + x + y + z.x);\n"
23245 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023246
23247 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23248 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23249
23250 VkPipelineObj pipe(m_device);
23251 pipe.AddColorAttachment();
23252 pipe.AddShader(&vs);
23253 pipe.AddShader(&fs);
23254
23255 VkDescriptorSetObj descriptorSet(m_device);
23256 descriptorSet.AppendDummy();
23257 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23258
23259 VkResult err = VK_SUCCESS;
23260 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23261 ASSERT_VK_SUCCESS(err);
23262
23263 m_errorMonitor->VerifyNotFound();
23264}
23265
23266TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023267 TEST_DESCRIPTION(
23268 "Test that pipeline validation accepts per-vertex variables "
23269 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023270 m_errorMonitor->ExpectSuccess();
23271
Tony Barbour1fa09702017-03-16 12:09:08 -060023272 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23274
23275 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023276 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023277 return;
23278 }
23279
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023280 char const *vsSource =
23281 "#version 450\n"
23282 "void main(){}\n";
23283 char const *tcsSource =
23284 "#version 450\n"
23285 "layout(location=0) out int x[];\n"
23286 "layout(vertices=3) out;\n"
23287 "void main(){\n"
23288 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
23289 " gl_TessLevelInner[0] = 1;\n"
23290 " x[gl_InvocationID] = gl_InvocationID;\n"
23291 "}\n";
23292 char const *tesSource =
23293 "#version 450\n"
23294 "layout(triangles, equal_spacing, cw) in;\n"
23295 "layout(location=0) in int x[];\n"
23296 "out gl_PerVertex { vec4 gl_Position; };\n"
23297 "void main(){\n"
23298 " gl_Position.xyz = gl_TessCoord;\n"
23299 " gl_Position.w = x[0] + x[1] + x[2];\n"
23300 "}\n";
23301 char const *fsSource =
23302 "#version 450\n"
23303 "layout(location=0) out vec4 color;\n"
23304 "void main(){\n"
23305 " color = vec4(1);\n"
23306 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023307
23308 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23309 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
23310 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
23311 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23312
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023313 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
23314 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023315
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023316 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023317
23318 VkPipelineObj pipe(m_device);
23319 pipe.SetInputAssembly(&iasci);
23320 pipe.SetTessellation(&tsci);
23321 pipe.AddColorAttachment();
23322 pipe.AddShader(&vs);
23323 pipe.AddShader(&tcs);
23324 pipe.AddShader(&tes);
23325 pipe.AddShader(&fs);
23326
23327 VkDescriptorSetObj descriptorSet(m_device);
23328 descriptorSet.AppendDummy();
23329 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23330
23331 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23332
23333 m_errorMonitor->VerifyNotFound();
23334}
23335
23336TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023337 TEST_DESCRIPTION(
23338 "Test that pipeline validation accepts a user-defined "
23339 "interface block passed into the geometry shader. This "
23340 "is interesting because the 'extra' array level is not "
23341 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023342 m_errorMonitor->ExpectSuccess();
23343
Tony Barbour1fa09702017-03-16 12:09:08 -060023344 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023345 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23346
23347 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023348 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023349 return;
23350 }
23351
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023352 char const *vsSource =
23353 "#version 450\n"
23354 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
23355 "void main(){\n"
23356 " vs_out.x = vec4(1);\n"
23357 "}\n";
23358 char const *gsSource =
23359 "#version 450\n"
23360 "layout(triangles) in;\n"
23361 "layout(triangle_strip, max_vertices=3) out;\n"
23362 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
23363 "out gl_PerVertex { vec4 gl_Position; };\n"
23364 "void main() {\n"
23365 " gl_Position = gs_in[0].x;\n"
23366 " EmitVertex();\n"
23367 "}\n";
23368 char const *fsSource =
23369 "#version 450\n"
23370 "layout(location=0) out vec4 color;\n"
23371 "void main(){\n"
23372 " color = vec4(1);\n"
23373 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023374
23375 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23376 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
23377 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23378
23379 VkPipelineObj pipe(m_device);
23380 pipe.AddColorAttachment();
23381 pipe.AddShader(&vs);
23382 pipe.AddShader(&gs);
23383 pipe.AddShader(&fs);
23384
23385 VkDescriptorSetObj descriptorSet(m_device);
23386 descriptorSet.AppendDummy();
23387 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23388
23389 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23390
23391 m_errorMonitor->VerifyNotFound();
23392}
23393
23394TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023395 TEST_DESCRIPTION(
23396 "Test that pipeline validation accepts basic use of 64bit vertex "
23397 "attributes. This is interesting because they consume multiple "
23398 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023399 m_errorMonitor->ExpectSuccess();
23400
Tony Barbour1fa09702017-03-16 12:09:08 -060023401 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23403
23404 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023405 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023406 return;
23407 }
23408
23409 VkVertexInputBindingDescription input_bindings[1];
23410 memset(input_bindings, 0, sizeof(input_bindings));
23411
23412 VkVertexInputAttributeDescription input_attribs[4];
23413 memset(input_attribs, 0, sizeof(input_attribs));
23414 input_attribs[0].location = 0;
23415 input_attribs[0].offset = 0;
23416 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23417 input_attribs[1].location = 2;
23418 input_attribs[1].offset = 32;
23419 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23420 input_attribs[2].location = 4;
23421 input_attribs[2].offset = 64;
23422 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23423 input_attribs[3].location = 6;
23424 input_attribs[3].offset = 96;
23425 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23426
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023427 char const *vsSource =
23428 "#version 450\n"
23429 "\n"
23430 "layout(location=0) in dmat4 x;\n"
23431 "out gl_PerVertex {\n"
23432 " vec4 gl_Position;\n"
23433 "};\n"
23434 "void main(){\n"
23435 " gl_Position = vec4(x[0][0]);\n"
23436 "}\n";
23437 char const *fsSource =
23438 "#version 450\n"
23439 "\n"
23440 "layout(location=0) out vec4 color;\n"
23441 "void main(){\n"
23442 " color = vec4(1);\n"
23443 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023444
23445 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23446 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23447
23448 VkPipelineObj pipe(m_device);
23449 pipe.AddColorAttachment();
23450 pipe.AddShader(&vs);
23451 pipe.AddShader(&fs);
23452
23453 pipe.AddVertexInputBindings(input_bindings, 1);
23454 pipe.AddVertexInputAttribs(input_attribs, 4);
23455
23456 VkDescriptorSetObj descriptorSet(m_device);
23457 descriptorSet.AppendDummy();
23458 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23459
23460 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23461
23462 m_errorMonitor->VerifyNotFound();
23463}
23464
23465TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
23466 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
23467 m_errorMonitor->ExpectSuccess();
23468
Tony Barbour1fa09702017-03-16 12:09:08 -060023469 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023470
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023471 char const *vsSource =
23472 "#version 450\n"
23473 "\n"
23474 "out gl_PerVertex {\n"
23475 " vec4 gl_Position;\n"
23476 "};\n"
23477 "void main(){\n"
23478 " gl_Position = vec4(1);\n"
23479 "}\n";
23480 char const *fsSource =
23481 "#version 450\n"
23482 "\n"
23483 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
23484 "layout(location=0) out vec4 color;\n"
23485 "void main() {\n"
23486 " color = subpassLoad(x);\n"
23487 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023488
23489 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23490 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23491
23492 VkPipelineObj pipe(m_device);
23493 pipe.AddShader(&vs);
23494 pipe.AddShader(&fs);
23495 pipe.AddColorAttachment();
23496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23497
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023498 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
23499 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023500 VkDescriptorSetLayout dsl;
23501 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23502 ASSERT_VK_SUCCESS(err);
23503
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023504 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023505 VkPipelineLayout pl;
23506 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23507 ASSERT_VK_SUCCESS(err);
23508
23509 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023510 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23511 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23512 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
23513 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23514 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 -060023515 };
23516 VkAttachmentReference color = {
23517 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23518 };
23519 VkAttachmentReference input = {
23520 1, VK_IMAGE_LAYOUT_GENERAL,
23521 };
23522
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023523 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023524
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023525 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023526 VkRenderPass rp;
23527 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23528 ASSERT_VK_SUCCESS(err);
23529
23530 // should be OK. would go wrong here if it's going to...
23531 pipe.CreateVKPipeline(pl, rp);
23532
23533 m_errorMonitor->VerifyNotFound();
23534
23535 vkDestroyRenderPass(m_device->device(), rp, nullptr);
23536 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23537 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23538}
23539
23540TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023541 TEST_DESCRIPTION(
23542 "Test that pipeline validation accepts a compute pipeline which declares a "
23543 "descriptor-backed resource which is not provided, but the shader does not "
23544 "statically use it. This is interesting because it requires compute pipelines "
23545 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023546 m_errorMonitor->ExpectSuccess();
23547
Tony Barbour1fa09702017-03-16 12:09:08 -060023548 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023549
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023550 char const *csSource =
23551 "#version 450\n"
23552 "\n"
23553 "layout(local_size_x=1) in;\n"
23554 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
23555 "void main(){\n"
23556 " // x is not used.\n"
23557 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023558
23559 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23560
23561 VkDescriptorSetObj descriptorSet(m_device);
23562 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23563
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023564 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23565 nullptr,
23566 0,
23567 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23568 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23569 descriptorSet.GetPipelineLayout(),
23570 VK_NULL_HANDLE,
23571 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023572
23573 VkPipeline pipe;
23574 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23575
23576 m_errorMonitor->VerifyNotFound();
23577
23578 if (err == VK_SUCCESS) {
23579 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23580 }
23581}
23582
23583TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023584 TEST_DESCRIPTION(
23585 "Test that pipeline validation accepts a shader consuming only the "
23586 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023587 m_errorMonitor->ExpectSuccess();
23588
Tony Barbour1fa09702017-03-16 12:09:08 -060023589 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023590
23591 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023592 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23593 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23594 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023595 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023596 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023597 VkDescriptorSetLayout dsl;
23598 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23599 ASSERT_VK_SUCCESS(err);
23600
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023601 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023602 VkPipelineLayout pl;
23603 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23604 ASSERT_VK_SUCCESS(err);
23605
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023606 char const *csSource =
23607 "#version 450\n"
23608 "\n"
23609 "layout(local_size_x=1) in;\n"
23610 "layout(set=0, binding=0) uniform sampler s;\n"
23611 "layout(set=0, binding=1) uniform texture2D t;\n"
23612 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
23613 "void main() {\n"
23614 " x = texture(sampler2D(t, s), vec2(0));\n"
23615 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023616 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23617
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023618 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23619 nullptr,
23620 0,
23621 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23622 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23623 pl,
23624 VK_NULL_HANDLE,
23625 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023626
23627 VkPipeline pipe;
23628 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23629
23630 m_errorMonitor->VerifyNotFound();
23631
23632 if (err == VK_SUCCESS) {
23633 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23634 }
23635
23636 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23637 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23638}
23639
23640TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023641 TEST_DESCRIPTION(
23642 "Test that pipeline validation accepts a shader consuming only the "
23643 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023644 m_errorMonitor->ExpectSuccess();
23645
Tony Barbour1fa09702017-03-16 12:09:08 -060023646 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023647
23648 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023649 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23650 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23651 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023652 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023653 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023654 VkDescriptorSetLayout dsl;
23655 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23656 ASSERT_VK_SUCCESS(err);
23657
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023658 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023659 VkPipelineLayout pl;
23660 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23661 ASSERT_VK_SUCCESS(err);
23662
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023663 char const *csSource =
23664 "#version 450\n"
23665 "\n"
23666 "layout(local_size_x=1) in;\n"
23667 "layout(set=0, binding=0) uniform texture2D t;\n"
23668 "layout(set=0, binding=1) uniform sampler s;\n"
23669 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
23670 "void main() {\n"
23671 " x = texture(sampler2D(t, s), vec2(0));\n"
23672 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023673 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23674
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023675 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23676 nullptr,
23677 0,
23678 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23679 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23680 pl,
23681 VK_NULL_HANDLE,
23682 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023683
23684 VkPipeline pipe;
23685 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23686
23687 m_errorMonitor->VerifyNotFound();
23688
23689 if (err == VK_SUCCESS) {
23690 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23691 }
23692
23693 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23694 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23695}
23696
23697TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023698 TEST_DESCRIPTION(
23699 "Test that pipeline validation accepts a shader consuming "
23700 "both the sampler and the image of a combined image+sampler "
23701 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023702 m_errorMonitor->ExpectSuccess();
23703
Tony Barbour1fa09702017-03-16 12:09:08 -060023704 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023705
23706 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023707 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23708 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023709 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023710 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023711 VkDescriptorSetLayout dsl;
23712 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23713 ASSERT_VK_SUCCESS(err);
23714
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023715 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023716 VkPipelineLayout pl;
23717 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23718 ASSERT_VK_SUCCESS(err);
23719
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023720 char const *csSource =
23721 "#version 450\n"
23722 "\n"
23723 "layout(local_size_x=1) in;\n"
23724 "layout(set=0, binding=0) uniform texture2D t;\n"
23725 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
23726 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
23727 "void main() {\n"
23728 " x = texture(sampler2D(t, s), vec2(0));\n"
23729 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023730 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23731
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023732 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23733 nullptr,
23734 0,
23735 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23736 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23737 pl,
23738 VK_NULL_HANDLE,
23739 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023740
23741 VkPipeline pipe;
23742 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23743
23744 m_errorMonitor->VerifyNotFound();
23745
23746 if (err == VK_SUCCESS) {
23747 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23748 }
23749
23750 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23751 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23752}
23753
Tony Barbour3ed87a02017-03-15 16:19:02 -060023754TEST_F(VkPositiveLayerTest, Maintenance1Tests) {
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023755 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
23756
Tony Barbour3ed87a02017-03-15 16:19:02 -060023757 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
Tony Barbour73c0f352017-03-16 15:55:38 -060023758 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour3ed87a02017-03-15 16:19:02 -060023759
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023760 // Ensure that extension is available and enabled.
23761 uint32_t extension_count = 0;
23762 bool supports_maintenance1_extension = false;
23763 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
23764 ASSERT_VK_SUCCESS(err);
23765 if (extension_count > 0) {
23766 std::vector<VkExtensionProperties> available_extensions(extension_count);
23767
23768 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
23769 ASSERT_VK_SUCCESS(err);
23770 for (const auto &extension_props : available_extensions) {
23771 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
23772 supports_maintenance1_extension = true;
23773 }
23774 }
23775 }
23776
23777 // Proceed if extension is supported by hardware
23778 if (!supports_maintenance1_extension) {
23779 printf(" Maintenance1 Extension not supported, skipping tests\n");
23780 return;
23781 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023782
23783 m_errorMonitor->ExpectSuccess();
Dave Houlton8e0fe7a2017-03-30 10:32:10 -060023784 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023785 VkCommandBuffer cmd_buf;
23786 VkCommandBufferAllocateInfo alloc_info;
23787 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23788 alloc_info.pNext = NULL;
23789 alloc_info.commandBufferCount = 1;
Mike Schuchardt06304c22017-03-01 17:09:09 -070023790 alloc_info.commandPool = m_commandPool->handle();
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023791 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23792 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
23793
23794 VkCommandBufferBeginInfo cb_binfo;
23795 cb_binfo.pNext = NULL;
23796 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23797 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
23798 cb_binfo.flags = 0;
23799 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
23800 // Set Negative height, should give error if Maintenance 1 is not enabled
23801 VkViewport viewport = {0, 0, 16, -16, 0, 1};
23802 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
23803 vkEndCommandBuffer(cmd_buf);
23804
23805 m_errorMonitor->VerifyNotFound();
23806}
23807
Mark Lobodzinski35ecad32017-03-27 13:09:07 -060023808TEST_F(VkLayerTest, DuplicateValidPNextStructures) {
23809 TEST_DESCRIPTION("Create a pNext chain containing valid strutures, but with a duplicate structure type");
23810
23811 ASSERT_NO_FATAL_FAILURE(Init());
23812
23813 uint32_t extension_count = 0;
23814 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
23815 ASSERT_VK_SUCCESS(err);
23816
23817 if (extension_count > 0) {
23818 std::vector<VkExtensionProperties> available_extensions(extension_count);
23819 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
23820 ASSERT_VK_SUCCESS(err);
23821
23822 for (const auto &extension_props : available_extensions) {
23823 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
23824 // Create two pNext structures which by themselves would be valid
23825 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
23826 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info_2 = {};
23827 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
23828 dedicated_buffer_create_info.pNext = &dedicated_buffer_create_info_2;
23829 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
23830
23831 dedicated_buffer_create_info_2.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
23832 dedicated_buffer_create_info_2.pNext = nullptr;
23833 dedicated_buffer_create_info_2.dedicatedAllocation = VK_TRUE;
23834
23835 uint32_t queue_family_index = 0;
23836 VkBufferCreateInfo buffer_create_info = {};
23837 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
23838 buffer_create_info.pNext = &dedicated_buffer_create_info;
23839 buffer_create_info.size = 1024;
23840 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
23841 buffer_create_info.queueFamilyIndexCount = 1;
23842 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
23843
23844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "chain contains duplicate structure types");
23845 VkBuffer buffer;
23846 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
23847 m_errorMonitor->VerifyFound();
23848 }
23849 }
23850 }
23851}
23852
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023853TEST_F(VkPositiveLayerTest, ValidStructPNext) {
23854 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
23855
Tony Barbour1fa09702017-03-16 12:09:08 -060023856 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023857
23858 // Positive test to check parameter_validation and unique_objects support
23859 // for NV_dedicated_allocation
23860 uint32_t extension_count = 0;
23861 bool supports_nv_dedicated_allocation = false;
23862 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
23863 ASSERT_VK_SUCCESS(err);
23864
23865 if (extension_count > 0) {
23866 std::vector<VkExtensionProperties> available_extensions(extension_count);
23867
23868 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
23869 ASSERT_VK_SUCCESS(err);
23870
23871 for (const auto &extension_props : available_extensions) {
23872 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
23873 supports_nv_dedicated_allocation = true;
23874 }
23875 }
23876 }
23877
23878 if (supports_nv_dedicated_allocation) {
23879 m_errorMonitor->ExpectSuccess();
23880
23881 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
23882 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
23883 dedicated_buffer_create_info.pNext = nullptr;
23884 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
23885
23886 uint32_t queue_family_index = 0;
23887 VkBufferCreateInfo buffer_create_info = {};
23888 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
23889 buffer_create_info.pNext = &dedicated_buffer_create_info;
23890 buffer_create_info.size = 1024;
23891 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
23892 buffer_create_info.queueFamilyIndexCount = 1;
23893 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
23894
23895 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070023896 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023897 ASSERT_VK_SUCCESS(err);
23898
23899 VkMemoryRequirements memory_reqs;
23900 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
23901
23902 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
23903 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
23904 dedicated_memory_info.pNext = nullptr;
23905 dedicated_memory_info.buffer = buffer;
23906 dedicated_memory_info.image = VK_NULL_HANDLE;
23907
23908 VkMemoryAllocateInfo memory_info = {};
23909 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
23910 memory_info.pNext = &dedicated_memory_info;
23911 memory_info.allocationSize = memory_reqs.size;
23912
23913 bool pass;
23914 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
23915 ASSERT_TRUE(pass);
23916
23917 VkDeviceMemory buffer_memory;
23918 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
23919 ASSERT_VK_SUCCESS(err);
23920
23921 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
23922 ASSERT_VK_SUCCESS(err);
23923
23924 vkDestroyBuffer(m_device->device(), buffer, NULL);
23925 vkFreeMemory(m_device->device(), buffer_memory, NULL);
23926
23927 m_errorMonitor->VerifyNotFound();
23928 }
23929}
23930
23931TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
23932 VkResult err;
23933
23934 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
23935
Tony Barbour1fa09702017-03-16 12:09:08 -060023936 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023937 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23938
23939 std::vector<const char *> device_extension_names;
23940 auto features = m_device->phy().features();
23941 // Artificially disable support for non-solid fill modes
23942 features.fillModeNonSolid = false;
23943 // The sacrificial device object
23944 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
23945
23946 VkRenderpassObj render_pass(&test_device);
23947
23948 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
23949 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
23950 pipeline_layout_ci.setLayoutCount = 0;
23951 pipeline_layout_ci.pSetLayouts = NULL;
23952
23953 VkPipelineLayout pipeline_layout;
23954 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
23955 ASSERT_VK_SUCCESS(err);
23956
23957 VkPipelineRasterizationStateCreateInfo rs_ci = {};
23958 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
23959 rs_ci.pNext = nullptr;
23960 rs_ci.lineWidth = 1.0f;
23961 rs_ci.rasterizerDiscardEnable = true;
23962
23963 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
23964 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23965
23966 // Set polygonMode=FILL. No error is expected
23967 m_errorMonitor->ExpectSuccess();
23968 {
23969 VkPipelineObj pipe(&test_device);
23970 pipe.AddShader(&vs);
23971 pipe.AddShader(&fs);
23972 pipe.AddColorAttachment();
23973 // Set polygonMode to a good value
23974 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
23975 pipe.SetRasterization(&rs_ci);
23976 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
23977 }
23978 m_errorMonitor->VerifyNotFound();
23979
23980 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
23981}
23982
Dave Houlton1150cf52017-04-27 14:38:11 -060023983TEST_F(VkPositiveLayerTest, LongSemaphoreChain) {
Chris Forbes94196952017-04-06 16:30:59 -070023984 m_errorMonitor->ExpectSuccess();
23985
23986 ASSERT_NO_FATAL_FAILURE(Init());
23987 VkResult err;
23988
23989 std::vector<VkSemaphore> semaphores;
23990
23991 const int chainLength = 32768;
23992 VkPipelineStageFlags flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
23993
23994 for (int i = 0; i < chainLength; i++) {
Dave Houlton1150cf52017-04-27 14:38:11 -060023995 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070023996 VkSemaphore semaphore;
23997 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &semaphore);
23998 ASSERT_VK_SUCCESS(err);
23999
24000 semaphores.push_back(semaphore);
24001
Chris Forbesfc50aaa2017-05-01 10:20:17 -070024002 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO,
24003 nullptr,
24004 semaphores.size() > 1 ? 1u : 0u,
24005 semaphores.size() > 1 ? &semaphores[semaphores.size() - 2] : nullptr,
24006 &flags,
24007 0,
24008 nullptr,
24009 1,
24010 &semaphores[semaphores.size() - 1]};
Chris Forbes94196952017-04-06 16:30:59 -070024011 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
24012 ASSERT_VK_SUCCESS(err);
24013 }
24014
Dave Houlton1150cf52017-04-27 14:38:11 -060024015 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024016 VkFence fence;
24017 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24018 ASSERT_VK_SUCCESS(err);
Dave Houlton1150cf52017-04-27 14:38:11 -060024019 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &semaphores.back(), &flags, 0, nullptr, 0, nullptr};
Chris Forbes94196952017-04-06 16:30:59 -070024020 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24021 ASSERT_VK_SUCCESS(err);
24022
24023 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
24024
Dave Houlton1150cf52017-04-27 14:38:11 -060024025 for (auto semaphore : semaphores) vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Chris Forbes94196952017-04-06 16:30:59 -070024026
24027 vkDestroyFence(m_device->device(), fence, nullptr);
24028
24029 m_errorMonitor->VerifyNotFound();
24030}
24031
Mike Stroyanca855662017-05-02 11:06:27 -060024032extern "C" void *ReleaseNullFence(void *arg) {
24033 struct thread_data_struct *data = (struct thread_data_struct *)arg;
24034
24035 for (int i = 0; i < 40000; i++) {
24036 vkDestroyFence(data->device, VK_NULL_HANDLE, NULL);
24037 if (data->bailout) {
24038 break;
24039 }
24040 }
24041 return NULL;
24042}
24043
24044TEST_F(VkPositiveLayerTest, ThreadNullFenceCollision) {
24045 test_platform_thread thread;
24046
24047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
24048
24049 ASSERT_NO_FATAL_FAILURE(Init());
24050
24051 struct thread_data_struct data;
24052 data.device = m_device->device();
24053 data.bailout = false;
24054 m_errorMonitor->SetBailout(&data.bailout);
24055
24056 // Call vkDestroyFence of VK_NULL_HANDLE repeatedly using multiple threads.
24057 // There should be no validation error from collision of that non-object.
24058 test_platform_thread_create(&thread, ReleaseNullFence, (void *)&data);
24059 for (int i = 0; i < 40000; i++) {
24060 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
24061 }
24062 test_platform_thread_join(thread, NULL);
24063
24064 m_errorMonitor->SetBailout(NULL);
24065
24066 m_errorMonitor->VerifyNotFound();
24067}
24068
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024069#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024070TEST_F(VkPositiveLayerTest, LongFenceChain)
24071{
24072 m_errorMonitor->ExpectSuccess();
24073
Tony Barbour1fa09702017-03-16 12:09:08 -060024074 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024075 VkResult err;
24076
24077 std::vector<VkFence> fences;
24078
24079 const int chainLength = 32768;
24080
24081 for (int i = 0; i < chainLength; i++) {
24082 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
24083 VkFence fence;
24084 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24085 ASSERT_VK_SUCCESS(err);
24086
24087 fences.push_back(fence);
24088
24089 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
24090 0, nullptr, 0, nullptr };
24091 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24092 ASSERT_VK_SUCCESS(err);
24093
24094 }
24095
24096 // BOOM, stack overflow.
24097 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
24098
24099 for (auto fence : fences)
24100 vkDestroyFence(m_device->device(), fence, nullptr);
24101
24102 m_errorMonitor->VerifyNotFound();
24103}
24104#endif
24105
Cody Northrop1242dfd2016-07-13 17:24:59 -060024106#if defined(ANDROID) && defined(VALIDATION_APK)
Cody Northropb94529f2017-04-05 13:05:51 -060024107const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060024108static bool initialized = false;
24109static bool active = false;
24110
24111// Convert Intents to argv
24112// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024113std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024114 std::vector<std::string> args;
24115 JavaVM &vm = *app.activity->vm;
24116 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024117 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024118
24119 JNIEnv &env = *p_env;
24120 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024121 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024122 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024123 jmethodID get_string_extra_method =
24124 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024125 jvalue get_string_extra_args;
24126 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024127 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060024128
24129 std::string args_str;
24130 if (extra_str) {
24131 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
24132 args_str = extra_utf;
24133 env.ReleaseStringUTFChars(extra_str, extra_utf);
24134 env.DeleteLocalRef(extra_str);
24135 }
24136
24137 env.DeleteLocalRef(get_string_extra_args.l);
24138 env.DeleteLocalRef(intent);
24139 vm.DetachCurrentThread();
24140
24141 // split args_str
24142 std::stringstream ss(args_str);
24143 std::string arg;
24144 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024145 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024146 }
24147
24148 return args;
24149}
24150
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024151void addFullTestCommentIfPresent(const ::testing::TestInfo &test_info, std::string &error_message) {
24152 const char *const type_param = test_info.type_param();
24153 const char *const value_param = test_info.value_param();
Cody Northropb94529f2017-04-05 13:05:51 -060024154
24155 if (type_param != NULL || value_param != NULL) {
24156 error_message.append(", where ");
24157 if (type_param != NULL) {
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024158 error_message.append("TypeParam = ").append(type_param);
24159 if (value_param != NULL) error_message.append(" and ");
Cody Northropb94529f2017-04-05 13:05:51 -060024160 }
24161 if (value_param != NULL) {
24162 error_message.append("GetParam() = ").append(value_param);
24163 }
24164 }
24165}
24166
24167// Inspired by https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md
24168class LogcatPrinter : public ::testing::EmptyTestEventListener {
24169 // Called before a test starts.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024170 virtual void OnTestStart(const ::testing::TestInfo &test_info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024171 __android_log_print(ANDROID_LOG_INFO, appTag, "[ RUN ] %s.%s", test_info.test_case_name(), test_info.name());
24172 }
24173
24174 // Called after a failed assertion or a SUCCEED() invocation.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024175 virtual void OnTestPartResult(const ::testing::TestPartResult &result) {
Cody Northropb94529f2017-04-05 13:05:51 -060024176 // If the test part succeeded, we don't need to do anything.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024177 if (result.type() == ::testing::TestPartResult::kSuccess) return;
Cody Northropb94529f2017-04-05 13:05:51 -060024178
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024179 __android_log_print(ANDROID_LOG_INFO, appTag, "%s in %s:%d %s", result.failed() ? "*** Failure" : "Success",
24180 result.file_name(), result.line_number(), result.summary());
Cody Northropb94529f2017-04-05 13:05:51 -060024181 }
24182
24183 // Called after a test ends.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024184 virtual void OnTestEnd(const ::testing::TestInfo &info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024185 std::string result;
24186 if (info.result()->Passed()) {
24187 result.append("[ OK ]");
24188 } else {
24189 result.append("[ FAILED ]");
24190 }
24191 result.append(info.test_case_name()).append(".").append(info.name());
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024192 if (info.result()->Failed()) addFullTestCommentIfPresent(info, result);
Cody Northropb94529f2017-04-05 13:05:51 -060024193
24194 if (::testing::GTEST_FLAG(print_time)) {
24195 std::ostringstream os;
24196 os << info.result()->elapsed_time();
24197 result.append(" (").append(os.str()).append(" ms)");
24198 }
24199
24200 __android_log_print(ANDROID_LOG_INFO, appTag, "%s", result.c_str());
24201 };
24202};
24203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024204static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024205
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024206static void processCommand(struct android_app *app, int32_t cmd) {
24207 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024208 case APP_CMD_INIT_WINDOW: {
24209 if (app->window) {
24210 initialized = true;
24211 }
24212 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024213 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024214 case APP_CMD_GAINED_FOCUS: {
24215 active = true;
24216 break;
24217 }
24218 case APP_CMD_LOST_FOCUS: {
24219 active = false;
24220 break;
24221 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024222 }
24223}
24224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024225void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024226 app_dummy();
24227
Cody Northrop1242dfd2016-07-13 17:24:59 -060024228 int vulkanSupport = InitVulkan();
24229 if (vulkanSupport == 0) {
24230 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
24231 return;
24232 }
24233
24234 app->onAppCmd = processCommand;
24235 app->onInputEvent = processInput;
24236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024237 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024238 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024239 struct android_poll_source *source;
24240 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024241 if (source) {
24242 source->process(app, source);
24243 }
24244
24245 if (app->destroyRequested != 0) {
24246 VkTestFramework::Finish();
24247 return;
24248 }
24249 }
24250
24251 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024252 // Use the following key to send arguments to gtest, i.e.
24253 // --es args "--gtest_filter=-VkLayerTest.foo"
24254 const char key[] = "args";
24255 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024256
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024257 std::string filter = "";
24258 if (args.size() > 0) {
24259 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
24260 filter += args[0];
24261 } else {
24262 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
24263 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024265 int argc = 2;
24266 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
24267 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024269 // Route output to files until we can override the gtest output
24270 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
24271 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024273 ::testing::InitGoogleTest(&argc, argv);
Cody Northropb94529f2017-04-05 13:05:51 -060024274
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024275 ::testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
Cody Northropb94529f2017-04-05 13:05:51 -060024276 listeners.Append(new LogcatPrinter);
24277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024278 VkTestFramework::InitArgs(&argc, argv);
24279 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024280
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024281 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024282
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024283 if (result != 0) {
24284 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
24285 } else {
24286 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
24287 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024288
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024289 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024290
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024291 fclose(stdout);
24292 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024294 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024295 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024296 }
24297 }
24298}
24299#endif
24300
Tony Barbour300a6082015-04-07 13:44:53 -060024301int main(int argc, char **argv) {
24302 int result;
24303
Cody Northrop8e54a402016-03-08 22:25:52 -070024304#ifdef ANDROID
24305 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024306 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070024307#endif
24308
Tony Barbour300a6082015-04-07 13:44:53 -060024309 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060024310 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060024311
24312 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
24313
24314 result = RUN_ALL_TESTS();
24315
Tony Barbour6918cd52015-04-09 12:58:51 -060024316 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060024317 return result;
24318}