blob: 1d7a7f8e2aff040a7059220a6e034f90c33114ed [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Dave Houlton3c9fca72017-03-27 17:25:54 -060038#include "vk_format_utils.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060039#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060040#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070041
42#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060043#include <limits.h>
44#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060045
Mark Lobodzinski3780e142015-05-14 15:08:13 -050046#define GLM_FORCE_RADIANS
47#include "glm/glm.hpp"
48#include <glm/gtc/matrix_transform.hpp>
49
50//--------------------------------------------------------------------------------------
51// Mesh and VertexFormat Data
52//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070053struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070054 float posX, posY, posZ, posW; // Position data
55 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050056};
57
Karl Schultz6addd812016-02-02 17:17:23 -070058#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050059
60typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070061 BsoFailNone = 0x00000000,
62 BsoFailLineWidth = 0x00000001,
63 BsoFailDepthBias = 0x00000002,
64 BsoFailViewport = 0x00000004,
65 BsoFailScissor = 0x00000008,
66 BsoFailBlend = 0x00000010,
67 BsoFailDepthBounds = 0x00000020,
68 BsoFailStencilReadMask = 0x00000040,
69 BsoFailStencilWriteMask = 0x00000080,
70 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060071 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060072 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050073} BsoFailSelect;
74
75struct vktriangle_vs_uniform {
76 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070077 float mvp[4][4];
78 float position[3][4];
79 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050080};
81
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070082static const char bindStateVertShaderText[] =
83 "#version 450\n"
84 "vec2 vertices[3];\n"
85 "out gl_PerVertex {\n"
86 " vec4 gl_Position;\n"
87 "};\n"
88 "void main() {\n"
89 " vertices[0] = vec2(-1.0, -1.0);\n"
90 " vertices[1] = vec2( 1.0, -1.0);\n"
91 " vertices[2] = vec2( 0.0, 1.0);\n"
92 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
93 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050094
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070095static const char bindStateFragShaderText[] =
96 "#version 450\n"
97 "\n"
98 "layout(location = 0) out vec4 uFragColor;\n"
99 "void main(){\n"
100 " uFragColor = vec4(0,1,0,1);\n"
101 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500102
Dave Houlton1d2022c2017-03-29 11:43:58 -0600103// Format search helper
104VkFormat FindSupportedDepthStencilFormat(VkPhysicalDevice phy) {
Dave Houltond7472002017-03-30 09:48:28 -0600105 VkFormat ds_formats[] = {VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT};
Dave Houlton1d2022c2017-03-29 11:43:58 -0600106 for (uint32_t i = 0; i < sizeof(ds_formats); i++) {
107 VkFormatProperties format_props;
108 vkGetPhysicalDeviceFormatProperties(phy, ds_formats[i], &format_props);
109
110 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
111 return ds_formats[i];
112 }
113 }
114 return (VkFormat)0;
115}
116
117// Validation report callback prototype
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600118static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
119 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
120 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600121
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600122// ErrorMonitor Usage:
123//
Dave Houltonfbf52152017-01-06 12:55:29 -0700124// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600125// encountered log messages, or a validation error enum identifying
126// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
127// will match all log messages. logMsg will return true for skipCall
128// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129//
Dave Houltonfbf52152017-01-06 12:55:29 -0700130// Call VerifyFound to determine if all desired failure messages
131// were encountered. Call VerifyNotFound to determine if any unexpected
132// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600133class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700134 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700135 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700136 test_platform_thread_create_mutex(&mutex_);
137 test_platform_thread_lock_mutex(&mutex_);
138 Reset();
139 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600140 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600141
Dave Houltonfbf52152017-01-06 12:55:29 -0700142 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600143
Dave Houltonfbf52152017-01-06 12:55:29 -0700144 // Set monitor to pristine state
145 void Reset() {
146 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
147 bailout_ = NULL;
148 message_found_ = VK_FALSE;
149 failure_message_strings_.clear();
150 desired_message_strings_.clear();
151 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700152 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700153 other_messages_.clear();
154 message_outstanding_count_ = 0;
155 }
156
157 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700158 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700159 test_platform_thread_lock_mutex(&mutex_);
160 desired_message_strings_.insert(msgString);
161 message_flags_ |= msgFlags;
162 message_outstanding_count_++;
163 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600164 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600165
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700166 // ErrorMonitor will look for an error message containing the specified string(s)
167 template <typename Iter>
168 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
169 for (; iter != end; ++iter) {
170 SetDesiredFailureMsg(msgFlags, *iter);
171 }
172 }
173
Dave Houltonfbf52152017-01-06 12:55:29 -0700174 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700175 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700176 test_platform_thread_lock_mutex(&mutex_);
177 desired_message_ids_.insert(msg_id);
178 message_flags_ |= msgFlags;
179 message_outstanding_count_++;
180 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600181 }
182
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700183 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
184 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
185 // function and its definition.
186 void SetUnexpectedError(const char *const msg) {
187 test_platform_thread_lock_mutex(&mutex_);
188
189 ignore_message_strings_.emplace_back(msg);
190
191 test_platform_thread_unlock_mutex(&mutex_);
192 }
193
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700194 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600195 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700196 test_platform_thread_lock_mutex(&mutex_);
197 if (bailout_ != NULL) {
198 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600199 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600200 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600201 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600202
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700203 if (!IgnoreMessage(errorString)) {
204 for (auto desired_msg : desired_message_strings_) {
205 if (desired_msg.length() == 0) {
206 // An empty desired_msg string "" indicates a positive test - not expecting an error.
207 // Return true to avoid calling layers/driver with this error.
208 // And don't erase the "" string, so it remains if another error is found.
209 result = VK_TRUE;
210 found_expected = true;
211 message_found_ = VK_TRUE;
212 failure_message_strings_.insert(errorString);
213 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600214 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700215 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700216 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700217 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700218 result = VK_TRUE;
219 // We only want one match for each expected error so remove from set here
220 // Since we're about the break the loop it's ok to remove from set we're iterating over
221 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600222 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600223 }
224 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700225 for (auto desired_id : desired_message_ids_) {
226 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
227 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
228 // Return true to avoid calling layers/driver with this error.
229 result = VK_TRUE;
230 } else if (desired_id == message_code) {
231 // Double-check that the string matches the error enum
232 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
233 found_expected = true;
234 message_outstanding_count_--;
235 result = VK_TRUE;
236 message_found_ = VK_TRUE;
237 desired_message_ids_.erase(desired_id);
238 break;
239 } else {
240 // Treat this message as a regular unexpected error, but print a warning jic
241 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
242 errorString.c_str(), desired_id, validation_error_map[desired_id]);
243 }
244 }
245 }
246
247 if (!found_expected) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600248 printf("Unexpected: %s\n", msgString);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700249 other_messages_.push_back(errorString);
250 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600251 }
252
Dave Houltonfbf52152017-01-06 12:55:29 -0700253 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600254 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600255 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600256
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600257 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
258
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700259 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600260
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700261 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600262
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700263 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700264
265 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600266
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600267 void DumpFailureMsgs(void) const {
268 vector<string> otherMsgs = GetOtherFailureMsgs();
269 if (otherMsgs.size()) {
270 cout << "Other error messages logged for this test were:" << endl;
271 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
272 cout << " " << *iter << endl;
Tony Barbour59b42282016-11-03 13:31:28 -0600273 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600274 }
275 }
276
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600277 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200278
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600279 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700280 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600281 // Match ANY message matching specified type
282 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700283 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200284 }
285
286 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600287 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 if (!AllDesiredMsgsFound()) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600289 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700290 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700291 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600292 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700293 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700294 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600295 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200296 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700297 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200298 }
299
300 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600301 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700302 if (AnyDesiredMsgFound()) {
Jeremy Hayes2a54c012017-03-16 13:32:05 -0600303 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700304 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700305 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600306 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200307 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700308 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200309 }
310
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700311 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
313 // function and its definition.
314 bool IgnoreMessage(std::string const &msg) const {
315 if (ignore_message_strings_.empty()) {
316 return false;
317 }
318
319 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
320 return msg.find(str) != std::string::npos;
321 }) != ignore_message_strings_.end();
322 }
323
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700324 VkFlags message_flags_;
325 std::unordered_set<uint32_t> desired_message_ids_;
326 std::unordered_set<string> desired_message_strings_;
327 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700328 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700329 vector<string> other_messages_;
330 test_platform_thread_mutex mutex_;
331 bool *bailout_;
332 VkBool32 message_found_;
333 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600334};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500335
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600336static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
337 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
338 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600339 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
340 if (msgFlags & errMonitor->GetMessageFlags()) {
Dave Houltonc85c4a82017-04-25 15:56:45 -0600341#ifdef _DEBUG
342 char embedded_code_string[2048];
343 snprintf(embedded_code_string, 2048, "%s [%05d]", pMsg, msgCode);
344 return errMonitor->CheckForDesiredMsg(msgCode, embedded_code_string);
345#else
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600346 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Dave Houltonc85c4a82017-04-25 15:56:45 -0600347#endif
Tony Barbour0b4d9562015-04-09 10:48:04 -0600348 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600349 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600350}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500351
Karl Schultz6addd812016-02-02 17:17:23 -0700352class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700353 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600354 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
355 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700356 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600357 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
358 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700359 }
Tony Barbour300a6082015-04-07 13:44:53 -0600360
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600361 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
362 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700363 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600364 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700365 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600366 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700367 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600368 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
369 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
370 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700371 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
372 }
373 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
374 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
375 }
Tony Barbour1fa09702017-03-16 12:09:08 -0600376 void Init(VkPhysicalDeviceFeatures *features = nullptr, const VkCommandPoolCreateFlags flags = 0) {
377 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
378 InitState(features, flags);
379 }
380
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700381 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700382 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600383 bool m_enableWSI;
Tony Barbour1fa09702017-03-16 12:09:08 -0600384 std::vector<const char *> instance_layer_names;
385 std::vector<const char *> instance_extension_names;
386 std::vector<const char *> device_extension_names;
Tony Barbour300a6082015-04-07 13:44:53 -0600387
388 virtual void SetUp() {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700389 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600390 /*
391 * Since CreateDbgMsgCallback is an instance level extension call
392 * any extension / layer that utilizes that feature also needs
393 * to be enabled at create instance time.
394 */
Karl Schultz6addd812016-02-02 17:17:23 -0700395 // Use Threading layer first to protect others from
396 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700397 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600398 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800399 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700400 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600401 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700402 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600403
Ian Elliott2c1daf52016-05-12 09:41:46 -0600404 if (m_enableWSI) {
405 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
406 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
407#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
408#if defined(VK_USE_PLATFORM_ANDROID_KHR)
409 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700410#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600411#if defined(VK_USE_PLATFORM_MIR_KHR)
412 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700413#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600414#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
415 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700416#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600417#if defined(VK_USE_PLATFORM_WIN32_KHR)
418 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700419#endif // VK_USE_PLATFORM_WIN32_KHR
420#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600421#if defined(VK_USE_PLATFORM_XCB_KHR)
422 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
423#elif defined(VK_USE_PLATFORM_XLIB_KHR)
424 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700425#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600426 }
427
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600428 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600429 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800430 this->app_info.pApplicationName = "layer_tests";
431 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600432 this->app_info.pEngineName = "unittest";
433 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600434 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600435
Tony Barbour15524c32015-04-29 17:34:29 -0600436 m_errorMonitor = new ErrorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600437 }
438
439 virtual void TearDown() {
440 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600441 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600442 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600443 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600444
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600445 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600446};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600448void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500449 // Create identity matrix
450 int i;
451 struct vktriangle_vs_uniform data;
452
453 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700454 glm::mat4 View = glm::mat4(1.0f);
455 glm::mat4 Model = glm::mat4(1.0f);
456 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700458 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500459
460 memcpy(&data.mvp, &MVP[0][0], matrixSize);
461
Karl Schultz6addd812016-02-02 17:17:23 -0700462 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600463 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500464 };
465
Karl Schultz6addd812016-02-02 17:17:23 -0700466 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 data.position[i][0] = tri_data[i].posX;
468 data.position[i][1] = tri_data[i].posY;
469 data.position[i][2] = tri_data[i].posZ;
470 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700471 data.color[i][0] = tri_data[i].r;
472 data.color[i][1] = tri_data[i].g;
473 data.color[i][2] = tri_data[i].b;
474 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500475 }
476
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500477 ASSERT_NO_FATAL_FAILURE(InitViewport());
478
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200479 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
480 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500481
Karl Schultz6addd812016-02-02 17:17:23 -0700482 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600483 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
485 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800486 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500487 pipelineobj.AddShader(&vs);
488 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600489 if (failMask & BsoFailLineWidth) {
490 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600491 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600492 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600493 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
494 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600495 }
496 if (failMask & BsoFailDepthBias) {
497 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600498 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600499 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600500 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600501 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600502 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600503 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700504 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700505 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600506 if (failMask & BsoFailViewport) {
507 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
508 }
509 if (failMask & BsoFailScissor) {
510 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
511 }
512 if (failMask & BsoFailBlend) {
513 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600514 VkPipelineColorBlendAttachmentState att_state = {};
515 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
516 att_state.blendEnable = VK_TRUE;
517 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600518 }
519 if (failMask & BsoFailDepthBounds) {
520 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
521 }
522 if (failMask & BsoFailStencilReadMask) {
523 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
524 }
525 if (failMask & BsoFailStencilWriteMask) {
526 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
527 }
528 if (failMask & BsoFailStencilReference) {
529 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
530 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500531
532 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600533 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534
535 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700536 m_commandBuffer->BeginCommandBuffer();
537 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538
Tony Barbourfe3351b2015-07-28 10:17:20 -0600539 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500540
541 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600542 if (failMask & BsoFailIndexBuffer) {
543 // Use DrawIndexed w/o an index buffer bound
544 DrawIndexed(3, 1, 0, 0, 0);
545 } else {
546 Draw(3, 1, 0, 0);
547 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500548
Mark Muellerd4914412016-06-13 17:52:06 -0600549 if (failMask & BsoFailCmdClearAttachments) {
550 VkClearAttachment color_attachment = {};
551 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700552 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600553 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
554
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600555 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600556 }
557
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500558 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700559 m_commandBuffer->EndRenderPass();
560 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600561 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500562}
563
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600564void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
565 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500566 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600567 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500568 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600569 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500570 }
571
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800572 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700573 // Make sure depthWriteEnable is set so that Depth fail test will work
574 // correctly
575 // Make sure stencilTestEnable is set so that Stencil fail test will work
576 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600577 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800578 stencil.failOp = VK_STENCIL_OP_KEEP;
579 stencil.passOp = VK_STENCIL_OP_KEEP;
580 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
581 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600582
583 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
584 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600585 ds_ci.pNext = NULL;
586 ds_ci.depthTestEnable = VK_FALSE;
587 ds_ci.depthWriteEnable = VK_TRUE;
588 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
589 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600590 if (failMask & BsoFailDepthBounds) {
591 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600592 ds_ci.maxDepthBounds = 0.0f;
593 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600594 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600595 ds_ci.stencilTestEnable = VK_TRUE;
596 ds_ci.front = stencil;
597 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600598
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600599 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600600 pipelineobj.SetViewport(m_viewports);
601 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800602 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600603 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600604 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800605 commandBuffer->BindPipeline(pipelineobj);
606 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500607}
608
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600609class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700610 public:
611 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600612};
613
Ian Elliott2c1daf52016-05-12 09:41:46 -0600614class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700615 public:
616 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600617 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600618};
619
Mark Muellerdfe37552016-07-07 14:47:42 -0600620class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700621 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 enum eTestEnFlags {
623 eDoubleDelete,
624 eInvalidDeviceOffset,
625 eInvalidMemoryOffset,
626 eBindNullBuffer,
627 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600628 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600629 };
630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
634 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600635 return true;
636 }
637 VkDeviceSize offset_limit = 0;
638 if (eInvalidMemoryOffset == aTestFlag) {
639 VkBuffer vulkanBuffer;
640 VkBufferCreateInfo buffer_create_info = {};
641 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
642 buffer_create_info.size = 32;
643 buffer_create_info.usage = aBufferUsage;
644
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600645 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600646 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600647
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600648 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600649 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
650 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
652 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600654 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600655 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600656 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600657 }
658 if (eOffsetAlignment < offset_limit) {
659 return true;
660 }
661 return false;
662 }
663
664 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600665 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
666 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600667 if (eBindNullBuffer == aTestFlag) {
668 VulkanMemory = 0;
669 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
670 } else {
671 VkBufferCreateInfo buffer_create_info = {};
672 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
673 buffer_create_info.size = 32;
674 buffer_create_info.usage = aBufferUsage;
675
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600676 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600677
678 CreateCurrent = true;
679
680 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600681 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600682
683 VkMemoryAllocateInfo memory_allocate_info = {};
684 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Stratton77a0d592017-02-17 13:14:13 -0800685 memory_allocate_info.allocationSize = memory_requirements.size + eOffsetAlignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600686 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
687 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600688 if (!pass) {
689 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
690 return;
691 }
692
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600693 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600694 AllocateCurrent = true;
695 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600696 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
697 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600698 BoundCurrent = true;
699
700 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
701 }
702 }
703
704 ~VkBufferTest() {
705 if (CreateCurrent) {
706 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
707 }
708 if (AllocateCurrent) {
709 if (InvalidDeleteEn) {
710 union {
711 VkDeviceMemory device_memory;
712 unsigned long long index_access;
713 } bad_index;
714
715 bad_index.device_memory = VulkanMemory;
716 bad_index.index_access++;
717
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 }
720 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
721 }
722 }
723
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600724 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600725
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600726 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600727
728 void TestDoubleDestroy() {
729 // Destroy the buffer but leave the flag set, which will cause
730 // the buffer to be destroyed again in the destructor.
731 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
732 }
733
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700734 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600735 bool AllocateCurrent;
736 bool BoundCurrent;
737 bool CreateCurrent;
738 bool InvalidDeleteEn;
739
740 VkBuffer VulkanBuffer;
741 VkDevice VulkanDevice;
742 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600743};
744
745class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700746 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600748 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700749 : BoundCurrent(false),
750 AttributeCount(aAttributeCount),
751 BindingCount(aBindingCount),
752 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600753 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600754 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
755 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700756 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600757
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
759 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600760
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600761 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
762 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
763 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
764 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
765 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600766
767 unsigned i = 0;
768 do {
769 VertexInputAttributeDescription[i].binding = BindId;
770 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
772 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600773 i++;
774 } while (AttributeCount < i);
775
776 i = 0;
777 do {
778 VertexInputBindingDescription[i].binding = BindId;
779 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600780 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600781 i++;
782 } while (BindingCount < i);
783 }
784
785 ~VkVerticesObj() {
786 if (VertexInputAttributeDescription) {
787 delete[] VertexInputAttributeDescription;
788 }
789 if (VertexInputBindingDescription) {
790 delete[] VertexInputBindingDescription;
791 }
792 }
793
794 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600795 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
796 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600797 return true;
798 }
799
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600800 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600801 VkDeviceSize *offsetList;
802 unsigned offsetCount;
803
804 if (aOffsetCount) {
805 offsetList = aOffsetList;
806 offsetCount = aOffsetCount;
807 } else {
808 offsetList = new VkDeviceSize[1]();
809 offsetCount = 1;
810 }
811
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600812 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600813 BoundCurrent = true;
814
815 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600817 }
818 }
819
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700820 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600821 static uint32_t BindIdGenerator;
822
823 bool BoundCurrent;
824 unsigned AttributeCount;
825 unsigned BindingCount;
826 uint32_t BindId;
827
828 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
829 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
830 VkVertexInputBindingDescription *VertexInputBindingDescription;
831 VkConstantBufferObj VulkanMemoryBuffer;
832};
833
834uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500835// ********************************************************************************************************************
836// ********************************************************************************************************************
837// ********************************************************************************************************************
838// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600839TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700840 TEST_DESCRIPTION(
841 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
842 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600843
Tony Barbour1fa09702017-03-16 12:09:08 -0600844 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600847 // Specify NULL for a pointer to a handle
848 // Expected to trigger an error with
849 // parameter_validation::validate_required_pointer
850 vkGetPhysicalDeviceFeatures(gpu(), NULL);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
854 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600855 // Specify NULL for pointer to array count
856 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600857 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600858 m_errorMonitor->VerifyFound();
859
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600861 // Specify 0 for a required array count
862 // Expected to trigger an error with parameter_validation::validate_array
863 VkViewport view_port = {};
864 m_commandBuffer->SetViewport(0, 0, &view_port);
865 m_errorMonitor->VerifyFound();
866
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600868 // Specify NULL for a required array
869 // Expected to trigger an error with parameter_validation::validate_array
870 m_commandBuffer->SetViewport(0, 1, NULL);
871 m_errorMonitor->VerifyFound();
872
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600874 // Specify VK_NULL_HANDLE for a required handle
875 // Expected to trigger an error with
876 // parameter_validation::validate_required_handle
877 vkUnmapMemory(device(), VK_NULL_HANDLE);
878 m_errorMonitor->VerifyFound();
879
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
881 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600882 // Specify VK_NULL_HANDLE for a required handle array entry
883 // Expected to trigger an error with
884 // parameter_validation::validate_required_handle_array
885 VkFence fence = VK_NULL_HANDLE;
886 vkResetFences(device(), 1, &fence);
887 m_errorMonitor->VerifyFound();
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600890 // Specify NULL for a required struct pointer
891 // Expected to trigger an error with
892 // parameter_validation::validate_struct_type
893 VkDeviceMemory memory = VK_NULL_HANDLE;
894 vkAllocateMemory(device(), NULL, NULL, &memory);
895 m_errorMonitor->VerifyFound();
896
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600898 // Specify 0 for a required VkFlags parameter
899 // Expected to trigger an error with parameter_validation::validate_flags
900 m_commandBuffer->SetStencilReference(0, 0);
901 m_errorMonitor->VerifyFound();
902
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600904 // Specify 0 for a required VkFlags array entry
905 // Expected to trigger an error with
906 // parameter_validation::validate_flags_array
907 VkSemaphore semaphore = VK_NULL_HANDLE;
908 VkPipelineStageFlags stageFlags = 0;
909 VkSubmitInfo submitInfo = {};
910 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
911 submitInfo.waitSemaphoreCount = 1;
912 submitInfo.pWaitSemaphores = &semaphore;
913 submitInfo.pWaitDstStageMask = &stageFlags;
914 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
915 m_errorMonitor->VerifyFound();
916}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600917
Dustin Gravesfce74c02016-05-10 11:42:58 -0600918TEST_F(VkLayerTest, ReservedParameter) {
919 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
920
Tony Barbour1fa09702017-03-16 12:09:08 -0600921 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesfce74c02016-05-10 11:42:58 -0600922
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600924 // Specify 0 for a reserved VkFlags parameter
925 // Expected to trigger an error with
926 // parameter_validation::validate_reserved_flags
927 VkEvent event_handle = VK_NULL_HANDLE;
928 VkEventCreateInfo event_info = {};
929 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
930 event_info.flags = 1;
931 vkCreateEvent(device(), &event_info, NULL, &event_handle);
932 m_errorMonitor->VerifyFound();
933}
934
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600935TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700936 TEST_DESCRIPTION(
937 "Specify an invalid VkStructureType for a Vulkan "
938 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600939
Tony Barbour1fa09702017-03-16 12:09:08 -0600940 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600941
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600943 // Zero struct memory, effectively setting sType to
944 // VK_STRUCTURE_TYPE_APPLICATION_INFO
945 // Expected to trigger an error with
946 // parameter_validation::validate_struct_type
947 VkMemoryAllocateInfo alloc_info = {};
948 VkDeviceMemory memory = VK_NULL_HANDLE;
949 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
950 m_errorMonitor->VerifyFound();
951
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600953 // Zero struct memory, effectively setting sType to
954 // VK_STRUCTURE_TYPE_APPLICATION_INFO
955 // Expected to trigger an error with
956 // parameter_validation::validate_struct_type_array
957 VkSubmitInfo submit_info = {};
958 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
959 m_errorMonitor->VerifyFound();
960}
961
962TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600963 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600964
Tony Barbour1fa09702017-03-16 12:09:08 -0600965 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600966
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600968 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600969 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600970 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600971 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600972 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600973 // Zero-initialization will provide the correct sType
974 VkApplicationInfo app_info = {};
975 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
976 event_alloc_info.pNext = &app_info;
977 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
978 m_errorMonitor->VerifyFound();
979
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
981 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600982 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
983 // a function that has allowed pNext structure types and specify
984 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600985 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600986 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600987 VkMemoryAllocateInfo memory_alloc_info = {};
988 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
989 memory_alloc_info.pNext = &app_info;
990 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600991 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600992}
Dustin Graves5d33d532016-05-09 16:21:12 -0600993
994TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600995 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600996
Tony Barbour1fa09702017-03-16 12:09:08 -0600997 ASSERT_NO_FATAL_FAILURE(Init());
Dustin Graves5d33d532016-05-09 16:21:12 -0600998
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1000 "does not fall within the begin..end "
1001 "range of the core VkFormat "
1002 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -06001003 // Specify an invalid VkFormat value
1004 // Expected to trigger an error with
1005 // parameter_validation::validate_ranged_enum
1006 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001007 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001008 m_errorMonitor->VerifyFound();
1009
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -06001011 // Specify an invalid VkFlags bitmask value
1012 // Expected to trigger an error with parameter_validation::validate_flags
1013 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001014 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1015 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001016 m_errorMonitor->VerifyFound();
1017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -06001019 // Specify an invalid VkFlags array entry
1020 // Expected to trigger an error with
1021 // parameter_validation::validate_flags_array
1022 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001023 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001024 VkSubmitInfo submit_info = {};
1025 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1026 submit_info.waitSemaphoreCount = 1;
1027 submit_info.pWaitSemaphores = &semaphore;
1028 submit_info.pWaitDstStageMask = &stage_flags;
1029 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1030 m_errorMonitor->VerifyFound();
1031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001033 // Specify an invalid VkBool32 value
1034 // Expected to trigger a warning with
1035 // parameter_validation::validate_bool32
1036 VkSampler sampler = VK_NULL_HANDLE;
1037 VkSamplerCreateInfo sampler_info = {};
1038 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1039 sampler_info.pNext = NULL;
1040 sampler_info.magFilter = VK_FILTER_NEAREST;
1041 sampler_info.minFilter = VK_FILTER_NEAREST;
1042 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1043 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1044 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1045 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1046 sampler_info.mipLodBias = 1.0;
1047 sampler_info.maxAnisotropy = 1;
1048 sampler_info.compareEnable = VK_FALSE;
1049 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1050 sampler_info.minLod = 1.0;
1051 sampler_info.maxLod = 1.0;
1052 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1053 sampler_info.unnormalizedCoordinates = VK_FALSE;
1054 // Not VK_TRUE or VK_FALSE
1055 sampler_info.anisotropyEnable = 3;
1056 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1057 m_errorMonitor->VerifyFound();
1058}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001059
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001060TEST_F(VkLayerTest, UpdateBufferAlignment) {
1061 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001062 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001063
Tony Barbour1fa09702017-03-16 12:09:08 -06001064 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065
1066 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1067 vk_testing::Buffer buffer;
1068 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1069
Tony Barbour552f6c02016-12-21 14:34:07 -07001070 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001071 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001073 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1074 m_errorMonitor->VerifyFound();
1075
1076 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001078 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1079 m_errorMonitor->VerifyFound();
1080
1081 // Introduce failure by using dataSize that is < 0
1082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001083 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001084 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1085 m_errorMonitor->VerifyFound();
1086
1087 // Introduce failure by using dataSize that is > 65536
1088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001089 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001090 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1091 m_errorMonitor->VerifyFound();
1092
Tony Barbour552f6c02016-12-21 14:34:07 -07001093 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001094}
1095
1096TEST_F(VkLayerTest, FillBufferAlignment) {
1097 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1098
Tony Barbour1fa09702017-03-16 12:09:08 -06001099 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001100
1101 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1102 vk_testing::Buffer buffer;
1103 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1104
Tony Barbour552f6c02016-12-21 14:34:07 -07001105 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106
1107 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001109 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1110 m_errorMonitor->VerifyFound();
1111
1112 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001114 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1115 m_errorMonitor->VerifyFound();
1116
1117 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001119 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1120 m_errorMonitor->VerifyFound();
1121
Tony Barbour552f6c02016-12-21 14:34:07 -07001122 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001123}
Dustin Graves40f35822016-06-23 11:12:53 -06001124
Cortd889ff92016-07-27 09:51:27 -07001125TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1126 VkResult err;
1127
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001128 TEST_DESCRIPTION(
1129 "Attempt to use a non-solid polygon fill mode in a "
1130 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001131
Tony Barbour1fa09702017-03-16 12:09:08 -06001132 ASSERT_NO_FATAL_FAILURE(Init());
Cortd889ff92016-07-27 09:51:27 -07001133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1134
1135 std::vector<const char *> device_extension_names;
1136 auto features = m_device->phy().features();
1137 // Artificially disable support for non-solid fill modes
Chris Forbes05054022017-05-17 16:29:06 -07001138 features.fillModeNonSolid = VK_FALSE;
Cortd889ff92016-07-27 09:51:27 -07001139 // The sacrificial device object
1140 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1141
1142 VkRenderpassObj render_pass(&test_device);
1143
1144 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1145 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1146 pipeline_layout_ci.setLayoutCount = 0;
1147 pipeline_layout_ci.pSetLayouts = NULL;
1148
1149 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001151 ASSERT_VK_SUCCESS(err);
1152
1153 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1154 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1155 rs_ci.pNext = nullptr;
1156 rs_ci.lineWidth = 1.0f;
Chris Forbes05054022017-05-17 16:29:06 -07001157 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Cortd889ff92016-07-27 09:51:27 -07001158
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001159 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1160 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001161
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001162 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1164 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001165 {
1166 VkPipelineObj pipe(&test_device);
1167 pipe.AddShader(&vs);
1168 pipe.AddShader(&fs);
1169 pipe.AddColorAttachment();
1170 // Introduce failure by setting unsupported polygon mode
1171 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1172 pipe.SetRasterization(&rs_ci);
1173 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1174 }
1175 m_errorMonitor->VerifyFound();
1176
1177 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1179 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001180 {
1181 VkPipelineObj pipe(&test_device);
1182 pipe.AddShader(&vs);
1183 pipe.AddShader(&fs);
1184 pipe.AddColorAttachment();
1185 // Introduce failure by setting unsupported polygon mode
1186 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1187 pipe.SetRasterization(&rs_ci);
1188 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1189 }
1190 m_errorMonitor->VerifyFound();
1191
Cortd889ff92016-07-27 09:51:27 -07001192 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1193}
1194
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001195#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001196TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001197{
1198 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001199 VkFenceCreateInfo fenceInfo = {};
1200 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1201 fenceInfo.pNext = NULL;
1202 fenceInfo.flags = 0;
1203
Mike Weiblencce7ec72016-10-17 19:33:05 -06001204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001205
Tony Barbour1fa09702017-03-16 12:09:08 -06001206 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001207
1208 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1209 vk_testing::Buffer buffer;
1210 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001211
Tony Barbourfe3351b2015-07-28 10:17:20 -06001212 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001213 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001214 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001215
1216 testFence.init(*m_device, fenceInfo);
1217
1218 // Bypass framework since it does the waits automatically
1219 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001220 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001221 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1222 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001223 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001224 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001225 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001226 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001227 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001228 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001229 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001230
1231 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232 ASSERT_VK_SUCCESS( err );
1233
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001234 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001235 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001236
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001237 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001238}
1239
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001240TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001241{
1242 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001243 VkFenceCreateInfo fenceInfo = {};
1244 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1245 fenceInfo.pNext = NULL;
1246 fenceInfo.flags = 0;
1247
Mike Weiblencce7ec72016-10-17 19:33:05 -06001248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001249
Tony Barbour1fa09702017-03-16 12:09:08 -06001250 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251 ASSERT_NO_FATAL_FAILURE(InitViewport());
1252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1253
Tony Barbourfe3351b2015-07-28 10:17:20 -06001254 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001255 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001256 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001257
1258 testFence.init(*m_device, fenceInfo);
1259
1260 // Bypass framework since it does the waits automatically
1261 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001262 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001263 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1264 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001265 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001266 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001267 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001268 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001269 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001270 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001271 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001272
1273 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001274 ASSERT_VK_SUCCESS( err );
1275
Jon Ashburnf19916e2016-01-11 13:12:43 -07001276 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001277 VkCommandBufferBeginInfo info = {};
1278 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1279 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001280 info.renderPass = VK_NULL_HANDLE;
1281 info.subpass = 0;
1282 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001283 info.occlusionQueryEnable = VK_FALSE;
1284 info.queryFlags = 0;
1285 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001286
1287 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001288 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001289
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001290 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001291}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001292#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001293
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001294TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1295 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1296
Tony Barbour1fa09702017-03-16 12:09:08 -06001297 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001298
1299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1300 VkBuffer buffer;
1301 VkBufferCreateInfo buf_info = {};
1302 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1303 buf_info.pNext = NULL;
1304 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1305 buf_info.size = 2048;
1306 buf_info.queueFamilyIndexCount = 0;
1307 buf_info.pQueueFamilyIndices = NULL;
1308 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1309 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1310 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1311 m_errorMonitor->VerifyFound();
1312
1313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1314 VkImage image;
1315 VkImageCreateInfo image_create_info = {};
1316 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1317 image_create_info.pNext = NULL;
1318 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1319 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1320 image_create_info.extent.width = 512;
1321 image_create_info.extent.height = 64;
1322 image_create_info.extent.depth = 1;
1323 image_create_info.mipLevels = 1;
1324 image_create_info.arrayLayers = 1;
1325 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1326 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1327 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1328 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1329 image_create_info.queueFamilyIndexCount = 0;
1330 image_create_info.pQueueFamilyIndices = NULL;
1331 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1332 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1333 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1334 m_errorMonitor->VerifyFound();
1335}
1336
Dave Houlton829c0d82017-01-24 15:09:17 -07001337TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1338 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1339
1340 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001341 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001342 ASSERT_NO_FATAL_FAILURE(
1343 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001344 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001345
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001346 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001347 device_features.sparseResidencyImage2D = VK_FALSE;
1348 device_features.sparseResidencyImage3D = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001349 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001350
1351 VkImage image = VK_NULL_HANDLE;
1352 VkResult result = VK_RESULT_MAX_ENUM;
1353 VkImageCreateInfo image_create_info = {};
1354 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1355 image_create_info.pNext = NULL;
1356 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1357 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1358 image_create_info.extent.width = 512;
1359 image_create_info.extent.height = 1;
1360 image_create_info.extent.depth = 1;
1361 image_create_info.mipLevels = 1;
1362 image_create_info.arrayLayers = 1;
1363 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1364 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1365 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1366 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1367 image_create_info.queueFamilyIndexCount = 0;
1368 image_create_info.pQueueFamilyIndices = NULL;
1369 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1370 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1371
1372 // 1D image w/ sparse residency is an error
1373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1374 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1375 m_errorMonitor->VerifyFound();
1376 if (VK_SUCCESS == result) {
1377 vkDestroyImage(m_device->device(), image, NULL);
1378 image = VK_NULL_HANDLE;
1379 }
1380
1381 // 2D image w/ sparse residency when feature isn't available
1382 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1383 image_create_info.extent.height = 64;
1384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1385 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1386 m_errorMonitor->VerifyFound();
1387 if (VK_SUCCESS == result) {
1388 vkDestroyImage(m_device->device(), image, NULL);
1389 image = VK_NULL_HANDLE;
1390 }
1391
1392 // 3D image w/ sparse residency when feature isn't available
1393 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1394 image_create_info.extent.depth = 8;
1395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1396 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1397 m_errorMonitor->VerifyFound();
1398 if (VK_SUCCESS == result) {
1399 vkDestroyImage(m_device->device(), image, NULL);
1400 image = VK_NULL_HANDLE;
1401 }
1402}
1403
1404TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1405 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1406
1407 // Determine which device feature are available
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001408 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001409 ASSERT_NO_FATAL_FAILURE(
1410 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor));
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001411 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001412
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001413 // These tests require that the device support sparse residency for 2D images
1414 if (VK_TRUE != device_features.sparseResidencyImage2D) {
1415 printf(" Test requires unsupported SparseResidencyImage2D feature. Skipped.\n");
Dave Houlton829c0d82017-01-24 15:09:17 -07001416 return;
1417 }
1418
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001419 // Mask out device features we don't want and initialize device state
Dave Houlton0ba0fdf2017-03-29 12:05:26 -06001420 device_features.sparseResidency2Samples = VK_FALSE;
1421 device_features.sparseResidency4Samples = VK_FALSE;
1422 device_features.sparseResidency8Samples = VK_FALSE;
1423 device_features.sparseResidency16Samples = VK_FALSE;
Dave Houlton8e0fe7a2017-03-30 10:32:10 -06001424 ASSERT_NO_FATAL_FAILURE(InitState(&device_features));
Dave Houlton829c0d82017-01-24 15:09:17 -07001425
1426 VkImage image = VK_NULL_HANDLE;
1427 VkResult result = VK_RESULT_MAX_ENUM;
1428 VkImageCreateInfo image_create_info = {};
1429 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1430 image_create_info.pNext = NULL;
1431 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1432 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1433 image_create_info.extent.width = 64;
1434 image_create_info.extent.height = 64;
1435 image_create_info.extent.depth = 1;
1436 image_create_info.mipLevels = 1;
1437 image_create_info.arrayLayers = 1;
1438 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1439 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1440 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1441 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1442 image_create_info.queueFamilyIndexCount = 0;
1443 image_create_info.pQueueFamilyIndices = NULL;
1444 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1445 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1446
1447 // 2D image w/ sparse residency and linear tiling is an error
1448 m_errorMonitor->SetDesiredFailureMsg(
1449 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1450 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1451 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1452 m_errorMonitor->VerifyFound();
1453 if (VK_SUCCESS == result) {
1454 vkDestroyImage(m_device->device(), image, NULL);
1455 image = VK_NULL_HANDLE;
1456 }
1457 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1458
1459 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1460 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1462 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1463 m_errorMonitor->VerifyFound();
1464 if (VK_SUCCESS == result) {
1465 vkDestroyImage(m_device->device(), image, NULL);
1466 image = VK_NULL_HANDLE;
1467 }
1468
1469 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1471 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1472 m_errorMonitor->VerifyFound();
1473 if (VK_SUCCESS == result) {
1474 vkDestroyImage(m_device->device(), image, NULL);
1475 image = VK_NULL_HANDLE;
1476 }
1477
1478 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1480 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1481 m_errorMonitor->VerifyFound();
1482 if (VK_SUCCESS == result) {
1483 vkDestroyImage(m_device->device(), image, NULL);
1484 image = VK_NULL_HANDLE;
1485 }
1486
1487 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1489 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1490 m_errorMonitor->VerifyFound();
1491 if (VK_SUCCESS == result) {
1492 vkDestroyImage(m_device->device(), image, NULL);
1493 image = VK_NULL_HANDLE;
1494 }
1495}
1496
Tobin Ehlisf11be982016-05-11 13:52:53 -06001497TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001498 TEST_DESCRIPTION(
1499 "Create a buffer and image, allocate memory, and bind the "
1500 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001501 VkResult err;
1502 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001503 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf11be982016-05-11 13:52:53 -06001504
Tobin Ehlis077ded32016-05-12 17:39:13 -06001505 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001506 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001507 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001508 VkDeviceMemory mem; // buffer will be bound first
1509 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001510 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001511 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001512
1513 VkBufferCreateInfo buf_info = {};
1514 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1515 buf_info.pNext = NULL;
1516 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1517 buf_info.size = 256;
1518 buf_info.queueFamilyIndexCount = 0;
1519 buf_info.pQueueFamilyIndices = NULL;
1520 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1521 buf_info.flags = 0;
1522 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1523 ASSERT_VK_SUCCESS(err);
1524
Tobin Ehlis077ded32016-05-12 17:39:13 -06001525 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001526
1527 VkImageCreateInfo image_create_info = {};
1528 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1529 image_create_info.pNext = NULL;
1530 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1531 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1532 image_create_info.extent.width = 64;
1533 image_create_info.extent.height = 64;
1534 image_create_info.extent.depth = 1;
1535 image_create_info.mipLevels = 1;
1536 image_create_info.arrayLayers = 1;
1537 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001538 // Image tiling must be optimal to trigger error when aliasing linear buffer
1539 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001540 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1541 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1542 image_create_info.queueFamilyIndexCount = 0;
1543 image_create_info.pQueueFamilyIndices = NULL;
1544 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1545 image_create_info.flags = 0;
1546
Tobin Ehlisf11be982016-05-11 13:52:53 -06001547 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1548 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001549 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1550 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001551
Tobin Ehlis077ded32016-05-12 17:39:13 -06001552 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1553
1554 VkMemoryAllocateInfo alloc_info = {};
1555 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1556 alloc_info.pNext = NULL;
1557 alloc_info.memoryTypeIndex = 0;
1558 // Ensure memory is big enough for both bindings
1559 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001560 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1561 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001562 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001563 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001564 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001565 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001566 return;
1567 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001568 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1569 ASSERT_VK_SUCCESS(err);
1570 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1571 ASSERT_VK_SUCCESS(err);
1572
Rene Lindsayd14f5572016-12-16 14:57:18 -07001573 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1574
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001576 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001577 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1578 m_errorMonitor->VerifyFound();
1579
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001580 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001581 // aliasing buffer2
1582 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1583 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001584 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1585 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001586 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001587 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001589 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001590 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001591 m_errorMonitor->VerifyFound();
1592
1593 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001594 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001595 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001596 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001597 vkFreeMemory(m_device->device(), mem, NULL);
1598 vkFreeMemory(m_device->device(), mem_img, NULL);
1599}
1600
Tobin Ehlis35372522016-05-12 08:32:31 -06001601TEST_F(VkLayerTest, InvalidMemoryMapping) {
1602 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1603 VkResult err;
1604 bool pass;
Tony Barbour1fa09702017-03-16 12:09:08 -06001605 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis35372522016-05-12 08:32:31 -06001606
1607 VkBuffer buffer;
1608 VkDeviceMemory mem;
1609 VkMemoryRequirements mem_reqs;
1610
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001611 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1612
Tobin Ehlis35372522016-05-12 08:32:31 -06001613 VkBufferCreateInfo buf_info = {};
1614 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1615 buf_info.pNext = NULL;
1616 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1617 buf_info.size = 256;
1618 buf_info.queueFamilyIndexCount = 0;
1619 buf_info.pQueueFamilyIndices = NULL;
1620 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1621 buf_info.flags = 0;
1622 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1623 ASSERT_VK_SUCCESS(err);
1624
1625 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1626 VkMemoryAllocateInfo alloc_info = {};
1627 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1628 alloc_info.pNext = NULL;
1629 alloc_info.memoryTypeIndex = 0;
1630
1631 // Ensure memory is big enough for both bindings
1632 static const VkDeviceSize allocation_size = 0x10000;
1633 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001634 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001635 if (!pass) {
1636 vkDestroyBuffer(m_device->device(), buffer, NULL);
1637 return;
1638 }
1639 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1640 ASSERT_VK_SUCCESS(err);
1641
1642 uint8_t *pData;
1643 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001645 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1646 m_errorMonitor->VerifyFound();
1647 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001649 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1651 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1652 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001653 m_errorMonitor->VerifyFound();
1654
1655 // Unmap the memory to avoid re-map error
1656 vkUnmapMemory(m_device->device(), mem);
1657 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1659 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1660 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001661 m_errorMonitor->VerifyFound();
1662 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1664 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001665 m_errorMonitor->VerifyFound();
1666 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001668 vkUnmapMemory(m_device->device(), mem);
1669 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001670
Tobin Ehlis35372522016-05-12 08:32:31 -06001671 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001672 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001673 ASSERT_VK_SUCCESS(err);
1674 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001675 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001676 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001677 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001679 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1680 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001681
Tobin Ehlis35372522016-05-12 08:32:31 -06001682 // Now flush range that oversteps mapped range
1683 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001684 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001685 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001686 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001687 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1689 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1690 m_errorMonitor->VerifyFound();
1691
1692 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1693 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001694 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001695 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001696 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001697 mmr.size = VK_WHOLE_SIZE;
1698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001699 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1700 m_errorMonitor->VerifyFound();
1701
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001702#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001703 // Some platforms have an atomsize of 1 which makes the test meaningless
1704 if (atom_size > 3) {
1705 // Now with an offset NOT a multiple of the device limit
1706 vkUnmapMemory(m_device->device(), mem);
1707 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1708 ASSERT_VK_SUCCESS(err);
1709 mmr.offset = 3; // Not a multiple of atom_size
1710 mmr.size = VK_WHOLE_SIZE;
1711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1712 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1713 m_errorMonitor->VerifyFound();
1714
1715 // Now with a size NOT a multiple of the device limit
1716 vkUnmapMemory(m_device->device(), mem);
1717 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1718 ASSERT_VK_SUCCESS(err);
1719 mmr.offset = atom_size;
1720 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1722 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1723 m_errorMonitor->VerifyFound();
1724 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001725#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001726 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1727 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001728 if (!pass) {
1729 vkFreeMemory(m_device->device(), mem, NULL);
1730 vkDestroyBuffer(m_device->device(), buffer, NULL);
1731 return;
1732 }
1733 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1734 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1735
1736 vkDestroyBuffer(m_device->device(), buffer, NULL);
1737 vkFreeMemory(m_device->device(), mem, NULL);
1738}
1739
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001740#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001741TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1742 VkResult err;
1743 bool pass;
1744
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001745 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1746 // following declaration (which is temporarily being moved below):
1747 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001748 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001749 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001750 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001751 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001752 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001753 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001754
Tony Barbour1fa09702017-03-16 12:09:08 -06001755 ASSERT_NO_FATAL_FAILURE(Init());
Ian Elliott1c32c772016-04-28 14:47:13 -06001756
Ian Elliott3f06ce52016-04-29 14:46:21 -06001757#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1758#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1759 // Use the functions from the VK_KHR_android_surface extension without
1760 // enabling that extension:
1761
1762 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001763 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1765 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001766 pass = (err != VK_SUCCESS);
1767 ASSERT_TRUE(pass);
1768 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001769#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001770
Ian Elliott3f06ce52016-04-29 14:46:21 -06001771#if defined(VK_USE_PLATFORM_MIR_KHR)
1772 // Use the functions from the VK_KHR_mir_surface extension without enabling
1773 // that extension:
1774
1775 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001776 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001778 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1779 pass = (err != VK_SUCCESS);
1780 ASSERT_TRUE(pass);
1781 m_errorMonitor->VerifyFound();
1782
1783 // Tell whether an mir_connection supports presentation:
1784 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1786 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001787 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001788#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001789
Ian Elliott3f06ce52016-04-29 14:46:21 -06001790#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1791 // Use the functions from the VK_KHR_wayland_surface extension without
1792 // enabling that extension:
1793
1794 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001795 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1797 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001798 pass = (err != VK_SUCCESS);
1799 ASSERT_TRUE(pass);
1800 m_errorMonitor->VerifyFound();
1801
1802 // Tell whether an wayland_display supports presentation:
1803 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1805 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001806 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001807#endif // VK_USE_PLATFORM_WAYLAND_KHR
1808#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001809
Ian Elliott3f06ce52016-04-29 14:46:21 -06001810#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001811 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1812 // TO NON-LINUX PLATFORMS:
1813 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001814 // Use the functions from the VK_KHR_win32_surface extension without
1815 // enabling that extension:
1816
1817 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001818 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1820 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001821 pass = (err != VK_SUCCESS);
1822 ASSERT_TRUE(pass);
1823 m_errorMonitor->VerifyFound();
1824
1825 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001827 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001828 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001829// Set this (for now, until all platforms are supported and tested):
1830#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001831#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001832#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001833 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1834 // TO NON-LINUX PLATFORMS:
1835 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001836#endif
1837#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001838 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1839 // that extension:
1840
1841 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001842 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001844 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1845 pass = (err != VK_SUCCESS);
1846 ASSERT_TRUE(pass);
1847 m_errorMonitor->VerifyFound();
1848
1849 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001850 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001851 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1853 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001854 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001855// Set this (for now, until all platforms are supported and tested):
1856#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001857#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001858
Ian Elliott12630812016-04-29 14:35:43 -06001859#if defined(VK_USE_PLATFORM_XLIB_KHR)
1860 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1861 // that extension:
1862
1863 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001864 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001866 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1867 pass = (err != VK_SUCCESS);
1868 ASSERT_TRUE(pass);
1869 m_errorMonitor->VerifyFound();
1870
1871 // Tell whether an Xlib VisualID supports presentation:
1872 Display *dpy = NULL;
1873 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001875 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1876 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001877// Set this (for now, until all platforms are supported and tested):
1878#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001879#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001880
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001881// Use the functions from the VK_KHR_surface extension without enabling
1882// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001883
Ian Elliott489eec02016-05-05 14:12:44 -06001884#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001885 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001887 vkDestroySurfaceKHR(instance(), surface, NULL);
1888 m_errorMonitor->VerifyFound();
1889
1890 // Check if surface supports presentation:
1891 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001893 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1894 pass = (err != VK_SUCCESS);
1895 ASSERT_TRUE(pass);
1896 m_errorMonitor->VerifyFound();
1897
1898 // Check surface capabilities:
1899 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1901 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001902 pass = (err != VK_SUCCESS);
1903 ASSERT_TRUE(pass);
1904 m_errorMonitor->VerifyFound();
1905
1906 // Check surface formats:
1907 uint32_t format_count = 0;
1908 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1910 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001911 pass = (err != VK_SUCCESS);
1912 ASSERT_TRUE(pass);
1913 m_errorMonitor->VerifyFound();
1914
1915 // Check surface present modes:
1916 uint32_t present_mode_count = 0;
1917 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1919 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001920 pass = (err != VK_SUCCESS);
1921 ASSERT_TRUE(pass);
1922 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001923#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001924
Ian Elliott1c32c772016-04-28 14:47:13 -06001925 // Use the functions from the VK_KHR_swapchain extension without enabling
1926 // that extension:
1927
1928 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001930 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1931 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001932 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001933 pass = (err != VK_SUCCESS);
1934 ASSERT_TRUE(pass);
1935 m_errorMonitor->VerifyFound();
1936
1937 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1939 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001940 pass = (err != VK_SUCCESS);
1941 ASSERT_TRUE(pass);
1942 m_errorMonitor->VerifyFound();
1943
Chris Forbeseb7d5502016-09-13 18:19:21 +12001944 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1945 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1946 VkFence fence;
1947 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1948
Ian Elliott1c32c772016-04-28 14:47:13 -06001949 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001951 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001952 pass = (err != VK_SUCCESS);
1953 ASSERT_TRUE(pass);
1954 m_errorMonitor->VerifyFound();
1955
Chris Forbeseb7d5502016-09-13 18:19:21 +12001956 vkDestroyFence(m_device->device(), fence, nullptr);
1957
Ian Elliott1c32c772016-04-28 14:47:13 -06001958 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001959 //
1960 // NOTE: Currently can't test this because a real swapchain is needed (as
1961 // opposed to the fake one we created) in order for the layer to lookup the
1962 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001963
1964 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001966 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1967 m_errorMonitor->VerifyFound();
1968}
Chris Forbes09368e42016-10-13 11:59:22 +13001969#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001970
Karl Schultz6addd812016-02-02 17:17:23 -07001971TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1972 VkResult err;
1973 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001974
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1976 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001977
Tony Barbour1fa09702017-03-16 12:09:08 -06001978 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001979
1980 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001981 VkImage image;
1982 VkDeviceMemory mem;
1983 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001984
Karl Schultz6addd812016-02-02 17:17:23 -07001985 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1986 const int32_t tex_width = 32;
1987 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001988
Tony Barboureb254902015-07-15 12:50:33 -06001989 VkImageCreateInfo image_create_info = {};
1990 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001991 image_create_info.pNext = NULL;
1992 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1993 image_create_info.format = tex_format;
1994 image_create_info.extent.width = tex_width;
1995 image_create_info.extent.height = tex_height;
1996 image_create_info.extent.depth = 1;
1997 image_create_info.mipLevels = 1;
1998 image_create_info.arrayLayers = 1;
1999 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2000 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2001 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2002 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002003 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002004
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002005 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002006 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002007 mem_alloc.pNext = NULL;
2008 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002009
Chia-I Wuf7458c52015-10-26 21:10:41 +08002010 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002011 ASSERT_VK_SUCCESS(err);
2012
Karl Schultz6addd812016-02-02 17:17:23 -07002013 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002014
Mark Lobodzinski23065352015-05-29 09:32:35 -05002015 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002016
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002017 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002018 if (!pass) { // If we can't find any unmappable memory this test doesn't
2019 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002020 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002021 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002022 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002023
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002024 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002025 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002026 ASSERT_VK_SUCCESS(err);
2027
2028 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002029 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030 ASSERT_VK_SUCCESS(err);
2031
2032 // Map memory as if to initialize the image
2033 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002034 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002035
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002036 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002037
Chia-I Wuf7458c52015-10-26 21:10:41 +08002038 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002039 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002040}
2041
Karl Schultz6addd812016-02-02 17:17:23 -07002042TEST_F(VkLayerTest, RebindMemory) {
2043 VkResult err;
2044 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002045
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002047
Tony Barbour1fa09702017-03-16 12:09:08 -06002048 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002049
2050 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002051 VkImage image;
2052 VkDeviceMemory mem1;
2053 VkDeviceMemory mem2;
2054 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002055
Karl Schultz6addd812016-02-02 17:17:23 -07002056 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2057 const int32_t tex_width = 32;
2058 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002059
Tony Barboureb254902015-07-15 12:50:33 -06002060 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002061 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2062 image_create_info.pNext = NULL;
2063 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2064 image_create_info.format = tex_format;
2065 image_create_info.extent.width = tex_width;
2066 image_create_info.extent.height = tex_height;
2067 image_create_info.extent.depth = 1;
2068 image_create_info.mipLevels = 1;
2069 image_create_info.arrayLayers = 1;
2070 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2071 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2072 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2073 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002074
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002075 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002076 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2077 mem_alloc.pNext = NULL;
2078 mem_alloc.allocationSize = 0;
2079 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002080
Karl Schultz6addd812016-02-02 17:17:23 -07002081 // Introduce failure, do NOT set memProps to
2082 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002083 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002084 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002085 ASSERT_VK_SUCCESS(err);
2086
Karl Schultz6addd812016-02-02 17:17:23 -07002087 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002088
2089 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002090 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002091 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002092
2093 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002094 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002095 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002096 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002097 ASSERT_VK_SUCCESS(err);
2098
2099 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002100 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002101 ASSERT_VK_SUCCESS(err);
2102
Karl Schultz6addd812016-02-02 17:17:23 -07002103 // Introduce validation failure, try to bind a different memory object to
2104 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002105 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002106
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002107 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002108
Chia-I Wuf7458c52015-10-26 21:10:41 +08002109 vkDestroyImage(m_device->device(), image, NULL);
2110 vkFreeMemory(m_device->device(), mem1, NULL);
2111 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002112}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002113
Karl Schultz6addd812016-02-02 17:17:23 -07002114TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002115 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002116
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2118 "submitted in SIGNALED state. Fences "
2119 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002120
2121 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002122 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2123 fenceInfo.pNext = NULL;
2124 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002125
Tony Barbour1fa09702017-03-16 12:09:08 -06002126 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour300a6082015-04-07 13:44:53 -06002127 ASSERT_NO_FATAL_FAILURE(InitViewport());
2128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2129
Tony Barbour552f6c02016-12-21 14:34:07 -07002130 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002131 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002132 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002133
2134 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002135
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002136 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002137 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2138 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002139 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002140 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002141 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002142 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002143 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002144 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002145 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002146
2147 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002148 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002149
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002150 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002151}
Chris Forbes4e44c912016-06-16 10:20:00 +12002152
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002153TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002154 TEST_DESCRIPTION(
2155 "Specify wrong usage for image then create conflicting view of image "
2156 "Initialize buffer with wrong usage then perform copy expecting errors "
2157 "from both the image and the buffer (2 calls)");
Mark Lobodzinski33826372017-04-13 11:10:11 -06002158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for Image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002159
Tony Barbour1fa09702017-03-16 12:09:08 -06002160 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06002161 auto format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07002162 if (!format) {
2163 printf(" No Depth + Stencil format found. Skipped.\n");
2164 return;
2165 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002166
Tony Barbourf92621a2016-05-02 14:28:12 -06002167 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002168 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06002169 image.Init(128, 128, 1, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002170 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002171
Tony Barbourf92621a2016-05-02 14:28:12 -06002172 VkImageView dsv;
2173 VkImageViewCreateInfo dsvci = {};
2174 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2175 dsvci.image = image.handle();
2176 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002177 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002178 dsvci.subresourceRange.layerCount = 1;
2179 dsvci.subresourceRange.baseMipLevel = 0;
2180 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002181 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002182
Tony Barbourf92621a2016-05-02 14:28:12 -06002183 // Create a view with depth / stencil aspect for image with different usage
2184 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002185
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002186 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002187
2188 // Initialize buffer with TRANSFER_DST usage
2189 vk_testing::Buffer buffer;
2190 VkMemoryPropertyFlags reqs = 0;
2191 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2192 VkBufferImageCopy region = {};
2193 region.bufferRowLength = 128;
2194 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002195 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002196 region.imageSubresource.layerCount = 1;
2197 region.imageExtent.height = 16;
2198 region.imageExtent.width = 16;
2199 region.imageExtent.depth = 1;
2200
Mark Lobodzinski80871462017-02-16 10:37:27 -07002201 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002202 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002203
Chris Forbesda581202016-10-06 18:25:26 +13002204 // two separate errors from this call:
Mark Lobodzinski33826372017-04-13 11:10:11 -06002205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
Chris Forbesda581202016-10-06 18:25:26 +13002207
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002208 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2209 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002210 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002211}
Tony Barbour75d79f02016-08-30 09:39:07 -06002212
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002213TEST_F(VkLayerTest, LeakAnObject) {
2214 VkResult err;
2215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002216 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002217
2218 // Note that we have to create a new device since destroying the
2219 // framework's device causes Teardown() to fail and just calling Teardown
2220 // will destroy the errorMonitor.
2221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002223
Tony Barbour1fa09702017-03-16 12:09:08 -06002224 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002225
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002226 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002227 std::vector<VkDeviceQueueCreateInfo> queue_info;
2228 queue_info.reserve(queue_props.size());
2229 std::vector<std::vector<float>> queue_priorities;
2230 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2231 VkDeviceQueueCreateInfo qi = {};
2232 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2233 qi.pNext = NULL;
2234 qi.queueFamilyIndex = i;
2235 qi.queueCount = queue_props[i].queueCount;
2236 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2237 qi.pQueuePriorities = queue_priorities[i].data();
2238 queue_info.push_back(qi);
2239 }
2240
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002241 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002242
2243 // The sacrificial device object
2244 VkDevice testDevice;
2245 VkDeviceCreateInfo device_create_info = {};
2246 auto features = m_device->phy().features();
2247 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2248 device_create_info.pNext = NULL;
2249 device_create_info.queueCreateInfoCount = queue_info.size();
2250 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002251 device_create_info.enabledLayerCount = 0;
2252 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002253 device_create_info.pEnabledFeatures = &features;
2254 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2255 ASSERT_VK_SUCCESS(err);
2256
2257 VkFence fence;
2258 VkFenceCreateInfo fence_create_info = {};
2259 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2260 fence_create_info.pNext = NULL;
2261 fence_create_info.flags = 0;
2262 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2263 ASSERT_VK_SUCCESS(err);
2264
2265 // Induce failure by not calling vkDestroyFence
2266 vkDestroyDevice(testDevice, NULL);
2267 m_errorMonitor->VerifyFound();
2268}
2269
2270TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002271 TEST_DESCRIPTION(
2272 "Allocate command buffers from one command pool and "
2273 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002274
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002276
Tony Barbour1fa09702017-03-16 12:09:08 -06002277 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002278 VkCommandPool command_pool_one;
2279 VkCommandPool command_pool_two;
2280
2281 VkCommandPoolCreateInfo pool_create_info{};
2282 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2283 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2284 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2285
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002286 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002287
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002288 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002289
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002290 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002291 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002292 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002293 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002294 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002295 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002296 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002297
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002298 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002299
2300 m_errorMonitor->VerifyFound();
2301
2302 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2303 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2304}
2305
2306TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2307 VkResult err;
2308
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002309 TEST_DESCRIPTION(
2310 "Allocate descriptor sets from one DS pool and "
2311 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002312
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002314
Tony Barbour1fa09702017-03-16 12:09:08 -06002315 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2317
2318 VkDescriptorPoolSize ds_type_count = {};
2319 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2320 ds_type_count.descriptorCount = 1;
2321
2322 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2323 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2324 ds_pool_ci.pNext = NULL;
2325 ds_pool_ci.flags = 0;
2326 ds_pool_ci.maxSets = 1;
2327 ds_pool_ci.poolSizeCount = 1;
2328 ds_pool_ci.pPoolSizes = &ds_type_count;
2329
2330 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002331 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002332 ASSERT_VK_SUCCESS(err);
2333
2334 // Create a second descriptor pool
2335 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002336 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002337 ASSERT_VK_SUCCESS(err);
2338
2339 VkDescriptorSetLayoutBinding dsl_binding = {};
2340 dsl_binding.binding = 0;
2341 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2342 dsl_binding.descriptorCount = 1;
2343 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2344 dsl_binding.pImmutableSamplers = NULL;
2345
2346 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2347 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2348 ds_layout_ci.pNext = NULL;
2349 ds_layout_ci.bindingCount = 1;
2350 ds_layout_ci.pBindings = &dsl_binding;
2351
2352 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002353 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002354 ASSERT_VK_SUCCESS(err);
2355
2356 VkDescriptorSet descriptorSet;
2357 VkDescriptorSetAllocateInfo alloc_info = {};
2358 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2359 alloc_info.descriptorSetCount = 1;
2360 alloc_info.descriptorPool = ds_pool_one;
2361 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002362 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002363 ASSERT_VK_SUCCESS(err);
2364
2365 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2366
2367 m_errorMonitor->VerifyFound();
2368
2369 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2370 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2371 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2372}
2373
2374TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002376
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002377 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002378
Tony Barbour1fa09702017-03-16 12:09:08 -06002379 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002380
2381 // Pass bogus handle into GetImageMemoryRequirements
2382 VkMemoryRequirements mem_reqs;
2383 uint64_t fakeImageHandle = 0xCADECADE;
2384 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2385
2386 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2387
2388 m_errorMonitor->VerifyFound();
2389}
2390
Mike Schuchardt17838902017-02-21 09:48:06 -07002391TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2392 TEST_DESCRIPTION(
2393 "Try to destroy a render pass object using a device other than the one it was created on. "
2394 "This should generate a distinct error from the invalid handle error.");
2395 // Create first device and renderpass
Tony Barbour1fa09702017-03-16 12:09:08 -06002396 ASSERT_NO_FATAL_FAILURE(Init());
Mike Schuchardt17838902017-02-21 09:48:06 -07002397 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2398
2399 // Create second device
2400 float priorities[] = {1.0f};
2401 VkDeviceQueueCreateInfo queue_info{};
2402 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2403 queue_info.pNext = NULL;
2404 queue_info.flags = 0;
2405 queue_info.queueFamilyIndex = 0;
2406 queue_info.queueCount = 1;
2407 queue_info.pQueuePriorities = &priorities[0];
2408
2409 VkDeviceCreateInfo device_create_info = {};
2410 auto features = m_device->phy().features();
2411 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2412 device_create_info.pNext = NULL;
2413 device_create_info.queueCreateInfoCount = 1;
2414 device_create_info.pQueueCreateInfos = &queue_info;
2415 device_create_info.enabledLayerCount = 0;
2416 device_create_info.ppEnabledLayerNames = NULL;
2417 device_create_info.pEnabledFeatures = &features;
2418
2419 VkDevice second_device;
2420 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2421
2422 // Try to destroy the renderpass from the first device using the second device
2423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2424 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2425 m_errorMonitor->VerifyFound();
2426
2427 vkDestroyDevice(second_device, NULL);
2428}
2429
Karl Schultz6addd812016-02-02 17:17:23 -07002430TEST_F(VkLayerTest, PipelineNotBound) {
2431 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002432
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002433 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002434
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002436
Tony Barbour1fa09702017-03-16 12:09:08 -06002437 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002439
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002440 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002441 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2442 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002443
2444 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002445 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2446 ds_pool_ci.pNext = NULL;
2447 ds_pool_ci.maxSets = 1;
2448 ds_pool_ci.poolSizeCount = 1;
2449 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002450
2451 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002452 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002453 ASSERT_VK_SUCCESS(err);
2454
2455 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002456 dsl_binding.binding = 0;
2457 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2458 dsl_binding.descriptorCount = 1;
2459 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2460 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002461
2462 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002463 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2464 ds_layout_ci.pNext = NULL;
2465 ds_layout_ci.bindingCount = 1;
2466 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002467
2468 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002469 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002470 ASSERT_VK_SUCCESS(err);
2471
2472 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002473 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002474 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002475 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002476 alloc_info.descriptorPool = ds_pool;
2477 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002478 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002479 ASSERT_VK_SUCCESS(err);
2480
2481 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002482 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2483 pipeline_layout_ci.pNext = NULL;
2484 pipeline_layout_ci.setLayoutCount = 1;
2485 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002486
2487 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002488 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002489 ASSERT_VK_SUCCESS(err);
2490
Mark Youngad779052016-01-06 14:26:04 -07002491 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002492
Tony Barbour552f6c02016-12-21 14:34:07 -07002493 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002494 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002495
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002496 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002497
Chia-I Wuf7458c52015-10-26 21:10:41 +08002498 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2499 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2500 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002501}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002502
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002503TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2504 VkResult err;
2505
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002506 TEST_DESCRIPTION(
2507 "Test validation check for an invalid memory type index "
2508 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002509
Tony Barbour1fa09702017-03-16 12:09:08 -06002510 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002511
2512 // Create an image, allocate memory, set a bad typeIndex and then try to
2513 // bind it
2514 VkImage image;
2515 VkDeviceMemory mem;
2516 VkMemoryRequirements mem_reqs;
2517 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2518 const int32_t tex_width = 32;
2519 const int32_t tex_height = 32;
2520
2521 VkImageCreateInfo image_create_info = {};
2522 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2523 image_create_info.pNext = NULL;
2524 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2525 image_create_info.format = tex_format;
2526 image_create_info.extent.width = tex_width;
2527 image_create_info.extent.height = tex_height;
2528 image_create_info.extent.depth = 1;
2529 image_create_info.mipLevels = 1;
2530 image_create_info.arrayLayers = 1;
2531 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2532 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2533 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2534 image_create_info.flags = 0;
2535
2536 VkMemoryAllocateInfo mem_alloc = {};
2537 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2538 mem_alloc.pNext = NULL;
2539 mem_alloc.allocationSize = 0;
2540 mem_alloc.memoryTypeIndex = 0;
2541
2542 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2543 ASSERT_VK_SUCCESS(err);
2544
2545 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2546 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002547
2548 // Introduce Failure, select invalid TypeIndex
2549 VkPhysicalDeviceMemoryProperties memory_info;
2550
2551 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2552 unsigned int i;
2553 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2554 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2555 mem_alloc.memoryTypeIndex = i;
2556 break;
2557 }
2558 }
2559 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002560 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002561 vkDestroyImage(m_device->device(), image, NULL);
2562 return;
2563 }
2564
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002566
2567 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2568 ASSERT_VK_SUCCESS(err);
2569
2570 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2571 (void)err;
2572
2573 m_errorMonitor->VerifyFound();
2574
2575 vkDestroyImage(m_device->device(), image, NULL);
2576 vkFreeMemory(m_device->device(), mem, NULL);
2577}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002578
Karl Schultz6addd812016-02-02 17:17:23 -07002579TEST_F(VkLayerTest, BindInvalidMemory) {
2580 VkResult err;
2581 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002582
Tony Barbour1fa09702017-03-16 12:09:08 -06002583 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002584
Cortf801b982017-01-17 18:10:21 -08002585 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002586 const int32_t tex_width = 256;
2587 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002588
2589 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002590 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2591 image_create_info.pNext = NULL;
2592 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2593 image_create_info.format = tex_format;
2594 image_create_info.extent.width = tex_width;
2595 image_create_info.extent.height = tex_height;
2596 image_create_info.extent.depth = 1;
2597 image_create_info.mipLevels = 1;
2598 image_create_info.arrayLayers = 1;
2599 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002600 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002601 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2602 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002603
Cortf801b982017-01-17 18:10:21 -08002604 VkBufferCreateInfo buffer_create_info = {};
2605 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2606 buffer_create_info.pNext = NULL;
2607 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002608 buffer_create_info.size = 4 * 1024 * 1024;
2609 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002610 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002611
Cortf801b982017-01-17 18:10:21 -08002612 // Create an image/buffer, allocate memory, free it, and then try to bind it
2613 {
2614 VkImage image = VK_NULL_HANDLE;
2615 VkBuffer buffer = VK_NULL_HANDLE;
2616 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2617 ASSERT_VK_SUCCESS(err);
2618 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2619 ASSERT_VK_SUCCESS(err);
2620 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2621 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2622 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002623
Cortf801b982017-01-17 18:10:21 -08002624 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2625 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2626 image_mem_alloc.allocationSize = image_mem_reqs.size;
2627 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2628 ASSERT_TRUE(pass);
2629 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2630 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2631 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2632 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002633
Cortf801b982017-01-17 18:10:21 -08002634 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2635 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2636 ASSERT_VK_SUCCESS(err);
2637 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2638 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002639
Cortf801b982017-01-17 18:10:21 -08002640 vkFreeMemory(device(), image_mem, NULL);
2641 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002642
Cortf801b982017-01-17 18:10:21 -08002643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2644 err = vkBindImageMemory(device(), image, image_mem, 0);
2645 (void)err; // This may very well return an error.
2646 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002647
Cortf801b982017-01-17 18:10:21 -08002648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2649 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2650 (void)err; // This may very well return an error.
2651 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002652
Cortf801b982017-01-17 18:10:21 -08002653 vkDestroyImage(m_device->device(), image, NULL);
2654 vkDestroyBuffer(m_device->device(), buffer, NULL);
2655 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002656
2657 // Try to bind memory to an object that already has a memory binding
2658 {
2659 VkImage image = VK_NULL_HANDLE;
2660 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2661 ASSERT_VK_SUCCESS(err);
2662 VkBuffer buffer = VK_NULL_HANDLE;
2663 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2664 ASSERT_VK_SUCCESS(err);
2665 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2666 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2667 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2668 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2669 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2670 image_alloc_info.allocationSize = image_mem_reqs.size;
2671 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2672 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2673 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2674 ASSERT_TRUE(pass);
2675 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2676 ASSERT_TRUE(pass);
2677 VkDeviceMemory image_mem, buffer_mem;
2678 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2679 ASSERT_VK_SUCCESS(err);
2680 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2681 ASSERT_VK_SUCCESS(err);
2682
2683 err = vkBindImageMemory(device(), image, image_mem, 0);
2684 ASSERT_VK_SUCCESS(err);
2685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2686 err = vkBindImageMemory(device(), image, image_mem, 0);
2687 (void)err; // This may very well return an error.
2688 m_errorMonitor->VerifyFound();
2689
2690 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2691 ASSERT_VK_SUCCESS(err);
2692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2693 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2694 (void)err; // This may very well return an error.
2695 m_errorMonitor->VerifyFound();
2696
2697 vkFreeMemory(device(), image_mem, NULL);
2698 vkFreeMemory(device(), buffer_mem, NULL);
2699 vkDestroyImage(device(), image, NULL);
2700 vkDestroyBuffer(device(), buffer, NULL);
2701 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002702
Cort Strattonde748202017-02-17 12:50:01 -08002703 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002704 {
2705 VkImage image = VK_NULL_HANDLE;
2706 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2707 ASSERT_VK_SUCCESS(err);
2708 VkBuffer buffer = VK_NULL_HANDLE;
2709 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2710 ASSERT_VK_SUCCESS(err);
2711 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2712 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2713 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2714 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2715 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002716 // Leave some extra space for alignment wiggle room
2717 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002718 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002719 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002720 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2721 ASSERT_TRUE(pass);
2722 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2723 ASSERT_TRUE(pass);
2724 VkDeviceMemory image_mem, buffer_mem;
2725 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2726 ASSERT_VK_SUCCESS(err);
2727 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2728 ASSERT_VK_SUCCESS(err);
2729
Cort Strattonde748202017-02-17 12:50:01 -08002730 // Test unaligned memory offset
2731 {
2732 if (image_mem_reqs.alignment > 1) {
2733 VkDeviceSize image_offset = 1;
2734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2735 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2736 (void)err; // This may very well return an error.
2737 m_errorMonitor->VerifyFound();
2738 }
Cort6c7dff72017-01-27 18:34:50 -08002739
Cort Strattonde748202017-02-17 12:50:01 -08002740 if (buffer_mem_reqs.alignment > 1) {
2741 VkDeviceSize buffer_offset = 1;
2742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2743 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2744 (void)err; // This may very well return an error.
2745 m_errorMonitor->VerifyFound();
2746 }
2747 }
2748
2749 // Test memory offsets outside the memory allocation
2750 {
2751 VkDeviceSize image_offset =
2752 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2754 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2755 (void)err; // This may very well return an error.
2756 m_errorMonitor->VerifyFound();
2757
2758 VkDeviceSize buffer_offset =
2759 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2761 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2762 (void)err; // This may very well return an error.
2763 m_errorMonitor->VerifyFound();
2764 }
2765
2766 // Test memory offsets within the memory allocation, but which leave too little memory for
2767 // the resource.
2768 {
2769 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
Tony Barbour02d08552017-03-24 16:36:01 -06002770 if ((image_offset > 0) && (image_mem_reqs.size < (image_alloc_info.allocationSize - image_mem_reqs.alignment))) {
Cort Strattonde748202017-02-17 12:50:01 -08002771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2772 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2773 (void)err; // This may very well return an error.
2774 m_errorMonitor->VerifyFound();
2775 }
2776
2777 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2778 if (buffer_offset > 0) {
2779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2780 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2781 (void)err; // This may very well return an error.
2782 m_errorMonitor->VerifyFound();
2783 }
2784 }
Cort6c7dff72017-01-27 18:34:50 -08002785
2786 vkFreeMemory(device(), image_mem, NULL);
2787 vkFreeMemory(device(), buffer_mem, NULL);
2788 vkDestroyImage(device(), image, NULL);
2789 vkDestroyBuffer(device(), buffer, NULL);
2790 }
2791
Cort Stratton4c38bb52017-01-28 13:33:10 -08002792 // Try to bind memory to an object with an invalid memory type
2793 {
2794 VkImage image = VK_NULL_HANDLE;
2795 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2796 ASSERT_VK_SUCCESS(err);
2797 VkBuffer buffer = VK_NULL_HANDLE;
2798 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2799 ASSERT_VK_SUCCESS(err);
2800 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2801 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2802 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2803 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2804 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2805 image_alloc_info.allocationSize = image_mem_reqs.size;
2806 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2807 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002808 // Create a mask of available memory types *not* supported by these resources,
2809 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002810 VkPhysicalDeviceMemoryProperties memory_properties = {};
2811 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002812 VkDeviceMemory image_mem, buffer_mem;
2813
Cort Stratton4c38bb52017-01-28 13:33:10 -08002814 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002815 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002816 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2817 ASSERT_TRUE(pass);
2818 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2819 ASSERT_VK_SUCCESS(err);
2820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2821 err = vkBindImageMemory(device(), image, image_mem, 0);
2822 (void)err; // This may very well return an error.
2823 m_errorMonitor->VerifyFound();
2824 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002825 }
2826
Cort Stratton4c38bb52017-01-28 13:33:10 -08002827 uint32_t buffer_unsupported_mem_type_bits =
2828 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002829 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002830 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2831 ASSERT_TRUE(pass);
2832 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2833 ASSERT_VK_SUCCESS(err);
2834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2835 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2836 (void)err; // This may very well return an error.
2837 m_errorMonitor->VerifyFound();
2838 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002839 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002840
Cort Stratton4c38bb52017-01-28 13:33:10 -08002841 vkDestroyImage(device(), image, NULL);
2842 vkDestroyBuffer(device(), buffer, NULL);
2843 }
2844
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002845 // Try to bind memory to an image created with sparse memory flags
2846 {
2847 VkImageCreateInfo sparse_image_create_info = image_create_info;
2848 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2849 VkImageFormatProperties image_format_properties = {};
2850 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2851 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2852 sparse_image_create_info.usage, sparse_image_create_info.flags,
2853 &image_format_properties);
2854 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2855 // most likely means sparse formats aren't supported here; skip this test.
2856 } else {
2857 ASSERT_VK_SUCCESS(err);
2858 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002859 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002860 return;
2861 } else {
2862 VkImage sparse_image = VK_NULL_HANDLE;
2863 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2864 ASSERT_VK_SUCCESS(err);
2865 VkMemoryRequirements sparse_mem_reqs = {};
2866 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2867 if (sparse_mem_reqs.memoryTypeBits != 0) {
2868 VkMemoryAllocateInfo sparse_mem_alloc = {};
2869 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2870 sparse_mem_alloc.pNext = NULL;
2871 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2872 sparse_mem_alloc.memoryTypeIndex = 0;
2873 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2874 ASSERT_TRUE(pass);
2875 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2876 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2877 ASSERT_VK_SUCCESS(err);
2878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2879 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2880 // This may very well return an error.
2881 (void)err;
2882 m_errorMonitor->VerifyFound();
2883 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2884 }
2885 vkDestroyImage(m_device->device(), sparse_image, NULL);
2886 }
2887 }
2888 }
2889
2890 // Try to bind memory to a buffer created with sparse memory flags
2891 {
2892 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2893 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2894 if (!m_device->phy().features().sparseResidencyBuffer) {
2895 // most likely means sparse formats aren't supported here; skip this test.
2896 } else {
2897 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2898 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2899 ASSERT_VK_SUCCESS(err);
2900 VkMemoryRequirements sparse_mem_reqs = {};
2901 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2902 if (sparse_mem_reqs.memoryTypeBits != 0) {
2903 VkMemoryAllocateInfo sparse_mem_alloc = {};
2904 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2905 sparse_mem_alloc.pNext = NULL;
2906 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2907 sparse_mem_alloc.memoryTypeIndex = 0;
2908 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2909 ASSERT_TRUE(pass);
2910 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2911 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2912 ASSERT_VK_SUCCESS(err);
2913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2914 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2915 // This may very well return an error.
2916 (void)err;
2917 m_errorMonitor->VerifyFound();
2918 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2919 }
2920 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2921 }
2922 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002923}
2924
Karl Schultz6addd812016-02-02 17:17:23 -07002925TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2926 VkResult err;
2927 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002928
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002930
Tony Barbour1fa09702017-03-16 12:09:08 -06002931 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisec598302015-09-15 15:02:17 -06002932
Karl Schultz6addd812016-02-02 17:17:23 -07002933 // Create an image object, allocate memory, destroy the object and then try
2934 // to bind it
2935 VkImage image;
2936 VkDeviceMemory mem;
2937 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002938
Karl Schultz6addd812016-02-02 17:17:23 -07002939 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2940 const int32_t tex_width = 32;
2941 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002942
2943 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002944 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2945 image_create_info.pNext = NULL;
2946 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2947 image_create_info.format = tex_format;
2948 image_create_info.extent.width = tex_width;
2949 image_create_info.extent.height = tex_height;
2950 image_create_info.extent.depth = 1;
2951 image_create_info.mipLevels = 1;
2952 image_create_info.arrayLayers = 1;
2953 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2954 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2955 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2956 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002957
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002958 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002959 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2960 mem_alloc.pNext = NULL;
2961 mem_alloc.allocationSize = 0;
2962 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002963
Chia-I Wuf7458c52015-10-26 21:10:41 +08002964 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002965 ASSERT_VK_SUCCESS(err);
2966
Karl Schultz6addd812016-02-02 17:17:23 -07002967 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002968
2969 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002970 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002971 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002972
2973 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002974 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002975 ASSERT_VK_SUCCESS(err);
2976
2977 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002978 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002979 ASSERT_VK_SUCCESS(err);
2980
2981 // Now Try to bind memory to this destroyed object
2982 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2983 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002984 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002985
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002986 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002987
Chia-I Wuf7458c52015-10-26 21:10:41 +08002988 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002989}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002990
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002991TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2992 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2993
Tony Barbour1fa09702017-03-16 12:09:08 -06002994 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2996
2997 VkVertexInputBindingDescription input_binding;
2998 memset(&input_binding, 0, sizeof(input_binding));
2999
3000 VkVertexInputAttributeDescription input_attribs;
3001 memset(&input_attribs, 0, sizeof(input_attribs));
3002
3003 // Pick a really bad format for this purpose and make sure it should fail
3004 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3005 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3006 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003007 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003008 return;
3009 }
3010
3011 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003012 char const *vsSource =
3013 "#version 450\n"
3014 "\n"
3015 "out gl_PerVertex {\n"
3016 " vec4 gl_Position;\n"
3017 "};\n"
3018 "void main(){\n"
3019 " gl_Position = vec4(1);\n"
3020 "}\n";
3021 char const *fsSource =
3022 "#version 450\n"
3023 "\n"
3024 "layout(location=0) out vec4 color;\n"
3025 "void main(){\n"
3026 " color = vec4(1);\n"
3027 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003028
3029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3030 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3031 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3032
3033 VkPipelineObj pipe(m_device);
3034 pipe.AddColorAttachment();
3035 pipe.AddShader(&vs);
3036 pipe.AddShader(&fs);
3037
3038 pipe.AddVertexInputBindings(&input_binding, 1);
3039 pipe.AddVertexInputAttribs(&input_attribs, 1);
3040
3041 VkDescriptorSetObj descriptorSet(m_device);
3042 descriptorSet.AppendDummy();
3043 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3044
3045 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3046
3047 m_errorMonitor->VerifyFound();
3048}
3049
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003050TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003051 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003052 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003053
3054 VkMemoryPropertyFlags reqs = 0;
3055 VkImageCreateInfo image_create_info = {};
3056 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3057 image_create_info.pNext = NULL;
3058 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3059 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3060 image_create_info.extent.width = 256;
3061 image_create_info.extent.height = 256;
3062 image_create_info.extent.depth = 1;
3063 image_create_info.mipLevels = 1;
3064 image_create_info.arrayLayers = 1;
3065 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3066 image_create_info.flags = 0;
3067
3068 VkImageBlit blit_region = {};
3069 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3070 blit_region.srcSubresource.baseArrayLayer = 0;
3071 blit_region.srcSubresource.layerCount = 1;
3072 blit_region.srcSubresource.mipLevel = 0;
3073 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3074 blit_region.dstSubresource.baseArrayLayer = 0;
3075 blit_region.dstSubresource.layerCount = 1;
3076 blit_region.dstSubresource.mipLevel = 0;
3077
3078 // Create two images, the source with sampleCount = 2, and attempt to blit
3079 // between them
3080 {
3081 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003082 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003083 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003084 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003085 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003086 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003087 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003088 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003089 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003090 m_errorMonitor->SetDesiredFailureMsg(
3091 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3092 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003093 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3094 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003095 m_errorMonitor->VerifyFound();
3096 m_commandBuffer->EndCommandBuffer();
3097 }
3098
3099 // Create two images, the dest with sampleCount = 4, and attempt to blit
3100 // between them
3101 {
3102 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003103 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003104 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003105 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003106 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003107 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003108 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003109 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003110 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003111 m_errorMonitor->SetDesiredFailureMsg(
3112 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3113 "was created with a sample count of VK_SAMPLE_COUNT_4_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003114 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3115 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003116 m_errorMonitor->VerifyFound();
3117 m_commandBuffer->EndCommandBuffer();
3118 }
3119
3120 VkBufferImageCopy copy_region = {};
3121 copy_region.bufferRowLength = 128;
3122 copy_region.bufferImageHeight = 128;
3123 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3124 copy_region.imageSubresource.layerCount = 1;
3125 copy_region.imageExtent.height = 64;
3126 copy_region.imageExtent.width = 64;
3127 copy_region.imageExtent.depth = 1;
3128
3129 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3130 // buffer to image
3131 {
3132 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003133 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3134 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003135 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003136 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003137 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003138 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003139 m_errorMonitor->SetDesiredFailureMsg(
3140 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3141 "was created with a sample count of VK_SAMPLE_COUNT_8_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003142 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3143 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003144 m_errorMonitor->VerifyFound();
3145 m_commandBuffer->EndCommandBuffer();
3146 }
3147
3148 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3149 // image to buffer
3150 {
3151 vk_testing::Buffer dst_buffer;
3152 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3153 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003154 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003155 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003156 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003157 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003158 m_errorMonitor->SetDesiredFailureMsg(
3159 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3160 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003161 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003162 dst_buffer.handle(), 1, &copy_region);
3163 m_errorMonitor->VerifyFound();
3164 m_commandBuffer->EndCommandBuffer();
3165 }
3166}
3167
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003168TEST_F(VkLayerTest, BlitImageFormats) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003169 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003170
3171 VkImageObj src_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003172 src_image.Init(64, 64, 1, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003173 VkImageObj dst_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003174 dst_image.Init(64, 64, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003175 VkImageObj dst_image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003176 dst_image2.Init(64, 64, 1, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003177
3178 VkImageBlit blitRegion = {};
3179 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3180 blitRegion.srcSubresource.baseArrayLayer = 0;
3181 blitRegion.srcSubresource.layerCount = 1;
3182 blitRegion.srcSubresource.mipLevel = 0;
3183 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3184 blitRegion.dstSubresource.baseArrayLayer = 0;
3185 blitRegion.dstSubresource.layerCount = 1;
3186 blitRegion.dstSubresource.mipLevel = 0;
3187
Dave Houlton34df4cb2016-12-01 16:43:06 -07003188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3189
3190 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3191 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003192
3193 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003194 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003195 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image.image(), dst_image.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003196 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003197
3198 m_errorMonitor->VerifyFound();
3199
Dave Houlton34df4cb2016-12-01 16:43:06 -07003200 // Test should generate 2 VU failures
3201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003203
3204 // Unsigned int vs signed int
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003205 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.Layout(), dst_image2.image(), dst_image2.Layout(), 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003206 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003207
Dave Houlton34df4cb2016-12-01 16:43:06 -07003208 // TODO: Note that this only verifies that at least one of the VU enums was found
3209 // Also, if any were not seen, they'll remain in the target list (Soln TBD, JIRA task: VL-72)
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003210 m_errorMonitor->VerifyFound();
3211
Tony Barbour552f6c02016-12-21 14:34:07 -07003212 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003213}
3214
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003215TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3216 VkResult err;
3217 bool pass;
3218
3219 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003220 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003221
3222 // If w/d/h granularity is 1, test is not meaningful
3223 // TODO: When virtual device limits are available, create a set of limits for this test that
3224 // will always have a granularity of > 1 for w, h, and d
3225 auto index = m_device->graphics_queue_node_index_;
3226 auto queue_family_properties = m_device->phy().queue_properties();
3227
3228 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3229 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3230 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3231 return;
3232 }
3233
3234 // Create two images of different types and try to copy between them
3235 VkImage srcImage;
3236 VkImage dstImage;
3237 VkDeviceMemory srcMem;
3238 VkDeviceMemory destMem;
3239 VkMemoryRequirements memReqs;
3240
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003241 VkImageCreateInfo image_create_info = {};
3242 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3243 image_create_info.pNext = NULL;
3244 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3245 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3246 image_create_info.extent.width = 32;
3247 image_create_info.extent.height = 32;
3248 image_create_info.extent.depth = 1;
3249 image_create_info.mipLevels = 1;
3250 image_create_info.arrayLayers = 4;
3251 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3252 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3253 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3254 image_create_info.flags = 0;
3255
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003256 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003257 ASSERT_VK_SUCCESS(err);
3258
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003259 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003260 ASSERT_VK_SUCCESS(err);
3261
3262 // Allocate memory
3263 VkMemoryAllocateInfo memAlloc = {};
3264 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3265 memAlloc.pNext = NULL;
3266 memAlloc.allocationSize = 0;
3267 memAlloc.memoryTypeIndex = 0;
3268
3269 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3270 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003271 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003272 ASSERT_TRUE(pass);
3273 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3274 ASSERT_VK_SUCCESS(err);
3275
3276 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3277 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003278 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003279 ASSERT_VK_SUCCESS(err);
3280 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3281 ASSERT_VK_SUCCESS(err);
3282
3283 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3284 ASSERT_VK_SUCCESS(err);
3285 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3286 ASSERT_VK_SUCCESS(err);
3287
Tony Barbour552f6c02016-12-21 14:34:07 -07003288 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003289 VkImageCopy copyRegion;
3290 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3291 copyRegion.srcSubresource.mipLevel = 0;
3292 copyRegion.srcSubresource.baseArrayLayer = 0;
3293 copyRegion.srcSubresource.layerCount = 1;
3294 copyRegion.srcOffset.x = 0;
3295 copyRegion.srcOffset.y = 0;
3296 copyRegion.srcOffset.z = 0;
3297 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3298 copyRegion.dstSubresource.mipLevel = 0;
3299 copyRegion.dstSubresource.baseArrayLayer = 0;
3300 copyRegion.dstSubresource.layerCount = 1;
3301 copyRegion.dstOffset.x = 0;
3302 copyRegion.dstOffset.y = 0;
3303 copyRegion.dstOffset.z = 0;
3304 copyRegion.extent.width = 1;
3305 copyRegion.extent.height = 1;
3306 copyRegion.extent.depth = 1;
3307
3308 // Introduce failure by setting srcOffset to a bad granularity value
3309 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3311 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003312 m_errorMonitor->VerifyFound();
3313
3314 // Introduce failure by setting extent to a bad granularity value
3315 copyRegion.srcOffset.y = 0;
3316 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3318 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003319 m_errorMonitor->VerifyFound();
3320
3321 // Now do some buffer/image copies
3322 vk_testing::Buffer buffer;
3323 VkMemoryPropertyFlags reqs = 0;
3324 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3325 VkBufferImageCopy region = {};
3326 region.bufferOffset = 0;
3327 region.bufferRowLength = 3;
3328 region.bufferImageHeight = 128;
3329 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3330 region.imageSubresource.layerCount = 1;
3331 region.imageExtent.height = 16;
3332 region.imageExtent.width = 16;
3333 region.imageExtent.depth = 1;
3334 region.imageOffset.x = 0;
3335 region.imageOffset.y = 0;
3336 region.imageOffset.z = 0;
3337
3338 // Introduce failure by setting bufferRowLength to a bad granularity value
3339 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3341 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3342 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003343 m_errorMonitor->VerifyFound();
3344 region.bufferRowLength = 128;
3345
3346 // Introduce failure by setting bufferOffset to a bad granularity value
3347 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3349 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3350 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003351 m_errorMonitor->VerifyFound();
3352 region.bufferOffset = 0;
3353
3354 // Introduce failure by setting bufferImageHeight to a bad granularity value
3355 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3357 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3358 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003359 m_errorMonitor->VerifyFound();
3360 region.bufferImageHeight = 128;
3361
3362 // Introduce failure by setting imageExtent to a bad granularity value
3363 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3365 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3366 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003367 m_errorMonitor->VerifyFound();
3368 region.imageExtent.width = 16;
3369
3370 // Introduce failure by setting imageOffset to a bad granularity value
3371 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3373 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3374 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003375 m_errorMonitor->VerifyFound();
3376
Tony Barbour552f6c02016-12-21 14:34:07 -07003377 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003378
3379 vkDestroyImage(m_device->device(), srcImage, NULL);
3380 vkDestroyImage(m_device->device(), dstImage, NULL);
3381 vkFreeMemory(m_device->device(), srcMem, NULL);
3382 vkFreeMemory(m_device->device(), destMem, NULL);
3383}
3384
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003385TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003386 TEST_DESCRIPTION(
3387 "Submit command buffer created using one queue family and "
3388 "attempt to submit them on a queue created in a different "
3389 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003390
Tony Barbour1fa09702017-03-16 12:09:08 -06003391 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003392
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003393 // This test is meaningless unless we have multiple queue families
3394 auto queue_family_properties = m_device->phy().queue_properties();
3395 if (queue_family_properties.size() < 2) {
3396 return;
3397 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003399 // Get safe index of another queue family
3400 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003401 VkQueue other_queue;
3402 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3403
3404 // Record an empty cmd buffer
3405 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3406 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3407 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3408 vkEndCommandBuffer(m_commandBuffer->handle());
3409
3410 // And submit on the wrong queue
3411 VkSubmitInfo submit_info = {};
3412 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3413 submit_info.commandBufferCount = 1;
3414 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003415 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003416
3417 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003418}
3419
Chris Forbes4c24a922016-11-16 08:59:10 +13003420TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
Tony Barbour1fa09702017-03-16 12:09:08 -06003421 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4c24a922016-11-16 08:59:10 +13003422
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003423 // There are no attachments, but refer to attachment 0.
3424 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003425 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003426 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003427 };
3428
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003429 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003430 VkRenderPass rp;
3431
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003432 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003434 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3435 m_errorMonitor->VerifyFound();
3436}
3437
Chris Forbesa58c4522016-09-28 15:19:39 +13003438TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3439 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
Tony Barbour1fa09702017-03-16 12:09:08 -06003440 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa58c4522016-09-28 15:19:39 +13003441
3442 // A renderpass with two subpasses, both writing the same attachment.
3443 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003444 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3445 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3446 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003447 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003448 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003449 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003450 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3451 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003452 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003453 VkSubpassDependency dep = {0,
3454 1,
3455 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3456 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3457 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3458 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3459 VK_DEPENDENCY_BY_REGION_BIT};
3460 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003461 VkRenderPass rp;
3462 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3463 ASSERT_VK_SUCCESS(err);
3464
3465 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003466 image.InitNoLayout(32, 32, 1, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbesa58c4522016-09-28 15:19:39 +13003467 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3468
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003469 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003470 VkFramebuffer fb;
3471 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3472 ASSERT_VK_SUCCESS(err);
3473
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003474 char const *vsSource =
3475 "#version 450\n"
3476 "void main() { gl_Position = vec4(1); }\n";
3477 char const *fsSource =
3478 "#version 450\n"
3479 "layout(location=0) out vec4 color;\n"
3480 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003481
3482 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3483 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3484 VkPipelineObj pipe(m_device);
3485 pipe.AddColorAttachment();
3486 pipe.AddShader(&vs);
3487 pipe.AddShader(&fs);
3488 VkViewport view_port = {};
3489 m_viewports.push_back(view_port);
3490 pipe.SetViewport(m_viewports);
3491 VkRect2D rect = {};
3492 m_scissors.push_back(rect);
3493 pipe.SetScissor(m_scissors);
3494
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003495 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003496 VkPipelineLayout pl;
3497 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3498 ASSERT_VK_SUCCESS(err);
3499 pipe.CreateVKPipeline(pl, rp);
3500
Tony Barbour552f6c02016-12-21 14:34:07 -07003501 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003502
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003503 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3504 nullptr,
3505 rp,
3506 fb,
3507 {{
3508 0, 0,
3509 },
3510 {32, 32}},
3511 0,
3512 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003513
3514 // subtest 1: bind in the wrong subpass
3515 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3516 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003518 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3519 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3520 m_errorMonitor->VerifyFound();
3521
3522 vkCmdEndRenderPass(m_commandBuffer->handle());
3523
3524 // subtest 2: bind in correct subpass, then transition to next subpass
3525 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3526 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3527 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003529 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3530 m_errorMonitor->VerifyFound();
3531
3532 vkCmdEndRenderPass(m_commandBuffer->handle());
3533
Tony Barbour552f6c02016-12-21 14:34:07 -07003534 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003535
3536 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3537 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3538 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3539}
3540
Tony Barbour4e919972016-08-09 13:27:40 -06003541TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003542 TEST_DESCRIPTION(
3543 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3544 "with extent outside of framebuffer");
Tony Barbour1fa09702017-03-16 12:09:08 -06003545 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour4e919972016-08-09 13:27:40 -06003546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3547
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3549 "Cannot execute a render pass with renderArea "
3550 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003551
3552 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3553 m_renderPassBeginInfo.renderArea.extent.width = 257;
3554 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003555 m_commandBuffer->BeginCommandBuffer();
3556 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003557 m_errorMonitor->VerifyFound();
3558}
3559
3560TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003561 TEST_DESCRIPTION(
3562 "Generate INDEPENDENT_BLEND by disabling independent "
3563 "blend and then specifying different blend states for two "
3564 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003565 VkPhysicalDeviceFeatures features = {};
3566 features.independentBlend = VK_FALSE;
Tony Barbour1fa09702017-03-16 12:09:08 -06003567 ASSERT_NO_FATAL_FAILURE(Init(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003568
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3570 "Invalid Pipeline CreateInfo: If independent blend feature not "
3571 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003572
Cody Northropc31a84f2016-08-22 10:41:47 -06003573 VkDescriptorSetObj descriptorSet(m_device);
3574 descriptorSet.AppendDummy();
3575 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003576
Cody Northropc31a84f2016-08-22 10:41:47 -06003577 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003578 // Create a renderPass with two color attachments
3579 VkAttachmentReference attachments[2] = {};
3580 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003581 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003582 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3583
3584 VkSubpassDescription subpass = {};
3585 subpass.pColorAttachments = attachments;
3586 subpass.colorAttachmentCount = 2;
3587
3588 VkRenderPassCreateInfo rpci = {};
3589 rpci.subpassCount = 1;
3590 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003591 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003592
Tony Barbourffd60bd2017-03-09 12:04:55 -07003593 VkAttachmentDescription attach_desc[2] = {};
3594 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3595 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3596 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3597 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3598 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3599 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3600 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3601 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003602
Tony Barbourffd60bd2017-03-09 12:04:55 -07003603 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003604 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3605
3606 VkRenderPass renderpass;
3607 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003608 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003609 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003610
Cody Northropc31a84f2016-08-22 10:41:47 -06003611 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3612 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3613 att_state1.blendEnable = VK_TRUE;
3614 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3615 att_state2.blendEnable = VK_FALSE;
3616 pipeline.AddColorAttachment(0, &att_state1);
3617 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003618 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003619 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003620 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003621}
3622
Mike Weiblen40b160e2017-02-06 19:21:52 -07003623// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3624TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3625 TEST_DESCRIPTION(
3626 "Create a graphics pipeline that is incompatible with the requirements "
3627 "of its contained Renderpass/subpasses.");
Tony Barbour1fa09702017-03-16 12:09:08 -06003628 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen40b160e2017-02-06 19:21:52 -07003629
3630 VkDescriptorSetObj ds_obj(m_device);
3631 ds_obj.AppendDummy();
3632 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3633
3634 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3635
3636 VkPipelineColorBlendAttachmentState att_state1 = {};
3637 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3638 att_state1.blendEnable = VK_TRUE;
3639
3640 VkRenderpassObj rp_obj(m_device);
3641
3642 {
3643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3644 VkPipelineObj pipeline(m_device);
3645 pipeline.AddShader(&vs_obj);
3646 pipeline.AddColorAttachment(0, &att_state1);
3647
3648 VkGraphicsPipelineCreateInfo info = {};
3649 pipeline.InitGraphicsPipelineCreateInfo(&info);
3650 info.pColorBlendState = nullptr;
3651
3652 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3653 m_errorMonitor->VerifyFound();
3654 }
3655}
3656
Cort Stratton7547f772017-05-04 15:18:52 -07003657TEST_F(VkLayerTest, CreateRenderPassAttachments) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003658 TEST_DESCRIPTION(
Cort Stratton7547f772017-05-04 15:18:52 -07003659 "Ensure that CreateRenderPass produces the expected validation errors "
3660 "when a subpass's attachments violate the valid usage conditions.");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003661
Tony Barbour1fa09702017-03-16 12:09:08 -06003662 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003663
Cort Stratton7547f772017-05-04 15:18:52 -07003664 std::vector<VkAttachmentDescription> attachments = {
3665 // input attachments
3666 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3667 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_GENERAL,
3668 VK_IMAGE_LAYOUT_GENERAL},
3669 // color attachments
3670 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3671 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3672 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3673 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3674 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3675 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3676 // depth attachment
3677 {0, VK_FORMAT_D24_UNORM_S8_UINT, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3678 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
3679 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
3680 // resolve attachment
3681 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3682 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3683 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3684 // preserve attachments
3685 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3686 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3687 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3688 };
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003689
Cort Stratton7547f772017-05-04 15:18:52 -07003690 std::vector<VkAttachmentReference> input = {
3691 {0, VK_IMAGE_LAYOUT_GENERAL},
3692 };
3693 std::vector<VkAttachmentReference> color = {
3694 {1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {2, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3695 };
3696 VkAttachmentReference depth = {3, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
3697 std::vector<VkAttachmentReference> resolve = {
3698 {4, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3699 };
3700 std::vector<uint32_t> preserve = {5};
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003701
Cort Stratton7547f772017-05-04 15:18:52 -07003702 VkSubpassDescription subpass = {0,
3703 VK_PIPELINE_BIND_POINT_GRAPHICS,
3704 (uint32_t)input.size(),
3705 input.data(),
3706 (uint32_t)color.size(),
3707 color.data(),
3708 resolve.data(),
3709 &depth,
3710 (uint32_t)preserve.size(),
3711 preserve.data()};
3712
3713 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
3714 nullptr,
3715 0,
3716 (uint32_t)attachments.size(),
3717 attachments.data(),
3718 1,
3719 &subpass,
3720 0,
3721 nullptr};
3722
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003723 VkRenderPass rp;
Cort Stratton7547f772017-05-04 15:18:52 -07003724 VkResult err;
3725 // Test too many color attachments
3726 {
3727 std::vector<VkAttachmentReference> too_many_colors(m_device->props.limits.maxColorAttachments + 1, color[0]);
3728 subpass.colorAttachmentCount = (uint32_t)too_many_colors.size();
3729 subpass.pColorAttachments = too_many_colors.data();
3730 subpass.pResolveAttachments = NULL;
3731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00348);
3732 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3733 m_errorMonitor->VerifyFound();
3734 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3735 subpass.colorAttachmentCount = (uint32_t)color.size();
3736 subpass.pColorAttachments = color.data();
3737 subpass.pResolveAttachments = resolve.data();
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003738 }
Cort Stratton7547f772017-05-04 15:18:52 -07003739 // Test sample count mismatch between color buffers
3740 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_8_BIT;
3741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00337);
3742 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbesc5389742016-06-29 11:49:23 +12003743 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003744 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003745 attachments[subpass.pColorAttachments[1].attachment].samples = attachments[subpass.pColorAttachments[0].attachment].samples;
3746 // Test sample count mismatch between color buffers and depth buffer
3747 attachments[subpass.pDepthStencilAttachment->attachment].samples = VK_SAMPLE_COUNT_8_BIT;
3748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00337);
3749 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbesc5389742016-06-29 11:49:23 +12003750 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003751 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003752 attachments[subpass.pDepthStencilAttachment->attachment].samples = attachments[subpass.pColorAttachments[0].attachment].samples;
3753 // Test resolve attachment with UNUSED color attachment
3754 color[0].attachment = VK_ATTACHMENT_UNUSED;
3755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00350);
3756 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003757 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003758 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Cort Stratton7547f772017-05-04 15:18:52 -07003759 color[0].attachment = 1;
3760 // Test resolve from a single-sampled color attachment
3761 attachments[subpass.pColorAttachments[0].attachment].samples = VK_SAMPLE_COUNT_1_BIT;
3762 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_1_BIT; // avoid mismatch (00337)
3763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00351);
3764 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3765 m_errorMonitor->VerifyFound();
3766 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3767 attachments[subpass.pColorAttachments[0].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3768 attachments[subpass.pColorAttachments[1].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3769 // Test resolve to a multi-sampled resolve attachment
3770 attachments[subpass.pResolveAttachments[0].attachment].samples = VK_SAMPLE_COUNT_4_BIT;
3771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00352);
3772 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3773 m_errorMonitor->VerifyFound();
3774 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3775 attachments[subpass.pResolveAttachments[0].attachment].samples = VK_SAMPLE_COUNT_1_BIT;
3776 // Test with color/resolve format mismatch
3777 attachments[subpass.pColorAttachments[0].attachment].format = VK_FORMAT_R8G8B8A8_SRGB;
3778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00353);
3779 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3780 m_errorMonitor->VerifyFound();
3781 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3782 attachments[subpass.pColorAttachments[0].attachment].format = attachments[subpass.pResolveAttachments[0].attachment].format;
3783 // Test for UNUSED preserve attachments
3784 preserve[0] = VK_ATTACHMENT_UNUSED;
3785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00356);
3786 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3787 m_errorMonitor->VerifyFound();
3788 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3789 preserve[0] = 5;
3790 // Test for preserve attachments used elsewhere in the subpass
3791 color[0].attachment = preserve[0];
3792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00357);
3793 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3794 m_errorMonitor->VerifyFound();
3795 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3796 color[0].attachment = 1;
3797 // test for layout mismatch between input attachment and color attachment
3798 input[0].attachment = color[0].attachment;
3799 input[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00358);
3801 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3802 m_errorMonitor->VerifyFound();
3803 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3804 input[0].attachment = 0;
3805 input[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3806 // test for layout mismatch between input attachment and depth attachment
3807 input[0].attachment = depth.attachment;
3808 input[0].layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
3809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00358);
3810 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3811 m_errorMonitor->VerifyFound();
3812 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3813 input[0].attachment = 0;
3814 input[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3815 // Test for attachment used first as input with loadOp=CLEAR
3816 {
3817 std::vector<VkSubpassDescription> subpasses = {subpass, subpass, subpass};
3818 subpasses[0].inputAttachmentCount = 0;
3819 subpasses[1].inputAttachmentCount = 0;
3820 attachments[input[0].attachment].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
3821 VkRenderPassCreateInfo rpci_multipass = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
3822 nullptr,
3823 0,
3824 (uint32_t)attachments.size(),
3825 attachments.data(),
3826 (uint32_t)subpasses.size(),
3827 subpasses.data(),
3828 0,
3829 nullptr};
3830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00349);
3831 err = vkCreateRenderPass(m_device->device(), &rpci_multipass, nullptr, &rp);
3832 m_errorMonitor->VerifyFound();
3833 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
3834 attachments[input[0].attachment].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
3835 }
Chris Forbes3f128ef2016-06-29 14:58:53 +12003836}
3837
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003838TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003839 TEST_DESCRIPTION(
3840 "Hit errors when attempting to create a framebuffer :\n"
3841 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3842 " 2. Use a color image as depthStencil attachment\n"
3843 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3844 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3845 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3846 " 6. Framebuffer attachment where dimensions don't match\n"
Cort Stratton8133ec22017-04-27 16:25:03 +02003847 " 7. Framebuffer attachment where dimensions don't match\n"
3848 " 8. Framebuffer attachment w/o identity swizzle\n"
3849 " 9. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003850
Tony Barbour1fa09702017-03-16 12:09:08 -06003851 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3853
Cort Stratton8133ec22017-04-27 16:25:03 +02003854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00404);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003855
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003856 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003857 VkAttachmentReference attach = {};
3858 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3859 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003860 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003861 VkRenderPassCreateInfo rpci = {};
3862 rpci.subpassCount = 1;
3863 rpci.pSubpasses = &subpass;
3864 rpci.attachmentCount = 1;
3865 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003866 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003867 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003868 rpci.pAttachments = &attach_desc;
3869 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3870 VkRenderPass rp;
3871 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3872 ASSERT_VK_SUCCESS(err);
3873
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003874 VkImageView ivs[2];
3875 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3876 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003877 VkFramebufferCreateInfo fb_info = {};
3878 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3879 fb_info.pNext = NULL;
3880 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003881 // Set mis-matching attachmentCount
3882 fb_info.attachmentCount = 2;
3883 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003884 fb_info.width = 100;
3885 fb_info.height = 100;
3886 fb_info.layers = 1;
3887
3888 VkFramebuffer fb;
3889 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3890
3891 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003892 if (err == VK_SUCCESS) {
3893 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3894 }
3895 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003896
3897 // Create a renderPass with a depth-stencil attachment created with
3898 // IMAGE_USAGE_COLOR_ATTACHMENT
3899 // Add our color attachment to pDepthStencilAttachment
3900 subpass.pDepthStencilAttachment = &attach;
3901 subpass.pColorAttachments = NULL;
3902 VkRenderPass rp_ds;
3903 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3904 ASSERT_VK_SUCCESS(err);
3905 // Set correct attachment count, but attachment has COLOR usage bit set
3906 fb_info.attachmentCount = 1;
3907 fb_info.renderPass = rp_ds;
3908
Cort Stratton8133ec22017-04-27 16:25:03 +02003909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00406);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003910 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3911
3912 m_errorMonitor->VerifyFound();
3913 if (err == VK_SUCCESS) {
3914 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3915 }
3916 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003917
3918 // Create new renderpass with alternate attachment format from fb
3919 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3920 subpass.pDepthStencilAttachment = NULL;
3921 subpass.pColorAttachments = &attach;
3922 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3923 ASSERT_VK_SUCCESS(err);
3924
3925 // Cause error due to mis-matched formats between rp & fb
3926 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3927 fb_info.renderPass = rp;
Cort Stratton8133ec22017-04-27 16:25:03 +02003928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00408);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003929 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3930
3931 m_errorMonitor->VerifyFound();
3932 if (err == VK_SUCCESS) {
3933 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3934 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003935 vkDestroyRenderPass(m_device->device(), rp, NULL);
3936
3937 // Create new renderpass with alternate sample count from fb
3938 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3939 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3940 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3941 ASSERT_VK_SUCCESS(err);
3942
3943 // Cause error due to mis-matched sample count between rp & fb
3944 fb_info.renderPass = rp;
Cort Stratton8133ec22017-04-27 16:25:03 +02003945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00409);
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003946 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3947
3948 m_errorMonitor->VerifyFound();
3949 if (err == VK_SUCCESS) {
3950 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3951 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003952
3953 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003954
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003955 {
3956 // Create an image with 2 mip levels.
3957 VkImageObj image(m_device);
3958 image.Init(128, 128, 2, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
3959 ASSERT_TRUE(image.initialized());
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003960
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003961 // Create a image view with two mip levels.
3962 VkImageView view;
3963 VkImageViewCreateInfo ivci = {};
3964 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3965 ivci.image = image.handle();
3966 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3967 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3968 ivci.subresourceRange.layerCount = 1;
3969 ivci.subresourceRange.baseMipLevel = 0;
3970 // Set level count to 2 (only 1 is allowed for FB attachment)
3971 ivci.subresourceRange.levelCount = 2;
3972 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3973 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3974 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003975
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003976 // Re-create renderpass to have matching sample count
3977 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3978 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3979 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003980
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003981 fb_info.renderPass = rp;
3982 fb_info.pAttachments = &view;
Cort Stratton8133ec22017-04-27 16:25:03 +02003983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00411);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003984 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3985
3986 m_errorMonitor->VerifyFound();
3987 if (err == VK_SUCCESS) {
3988 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3989 }
3990 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003991 }
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06003992
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003993 // Update view to original color buffer and grow FB dimensions too big
3994 fb_info.pAttachments = ivs;
3995 fb_info.height = 1024;
3996 fb_info.width = 1024;
3997 fb_info.layers = 2;
Cort Stratton8133ec22017-04-27 16:25:03 +02003998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003999 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4000
4001 m_errorMonitor->VerifyFound();
4002 if (err == VK_SUCCESS) {
4003 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4004 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004005
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004006 {
4007 // Create an image with one mip level.
4008 VkImageObj image(m_device);
4009 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4010 ASSERT_TRUE(image.initialized());
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004011
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004012 // Create view attachment with non-identity swizzle
4013 VkImageView view;
4014 VkImageViewCreateInfo ivci = {};
4015 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4016 ivci.image = image.handle();
4017 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4018 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4019 ivci.subresourceRange.layerCount = 1;
4020 ivci.subresourceRange.baseMipLevel = 0;
4021 ivci.subresourceRange.levelCount = 1;
4022 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4023 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4024 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4025 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4026 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4027 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4028 ASSERT_VK_SUCCESS(err);
4029
4030 fb_info.pAttachments = &view;
4031 fb_info.height = 100;
4032 fb_info.width = 100;
4033 fb_info.layers = 1;
4034
Cort Stratton8133ec22017-04-27 16:25:03 +02004035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00412);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004036 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4037
4038 m_errorMonitor->VerifyFound();
4039 if (err == VK_SUCCESS) {
4040 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4041 }
4042 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004043 }
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06004044
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004045 // reset attachment to color attachment
4046 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004047
4048 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004049 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004050 fb_info.height = 100;
4051 fb_info.layers = 1;
4052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Cort Stratton8133ec22017-04-27 16:25:03 +02004053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004054 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004055 m_errorMonitor->VerifyFound();
4056 if (err == VK_SUCCESS) {
4057 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4058 }
4059 // and width=0
4060 fb_info.width = 0;
4061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02806);
4062 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004063 m_errorMonitor->VerifyFound();
4064 if (err == VK_SUCCESS) {
4065 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4066 }
4067
4068 // Request fb that exceeds max height
4069 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004070 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004071 fb_info.layers = 1;
4072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Cort Stratton8133ec22017-04-27 16:25:03 +02004073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004074 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004075 m_errorMonitor->VerifyFound();
4076 if (err == VK_SUCCESS) {
4077 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4078 }
4079 // and height=0
4080 fb_info.height = 0;
4081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02807);
4082 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004083 m_errorMonitor->VerifyFound();
4084 if (err == VK_SUCCESS) {
4085 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4086 }
4087
4088 // Request fb that exceeds max layers
4089 fb_info.width = 100;
4090 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004091 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Cort Stratton8133ec22017-04-27 16:25:03 +02004093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00410);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004094 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Cort Stratton8133ec22017-04-27 16:25:03 +02004095 m_errorMonitor->VerifyFound();
4096 if (err == VK_SUCCESS) {
4097 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4098 }
4099 // and layers=0
4100 fb_info.layers = 0;
4101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02808);
4102 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004103 m_errorMonitor->VerifyFound();
4104 if (err == VK_SUCCESS) {
4105 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4106 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004107
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004108 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004109}
4110
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004111TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004112 TEST_DESCRIPTION(
4113 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4114 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004115
Tony Barbour1fa09702017-03-16 12:09:08 -06004116 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004117 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4119 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004120 m_errorMonitor->VerifyFound();
4121}
4122
4123TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004124 TEST_DESCRIPTION(
4125 "Run a simple draw calls to validate failure when Line Width dynamic "
4126 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004127
Tony Barbour1fa09702017-03-16 12:09:08 -06004128 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004129 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4131 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004132 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004133}
4134
4135TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004136 TEST_DESCRIPTION(
4137 "Run a simple draw calls to validate failure when Viewport dynamic "
4138 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004139
Tony Barbour1fa09702017-03-16 12:09:08 -06004140 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004141 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4143 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004144 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004145 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004146}
4147
4148TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004149 TEST_DESCRIPTION(
4150 "Run a simple draw calls to validate failure when Scissor dynamic "
4151 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004152
Tony Barbour1fa09702017-03-16 12:09:08 -06004153 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004154 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4156 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004157 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004158 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004159}
4160
Cortd713fe82016-07-27 09:51:27 -07004161TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004162 TEST_DESCRIPTION(
4163 "Run a simple draw calls to validate failure when Blend Constants "
4164 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004165
Tony Barbour1fa09702017-03-16 12:09:08 -06004166 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004167 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4169 "Dynamic blend constants state not set for this command buffer");
4170 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004171 m_errorMonitor->VerifyFound();
4172}
4173
4174TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004175 TEST_DESCRIPTION(
4176 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4177 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004178
Tony Barbour1fa09702017-03-16 12:09:08 -06004179 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004180 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004181 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004182 return;
4183 }
4184 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4186 "Dynamic depth bounds state not set for this command buffer");
4187 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004188 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004189}
4190
4191TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004192 TEST_DESCRIPTION(
4193 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4194 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004195
Tony Barbour1fa09702017-03-16 12:09:08 -06004196 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004197 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4199 "Dynamic stencil read mask state not set for this command buffer");
4200 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004201 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004202}
4203
4204TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004205 TEST_DESCRIPTION(
4206 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4207 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004208
Tony Barbour1fa09702017-03-16 12:09:08 -06004209 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004210 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4212 "Dynamic stencil write mask state not set for this command buffer");
4213 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004214 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004215}
4216
4217TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004218 TEST_DESCRIPTION(
4219 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4220 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004221
Tony Barbour1fa09702017-03-16 12:09:08 -06004222 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004223 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4225 "Dynamic stencil reference state not set for this command buffer");
4226 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004227 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004228}
4229
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004230TEST_F(VkLayerTest, IndexBufferNotBound) {
4231 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004232
Tony Barbour1fa09702017-03-16 12:09:08 -06004233 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4235 "Index buffer object not bound to this command buffer when Indexed ");
4236 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004237 m_errorMonitor->VerifyFound();
4238}
4239
Karl Schultz6addd812016-02-02 17:17:23 -07004240TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4242 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4243 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004244
Tony Barbour1fa09702017-03-16 12:09:08 -06004245 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004246 ASSERT_NO_FATAL_FAILURE(InitViewport());
4247 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4248
Karl Schultz6addd812016-02-02 17:17:23 -07004249 // We luck out b/c by default the framework creates CB w/ the
4250 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004251 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004252 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004253 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004254
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004255 // Bypass framework since it does the waits automatically
4256 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004257 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004258 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4259 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004260 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004261 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004262 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004263 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004264 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004265 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004266 submit_info.pSignalSemaphores = NULL;
4267
Chris Forbes40028e22016-06-13 09:59:34 +12004268 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004269 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004270 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004271
Karl Schultz6addd812016-02-02 17:17:23 -07004272 // Cause validation error by re-submitting cmd buffer that should only be
4273 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004274 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004275 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004276
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004277 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004278}
4279
Karl Schultz6addd812016-02-02 17:17:23 -07004280TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004281 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004282 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004283
Tony Barbour1fa09702017-03-16 12:09:08 -06004284 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004286
Karl Schultz6addd812016-02-02 17:17:23 -07004287 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4288 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004289 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004290 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004291 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004292
4293 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004294 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4295 ds_pool_ci.pNext = NULL;
4296 ds_pool_ci.flags = 0;
4297 ds_pool_ci.maxSets = 1;
4298 ds_pool_ci.poolSizeCount = 1;
4299 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004300
4301 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004302 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004303 ASSERT_VK_SUCCESS(err);
4304
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004305 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4306 dsl_binding_samp.binding = 0;
4307 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4308 dsl_binding_samp.descriptorCount = 1;
4309 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4310 dsl_binding_samp.pImmutableSamplers = NULL;
4311
4312 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4313 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4314 ds_layout_ci.pNext = NULL;
4315 ds_layout_ci.bindingCount = 1;
4316 ds_layout_ci.pBindings = &dsl_binding_samp;
4317
4318 VkDescriptorSetLayout ds_layout_samp;
4319 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4320 ASSERT_VK_SUCCESS(err);
4321
4322 // Try to allocate 2 sets when pool only has 1 set
4323 VkDescriptorSet descriptor_sets[2];
4324 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4325 VkDescriptorSetAllocateInfo alloc_info = {};
4326 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4327 alloc_info.descriptorSetCount = 2;
4328 alloc_info.descriptorPool = ds_pool;
4329 alloc_info.pSetLayouts = set_layouts;
4330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4331 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4332 m_errorMonitor->VerifyFound();
4333
4334 alloc_info.descriptorSetCount = 1;
4335 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004336 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004337 dsl_binding.binding = 0;
4338 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4339 dsl_binding.descriptorCount = 1;
4340 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4341 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004342
Karl Schultz6addd812016-02-02 17:17:23 -07004343 ds_layout_ci.bindingCount = 1;
4344 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004345
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004346 VkDescriptorSetLayout ds_layout_ub;
4347 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004348 ASSERT_VK_SUCCESS(err);
4349
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004350 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004351 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004352 alloc_info.pSetLayouts = &ds_layout_ub;
4353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4354 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004355
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004356 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004357
Karl Schultz2825ab92016-12-02 08:23:14 -07004358 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004359 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004360 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004361}
4362
Karl Schultz6addd812016-02-02 17:17:23 -07004363TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4364 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004365
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004367
Tony Barbour1fa09702017-03-16 12:09:08 -06004368 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise735c692015-10-08 13:13:50 -06004369 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004370
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004371 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004372 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4373 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004374
4375 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004376 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4377 ds_pool_ci.pNext = NULL;
4378 ds_pool_ci.maxSets = 1;
4379 ds_pool_ci.poolSizeCount = 1;
4380 ds_pool_ci.flags = 0;
4381 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4382 // app can only call vkResetDescriptorPool on this pool.;
4383 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004384
4385 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004386 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004387 ASSERT_VK_SUCCESS(err);
4388
4389 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004390 dsl_binding.binding = 0;
4391 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4392 dsl_binding.descriptorCount = 1;
4393 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4394 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004395
4396 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004397 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4398 ds_layout_ci.pNext = NULL;
4399 ds_layout_ci.bindingCount = 1;
4400 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004401
4402 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004403 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004404 ASSERT_VK_SUCCESS(err);
4405
4406 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004407 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004408 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004409 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004410 alloc_info.descriptorPool = ds_pool;
4411 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004412 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004413 ASSERT_VK_SUCCESS(err);
4414
4415 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004416 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004417
Chia-I Wuf7458c52015-10-26 21:10:41 +08004418 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4419 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004420}
4421
Karl Schultz6addd812016-02-02 17:17:23 -07004422TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004423 // Attempt to clear Descriptor Pool with bad object.
4424 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004425
Tony Barbour1fa09702017-03-16 12:09:08 -06004426 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004428 uint64_t fake_pool_handle = 0xbaad6001;
4429 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4430 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004431 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004432}
4433
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004434TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004435 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4436 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004437 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004438 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004439
4440 uint64_t fake_set_handle = 0xbaad6001;
4441 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004442 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004444
Tony Barbour1fa09702017-03-16 12:09:08 -06004445 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -06004446
4447 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4448 layout_bindings[0].binding = 0;
4449 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4450 layout_bindings[0].descriptorCount = 1;
4451 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4452 layout_bindings[0].pImmutableSamplers = NULL;
4453
4454 VkDescriptorSetLayout descriptor_set_layout;
4455 VkDescriptorSetLayoutCreateInfo dslci = {};
4456 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4457 dslci.pNext = NULL;
4458 dslci.bindingCount = 1;
4459 dslci.pBindings = layout_bindings;
4460 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004461 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004462
4463 VkPipelineLayout pipeline_layout;
4464 VkPipelineLayoutCreateInfo plci = {};
4465 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4466 plci.pNext = NULL;
4467 plci.setLayoutCount = 1;
4468 plci.pSetLayouts = &descriptor_set_layout;
4469 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004470 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004471
Tony Barbour552f6c02016-12-21 14:34:07 -07004472 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004473 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4474 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004475 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004476 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004477 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4478 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004479}
4480
Karl Schultz6addd812016-02-02 17:17:23 -07004481TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004482 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4483 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004484 uint64_t fake_layout_handle = 0xbaad6001;
4485 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Tony Barbour1fa09702017-03-16 12:09:08 -06004487 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -06004488 VkPipelineLayout pipeline_layout;
4489 VkPipelineLayoutCreateInfo plci = {};
4490 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4491 plci.pNext = NULL;
4492 plci.setLayoutCount = 1;
4493 plci.pSetLayouts = &bad_layout;
4494 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4495
4496 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004497}
4498
Mark Muellerd4914412016-06-13 17:52:06 -06004499TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004500 TEST_DESCRIPTION(
4501 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4502 "1) A uniform buffer update must have a valid buffer index."
4503 "2) When using an array of descriptors in a single WriteDescriptor,"
4504 " the descriptor types and stageflags must all be the same."
4505 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004506
Mike Weiblena6666382017-01-05 15:16:11 -07004507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004508
Tony Barbour1fa09702017-03-16 12:09:08 -06004509 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerd4914412016-06-13 17:52:06 -06004510 VkDescriptorPoolSize ds_type_count[4] = {};
4511 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4512 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004513 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004514 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004515 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004516 ds_type_count[2].descriptorCount = 1;
4517 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4518 ds_type_count[3].descriptorCount = 1;
4519
4520 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4521 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4522 ds_pool_ci.maxSets = 1;
4523 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4524 ds_pool_ci.pPoolSizes = ds_type_count;
4525
4526 VkDescriptorPool ds_pool;
4527 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4528 ASSERT_VK_SUCCESS(err);
4529
Mark Muellerb9896722016-06-16 09:54:29 -06004530 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004531 layout_binding[0].binding = 0;
4532 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4533 layout_binding[0].descriptorCount = 1;
4534 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4535 layout_binding[0].pImmutableSamplers = NULL;
4536
4537 layout_binding[1].binding = 1;
4538 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4539 layout_binding[1].descriptorCount = 1;
4540 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4541 layout_binding[1].pImmutableSamplers = NULL;
4542
4543 VkSamplerCreateInfo sampler_ci = {};
4544 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4545 sampler_ci.pNext = NULL;
4546 sampler_ci.magFilter = VK_FILTER_NEAREST;
4547 sampler_ci.minFilter = VK_FILTER_NEAREST;
4548 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4549 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4550 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4551 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4552 sampler_ci.mipLodBias = 1.0;
4553 sampler_ci.anisotropyEnable = VK_FALSE;
4554 sampler_ci.maxAnisotropy = 1;
4555 sampler_ci.compareEnable = VK_FALSE;
4556 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4557 sampler_ci.minLod = 1.0;
4558 sampler_ci.maxLod = 1.0;
4559 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4560 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4561 VkSampler sampler;
4562
4563 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4564 ASSERT_VK_SUCCESS(err);
4565
4566 layout_binding[2].binding = 2;
4567 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4568 layout_binding[2].descriptorCount = 1;
4569 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4570 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4571
Mark Muellerd4914412016-06-13 17:52:06 -06004572 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4573 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4574 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4575 ds_layout_ci.pBindings = layout_binding;
4576 VkDescriptorSetLayout ds_layout;
4577 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4578 ASSERT_VK_SUCCESS(err);
4579
4580 VkDescriptorSetAllocateInfo alloc_info = {};
4581 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4582 alloc_info.descriptorSetCount = 1;
4583 alloc_info.descriptorPool = ds_pool;
4584 alloc_info.pSetLayouts = &ds_layout;
4585 VkDescriptorSet descriptorSet;
4586 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4587 ASSERT_VK_SUCCESS(err);
4588
4589 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4590 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4591 pipeline_layout_ci.pNext = NULL;
4592 pipeline_layout_ci.setLayoutCount = 1;
4593 pipeline_layout_ci.pSetLayouts = &ds_layout;
4594
4595 VkPipelineLayout pipeline_layout;
4596 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4597 ASSERT_VK_SUCCESS(err);
4598
Mark Mueller5c838ce2016-06-16 09:54:29 -06004599 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004600 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4601 descriptor_write.dstSet = descriptorSet;
4602 descriptor_write.dstBinding = 0;
4603 descriptor_write.descriptorCount = 1;
4604 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4605
Mark Mueller5c838ce2016-06-16 09:54:29 -06004606 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004607 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4608 m_errorMonitor->VerifyFound();
4609
4610 // Create a buffer to update the descriptor with
4611 uint32_t qfi = 0;
4612 VkBufferCreateInfo buffCI = {};
4613 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4614 buffCI.size = 1024;
4615 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4616 buffCI.queueFamilyIndexCount = 1;
4617 buffCI.pQueueFamilyIndices = &qfi;
4618
4619 VkBuffer dyub;
4620 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4621 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004622
Tony Barboure132c5f2016-12-12 11:50:20 -07004623 VkDeviceMemory mem;
4624 VkMemoryRequirements mem_reqs;
4625 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4626
4627 VkMemoryAllocateInfo mem_alloc_info = {};
4628 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4629 mem_alloc_info.allocationSize = mem_reqs.size;
4630 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4631 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4632 ASSERT_VK_SUCCESS(err);
4633
4634 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4635 ASSERT_VK_SUCCESS(err);
4636
4637 VkDescriptorBufferInfo buffInfo[2] = {};
4638 buffInfo[0].buffer = dyub;
4639 buffInfo[0].offset = 0;
4640 buffInfo[0].range = 1024;
4641 buffInfo[1].buffer = dyub;
4642 buffInfo[1].offset = 0;
4643 buffInfo[1].range = 1024;
4644 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004645 descriptor_write.descriptorCount = 2;
4646
Mark Mueller5c838ce2016-06-16 09:54:29 -06004647 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004649 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4650 m_errorMonitor->VerifyFound();
4651
Mark Mueller5c838ce2016-06-16 09:54:29 -06004652 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4653 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004654 descriptor_write.dstBinding = 1;
4655 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004656
Mark Mueller5c838ce2016-06-16 09:54:29 -06004657 // Make pImageInfo index non-null to avoid complaints of it missing
4658 VkDescriptorImageInfo imageInfo = {};
4659 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4660 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004662 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4663 m_errorMonitor->VerifyFound();
4664
Mark Muellerd4914412016-06-13 17:52:06 -06004665 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004666 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004667 vkDestroySampler(m_device->device(), sampler, NULL);
4668 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4669 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4670 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4671}
4672
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004673TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004674 TEST_DESCRIPTION(
4675 "Attempt to draw with a command buffer that is invalid "
4676 "due to a buffer dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004677 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004678
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004679 VkBuffer buffer;
4680 VkDeviceMemory mem;
4681 VkMemoryRequirements mem_reqs;
4682
4683 VkBufferCreateInfo buf_info = {};
4684 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004685 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004686 buf_info.size = 256;
4687 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4688 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4689 ASSERT_VK_SUCCESS(err);
4690
4691 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4692
4693 VkMemoryAllocateInfo alloc_info = {};
4694 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4695 alloc_info.allocationSize = 256;
4696 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004697 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004698 if (!pass) {
4699 vkDestroyBuffer(m_device->device(), buffer, NULL);
4700 return;
4701 }
4702 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4703 ASSERT_VK_SUCCESS(err);
4704
4705 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4706 ASSERT_VK_SUCCESS(err);
4707
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004708 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004709 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004710 m_commandBuffer->EndCommandBuffer();
4711
Mark Lobodzinski33826372017-04-13 11:10:11 -06004712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004713 // Destroy buffer dependency prior to submit to cause ERROR
4714 vkDestroyBuffer(m_device->device(), buffer, NULL);
4715
4716 VkSubmitInfo submit_info = {};
4717 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4718 submit_info.commandBufferCount = 1;
4719 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4720 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4721
4722 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004723 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004724 vkFreeMemory(m_device->handle(), mem, NULL);
4725}
4726
Tobin Ehlisea413442016-09-28 10:23:59 -06004727TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4728 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4729
Tony Barbour1fa09702017-03-16 12:09:08 -06004730 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisea413442016-09-28 10:23:59 -06004731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4732
4733 VkDescriptorPoolSize ds_type_count;
4734 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4735 ds_type_count.descriptorCount = 1;
4736
4737 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4738 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4739 ds_pool_ci.maxSets = 1;
4740 ds_pool_ci.poolSizeCount = 1;
4741 ds_pool_ci.pPoolSizes = &ds_type_count;
4742
4743 VkDescriptorPool ds_pool;
4744 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4745 ASSERT_VK_SUCCESS(err);
4746
4747 VkDescriptorSetLayoutBinding layout_binding;
4748 layout_binding.binding = 0;
4749 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4750 layout_binding.descriptorCount = 1;
4751 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4752 layout_binding.pImmutableSamplers = NULL;
4753
4754 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4755 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4756 ds_layout_ci.bindingCount = 1;
4757 ds_layout_ci.pBindings = &layout_binding;
4758 VkDescriptorSetLayout ds_layout;
4759 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4760 ASSERT_VK_SUCCESS(err);
4761
4762 VkDescriptorSetAllocateInfo alloc_info = {};
4763 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4764 alloc_info.descriptorSetCount = 1;
4765 alloc_info.descriptorPool = ds_pool;
4766 alloc_info.pSetLayouts = &ds_layout;
4767 VkDescriptorSet descriptor_set;
4768 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4769 ASSERT_VK_SUCCESS(err);
4770
4771 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4772 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4773 pipeline_layout_ci.pNext = NULL;
4774 pipeline_layout_ci.setLayoutCount = 1;
4775 pipeline_layout_ci.pSetLayouts = &ds_layout;
4776
4777 VkPipelineLayout pipeline_layout;
4778 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4779 ASSERT_VK_SUCCESS(err);
4780
4781 VkBuffer buffer;
4782 uint32_t queue_family_index = 0;
4783 VkBufferCreateInfo buffer_create_info = {};
4784 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4785 buffer_create_info.size = 1024;
4786 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4787 buffer_create_info.queueFamilyIndexCount = 1;
4788 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4789
4790 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4791 ASSERT_VK_SUCCESS(err);
4792
4793 VkMemoryRequirements memory_reqs;
4794 VkDeviceMemory buffer_memory;
4795
4796 VkMemoryAllocateInfo memory_info = {};
4797 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4798 memory_info.allocationSize = 0;
4799 memory_info.memoryTypeIndex = 0;
4800
4801 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4802 memory_info.allocationSize = memory_reqs.size;
4803 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4804 ASSERT_TRUE(pass);
4805
4806 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4807 ASSERT_VK_SUCCESS(err);
4808 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4809 ASSERT_VK_SUCCESS(err);
4810
4811 VkBufferView view;
4812 VkBufferViewCreateInfo bvci = {};
4813 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4814 bvci.buffer = buffer;
4815 bvci.format = VK_FORMAT_R8_UNORM;
4816 bvci.range = VK_WHOLE_SIZE;
4817
4818 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4819 ASSERT_VK_SUCCESS(err);
4820
4821 VkWriteDescriptorSet descriptor_write = {};
4822 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4823 descriptor_write.dstSet = descriptor_set;
4824 descriptor_write.dstBinding = 0;
4825 descriptor_write.descriptorCount = 1;
4826 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4827 descriptor_write.pTexelBufferView = &view;
4828
4829 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4830
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004831 char const *vsSource =
4832 "#version 450\n"
4833 "\n"
4834 "out gl_PerVertex { \n"
4835 " vec4 gl_Position;\n"
4836 "};\n"
4837 "void main(){\n"
4838 " gl_Position = vec4(1);\n"
4839 "}\n";
4840 char const *fsSource =
4841 "#version 450\n"
4842 "\n"
4843 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4844 "layout(location=0) out vec4 x;\n"
4845 "void main(){\n"
4846 " x = imageLoad(s, 0);\n"
4847 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004848 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4849 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4850 VkPipelineObj pipe(m_device);
4851 pipe.AddShader(&vs);
4852 pipe.AddShader(&fs);
4853 pipe.AddColorAttachment();
4854 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4855
Mark Lobodzinski33826372017-04-13 11:10:11 -06004856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound BufferView ");
Tobin Ehlisea413442016-09-28 10:23:59 -06004857
Tony Barbour552f6c02016-12-21 14:34:07 -07004858 m_commandBuffer->BeginCommandBuffer();
4859 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4860
Tobin Ehlisea413442016-09-28 10:23:59 -06004861 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4862 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4863 VkRect2D scissor = {{0, 0}, {16, 16}};
4864 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4865 // Bind pipeline to cmd buffer
4866 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4867 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4868 &descriptor_set, 0, nullptr);
4869 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004870 m_commandBuffer->EndRenderPass();
4871 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004872
4873 // Delete BufferView in order to invalidate cmd buffer
4874 vkDestroyBufferView(m_device->device(), view, NULL);
4875 // Now attempt submit of cmd buffer
4876 VkSubmitInfo submit_info = {};
4877 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4878 submit_info.commandBufferCount = 1;
4879 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4880 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4881 m_errorMonitor->VerifyFound();
4882
4883 // Clean-up
4884 vkDestroyBuffer(m_device->device(), buffer, NULL);
4885 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4886 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4887 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4888 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4889}
4890
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004891TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004892 TEST_DESCRIPTION(
4893 "Attempt to draw with a command buffer that is invalid "
4894 "due to an image dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004895 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004896
4897 VkImage image;
4898 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4899 VkImageCreateInfo image_create_info = {};
4900 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4901 image_create_info.pNext = NULL;
4902 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4903 image_create_info.format = tex_format;
4904 image_create_info.extent.width = 32;
4905 image_create_info.extent.height = 32;
4906 image_create_info.extent.depth = 1;
4907 image_create_info.mipLevels = 1;
4908 image_create_info.arrayLayers = 1;
4909 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4910 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004911 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004912 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004913 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004914 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004915 // Have to bind memory to image before recording cmd in cmd buffer using it
4916 VkMemoryRequirements mem_reqs;
4917 VkDeviceMemory image_mem;
4918 bool pass;
4919 VkMemoryAllocateInfo mem_alloc = {};
4920 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4921 mem_alloc.pNext = NULL;
4922 mem_alloc.memoryTypeIndex = 0;
4923 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4924 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004925 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004926 ASSERT_TRUE(pass);
4927 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4928 ASSERT_VK_SUCCESS(err);
4929 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4930 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004931
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004932 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004933 VkClearColorValue ccv;
4934 ccv.float32[0] = 1.0f;
4935 ccv.float32[1] = 1.0f;
4936 ccv.float32[2] = 1.0f;
4937 ccv.float32[3] = 1.0f;
4938 VkImageSubresourceRange isr = {};
4939 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004940 isr.baseArrayLayer = 0;
4941 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004942 isr.layerCount = 1;
4943 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004944 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004945 m_commandBuffer->EndCommandBuffer();
4946
Mark Lobodzinski33826372017-04-13 11:10:11 -06004947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004948 // Destroy image dependency prior to submit to cause ERROR
4949 vkDestroyImage(m_device->device(), image, NULL);
4950
4951 VkSubmitInfo submit_info = {};
4952 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4953 submit_info.commandBufferCount = 1;
4954 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4955 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4956
4957 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004958 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004959}
4960
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004961TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004962 TEST_DESCRIPTION(
4963 "Attempt to draw with a command buffer that is invalid "
4964 "due to a framebuffer image dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06004965 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004966 VkFormatProperties format_properties;
4967 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004968 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4969 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004970 return;
4971 }
4972
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4974
4975 VkImageCreateInfo image_ci = {};
4976 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4977 image_ci.pNext = NULL;
4978 image_ci.imageType = VK_IMAGE_TYPE_2D;
4979 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4980 image_ci.extent.width = 32;
4981 image_ci.extent.height = 32;
4982 image_ci.extent.depth = 1;
4983 image_ci.mipLevels = 1;
4984 image_ci.arrayLayers = 1;
4985 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4986 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004987 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004988 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4989 image_ci.flags = 0;
4990 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004991 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004992
4993 VkMemoryRequirements memory_reqs;
4994 VkDeviceMemory image_memory;
4995 bool pass;
4996 VkMemoryAllocateInfo memory_info = {};
4997 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4998 memory_info.pNext = NULL;
4999 memory_info.allocationSize = 0;
5000 memory_info.memoryTypeIndex = 0;
5001 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5002 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005003 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005004 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005005 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005006 ASSERT_VK_SUCCESS(err);
5007 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5008 ASSERT_VK_SUCCESS(err);
5009
5010 VkImageViewCreateInfo ivci = {
5011 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5012 nullptr,
5013 0,
5014 image,
5015 VK_IMAGE_VIEW_TYPE_2D,
5016 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005017 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005018 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5019 };
5020 VkImageView view;
5021 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5022 ASSERT_VK_SUCCESS(err);
5023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005024 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005025 VkFramebuffer fb;
5026 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5027 ASSERT_VK_SUCCESS(err);
5028
5029 // Just use default renderpass with our framebuffer
5030 m_renderPassBeginInfo.framebuffer = fb;
Jeremy Hayesba817e12017-03-03 15:51:11 -07005031 m_renderPassBeginInfo.renderArea.extent.width = 32;
5032 m_renderPassBeginInfo.renderArea.extent.height = 32;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005033 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005034 m_commandBuffer->BeginCommandBuffer();
5035 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5036 m_commandBuffer->EndRenderPass();
5037 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005038 // Destroy image attached to framebuffer to invalidate cmd buffer
5039 vkDestroyImage(m_device->device(), image, NULL);
5040 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinski33826372017-04-13 11:10:11 -06005041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005042 QueueCommandBuffer(false);
5043 m_errorMonitor->VerifyFound();
5044
5045 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5046 vkDestroyImageView(m_device->device(), view, nullptr);
5047 vkFreeMemory(m_device->device(), image_memory, nullptr);
5048}
5049
Tobin Ehlisb329f992016-10-12 13:20:29 -06005050TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5051 TEST_DESCRIPTION("Delete in-use framebuffer.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005052 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb329f992016-10-12 13:20:29 -06005053 VkFormatProperties format_properties;
5054 VkResult err = VK_SUCCESS;
5055 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5056
Tobin Ehlisb329f992016-10-12 13:20:29 -06005057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5058
5059 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06005060 image.Init(256, 256, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005061 ASSERT_TRUE(image.initialized());
5062 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5063
5064 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5065 VkFramebuffer fb;
5066 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5067 ASSERT_VK_SUCCESS(err);
5068
5069 // Just use default renderpass with our framebuffer
5070 m_renderPassBeginInfo.framebuffer = fb;
5071 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005072 m_commandBuffer->BeginCommandBuffer();
5073 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5074 m_commandBuffer->EndRenderPass();
5075 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005076 // Submit cmd buffer to put it in-flight
5077 VkSubmitInfo submit_info = {};
5078 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5079 submit_info.commandBufferCount = 1;
5080 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5081 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5082 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005084 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5085 m_errorMonitor->VerifyFound();
5086 // Wait for queue to complete so we can safely destroy everything
5087 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005088 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5089 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005090 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5091}
5092
Tobin Ehlis88becd72016-09-21 14:33:41 -06005093TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5094 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005095 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis88becd72016-09-21 14:33:41 -06005096 VkFormatProperties format_properties;
5097 VkResult err = VK_SUCCESS;
5098 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005099
Tobin Ehlis88becd72016-09-21 14:33:41 -06005100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5101
5102 VkImageCreateInfo image_ci = {};
5103 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5104 image_ci.pNext = NULL;
5105 image_ci.imageType = VK_IMAGE_TYPE_2D;
5106 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5107 image_ci.extent.width = 256;
5108 image_ci.extent.height = 256;
5109 image_ci.extent.depth = 1;
5110 image_ci.mipLevels = 1;
5111 image_ci.arrayLayers = 1;
5112 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5113 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005114 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005115 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5116 image_ci.flags = 0;
5117 VkImage image;
5118 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5119
5120 VkMemoryRequirements memory_reqs;
5121 VkDeviceMemory image_memory;
5122 bool pass;
5123 VkMemoryAllocateInfo memory_info = {};
5124 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5125 memory_info.pNext = NULL;
5126 memory_info.allocationSize = 0;
5127 memory_info.memoryTypeIndex = 0;
5128 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5129 memory_info.allocationSize = memory_reqs.size;
5130 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5131 ASSERT_TRUE(pass);
5132 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5133 ASSERT_VK_SUCCESS(err);
5134 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5135 ASSERT_VK_SUCCESS(err);
5136
5137 VkImageViewCreateInfo ivci = {
5138 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5139 nullptr,
5140 0,
5141 image,
5142 VK_IMAGE_VIEW_TYPE_2D,
5143 VK_FORMAT_B8G8R8A8_UNORM,
5144 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5145 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5146 };
5147 VkImageView view;
5148 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5149 ASSERT_VK_SUCCESS(err);
5150
5151 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5152 VkFramebuffer fb;
5153 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5154 ASSERT_VK_SUCCESS(err);
5155
5156 // Just use default renderpass with our framebuffer
5157 m_renderPassBeginInfo.framebuffer = fb;
5158 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005159 m_commandBuffer->BeginCommandBuffer();
5160 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5161 m_commandBuffer->EndRenderPass();
5162 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005163 // Submit cmd buffer to put it (and attached imageView) in-flight
5164 VkSubmitInfo submit_info = {};
5165 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5166 submit_info.commandBufferCount = 1;
5167 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5168 // Submit cmd buffer to put framebuffer and children in-flight
5169 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5170 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005172 vkDestroyImage(m_device->device(), image, NULL);
5173 m_errorMonitor->VerifyFound();
5174 // Wait for queue to complete so we can safely destroy image and other objects
5175 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005176 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5177 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005178 vkDestroyImage(m_device->device(), image, NULL);
5179 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5180 vkDestroyImageView(m_device->device(), view, nullptr);
5181 vkFreeMemory(m_device->device(), image_memory, nullptr);
5182}
5183
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005184TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5185 TEST_DESCRIPTION("Delete in-use renderPass.");
5186
Tony Barbour1fa09702017-03-16 12:09:08 -06005187 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5189
5190 // Create simple renderpass
5191 VkAttachmentReference attach = {};
5192 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5193 VkSubpassDescription subpass = {};
Dave Houlton756e6742017-03-23 14:33:22 -06005194 subpass.colorAttachmentCount = 1;
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005195 subpass.pColorAttachments = &attach;
5196 VkRenderPassCreateInfo rpci = {};
5197 rpci.subpassCount = 1;
5198 rpci.pSubpasses = &subpass;
5199 rpci.attachmentCount = 1;
5200 VkAttachmentDescription attach_desc = {};
5201 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5202 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5203 rpci.pAttachments = &attach_desc;
5204 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5205 VkRenderPass rp;
5206 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5207 ASSERT_VK_SUCCESS(err);
5208
5209 // Create a pipeline that uses the given renderpass
5210 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5211 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5212
5213 VkPipelineLayout pipeline_layout;
5214 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5215 ASSERT_VK_SUCCESS(err);
5216
5217 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5218 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5219 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005220 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005221 vp_state_ci.pViewports = &vp;
5222 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005223 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005224 vp_state_ci.pScissors = &scissors;
5225
5226 VkPipelineShaderStageCreateInfo shaderStages[2];
5227 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5228
5229 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005230 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005231 // but add it to be able to run on more devices
5232 shaderStages[0] = vs.GetStageCreateInfo();
5233 shaderStages[1] = fs.GetStageCreateInfo();
5234
5235 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5236 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5237
5238 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5239 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5240 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5241
5242 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5243 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5244 rs_ci.rasterizerDiscardEnable = true;
5245 rs_ci.lineWidth = 1.0f;
5246
5247 VkPipelineColorBlendAttachmentState att = {};
5248 att.blendEnable = VK_FALSE;
5249 att.colorWriteMask = 0xf;
5250
5251 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5252 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5253 cb_ci.attachmentCount = 1;
5254 cb_ci.pAttachments = &att;
5255
5256 VkGraphicsPipelineCreateInfo gp_ci = {};
5257 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5258 gp_ci.stageCount = 2;
5259 gp_ci.pStages = shaderStages;
5260 gp_ci.pVertexInputState = &vi_ci;
5261 gp_ci.pInputAssemblyState = &ia_ci;
5262 gp_ci.pViewportState = &vp_state_ci;
5263 gp_ci.pRasterizationState = &rs_ci;
5264 gp_ci.pColorBlendState = &cb_ci;
5265 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5266 gp_ci.layout = pipeline_layout;
5267 gp_ci.renderPass = rp;
5268
5269 VkPipelineCacheCreateInfo pc_ci = {};
5270 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5271
Dave Houlton756e6742017-03-23 14:33:22 -06005272 m_errorMonitor->ExpectSuccess();
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005273 VkPipeline pipeline;
5274 VkPipelineCache pipe_cache;
5275 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5276 ASSERT_VK_SUCCESS(err);
5277
5278 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5279 ASSERT_VK_SUCCESS(err);
Dave Houlton756e6742017-03-23 14:33:22 -06005280
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005281 // Bind pipeline to cmd buffer, will also bind renderpass
5282 m_commandBuffer->BeginCommandBuffer();
5283 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5284 m_commandBuffer->EndCommandBuffer();
5285
5286 VkSubmitInfo submit_info = {};
5287 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5288 submit_info.commandBufferCount = 1;
5289 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5290 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houlton756e6742017-03-23 14:33:22 -06005291 m_errorMonitor->VerifyNotFound();
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005292
5293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5294 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5295 m_errorMonitor->VerifyFound();
5296
5297 // Wait for queue to complete so we can safely destroy everything
5298 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005299 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -06005300 m_errorMonitor->SetUnexpectedError("Unable to remove RenderPass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005301 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5302 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5303 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5304 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5305}
5306
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005307TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005308 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005309 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005310
5311 VkImage image;
5312 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5313 VkImageCreateInfo image_create_info = {};
5314 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5315 image_create_info.pNext = NULL;
5316 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5317 image_create_info.format = tex_format;
5318 image_create_info.extent.width = 32;
5319 image_create_info.extent.height = 32;
5320 image_create_info.extent.depth = 1;
5321 image_create_info.mipLevels = 1;
5322 image_create_info.arrayLayers = 1;
5323 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5324 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005325 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005326 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005327 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005328 ASSERT_VK_SUCCESS(err);
5329 // Have to bind memory to image before recording cmd in cmd buffer using it
5330 VkMemoryRequirements mem_reqs;
5331 VkDeviceMemory image_mem;
5332 bool pass;
5333 VkMemoryAllocateInfo mem_alloc = {};
5334 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5335 mem_alloc.pNext = NULL;
5336 mem_alloc.memoryTypeIndex = 0;
5337 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5338 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005339 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005340 ASSERT_TRUE(pass);
5341 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5342 ASSERT_VK_SUCCESS(err);
5343
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005344 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005346 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005347
5348 m_commandBuffer->BeginCommandBuffer();
5349 VkClearColorValue ccv;
5350 ccv.float32[0] = 1.0f;
5351 ccv.float32[1] = 1.0f;
5352 ccv.float32[2] = 1.0f;
5353 ccv.float32[3] = 1.0f;
5354 VkImageSubresourceRange isr = {};
5355 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5356 isr.baseArrayLayer = 0;
5357 isr.baseMipLevel = 0;
5358 isr.layerCount = 1;
5359 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005360 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005361 m_commandBuffer->EndCommandBuffer();
5362
5363 m_errorMonitor->VerifyFound();
5364 vkDestroyImage(m_device->device(), image, NULL);
5365 vkFreeMemory(m_device->device(), image_mem, nullptr);
5366}
5367
5368TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005369 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005370 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005371
5372 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06005373 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005374 VK_IMAGE_TILING_OPTIMAL, 0);
5375 ASSERT_TRUE(image.initialized());
5376
5377 VkBuffer buffer;
5378 VkDeviceMemory mem;
5379 VkMemoryRequirements mem_reqs;
5380
5381 VkBufferCreateInfo buf_info = {};
5382 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005383 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005384 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005385 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5386 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5387 ASSERT_VK_SUCCESS(err);
5388
5389 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5390
5391 VkMemoryAllocateInfo alloc_info = {};
5392 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005393 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005394 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005395 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005396 if (!pass) {
5397 vkDestroyBuffer(m_device->device(), buffer, NULL);
5398 return;
5399 }
5400 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5401 ASSERT_VK_SUCCESS(err);
5402
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005403 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5404 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005405 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005406 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005407 region.bufferRowLength = 16;
5408 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005409 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5410
5411 region.imageSubresource.layerCount = 1;
5412 region.imageExtent.height = 4;
5413 region.imageExtent.width = 4;
5414 region.imageExtent.depth = 1;
5415 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005416 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5417 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005418 m_commandBuffer->EndCommandBuffer();
5419
5420 m_errorMonitor->VerifyFound();
5421
5422 vkDestroyBuffer(m_device->device(), buffer, NULL);
5423 vkFreeMemory(m_device->handle(), mem, NULL);
5424}
5425
Tobin Ehlis85940f52016-07-07 16:57:21 -06005426TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005427 TEST_DESCRIPTION(
5428 "Attempt to draw with a command buffer that is invalid "
5429 "due to an event dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005430 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85940f52016-07-07 16:57:21 -06005431
5432 VkEvent event;
5433 VkEventCreateInfo evci = {};
5434 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5435 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5436 ASSERT_VK_SUCCESS(result);
5437
5438 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005439 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005440 m_commandBuffer->EndCommandBuffer();
5441
Mark Lobodzinski33826372017-04-13 11:10:11 -06005442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005443 // Destroy event dependency prior to submit to cause ERROR
5444 vkDestroyEvent(m_device->device(), event, NULL);
5445
5446 VkSubmitInfo submit_info = {};
5447 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5448 submit_info.commandBufferCount = 1;
5449 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5450 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5451
5452 m_errorMonitor->VerifyFound();
5453}
5454
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005455TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005456 TEST_DESCRIPTION(
5457 "Attempt to draw with a command buffer that is invalid "
5458 "due to a query pool dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005459 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005460
5461 VkQueryPool query_pool;
5462 VkQueryPoolCreateInfo qpci{};
5463 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5464 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5465 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005466 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005467 ASSERT_VK_SUCCESS(result);
5468
5469 m_commandBuffer->BeginCommandBuffer();
5470 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5471 m_commandBuffer->EndCommandBuffer();
5472
Mark Lobodzinski33826372017-04-13 11:10:11 -06005473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound QueryPool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005474 // Destroy query pool dependency prior to submit to cause ERROR
5475 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5476
5477 VkSubmitInfo submit_info = {};
5478 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5479 submit_info.commandBufferCount = 1;
5480 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5481 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5482
5483 m_errorMonitor->VerifyFound();
5484}
5485
Tobin Ehlis24130d92016-07-08 15:50:53 -06005486TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005487 TEST_DESCRIPTION(
5488 "Attempt to draw with a command buffer that is invalid "
5489 "due to a pipeline dependency being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005490 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis24130d92016-07-08 15:50:53 -06005491 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5492
5493 VkResult err;
5494
5495 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5496 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5497
5498 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005499 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005500 ASSERT_VK_SUCCESS(err);
5501
5502 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5503 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5504 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005505 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005506 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005507 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005508 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005509 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005510
5511 VkPipelineShaderStageCreateInfo shaderStages[2];
5512 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5513
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005514 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005515 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005516 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005517 shaderStages[0] = vs.GetStageCreateInfo();
5518 shaderStages[1] = fs.GetStageCreateInfo();
5519
5520 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5521 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5522
5523 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5524 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5525 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5526
5527 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5528 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005529 rs_ci.rasterizerDiscardEnable = true;
5530 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005531
5532 VkPipelineColorBlendAttachmentState att = {};
5533 att.blendEnable = VK_FALSE;
5534 att.colorWriteMask = 0xf;
5535
5536 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5537 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5538 cb_ci.attachmentCount = 1;
5539 cb_ci.pAttachments = &att;
5540
5541 VkGraphicsPipelineCreateInfo gp_ci = {};
5542 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5543 gp_ci.stageCount = 2;
5544 gp_ci.pStages = shaderStages;
5545 gp_ci.pVertexInputState = &vi_ci;
5546 gp_ci.pInputAssemblyState = &ia_ci;
5547 gp_ci.pViewportState = &vp_state_ci;
5548 gp_ci.pRasterizationState = &rs_ci;
5549 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005550 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5551 gp_ci.layout = pipeline_layout;
5552 gp_ci.renderPass = renderPass();
5553
5554 VkPipelineCacheCreateInfo pc_ci = {};
5555 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5556
5557 VkPipeline pipeline;
5558 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005559 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005560 ASSERT_VK_SUCCESS(err);
5561
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005562 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005563 ASSERT_VK_SUCCESS(err);
5564
5565 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005566 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005567 m_commandBuffer->EndCommandBuffer();
5568 // Now destroy pipeline in order to cause error when submitting
5569 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5570
Mark Lobodzinski33826372017-04-13 11:10:11 -06005571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005572
5573 VkSubmitInfo submit_info = {};
5574 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5575 submit_info.commandBufferCount = 1;
5576 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5577 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5578
5579 m_errorMonitor->VerifyFound();
5580 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5581 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5582}
5583
Tobin Ehlis31289162016-08-17 14:57:58 -06005584TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005585 TEST_DESCRIPTION(
5586 "Attempt to draw with a command buffer that is invalid "
5587 "due to a bound descriptor set with a buffer dependency "
5588 "being destroyed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005589 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis31289162016-08-17 14:57:58 -06005590 ASSERT_NO_FATAL_FAILURE(InitViewport());
5591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5592
5593 VkDescriptorPoolSize ds_type_count = {};
5594 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5595 ds_type_count.descriptorCount = 1;
5596
5597 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5598 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5599 ds_pool_ci.pNext = NULL;
5600 ds_pool_ci.maxSets = 1;
5601 ds_pool_ci.poolSizeCount = 1;
5602 ds_pool_ci.pPoolSizes = &ds_type_count;
5603
5604 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005605 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005606 ASSERT_VK_SUCCESS(err);
5607
5608 VkDescriptorSetLayoutBinding dsl_binding = {};
5609 dsl_binding.binding = 0;
5610 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5611 dsl_binding.descriptorCount = 1;
5612 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5613 dsl_binding.pImmutableSamplers = NULL;
5614
5615 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5616 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5617 ds_layout_ci.pNext = NULL;
5618 ds_layout_ci.bindingCount = 1;
5619 ds_layout_ci.pBindings = &dsl_binding;
5620 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005621 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005622 ASSERT_VK_SUCCESS(err);
5623
5624 VkDescriptorSet descriptorSet;
5625 VkDescriptorSetAllocateInfo alloc_info = {};
5626 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5627 alloc_info.descriptorSetCount = 1;
5628 alloc_info.descriptorPool = ds_pool;
5629 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005630 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005631 ASSERT_VK_SUCCESS(err);
5632
5633 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5634 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5635 pipeline_layout_ci.pNext = NULL;
5636 pipeline_layout_ci.setLayoutCount = 1;
5637 pipeline_layout_ci.pSetLayouts = &ds_layout;
5638
5639 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005640 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005641 ASSERT_VK_SUCCESS(err);
5642
5643 // Create a buffer to update the descriptor with
5644 uint32_t qfi = 0;
5645 VkBufferCreateInfo buffCI = {};
5646 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5647 buffCI.size = 1024;
5648 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5649 buffCI.queueFamilyIndexCount = 1;
5650 buffCI.pQueueFamilyIndices = &qfi;
5651
5652 VkBuffer buffer;
5653 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5654 ASSERT_VK_SUCCESS(err);
5655 // Allocate memory and bind to buffer so we can make it to the appropriate
5656 // error
5657 VkMemoryAllocateInfo mem_alloc = {};
5658 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5659 mem_alloc.pNext = NULL;
5660 mem_alloc.allocationSize = 1024;
5661 mem_alloc.memoryTypeIndex = 0;
5662
5663 VkMemoryRequirements memReqs;
5664 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005665 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005666 if (!pass) {
5667 vkDestroyBuffer(m_device->device(), buffer, NULL);
5668 return;
5669 }
5670
5671 VkDeviceMemory mem;
5672 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5673 ASSERT_VK_SUCCESS(err);
5674 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5675 ASSERT_VK_SUCCESS(err);
5676 // Correctly update descriptor to avoid "NOT_UPDATED" error
5677 VkDescriptorBufferInfo buffInfo = {};
5678 buffInfo.buffer = buffer;
5679 buffInfo.offset = 0;
5680 buffInfo.range = 1024;
5681
5682 VkWriteDescriptorSet descriptor_write;
5683 memset(&descriptor_write, 0, sizeof(descriptor_write));
5684 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5685 descriptor_write.dstSet = descriptorSet;
5686 descriptor_write.dstBinding = 0;
5687 descriptor_write.descriptorCount = 1;
5688 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5689 descriptor_write.pBufferInfo = &buffInfo;
5690
5691 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5692
5693 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005694 char const *vsSource =
5695 "#version 450\n"
5696 "\n"
5697 "out gl_PerVertex { \n"
5698 " vec4 gl_Position;\n"
5699 "};\n"
5700 "void main(){\n"
5701 " gl_Position = vec4(1);\n"
5702 "}\n";
5703 char const *fsSource =
5704 "#version 450\n"
5705 "\n"
5706 "layout(location=0) out vec4 x;\n"
5707 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5708 "void main(){\n"
5709 " x = vec4(bar.y);\n"
5710 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005711 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5712 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5713 VkPipelineObj pipe(m_device);
5714 pipe.AddShader(&vs);
5715 pipe.AddShader(&fs);
5716 pipe.AddColorAttachment();
5717 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5718
Tony Barbour552f6c02016-12-21 14:34:07 -07005719 m_commandBuffer->BeginCommandBuffer();
5720 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005721 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5722 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5723 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005724
5725 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5726 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5727
Tobin Ehlis31289162016-08-17 14:57:58 -06005728 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005729 m_commandBuffer->EndRenderPass();
5730 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski33826372017-04-13 11:10:11 -06005731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005732 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5733 vkDestroyBuffer(m_device->device(), buffer, NULL);
5734 // Attempt to submit cmd buffer
5735 VkSubmitInfo submit_info = {};
5736 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5737 submit_info.commandBufferCount = 1;
5738 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5739 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5740 m_errorMonitor->VerifyFound();
5741 // Cleanup
5742 vkFreeMemory(m_device->device(), mem, NULL);
5743
5744 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5745 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5746 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5747}
5748
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005749TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005750 TEST_DESCRIPTION(
5751 "Attempt to draw with a command buffer that is invalid "
5752 "due to a bound descriptor sets with a combined image "
5753 "sampler having their image, sampler, and descriptor set "
5754 "each respectively destroyed and then attempting to "
5755 "submit associated cmd buffers. Attempt to destroy a "
5756 "DescriptorSet that is in use.");
Tony Barbour1fa09702017-03-16 12:09:08 -06005757 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005758 ASSERT_NO_FATAL_FAILURE(InitViewport());
5759 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5760
5761 VkDescriptorPoolSize ds_type_count = {};
5762 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5763 ds_type_count.descriptorCount = 1;
5764
5765 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5766 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5767 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005768 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005769 ds_pool_ci.maxSets = 1;
5770 ds_pool_ci.poolSizeCount = 1;
5771 ds_pool_ci.pPoolSizes = &ds_type_count;
5772
5773 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005774 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005775 ASSERT_VK_SUCCESS(err);
5776
5777 VkDescriptorSetLayoutBinding dsl_binding = {};
5778 dsl_binding.binding = 0;
5779 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5780 dsl_binding.descriptorCount = 1;
5781 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5782 dsl_binding.pImmutableSamplers = NULL;
5783
5784 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5785 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5786 ds_layout_ci.pNext = NULL;
5787 ds_layout_ci.bindingCount = 1;
5788 ds_layout_ci.pBindings = &dsl_binding;
5789 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005790 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005791 ASSERT_VK_SUCCESS(err);
5792
5793 VkDescriptorSet descriptorSet;
5794 VkDescriptorSetAllocateInfo alloc_info = {};
5795 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5796 alloc_info.descriptorSetCount = 1;
5797 alloc_info.descriptorPool = ds_pool;
5798 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005799 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005800 ASSERT_VK_SUCCESS(err);
5801
5802 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5803 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5804 pipeline_layout_ci.pNext = NULL;
5805 pipeline_layout_ci.setLayoutCount = 1;
5806 pipeline_layout_ci.pSetLayouts = &ds_layout;
5807
5808 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005809 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005810 ASSERT_VK_SUCCESS(err);
5811
5812 // Create images to update the descriptor with
5813 VkImage image;
5814 VkImage image2;
5815 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5816 const int32_t tex_width = 32;
5817 const int32_t tex_height = 32;
5818 VkImageCreateInfo image_create_info = {};
5819 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5820 image_create_info.pNext = NULL;
5821 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5822 image_create_info.format = tex_format;
5823 image_create_info.extent.width = tex_width;
5824 image_create_info.extent.height = tex_height;
5825 image_create_info.extent.depth = 1;
5826 image_create_info.mipLevels = 1;
5827 image_create_info.arrayLayers = 1;
5828 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5829 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5830 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5831 image_create_info.flags = 0;
5832 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5833 ASSERT_VK_SUCCESS(err);
5834 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5835 ASSERT_VK_SUCCESS(err);
5836
5837 VkMemoryRequirements memory_reqs;
5838 VkDeviceMemory image_memory;
5839 bool pass;
5840 VkMemoryAllocateInfo memory_info = {};
5841 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5842 memory_info.pNext = NULL;
5843 memory_info.allocationSize = 0;
5844 memory_info.memoryTypeIndex = 0;
5845 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5846 // Allocate enough memory for both images
5847 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005848 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005849 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005850 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005851 ASSERT_VK_SUCCESS(err);
5852 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5853 ASSERT_VK_SUCCESS(err);
5854 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005855 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005856 ASSERT_VK_SUCCESS(err);
5857
5858 VkImageViewCreateInfo image_view_create_info = {};
5859 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5860 image_view_create_info.image = image;
5861 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5862 image_view_create_info.format = tex_format;
5863 image_view_create_info.subresourceRange.layerCount = 1;
5864 image_view_create_info.subresourceRange.baseMipLevel = 0;
5865 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005866 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005867
5868 VkImageView view;
5869 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005870 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005871 ASSERT_VK_SUCCESS(err);
5872 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005873 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005874 ASSERT_VK_SUCCESS(err);
5875 // Create Samplers
5876 VkSamplerCreateInfo sampler_ci = {};
5877 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5878 sampler_ci.pNext = NULL;
5879 sampler_ci.magFilter = VK_FILTER_NEAREST;
5880 sampler_ci.minFilter = VK_FILTER_NEAREST;
5881 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5882 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5883 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5884 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5885 sampler_ci.mipLodBias = 1.0;
5886 sampler_ci.anisotropyEnable = VK_FALSE;
5887 sampler_ci.maxAnisotropy = 1;
5888 sampler_ci.compareEnable = VK_FALSE;
5889 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5890 sampler_ci.minLod = 1.0;
5891 sampler_ci.maxLod = 1.0;
5892 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5893 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5894 VkSampler sampler;
5895 VkSampler sampler2;
5896 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5897 ASSERT_VK_SUCCESS(err);
5898 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5899 ASSERT_VK_SUCCESS(err);
5900 // Update descriptor with image and sampler
5901 VkDescriptorImageInfo img_info = {};
5902 img_info.sampler = sampler;
5903 img_info.imageView = view;
5904 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5905
5906 VkWriteDescriptorSet descriptor_write;
5907 memset(&descriptor_write, 0, sizeof(descriptor_write));
5908 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5909 descriptor_write.dstSet = descriptorSet;
5910 descriptor_write.dstBinding = 0;
5911 descriptor_write.descriptorCount = 1;
5912 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5913 descriptor_write.pImageInfo = &img_info;
5914
5915 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5916
5917 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005918 char const *vsSource =
5919 "#version 450\n"
5920 "\n"
5921 "out gl_PerVertex { \n"
5922 " vec4 gl_Position;\n"
5923 "};\n"
5924 "void main(){\n"
5925 " gl_Position = vec4(1);\n"
5926 "}\n";
5927 char const *fsSource =
5928 "#version 450\n"
5929 "\n"
5930 "layout(set=0, binding=0) uniform sampler2D s;\n"
5931 "layout(location=0) out vec4 x;\n"
5932 "void main(){\n"
5933 " x = texture(s, vec2(1));\n"
5934 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005935 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5936 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5937 VkPipelineObj pipe(m_device);
5938 pipe.AddShader(&vs);
5939 pipe.AddShader(&fs);
5940 pipe.AddColorAttachment();
5941 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5942
5943 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinski33826372017-04-13 11:10:11 -06005944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound Sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005945 m_commandBuffer->BeginCommandBuffer();
5946 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005947 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5948 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5949 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005950 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5951 VkRect2D scissor = {{0, 0}, {16, 16}};
5952 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5953 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005954 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005955 m_commandBuffer->EndRenderPass();
5956 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005957 // Destroy sampler invalidates the cmd buffer, causing error on submit
5958 vkDestroySampler(m_device->device(), sampler, NULL);
5959 // Attempt to submit cmd buffer
5960 VkSubmitInfo submit_info = {};
5961 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5962 submit_info.commandBufferCount = 1;
5963 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5964 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5965 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005966
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005967 // Now re-update descriptor with valid sampler and delete image
5968 img_info.sampler = sampler2;
5969 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005970
5971 VkCommandBufferBeginInfo info = {};
5972 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5973 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5974
Mark Lobodzinski33826372017-04-13 11:10:11 -06005975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound Image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005976 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005977 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005978 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5979 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5980 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005981 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5982 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005983 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005984 m_commandBuffer->EndRenderPass();
5985 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005986 // Destroy image invalidates the cmd buffer, causing error on submit
5987 vkDestroyImage(m_device->device(), image, NULL);
5988 // Attempt to submit cmd buffer
5989 submit_info = {};
5990 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5991 submit_info.commandBufferCount = 1;
5992 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5993 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5994 m_errorMonitor->VerifyFound();
5995 // Now update descriptor to be valid, but then free descriptor
5996 img_info.imageView = view2;
5997 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005998 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005999 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006000 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6001 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6002 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006003 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6004 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006005 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006006 m_commandBuffer->EndRenderPass();
6007 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07006008 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07006009
6010 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006012 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06006013 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006014
6015 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006016 // TODO - though the particular error above doesn't re-occur, there are other 'unexpecteds' still to clean up
Dave Houltonfbf52152017-01-06 12:55:29 -07006017 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006018 m_errorMonitor->SetUnexpectedError(
6019 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6020 "either be a valid handle or VK_NULL_HANDLE");
Mark Lobodzinski74597792017-04-11 15:43:49 -06006021 m_errorMonitor->SetUnexpectedError("Unable to remove DescriptorSet obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006022 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6023
6024 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006025 submit_info = {};
6026 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6027 submit_info.commandBufferCount = 1;
6028 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinski33826372017-04-13 11:10:11 -06006029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound DescriptorSet ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006030 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6031 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006032
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006033 // Cleanup
6034 vkFreeMemory(m_device->device(), image_memory, NULL);
6035 vkDestroySampler(m_device->device(), sampler2, NULL);
6036 vkDestroyImage(m_device->device(), image2, NULL);
6037 vkDestroyImageView(m_device->device(), view, NULL);
6038 vkDestroyImageView(m_device->device(), view2, NULL);
6039 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6040 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6041 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6042}
6043
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006044TEST_F(VkLayerTest, ImageDescriptorLayoutMismatch) {
6045 TEST_DESCRIPTION("Update an image sampler with a layout that doesn't match the actual image layout at the image is used.");
6046 ASSERT_NO_FATAL_FAILURE(Init(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
6047 ASSERT_NO_FATAL_FAILURE(InitViewport());
6048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6049
6050 VkDescriptorPoolSize ds_type_count = {};
6051 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6052 ds_type_count.descriptorCount = 1;
6053
6054 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6055 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6056 ds_pool_ci.pNext = NULL;
6057 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
6058 ds_pool_ci.maxSets = 1;
6059 ds_pool_ci.poolSizeCount = 1;
6060 ds_pool_ci.pPoolSizes = &ds_type_count;
6061
6062 VkDescriptorPool ds_pool;
6063 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6064 ASSERT_VK_SUCCESS(err);
6065
6066 VkDescriptorSetLayoutBinding dsl_binding = {};
6067 dsl_binding.binding = 0;
6068 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6069 dsl_binding.descriptorCount = 1;
6070 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6071 dsl_binding.pImmutableSamplers = NULL;
6072
6073 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6074 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6075 ds_layout_ci.pNext = NULL;
6076 ds_layout_ci.bindingCount = 1;
6077 ds_layout_ci.pBindings = &dsl_binding;
6078 VkDescriptorSetLayout ds_layout;
6079 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6080 ASSERT_VK_SUCCESS(err);
6081
6082 VkDescriptorSet descriptorSet;
6083 VkDescriptorSetAllocateInfo alloc_info = {};
6084 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6085 alloc_info.descriptorSetCount = 1;
6086 alloc_info.descriptorPool = ds_pool;
6087 alloc_info.pSetLayouts = &ds_layout;
6088 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6089 ASSERT_VK_SUCCESS(err);
6090
6091 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6092 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6093 pipeline_layout_ci.pNext = NULL;
6094 pipeline_layout_ci.setLayoutCount = 1;
6095 pipeline_layout_ci.pSetLayouts = &ds_layout;
6096
6097 VkPipelineLayout pipeline_layout;
6098 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6099 ASSERT_VK_SUCCESS(err);
6100
6101 // Create images to update the descriptor with
6102 const VkFormat format = VK_FORMAT_B8G8R8A8_UNORM;
6103 VkImageObj image(m_device);
6104 image.Init(32, 32, 1, format, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_TILING_OPTIMAL,
6105 0);
6106 ASSERT_TRUE(image.initialized());
6107
6108 VkImageViewCreateInfo image_view_create_info = {};
6109 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6110 image_view_create_info.image = image.handle();
6111 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6112 image_view_create_info.format = format;
6113 image_view_create_info.subresourceRange.layerCount = 1;
6114 image_view_create_info.subresourceRange.baseMipLevel = 0;
6115 image_view_create_info.subresourceRange.levelCount = 1;
6116 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6117
6118 VkImageView view;
6119 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6120 ASSERT_VK_SUCCESS(err);
6121 // Create Sampler
6122 VkSamplerCreateInfo sampler_ci = {};
6123 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6124 sampler_ci.pNext = NULL;
6125 sampler_ci.magFilter = VK_FILTER_NEAREST;
6126 sampler_ci.minFilter = VK_FILTER_NEAREST;
6127 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6128 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6129 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6130 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6131 sampler_ci.mipLodBias = 1.0;
6132 sampler_ci.anisotropyEnable = VK_FALSE;
6133 sampler_ci.maxAnisotropy = 1;
6134 sampler_ci.compareEnable = VK_FALSE;
6135 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6136 sampler_ci.minLod = 1.0;
6137 sampler_ci.maxLod = 1.0;
6138 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6139 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6140 VkSampler sampler;
6141 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6142 ASSERT_VK_SUCCESS(err);
6143 // Update descriptor with image and sampler
6144 VkDescriptorImageInfo img_info = {};
6145 img_info.sampler = sampler;
6146 img_info.imageView = view;
6147 // This should cause a mis-match. Actual layout at use time is SHADER_RO
6148 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6149
6150 VkWriteDescriptorSet descriptor_write;
6151 memset(&descriptor_write, 0, sizeof(descriptor_write));
6152 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6153 descriptor_write.dstSet = descriptorSet;
6154 descriptor_write.dstBinding = 0;
6155 descriptor_write.descriptorCount = 1;
6156 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6157 descriptor_write.pImageInfo = &img_info;
6158
6159 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6160
6161 // Create PSO to be used for draw-time errors below
6162 char const *vsSource =
6163 "#version 450\n"
6164 "\n"
6165 "out gl_PerVertex { \n"
6166 " vec4 gl_Position;\n"
6167 "};\n"
6168 "void main(){\n"
6169 " gl_Position = vec4(1);\n"
6170 "}\n";
6171 char const *fsSource =
6172 "#version 450\n"
6173 "\n"
6174 "layout(set=0, binding=0) uniform sampler2D s;\n"
6175 "layout(location=0) out vec4 x;\n"
6176 "void main(){\n"
6177 " x = texture(s, vec2(1));\n"
6178 "}\n";
6179 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6180 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6181 VkPipelineObj pipe(m_device);
6182 pipe.AddShader(&vs);
6183 pipe.AddShader(&fs);
6184 pipe.AddColorAttachment();
6185 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6186
6187 VkCommandBufferObj cmd_buf(m_device, m_commandPool);
6188 cmd_buf.BeginCommandBuffer();
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006189 // record layout different than actual descriptor layout of SHADER_RO
6190 image.SetLayout(&cmd_buf, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
Mark Lobodzinski95512b72017-05-10 12:21:30 -06006191 cmd_buf.BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlisaabbcd02017-04-13 14:15:21 -06006192 vkCmdBindPipeline(cmd_buf.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6193 vkCmdBindDescriptorSets(cmd_buf.handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &descriptorSet, 0, NULL);
6194 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6195 VkRect2D scissor = {{0, 0}, {16, 16}};
6196 vkCmdSetViewport(cmd_buf.handle(), 0, 1, &viewport);
6197 vkCmdSetScissor(cmd_buf.handle(), 0, 1, &scissor);
6198 // At draw time the update layout will mis-match the actual layout
6199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6200 " with specific layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL that doesn't match the "
6201 "actual current layout VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL.");
6202 m_errorMonitor->SetDesiredFailureMsg(
6203 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6204 " Image layout specified at vkUpdateDescriptorSets() time doesn't match actual image layout at time descriptor is used.");
6205 cmd_buf.Draw(1, 0, 0, 0);
6206 m_errorMonitor->VerifyFound();
6207 cmd_buf.EndRenderPass();
6208 cmd_buf.EndCommandBuffer();
6209 // Submit cmd buffer
6210 VkSubmitInfo submit_info = {};
6211 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6212 submit_info.commandBufferCount = 1;
6213 submit_info.pCommandBuffers = &cmd_buf.handle();
6214 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6215 vkQueueWaitIdle(m_device->m_queue);
6216 // Cleanup
6217 vkDestroySampler(m_device->device(), sampler, NULL);
6218 vkDestroyImageView(m_device->device(), view, NULL);
6219 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6220 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6221 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6222}
6223
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006224TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6225 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
Tony Barbour1fa09702017-03-16 12:09:08 -06006226 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006227 ASSERT_NO_FATAL_FAILURE(InitViewport());
6228 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6229
6230 VkDescriptorPoolSize ds_type_count = {};
6231 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6232 ds_type_count.descriptorCount = 1;
6233
6234 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6235 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6236 ds_pool_ci.pNext = NULL;
6237 ds_pool_ci.maxSets = 1;
6238 ds_pool_ci.poolSizeCount = 1;
6239 ds_pool_ci.pPoolSizes = &ds_type_count;
6240
6241 VkDescriptorPool ds_pool;
6242 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6243 ASSERT_VK_SUCCESS(err);
6244
6245 VkDescriptorSetLayoutBinding dsl_binding = {};
6246 dsl_binding.binding = 0;
6247 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6248 dsl_binding.descriptorCount = 1;
6249 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6250 dsl_binding.pImmutableSamplers = NULL;
6251
6252 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6253 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6254 ds_layout_ci.pNext = NULL;
6255 ds_layout_ci.bindingCount = 1;
6256 ds_layout_ci.pBindings = &dsl_binding;
6257 VkDescriptorSetLayout ds_layout;
6258 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6259 ASSERT_VK_SUCCESS(err);
6260
6261 VkDescriptorSet descriptor_set;
6262 VkDescriptorSetAllocateInfo alloc_info = {};
6263 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6264 alloc_info.descriptorSetCount = 1;
6265 alloc_info.descriptorPool = ds_pool;
6266 alloc_info.pSetLayouts = &ds_layout;
6267 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6268 ASSERT_VK_SUCCESS(err);
6269
6270 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6271 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6272 pipeline_layout_ci.pNext = NULL;
6273 pipeline_layout_ci.setLayoutCount = 1;
6274 pipeline_layout_ci.pSetLayouts = &ds_layout;
6275
6276 VkPipelineLayout pipeline_layout;
6277 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6278 ASSERT_VK_SUCCESS(err);
6279
6280 // Create image to update the descriptor with
6281 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06006282 image.Init(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006283 ASSERT_TRUE(image.initialized());
6284
6285 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6286 // Create Sampler
6287 VkSamplerCreateInfo sampler_ci = {};
6288 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6289 sampler_ci.pNext = NULL;
6290 sampler_ci.magFilter = VK_FILTER_NEAREST;
6291 sampler_ci.minFilter = VK_FILTER_NEAREST;
6292 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6293 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6294 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6295 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6296 sampler_ci.mipLodBias = 1.0;
6297 sampler_ci.anisotropyEnable = VK_FALSE;
6298 sampler_ci.maxAnisotropy = 1;
6299 sampler_ci.compareEnable = VK_FALSE;
6300 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6301 sampler_ci.minLod = 1.0;
6302 sampler_ci.maxLod = 1.0;
6303 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6304 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6305 VkSampler sampler;
6306 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6307 ASSERT_VK_SUCCESS(err);
6308 // Update descriptor with image and sampler
6309 VkDescriptorImageInfo img_info = {};
6310 img_info.sampler = sampler;
6311 img_info.imageView = view;
6312 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6313
6314 VkWriteDescriptorSet descriptor_write;
6315 memset(&descriptor_write, 0, sizeof(descriptor_write));
6316 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6317 descriptor_write.dstSet = descriptor_set;
6318 descriptor_write.dstBinding = 0;
6319 descriptor_write.descriptorCount = 1;
6320 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6321 descriptor_write.pImageInfo = &img_info;
6322
6323 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6324
6325 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006326 char const *vsSource =
6327 "#version 450\n"
6328 "\n"
6329 "out gl_PerVertex { \n"
6330 " vec4 gl_Position;\n"
6331 "};\n"
6332 "void main(){\n"
6333 " gl_Position = vec4(1);\n"
6334 "}\n";
6335 char const *fsSource =
6336 "#version 450\n"
6337 "\n"
6338 "layout(set=0, binding=0) uniform sampler2D s;\n"
6339 "layout(location=0) out vec4 x;\n"
6340 "void main(){\n"
6341 " x = texture(s, vec2(1));\n"
6342 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006343 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6344 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6345 VkPipelineObj pipe(m_device);
6346 pipe.AddShader(&vs);
6347 pipe.AddShader(&fs);
6348 pipe.AddColorAttachment();
6349 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6350
Tony Barbour552f6c02016-12-21 14:34:07 -07006351 m_commandBuffer->BeginCommandBuffer();
6352 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006353 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6354 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6355 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006356
6357 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6358 VkRect2D scissor = {{0, 0}, {16, 16}};
6359 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6360 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6361
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006362 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006363 m_commandBuffer->EndRenderPass();
6364 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006365 // Submit cmd buffer to put pool in-flight
6366 VkSubmitInfo submit_info = {};
6367 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6368 submit_info.commandBufferCount = 1;
6369 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6370 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6371 // Destroy pool while in-flight, causing error
Mark Lobodzinski33826372017-04-13 11:10:11 -06006372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete DescriptorPool ");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006373 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6374 m_errorMonitor->VerifyFound();
6375 vkQueueWaitIdle(m_device->m_queue);
6376 // Cleanup
6377 vkDestroySampler(m_device->device(), sampler, NULL);
6378 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6379 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006380 m_errorMonitor->SetUnexpectedError(
6381 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -06006382 m_errorMonitor->SetUnexpectedError("Unable to remove DescriptorPool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006383 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006384 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006385}
6386
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006387TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6388 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
Tony Barbour1fa09702017-03-16 12:09:08 -06006389 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006390 ASSERT_NO_FATAL_FAILURE(InitViewport());
6391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6392
6393 VkDescriptorPoolSize ds_type_count = {};
6394 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6395 ds_type_count.descriptorCount = 1;
6396
6397 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6398 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6399 ds_pool_ci.pNext = NULL;
6400 ds_pool_ci.maxSets = 1;
6401 ds_pool_ci.poolSizeCount = 1;
6402 ds_pool_ci.pPoolSizes = &ds_type_count;
6403
6404 VkDescriptorPool ds_pool;
6405 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6406 ASSERT_VK_SUCCESS(err);
6407
6408 VkDescriptorSetLayoutBinding dsl_binding = {};
6409 dsl_binding.binding = 0;
6410 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6411 dsl_binding.descriptorCount = 1;
6412 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6413 dsl_binding.pImmutableSamplers = NULL;
6414
6415 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6416 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6417 ds_layout_ci.pNext = NULL;
6418 ds_layout_ci.bindingCount = 1;
6419 ds_layout_ci.pBindings = &dsl_binding;
6420 VkDescriptorSetLayout ds_layout;
6421 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6422 ASSERT_VK_SUCCESS(err);
6423
6424 VkDescriptorSet descriptorSet;
6425 VkDescriptorSetAllocateInfo alloc_info = {};
6426 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6427 alloc_info.descriptorSetCount = 1;
6428 alloc_info.descriptorPool = ds_pool;
6429 alloc_info.pSetLayouts = &ds_layout;
6430 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6431 ASSERT_VK_SUCCESS(err);
6432
6433 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6434 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6435 pipeline_layout_ci.pNext = NULL;
6436 pipeline_layout_ci.setLayoutCount = 1;
6437 pipeline_layout_ci.pSetLayouts = &ds_layout;
6438
6439 VkPipelineLayout pipeline_layout;
6440 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6441 ASSERT_VK_SUCCESS(err);
6442
6443 // Create images to update the descriptor with
6444 VkImage image;
6445 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6446 const int32_t tex_width = 32;
6447 const int32_t tex_height = 32;
6448 VkImageCreateInfo image_create_info = {};
6449 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6450 image_create_info.pNext = NULL;
6451 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6452 image_create_info.format = tex_format;
6453 image_create_info.extent.width = tex_width;
6454 image_create_info.extent.height = tex_height;
6455 image_create_info.extent.depth = 1;
6456 image_create_info.mipLevels = 1;
6457 image_create_info.arrayLayers = 1;
6458 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6459 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6460 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6461 image_create_info.flags = 0;
6462 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6463 ASSERT_VK_SUCCESS(err);
6464 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6465 VkMemoryRequirements memory_reqs;
6466 VkDeviceMemory image_memory;
6467 bool pass;
6468 VkMemoryAllocateInfo memory_info = {};
6469 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6470 memory_info.pNext = NULL;
6471 memory_info.allocationSize = 0;
6472 memory_info.memoryTypeIndex = 0;
6473 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6474 // Allocate enough memory for image
6475 memory_info.allocationSize = memory_reqs.size;
6476 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6477 ASSERT_TRUE(pass);
6478 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6479 ASSERT_VK_SUCCESS(err);
6480 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6481 ASSERT_VK_SUCCESS(err);
6482
6483 VkImageViewCreateInfo image_view_create_info = {};
6484 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6485 image_view_create_info.image = image;
6486 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6487 image_view_create_info.format = tex_format;
6488 image_view_create_info.subresourceRange.layerCount = 1;
6489 image_view_create_info.subresourceRange.baseMipLevel = 0;
6490 image_view_create_info.subresourceRange.levelCount = 1;
6491 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6492
6493 VkImageView view;
6494 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6495 ASSERT_VK_SUCCESS(err);
6496 // Create Samplers
6497 VkSamplerCreateInfo sampler_ci = {};
6498 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6499 sampler_ci.pNext = NULL;
6500 sampler_ci.magFilter = VK_FILTER_NEAREST;
6501 sampler_ci.minFilter = VK_FILTER_NEAREST;
6502 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6503 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6504 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6505 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6506 sampler_ci.mipLodBias = 1.0;
6507 sampler_ci.anisotropyEnable = VK_FALSE;
6508 sampler_ci.maxAnisotropy = 1;
6509 sampler_ci.compareEnable = VK_FALSE;
6510 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6511 sampler_ci.minLod = 1.0;
6512 sampler_ci.maxLod = 1.0;
6513 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6514 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6515 VkSampler sampler;
6516 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6517 ASSERT_VK_SUCCESS(err);
6518 // Update descriptor with image and sampler
6519 VkDescriptorImageInfo img_info = {};
6520 img_info.sampler = sampler;
6521 img_info.imageView = view;
6522 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6523
6524 VkWriteDescriptorSet descriptor_write;
6525 memset(&descriptor_write, 0, sizeof(descriptor_write));
6526 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6527 descriptor_write.dstSet = descriptorSet;
6528 descriptor_write.dstBinding = 0;
6529 descriptor_write.descriptorCount = 1;
6530 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6531 descriptor_write.pImageInfo = &img_info;
6532 // Break memory binding and attempt update
6533 vkFreeMemory(m_device->device(), image_memory, nullptr);
6534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006535 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6537 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6538 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6539 m_errorMonitor->VerifyFound();
6540 // Cleanup
6541 vkDestroyImage(m_device->device(), image, NULL);
6542 vkDestroySampler(m_device->device(), sampler, NULL);
6543 vkDestroyImageView(m_device->device(), view, NULL);
6544 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6545 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6546 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6547}
6548
Karl Schultz6addd812016-02-02 17:17:23 -07006549TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006550 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6551 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006552 // Create a valid cmd buffer
6553 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006554 uint64_t fake_pipeline_handle = 0xbaad6001;
6555 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Tony Barbour1fa09702017-03-16 12:09:08 -06006556 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006557 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6558
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006560 m_commandBuffer->BeginCommandBuffer();
6561 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006562 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006563 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006564
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006565 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006567 Draw(1, 0, 0, 0);
6568 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006569
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006570 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006572 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006573 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6574 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006575}
6576
Karl Schultz6addd812016-02-02 17:17:23 -07006577TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006578 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006579 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006580
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006582
Tony Barbour1fa09702017-03-16 12:09:08 -06006583 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006584 ASSERT_NO_FATAL_FAILURE(InitViewport());
6585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006586 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006587 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6588 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006589
6590 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006591 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6592 ds_pool_ci.pNext = NULL;
6593 ds_pool_ci.maxSets = 1;
6594 ds_pool_ci.poolSizeCount = 1;
6595 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006596
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006597 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006598 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006599 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006600
Tony Barboureb254902015-07-15 12:50:33 -06006601 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006602 dsl_binding.binding = 0;
6603 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6604 dsl_binding.descriptorCount = 1;
6605 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6606 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006607
Tony Barboureb254902015-07-15 12:50:33 -06006608 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006609 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6610 ds_layout_ci.pNext = NULL;
6611 ds_layout_ci.bindingCount = 1;
6612 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006613 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006614 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006615 ASSERT_VK_SUCCESS(err);
6616
6617 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006618 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006619 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006620 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006621 alloc_info.descriptorPool = ds_pool;
6622 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006623 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006624 ASSERT_VK_SUCCESS(err);
6625
Tony Barboureb254902015-07-15 12:50:33 -06006626 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006627 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6628 pipeline_layout_ci.pNext = NULL;
6629 pipeline_layout_ci.setLayoutCount = 1;
6630 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006631
6632 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006633 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006634 ASSERT_VK_SUCCESS(err);
6635
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006636 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006637 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006638 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006639 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006640
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006641 VkPipelineObj pipe(m_device);
6642 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006643 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006644 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006645 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006646
Tony Barbour552f6c02016-12-21 14:34:07 -07006647 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006648 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6649 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6650 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006651
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006652 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006653
Chia-I Wuf7458c52015-10-26 21:10:41 +08006654 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6655 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6656 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006657}
6658
Karl Schultz6addd812016-02-02 17:17:23 -07006659TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006660 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006661 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006662
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006664
Tony Barbour1fa09702017-03-16 12:09:08 -06006665 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006666 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006667 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6668 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006669
6670 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006671 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6672 ds_pool_ci.pNext = NULL;
6673 ds_pool_ci.maxSets = 1;
6674 ds_pool_ci.poolSizeCount = 1;
6675 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006676
6677 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006678 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006679 ASSERT_VK_SUCCESS(err);
6680
6681 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006682 dsl_binding.binding = 0;
6683 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6684 dsl_binding.descriptorCount = 1;
6685 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6686 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006687
6688 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006689 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6690 ds_layout_ci.pNext = NULL;
6691 ds_layout_ci.bindingCount = 1;
6692 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006693 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006694 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006695 ASSERT_VK_SUCCESS(err);
6696
6697 VkDescriptorSet descriptorSet;
6698 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006699 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006700 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006701 alloc_info.descriptorPool = ds_pool;
6702 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006703 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006704 ASSERT_VK_SUCCESS(err);
6705
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006706 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006707 VkWriteDescriptorSet descriptor_write;
6708 memset(&descriptor_write, 0, sizeof(descriptor_write));
6709 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6710 descriptor_write.dstSet = descriptorSet;
6711 descriptor_write.dstBinding = 0;
6712 descriptor_write.descriptorCount = 1;
6713 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6714 descriptor_write.pTexelBufferView = &view;
6715
6716 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6717
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006718 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006719
6720 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6721 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6722}
6723
Mark Youngd339ba32016-05-30 13:28:35 -06006724TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006725 TEST_DESCRIPTION("Attempt to create a buffer view with a buffer that has no memory bound to it.");
Mark Youngd339ba32016-05-30 13:28:35 -06006726
6727 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006729 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006730
Tony Barbour1fa09702017-03-16 12:09:08 -06006731 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -06006732
6733 // Create a buffer with no bound memory and then attempt to create
6734 // a buffer view.
6735 VkBufferCreateInfo buff_ci = {};
6736 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006737 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006738 buff_ci.size = 256;
6739 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6740 VkBuffer buffer;
6741 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6742 ASSERT_VK_SUCCESS(err);
6743
6744 VkBufferViewCreateInfo buff_view_ci = {};
6745 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6746 buff_view_ci.buffer = buffer;
6747 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6748 buff_view_ci.range = VK_WHOLE_SIZE;
6749 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006750 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006751
6752 m_errorMonitor->VerifyFound();
6753 vkDestroyBuffer(m_device->device(), buffer, NULL);
6754 // If last error is success, it still created the view, so delete it.
6755 if (err == VK_SUCCESS) {
6756 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6757 }
6758}
6759
Karl Schultz6addd812016-02-02 17:17:23 -07006760TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6761 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6762 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006763 // 1. No dynamicOffset supplied
6764 // 2. Too many dynamicOffsets supplied
6765 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006766 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6768 " requires 1 dynamicOffsets, but only "
6769 "0 dynamicOffsets are left in "
6770 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006771
Tony Barbour1fa09702017-03-16 12:09:08 -06006772 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006773 ASSERT_NO_FATAL_FAILURE(InitViewport());
6774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6775
6776 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006777 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6778 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006779
6780 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006781 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6782 ds_pool_ci.pNext = NULL;
6783 ds_pool_ci.maxSets = 1;
6784 ds_pool_ci.poolSizeCount = 1;
6785 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006786
6787 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006788 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006789 ASSERT_VK_SUCCESS(err);
6790
6791 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006792 dsl_binding.binding = 0;
6793 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6794 dsl_binding.descriptorCount = 1;
6795 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6796 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006797
6798 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006799 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6800 ds_layout_ci.pNext = NULL;
6801 ds_layout_ci.bindingCount = 1;
6802 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006803 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006804 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006805 ASSERT_VK_SUCCESS(err);
6806
6807 VkDescriptorSet descriptorSet;
6808 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006809 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006810 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006811 alloc_info.descriptorPool = ds_pool;
6812 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006813 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006814 ASSERT_VK_SUCCESS(err);
6815
6816 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006817 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6818 pipeline_layout_ci.pNext = NULL;
6819 pipeline_layout_ci.setLayoutCount = 1;
6820 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006821
6822 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006823 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006824 ASSERT_VK_SUCCESS(err);
6825
6826 // Create a buffer to update the descriptor with
6827 uint32_t qfi = 0;
6828 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006829 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6830 buffCI.size = 1024;
6831 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6832 buffCI.queueFamilyIndexCount = 1;
6833 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006834
6835 VkBuffer dyub;
6836 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6837 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006838 // Allocate memory and bind to buffer so we can make it to the appropriate
6839 // error
6840 VkMemoryAllocateInfo mem_alloc = {};
6841 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6842 mem_alloc.pNext = NULL;
6843 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006844 mem_alloc.memoryTypeIndex = 0;
6845
6846 VkMemoryRequirements memReqs;
6847 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006848 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006849 if (!pass) {
6850 vkDestroyBuffer(m_device->device(), dyub, NULL);
6851 return;
6852 }
6853
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006854 VkDeviceMemory mem;
6855 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6856 ASSERT_VK_SUCCESS(err);
6857 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6858 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006859 // Correctly update descriptor to avoid "NOT_UPDATED" error
6860 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006861 buffInfo.buffer = dyub;
6862 buffInfo.offset = 0;
6863 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006864
6865 VkWriteDescriptorSet descriptor_write;
6866 memset(&descriptor_write, 0, sizeof(descriptor_write));
6867 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6868 descriptor_write.dstSet = descriptorSet;
6869 descriptor_write.dstBinding = 0;
6870 descriptor_write.descriptorCount = 1;
6871 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6872 descriptor_write.pBufferInfo = &buffInfo;
6873
6874 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6875
Tony Barbour552f6c02016-12-21 14:34:07 -07006876 m_commandBuffer->BeginCommandBuffer();
6877 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006878 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6879 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006880 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006881 uint32_t pDynOff[2] = {512, 756};
6882 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6884 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6885 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6886 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006887 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006888 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6890 " dynamic offset 512 combined with "
6891 "offset 0 and range 1024 that "
6892 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006893 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006894 char const *vsSource =
6895 "#version 450\n"
6896 "\n"
6897 "out gl_PerVertex { \n"
6898 " vec4 gl_Position;\n"
6899 "};\n"
6900 "void main(){\n"
6901 " gl_Position = vec4(1);\n"
6902 "}\n";
6903 char const *fsSource =
6904 "#version 450\n"
6905 "\n"
6906 "layout(location=0) out vec4 x;\n"
6907 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6908 "void main(){\n"
6909 " x = vec4(bar.y);\n"
6910 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006911 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6912 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6913 VkPipelineObj pipe(m_device);
6914 pipe.AddShader(&vs);
6915 pipe.AddShader(&fs);
6916 pipe.AddColorAttachment();
6917 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6918
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006919 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6920 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6921 VkRect2D scissor = {{0, 0}, {16, 16}};
6922 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6923
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006924 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006925 // This update should succeed, but offset size of 512 will overstep buffer
6926 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006927 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6928 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006929 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006930 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006931
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006932 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006933 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006934
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006935 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006936 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006937 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6938}
6939
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006940TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006941 TEST_DESCRIPTION(
6942 "Attempt to update a descriptor with a non-sparse buffer "
6943 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006944 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006946 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6948 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006949
Tony Barbour1fa09702017-03-16 12:09:08 -06006950 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006951 ASSERT_NO_FATAL_FAILURE(InitViewport());
6952 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6953
6954 VkDescriptorPoolSize ds_type_count = {};
6955 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6956 ds_type_count.descriptorCount = 1;
6957
6958 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6959 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6960 ds_pool_ci.pNext = NULL;
6961 ds_pool_ci.maxSets = 1;
6962 ds_pool_ci.poolSizeCount = 1;
6963 ds_pool_ci.pPoolSizes = &ds_type_count;
6964
6965 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006966 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006967 ASSERT_VK_SUCCESS(err);
6968
6969 VkDescriptorSetLayoutBinding dsl_binding = {};
6970 dsl_binding.binding = 0;
6971 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6972 dsl_binding.descriptorCount = 1;
6973 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6974 dsl_binding.pImmutableSamplers = NULL;
6975
6976 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6977 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6978 ds_layout_ci.pNext = NULL;
6979 ds_layout_ci.bindingCount = 1;
6980 ds_layout_ci.pBindings = &dsl_binding;
6981 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006982 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006983 ASSERT_VK_SUCCESS(err);
6984
6985 VkDescriptorSet descriptorSet;
6986 VkDescriptorSetAllocateInfo alloc_info = {};
6987 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6988 alloc_info.descriptorSetCount = 1;
6989 alloc_info.descriptorPool = ds_pool;
6990 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006991 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006992 ASSERT_VK_SUCCESS(err);
6993
6994 // Create a buffer to update the descriptor with
6995 uint32_t qfi = 0;
6996 VkBufferCreateInfo buffCI = {};
6997 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6998 buffCI.size = 1024;
6999 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
7000 buffCI.queueFamilyIndexCount = 1;
7001 buffCI.pQueueFamilyIndices = &qfi;
7002
7003 VkBuffer dyub;
7004 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
7005 ASSERT_VK_SUCCESS(err);
7006
7007 // Attempt to update descriptor without binding memory to it
7008 VkDescriptorBufferInfo buffInfo = {};
7009 buffInfo.buffer = dyub;
7010 buffInfo.offset = 0;
7011 buffInfo.range = 1024;
7012
7013 VkWriteDescriptorSet descriptor_write;
7014 memset(&descriptor_write, 0, sizeof(descriptor_write));
7015 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
7016 descriptor_write.dstSet = descriptorSet;
7017 descriptor_write.dstBinding = 0;
7018 descriptor_write.descriptorCount = 1;
7019 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
7020 descriptor_write.pBufferInfo = &buffInfo;
7021
7022 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
7023 m_errorMonitor->VerifyFound();
7024
7025 vkDestroyBuffer(m_device->device(), dyub, NULL);
7026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7027 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7028}
7029
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007030TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007031 VkResult err;
Tony Barbour1fa09702017-03-16 12:09:08 -06007032 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007033 ASSERT_NO_FATAL_FAILURE(InitViewport());
7034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7035
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007036 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007037 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007038 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7039 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7040 pipeline_layout_ci.pushConstantRangeCount = 1;
7041 pipeline_layout_ci.pPushConstantRanges = &pc_range;
7042
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007043 //
7044 // Check for invalid push constant ranges in pipeline layouts.
7045 //
7046 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06007047 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007048 char const *msg;
7049 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007050
Karl Schultzc81037d2016-05-12 08:11:23 -06007051 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
7052 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
7053 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
7054 "vkCreatePipelineLayout() call has push constants index 0 with "
7055 "size 0."},
7056 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
7057 "vkCreatePipelineLayout() call has push constants index 0 with "
7058 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007059 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06007060 "vkCreatePipelineLayout() call has push constants index 0 with "
7061 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007062 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06007063 "vkCreatePipelineLayout() call has push constants index 0 with "
7064 "size 0."},
7065 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
7066 "vkCreatePipelineLayout() call has push constants index 0 with "
7067 "offset 1. Offset must"},
7068 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
7069 "vkCreatePipelineLayout() call has push constants index 0 "
7070 "with offset "},
7071 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
7072 "vkCreatePipelineLayout() call has push constants "
7073 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007074 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007075 "vkCreatePipelineLayout() call has push constants index 0 "
7076 "with offset "},
7077 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
7078 "vkCreatePipelineLayout() call has push "
7079 "constants index 0 with offset "},
7080 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
7081 "vkCreatePipelineLayout() call has push "
7082 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007083 }};
7084
7085 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06007086 for (const auto &iter : range_tests) {
7087 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7089 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007090 m_errorMonitor->VerifyFound();
7091 if (VK_SUCCESS == err) {
7092 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7093 }
7094 }
7095
7096 // Check for invalid stage flag
7097 pc_range.offset = 0;
7098 pc_range.size = 16;
7099 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007100 m_errorMonitor->SetDesiredFailureMsg(
7101 VK_DEBUG_REPORT_ERROR_BIT_EXT,
7102 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007103 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007104 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007105 if (VK_SUCCESS == err) {
7106 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7107 }
7108
Karl Schultzc59b72d2017-02-24 15:45:05 -07007109 // Check for duplicate stage flags in a list of push constant ranges.
7110 // A shader can only have one push constant block and that block is mapped
7111 // to the push constant range that has that shader's stage flag set.
7112 // The shader's stage flag can only appear once in all the ranges, so the
7113 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06007114 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07007115 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06007116 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07007117 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007118 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07007119 // Overlapping ranges are OK, but a stage flag can appear only once.
7120 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
7121 {
7122 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7123 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7124 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7125 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007126 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07007127 {
7128 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
7129 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
7130 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
7131 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
7132 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
7133 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
7134 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
7135 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
7136 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
7137 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
7138 }},
7139 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7140 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
7141 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
7142 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7143 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
7144 {
7145 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
7146 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
7147 }},
7148 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
7149 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
7150 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7151 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
7152 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
7153 {
7154 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
7155 }},
7156 },
7157 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007158
Karl Schultzc59b72d2017-02-24 15:45:05 -07007159 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007160 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06007161 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07007162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007163 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007164 m_errorMonitor->VerifyFound();
7165 if (VK_SUCCESS == err) {
7166 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7167 }
7168 }
7169
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007170 //
7171 // CmdPushConstants tests
7172 //
7173
Karl Schultzc59b72d2017-02-24 15:45:05 -07007174 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06007175 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07007176 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007177 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007178 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007179 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007180 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007181 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07007182
7183 const uint8_t dummy_values[100] = {};
7184
7185 m_commandBuffer->BeginCommandBuffer();
7186 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007187
7188 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07007189 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007191 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007192 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007193
Karl Schultzc59b72d2017-02-24 15:45:05 -07007194 m_errorMonitor->ExpectSuccess();
7195 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7196 m_errorMonitor->VerifyNotFound();
7197 m_errorMonitor->ExpectSuccess();
7198 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7199 m_errorMonitor->VerifyNotFound();
7200 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7201 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7202 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7203 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7204 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7205 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7206 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007207 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007208 for (const auto &iter : cmd_range_tests) {
7209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7210 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7211 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007212 m_errorMonitor->VerifyFound();
7213 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007214
Tony Barbour552f6c02016-12-21 14:34:07 -07007215 m_commandBuffer->EndRenderPass();
7216 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007217 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007218}
7219
Karl Schultz6addd812016-02-02 17:17:23 -07007220TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007221 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007222 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007223
Tony Barbour1fa09702017-03-16 12:09:08 -06007224 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007225 ASSERT_NO_FATAL_FAILURE(InitViewport());
7226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7227
7228 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7229 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007230 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7231 ds_type_count[0].descriptorCount = 10;
7232 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7233 ds_type_count[1].descriptorCount = 2;
7234 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7235 ds_type_count[2].descriptorCount = 2;
7236 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7237 ds_type_count[3].descriptorCount = 5;
7238 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7239 // type
7240 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7241 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7242 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007243
7244 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007245 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7246 ds_pool_ci.pNext = NULL;
7247 ds_pool_ci.maxSets = 5;
7248 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7249 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007250
7251 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007252 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007253 ASSERT_VK_SUCCESS(err);
7254
7255 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7256 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007257 dsl_binding[0].binding = 0;
7258 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7259 dsl_binding[0].descriptorCount = 5;
7260 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7261 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007262
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007263 // Create layout identical to set0 layout but w/ different stageFlags
7264 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007265 dsl_fs_stage_only.binding = 0;
7266 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7267 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007268 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7269 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007270 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007271 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007272 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7273 ds_layout_ci.pNext = NULL;
7274 ds_layout_ci.bindingCount = 1;
7275 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007276 static const uint32_t NUM_LAYOUTS = 4;
7277 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007278 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007279 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7280 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007281 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007282 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007283 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007284 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007285 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007286 dsl_binding[0].binding = 0;
7287 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007288 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007289 dsl_binding[1].binding = 1;
7290 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7291 dsl_binding[1].descriptorCount = 2;
7292 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7293 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007294 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007295 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007296 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007297 ASSERT_VK_SUCCESS(err);
7298 dsl_binding[0].binding = 0;
7299 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007300 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007301 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007302 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007303 ASSERT_VK_SUCCESS(err);
7304 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007305 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007306 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007307 ASSERT_VK_SUCCESS(err);
7308
7309 static const uint32_t NUM_SETS = 4;
7310 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7311 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007312 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007313 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007314 alloc_info.descriptorPool = ds_pool;
7315 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007316 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007317 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007318 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007319 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007320 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007321 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007322 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007323
7324 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007325 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7326 pipeline_layout_ci.pNext = NULL;
7327 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7328 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007329
7330 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007331 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007332 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007333 // Create pipelineLayout with only one setLayout
7334 pipeline_layout_ci.setLayoutCount = 1;
7335 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007336 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007337 ASSERT_VK_SUCCESS(err);
7338 // Create pipelineLayout with 2 descriptor setLayout at index 0
7339 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7340 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007341 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007342 ASSERT_VK_SUCCESS(err);
7343 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7344 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7345 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007346 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007347 ASSERT_VK_SUCCESS(err);
7348 // Create pipelineLayout with UB type, but stageFlags for FS only
7349 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7350 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007351 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007352 ASSERT_VK_SUCCESS(err);
7353 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7354 VkDescriptorSetLayout pl_bad_s0[2] = {};
7355 pl_bad_s0[0] = ds_layout_fs_only;
7356 pl_bad_s0[1] = ds_layout[1];
7357 pipeline_layout_ci.setLayoutCount = 2;
7358 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7359 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007360 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007361 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007362
Tobin Ehlis88452832015-12-03 09:40:56 -07007363 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007364 char const *vsSource =
7365 "#version 450\n"
7366 "\n"
7367 "out gl_PerVertex {\n"
7368 " vec4 gl_Position;\n"
7369 "};\n"
7370 "void main(){\n"
7371 " gl_Position = vec4(1);\n"
7372 "}\n";
7373 char const *fsSource =
7374 "#version 450\n"
7375 "\n"
7376 "layout(location=0) out vec4 x;\n"
7377 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7378 "void main(){\n"
7379 " x = vec4(bar.y);\n"
7380 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007381 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7382 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007383 VkPipelineObj pipe(m_device);
7384 pipe.AddShader(&vs);
7385 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007386 pipe.AddColorAttachment();
7387 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007388
Tony Barbour552f6c02016-12-21 14:34:07 -07007389 m_commandBuffer->BeginCommandBuffer();
7390 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007392 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007393 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7394 // of PSO
7395 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7396 // cmd_pipeline.c
7397 // due to the fact that cmd_alloc_dset_data() has not been called in
7398 // cmd_bind_graphics_pipeline()
7399 // TODO : Want to cause various binding incompatibility issues here to test
7400 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007401 // First cause various verify_layout_compatibility() fails
7402 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007403 // verify_set_layout_compatibility fail cases:
7404 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007406 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7407 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007408 m_errorMonitor->VerifyFound();
7409
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007410 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7412 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7413 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007414 m_errorMonitor->VerifyFound();
7415
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007416 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007417 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7418 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7420 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7421 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007422 m_errorMonitor->VerifyFound();
7423
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007424 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7425 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7427 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7428 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007429 m_errorMonitor->VerifyFound();
7430
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007431 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7432 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7434 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7435 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7436 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007437 m_errorMonitor->VerifyFound();
7438
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007439 // Cause INFO messages due to disturbing previously bound Sets
7440 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007441 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7442 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007443 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7445 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7446 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007447 m_errorMonitor->VerifyFound();
7448
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007449 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7450 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007451 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7453 " newly bound as set #0 so set #1 and "
7454 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007455 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7456 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007457 m_errorMonitor->VerifyFound();
7458
Tobin Ehlis10fad692016-07-07 12:00:36 -06007459 // Now that we're done actively using the pipelineLayout that gfx pipeline
7460 // was created with, we should be able to delete it. Do that now to verify
7461 // that validation obeys pipelineLayout lifetime
7462 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7463
Tobin Ehlis88452832015-12-03 09:40:56 -07007464 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007465 // 1. Error due to not binding required set (we actually use same code as
7466 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007467 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7468 &descriptorSet[0], 0, NULL);
7469 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7470 &descriptorSet[1], 0, NULL);
7471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " uses set #0 but that set is not bound.");
Rene Lindsay9f228e42017-01-16 13:57:45 -07007472
7473 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7474 VkRect2D scissor = {{0, 0}, {16, 16}};
7475 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7476 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7477
Tobin Ehlis88452832015-12-03 09:40:56 -07007478 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007479 m_errorMonitor->VerifyFound();
7480
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007481 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007482 // 2. Error due to bound set not being compatible with PSO's
7483 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007484 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7485 &descriptorSet[0], 0, NULL);
7486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007487 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007488 m_errorMonitor->VerifyFound();
7489
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007490 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007491 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007492 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7493 }
7494 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007495 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7496 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7497}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007498
Karl Schultz6addd812016-02-02 17:17:23 -07007499TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7501 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007502
Tony Barbour1fa09702017-03-16 12:09:08 -06007503 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007504 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007505 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007506 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007507
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007508 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007509}
7510
Karl Schultz6addd812016-02-02 17:17:23 -07007511TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7512 VkResult err;
7513 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007514
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007516
Tony Barbour1fa09702017-03-16 12:09:08 -06007517 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007518
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007519 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007520 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007521 cmd.pNext = NULL;
Mike Schuchardt06304c22017-03-01 17:09:09 -07007522 cmd.commandPool = m_commandPool->handle();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007523 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007524 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007525
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007526 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007527 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007528
7529 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007530 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007531 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7532
7533 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007534 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007535 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007536 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007537 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007538
7539 // The error should be caught by validation of the BeginCommandBuffer call
7540 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7541
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007542 m_errorMonitor->VerifyFound();
Mike Schuchardt06304c22017-03-01 17:09:09 -07007543 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007544}
7545
Chris Forbes5b3725e2017-05-18 16:01:20 -07007546TEST_F(VkLayerTest, SecondaryCommandBufferRerecordedExplicitReset) {
Chris Forbes9480ae92017-05-17 17:14:34 -07007547 ASSERT_NO_FATAL_FAILURE(Init());
7548
Chris Forbes5b3725e2017-05-18 16:01:20 -07007549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was destroyed or rerecorded");
Chris Forbes9480ae92017-05-17 17:14:34 -07007550
7551 // A pool we can reset in.
7552 VkCommandPoolObj pool(m_device, m_device->graphics_queue_node_index_,
7553 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
7554 VkCommandBufferObj secondary(m_device, &pool,
7555 VK_COMMAND_BUFFER_LEVEL_SECONDARY);
7556
7557 secondary.begin();
7558 secondary.end();
7559
7560 m_commandBuffer->begin();
7561 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
7562
7563 // rerecording of secondary
Chris Forbes5b3725e2017-05-18 16:01:20 -07007564 secondary.reset(); // explicit reset here.
Chris Forbes9480ae92017-05-17 17:14:34 -07007565 secondary.begin();
7566 secondary.end();
7567
7568 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Chris Forbes5b3725e2017-05-18 16:01:20 -07007569 m_errorMonitor->VerifyFound();
7570}
Chris Forbes9480ae92017-05-17 17:14:34 -07007571
Chris Forbes5b3725e2017-05-18 16:01:20 -07007572TEST_F(VkLayerTest, SecondaryCommandBufferRerecordedNoReset) {
7573 ASSERT_NO_FATAL_FAILURE(Init());
7574
7575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was destroyed or rerecorded");
7576
7577 // A pool we can reset in.
7578 VkCommandPoolObj pool(m_device, m_device->graphics_queue_node_index_,
7579 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
7580 VkCommandBufferObj secondary(m_device, &pool,
7581 VK_COMMAND_BUFFER_LEVEL_SECONDARY);
7582
7583 secondary.begin();
7584 secondary.end();
7585
7586 m_commandBuffer->begin();
7587 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
7588
7589 // rerecording of secondary
7590 secondary.begin(); // implicit reset in begin
7591 secondary.end();
7592
7593 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Chris Forbes9480ae92017-05-17 17:14:34 -07007594 m_errorMonitor->VerifyFound();
7595}
7596
Karl Schultz6addd812016-02-02 17:17:23 -07007597TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007598 // Cause error due to Begin while recording CB
7599 // Then cause 2 errors for attempting to reset CB w/o having
7600 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7601 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007603
Tony Barbour1fa09702017-03-16 12:09:08 -06007604 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007605
7606 // Calls AllocateCommandBuffers
7607 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7608
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007609 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007610 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007611 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7612 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007613 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7614 cmd_buf_info.pNext = NULL;
7615 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007616 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007617
7618 // Begin CB to transition to recording state
7619 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7620 // Can't re-begin. This should trigger error
7621 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007622 m_errorMonitor->VerifyFound();
7623
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007625 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007626 // Reset attempt will trigger error due to incorrect CommandPool state
7627 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007628 m_errorMonitor->VerifyFound();
7629
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007631 // Transition CB to RECORDED state
7632 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7633 // Now attempting to Begin will implicitly reset, which triggers error
7634 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007635 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007636}
7637
Karl Schultz6addd812016-02-02 17:17:23 -07007638TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007639 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007640 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007641
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7643 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007644
Tony Barbour1fa09702017-03-16 12:09:08 -06007645 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007647
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007648 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007649 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7650 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007651
7652 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007653 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7654 ds_pool_ci.pNext = NULL;
7655 ds_pool_ci.maxSets = 1;
7656 ds_pool_ci.poolSizeCount = 1;
7657 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007658
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007659 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007660 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007661 ASSERT_VK_SUCCESS(err);
7662
Tony Barboureb254902015-07-15 12:50:33 -06007663 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007664 dsl_binding.binding = 0;
7665 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7666 dsl_binding.descriptorCount = 1;
7667 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7668 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007669
Tony Barboureb254902015-07-15 12:50:33 -06007670 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007671 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7672 ds_layout_ci.pNext = NULL;
7673 ds_layout_ci.bindingCount = 1;
7674 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007675
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007676 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007677 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007678 ASSERT_VK_SUCCESS(err);
7679
7680 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007681 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007682 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007683 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007684 alloc_info.descriptorPool = ds_pool;
7685 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007686 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007687 ASSERT_VK_SUCCESS(err);
7688
Tony Barboureb254902015-07-15 12:50:33 -06007689 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007690 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7691 pipeline_layout_ci.setLayoutCount = 1;
7692 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007693
7694 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007695 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007696 ASSERT_VK_SUCCESS(err);
7697
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007698 VkViewport vp = {}; // Just need dummy vp to point to
7699 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007700
7701 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007702 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7703 vp_state_ci.scissorCount = 1;
7704 vp_state_ci.pScissors = &sc;
7705 vp_state_ci.viewportCount = 1;
7706 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007707
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007708 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7709 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7710 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7711 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7712 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7713 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007714 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007715 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007716 rs_state_ci.lineWidth = 1.0f;
7717
7718 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7719 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7720 vi_ci.pNext = nullptr;
7721 vi_ci.vertexBindingDescriptionCount = 0;
7722 vi_ci.pVertexBindingDescriptions = nullptr;
7723 vi_ci.vertexAttributeDescriptionCount = 0;
7724 vi_ci.pVertexAttributeDescriptions = nullptr;
7725
7726 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7727 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7728 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7729
7730 VkPipelineShaderStageCreateInfo shaderStages[2];
7731 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7732
7733 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7734 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007735 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007736 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007737
Tony Barboureb254902015-07-15 12:50:33 -06007738 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007739 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7740 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007741 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007742 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7743 gp_ci.layout = pipeline_layout;
7744 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007745 gp_ci.pVertexInputState = &vi_ci;
7746 gp_ci.pInputAssemblyState = &ia_ci;
7747
7748 gp_ci.stageCount = 1;
7749 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007750
7751 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007752 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7753 pc_ci.initialDataSize = 0;
7754 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007755
7756 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007757 VkPipelineCache pipelineCache;
7758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007759 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007760 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007761 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007762 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007763
Chia-I Wuf7458c52015-10-26 21:10:41 +08007764 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7765 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7766 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7767 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007768}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007769
Tobin Ehlis912df022015-09-17 08:46:18 -06007770/*// TODO : This test should be good, but needs Tess support in compiler to run
7771TEST_F(VkLayerTest, InvalidPatchControlPoints)
7772{
7773 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007774 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007775
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007777 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7778primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007779
Tony Barbour1fa09702017-03-16 12:09:08 -06007780 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis912df022015-09-17 08:46:18 -06007781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007782
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007783 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007784 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007785 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007786
7787 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7788 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7789 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007790 ds_pool_ci.poolSizeCount = 1;
7791 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007792
7793 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007794 err = vkCreateDescriptorPool(m_device->device(),
7795VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007796 ASSERT_VK_SUCCESS(err);
7797
7798 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007799 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007800 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007801 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007802 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7803 dsl_binding.pImmutableSamplers = NULL;
7804
7805 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007806 ds_layout_ci.sType =
7807VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007808 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007809 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007810 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007811
7812 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007813 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7814&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007815 ASSERT_VK_SUCCESS(err);
7816
7817 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007818 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7819VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007820 ASSERT_VK_SUCCESS(err);
7821
7822 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007823 pipeline_layout_ci.sType =
7824VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007825 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007826 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007827 pipeline_layout_ci.pSetLayouts = &ds_layout;
7828
7829 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007830 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7831&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007832 ASSERT_VK_SUCCESS(err);
7833
7834 VkPipelineShaderStageCreateInfo shaderStages[3];
7835 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7836
Karl Schultz6addd812016-02-02 17:17:23 -07007837 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7838this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007839 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007840 VkShaderObj
7841tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7842this);
7843 VkShaderObj
7844te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7845this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007846
Karl Schultz6addd812016-02-02 17:17:23 -07007847 shaderStages[0].sType =
7848VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007849 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007850 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007851 shaderStages[1].sType =
7852VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007853 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007854 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007855 shaderStages[2].sType =
7856VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007857 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007858 shaderStages[2].shader = te.handle();
7859
7860 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007861 iaCI.sType =
7862VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007863 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007864
7865 VkPipelineTessellationStateCreateInfo tsCI = {};
7866 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7867 tsCI.patchControlPoints = 0; // This will cause an error
7868
7869 VkGraphicsPipelineCreateInfo gp_ci = {};
7870 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7871 gp_ci.pNext = NULL;
7872 gp_ci.stageCount = 3;
7873 gp_ci.pStages = shaderStages;
7874 gp_ci.pVertexInputState = NULL;
7875 gp_ci.pInputAssemblyState = &iaCI;
7876 gp_ci.pTessellationState = &tsCI;
7877 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007878 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007879 gp_ci.pMultisampleState = NULL;
7880 gp_ci.pDepthStencilState = NULL;
7881 gp_ci.pColorBlendState = NULL;
7882 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7883 gp_ci.layout = pipeline_layout;
7884 gp_ci.renderPass = renderPass();
7885
7886 VkPipelineCacheCreateInfo pc_ci = {};
7887 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7888 pc_ci.pNext = NULL;
7889 pc_ci.initialSize = 0;
7890 pc_ci.initialData = 0;
7891 pc_ci.maxSize = 0;
7892
7893 VkPipeline pipeline;
7894 VkPipelineCache pipelineCache;
7895
Karl Schultz6addd812016-02-02 17:17:23 -07007896 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7897&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007898 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007899 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7900&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007901
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007902 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007903
Chia-I Wuf7458c52015-10-26 21:10:41 +08007904 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7905 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7906 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7907 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007908}
7909*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007910
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007911TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007912 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007913
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007914 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007915
Tony Barbour1fa09702017-03-16 12:09:08 -06007916 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007918
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007919 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007920 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7921 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007922
7923 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007924 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7925 ds_pool_ci.maxSets = 1;
7926 ds_pool_ci.poolSizeCount = 1;
7927 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007928
7929 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007930 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007931 ASSERT_VK_SUCCESS(err);
7932
7933 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007934 dsl_binding.binding = 0;
7935 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7936 dsl_binding.descriptorCount = 1;
7937 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007938
7939 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007940 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7941 ds_layout_ci.bindingCount = 1;
7942 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007943
7944 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007945 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007946 ASSERT_VK_SUCCESS(err);
7947
7948 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007949 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007950 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007951 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007952 alloc_info.descriptorPool = ds_pool;
7953 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007954 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007955 ASSERT_VK_SUCCESS(err);
7956
7957 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007958 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7959 pipeline_layout_ci.setLayoutCount = 1;
7960 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007961
7962 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007963 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007964 ASSERT_VK_SUCCESS(err);
7965
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007966 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007967 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007968 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007969 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007970 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007971 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007972
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007973 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7974 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7975 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7976 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7977 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7978 rs_state_ci.depthClampEnable = VK_FALSE;
7979 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7980 rs_state_ci.depthBiasEnable = VK_FALSE;
7981
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007982 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7983 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7984 vi_ci.pNext = nullptr;
7985 vi_ci.vertexBindingDescriptionCount = 0;
7986 vi_ci.pVertexBindingDescriptions = nullptr;
7987 vi_ci.vertexAttributeDescriptionCount = 0;
7988 vi_ci.pVertexAttributeDescriptions = nullptr;
7989
7990 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7991 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7992 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7993
7994 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7995 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7996 pipe_ms_state_ci.pNext = NULL;
7997 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7998 pipe_ms_state_ci.sampleShadingEnable = 0;
7999 pipe_ms_state_ci.minSampleShading = 1.0;
8000 pipe_ms_state_ci.pSampleMask = NULL;
8001
Cody Northropeb3a6c12015-10-05 14:44:45 -06008002 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008003 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008004
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008005 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008006 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08008007 shaderStages[0] = vs.GetStageCreateInfo();
8008 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008009
8010 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008011 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8012 gp_ci.stageCount = 2;
8013 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008014 gp_ci.pVertexInputState = &vi_ci;
8015 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008016 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07008017 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008018 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008019 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8020 gp_ci.layout = pipeline_layout;
8021 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008022
8023 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008024 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008025
8026 VkPipeline pipeline;
8027 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008028 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008029 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008030
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008031 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008032 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008033
8034 // Check case where multiViewport is disabled and viewport count is not 1
8035 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
8037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
8038 vp_state_ci.scissorCount = 0;
8039 vp_state_ci.viewportCount = 0;
8040 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8041 m_errorMonitor->VerifyFound();
8042 } else {
8043 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008044 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008045 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008046 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008047
8048 // Check is that viewportcount and scissorcount match
8049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
8050 vp_state_ci.scissorCount = 1;
8051 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
8052 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8053 m_errorMonitor->VerifyFound();
8054
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07008055 // Check case where multiViewport is enabled and viewport count is greater than max
8056 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
8057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
8058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
8059 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
8060 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
8061 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
8062 m_errorMonitor->VerifyFound();
8063 }
8064 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06008065
Chia-I Wuf7458c52015-10-26 21:10:41 +08008066 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8067 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8068 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8069 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008070}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008071
8072// 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
8073// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07008074TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07008075 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008076
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008077 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
8078
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008080
Tony Barbour1fa09702017-03-16 12:09:08 -06008081 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008083
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008084 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008085 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8086 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008087
8088 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008089 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8090 ds_pool_ci.maxSets = 1;
8091 ds_pool_ci.poolSizeCount = 1;
8092 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008093
8094 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008095 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008096 ASSERT_VK_SUCCESS(err);
8097
8098 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008099 dsl_binding.binding = 0;
8100 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8101 dsl_binding.descriptorCount = 1;
8102 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008103
8104 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008105 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8106 ds_layout_ci.bindingCount = 1;
8107 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008108
8109 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008110 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008111 ASSERT_VK_SUCCESS(err);
8112
8113 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008114 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008115 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008116 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008117 alloc_info.descriptorPool = ds_pool;
8118 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008119 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008120 ASSERT_VK_SUCCESS(err);
8121
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008122 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8123 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8124 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8125
8126 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8127 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8128 vi_ci.pNext = nullptr;
8129 vi_ci.vertexBindingDescriptionCount = 0;
8130 vi_ci.pVertexBindingDescriptions = nullptr;
8131 vi_ci.vertexAttributeDescriptionCount = 0;
8132 vi_ci.pVertexAttributeDescriptions = nullptr;
8133
8134 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8135 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8136 pipe_ms_state_ci.pNext = NULL;
8137 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
8138 pipe_ms_state_ci.sampleShadingEnable = 0;
8139 pipe_ms_state_ci.minSampleShading = 1.0;
8140 pipe_ms_state_ci.pSampleMask = NULL;
8141
Tobin Ehlise68360f2015-10-01 11:15:13 -06008142 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008143 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8144 pipeline_layout_ci.setLayoutCount = 1;
8145 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008146
8147 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008148 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008149 ASSERT_VK_SUCCESS(err);
8150
8151 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8152 // Set scissor as dynamic to avoid second error
8153 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008154 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8155 dyn_state_ci.dynamicStateCount = 1;
8156 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008157
Cody Northropeb3a6c12015-10-05 14:44:45 -06008158 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008159 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008160
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008161 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008162 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8163 // 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 +08008164 shaderStages[0] = vs.GetStageCreateInfo();
8165 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008166
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008167 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
8168 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8169 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
8170 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
8171 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8172 rs_state_ci.depthClampEnable = VK_FALSE;
8173 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
8174 rs_state_ci.depthBiasEnable = VK_FALSE;
8175
Tobin Ehlise68360f2015-10-01 11:15:13 -06008176 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008177 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8178 gp_ci.stageCount = 2;
8179 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07008180 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008181 // Not setting VP state w/o dynamic vp state should cause validation error
8182 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07008183 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07008184 gp_ci.pVertexInputState = &vi_ci;
8185 gp_ci.pInputAssemblyState = &ia_ci;
8186 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008187 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8188 gp_ci.layout = pipeline_layout;
8189 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008190
8191 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008192 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008193
8194 VkPipeline pipeline;
8195 VkPipelineCache pipelineCache;
8196
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008197 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008198 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008199 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008200
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008201 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008202
Chia-I Wuf7458c52015-10-26 21:10:41 +08008203 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8204 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8205 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8206 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008207}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008208
8209// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
8210// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07008211TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
8212 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008213
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008215
Tony Barbour1fa09702017-03-16 12:09:08 -06008216 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008217
8218 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008219 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008220 return;
8221 }
8222
Tobin Ehlise68360f2015-10-01 11:15:13 -06008223 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06008224
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008225 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008226 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8227 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008228
8229 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008230 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8231 ds_pool_ci.maxSets = 1;
8232 ds_pool_ci.poolSizeCount = 1;
8233 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008234
8235 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008236 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008237 ASSERT_VK_SUCCESS(err);
8238
8239 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008240 dsl_binding.binding = 0;
8241 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8242 dsl_binding.descriptorCount = 1;
8243 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008244
8245 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008246 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8247 ds_layout_ci.bindingCount = 1;
8248 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008249
8250 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008251 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008252 ASSERT_VK_SUCCESS(err);
8253
8254 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008255 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008256 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008257 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008258 alloc_info.descriptorPool = ds_pool;
8259 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008260 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008261 ASSERT_VK_SUCCESS(err);
8262
8263 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008264 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8265 pipeline_layout_ci.setLayoutCount = 1;
8266 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008267
8268 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008269 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008270 ASSERT_VK_SUCCESS(err);
8271
8272 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008273 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8274 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008275 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008276 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008277 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008278
8279 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8280 // Set scissor as dynamic to avoid that error
8281 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008282 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8283 dyn_state_ci.dynamicStateCount = 1;
8284 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008285
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008286 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8287 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8288 pipe_ms_state_ci.pNext = NULL;
8289 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8290 pipe_ms_state_ci.sampleShadingEnable = 0;
8291 pipe_ms_state_ci.minSampleShading = 1.0;
8292 pipe_ms_state_ci.pSampleMask = NULL;
8293
Cody Northropeb3a6c12015-10-05 14:44:45 -06008294 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008295 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008296
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008297 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008298 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8299 // 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 +08008300 shaderStages[0] = vs.GetStageCreateInfo();
8301 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008302
Cody Northropf6622dc2015-10-06 10:33:21 -06008303 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8304 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8305 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008306 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008307 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008308 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008309 vi_ci.pVertexAttributeDescriptions = nullptr;
8310
8311 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8312 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8313 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8314
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008315 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008316 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008317 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008318 rs_ci.pNext = nullptr;
8319
Mark Youngc89c6312016-03-31 16:03:20 -06008320 VkPipelineColorBlendAttachmentState att = {};
8321 att.blendEnable = VK_FALSE;
8322 att.colorWriteMask = 0xf;
8323
Cody Northropf6622dc2015-10-06 10:33:21 -06008324 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8325 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8326 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008327 cb_ci.attachmentCount = 1;
8328 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008329
Tobin Ehlise68360f2015-10-01 11:15:13 -06008330 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008331 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8332 gp_ci.stageCount = 2;
8333 gp_ci.pStages = shaderStages;
8334 gp_ci.pVertexInputState = &vi_ci;
8335 gp_ci.pInputAssemblyState = &ia_ci;
8336 gp_ci.pViewportState = &vp_state_ci;
8337 gp_ci.pRasterizationState = &rs_ci;
8338 gp_ci.pColorBlendState = &cb_ci;
8339 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008340 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008341 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8342 gp_ci.layout = pipeline_layout;
8343 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008344
8345 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008346 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008347
8348 VkPipeline pipeline;
8349 VkPipelineCache pipelineCache;
8350
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008351 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008352 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008353 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008354
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008355 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008356
Tobin Ehlisd332f282015-10-02 11:00:56 -06008357 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008358 // First need to successfully create the PSO from above by setting
8359 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008360 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 -07008361
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008362 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008363 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008364 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008365 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008366 m_commandBuffer->BeginCommandBuffer();
8367 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008368 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008369 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008370 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008371 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008372 Draw(1, 0, 0, 0);
8373
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008374 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008375
8376 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8377 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8378 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8379 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008380 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008381}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008382
8383// 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 -07008384// viewportCount
8385TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8386 VkResult err;
8387
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008389
Tony Barbour1fa09702017-03-16 12:09:08 -06008390 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008391
8392 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008393 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008394 return;
8395 }
8396
Karl Schultz6addd812016-02-02 17:17:23 -07008397 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8398
8399 VkDescriptorPoolSize ds_type_count = {};
8400 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8401 ds_type_count.descriptorCount = 1;
8402
8403 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8404 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8405 ds_pool_ci.maxSets = 1;
8406 ds_pool_ci.poolSizeCount = 1;
8407 ds_pool_ci.pPoolSizes = &ds_type_count;
8408
8409 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008410 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008411 ASSERT_VK_SUCCESS(err);
8412
8413 VkDescriptorSetLayoutBinding dsl_binding = {};
8414 dsl_binding.binding = 0;
8415 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8416 dsl_binding.descriptorCount = 1;
8417 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8418
8419 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8420 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8421 ds_layout_ci.bindingCount = 1;
8422 ds_layout_ci.pBindings = &dsl_binding;
8423
8424 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008425 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008426 ASSERT_VK_SUCCESS(err);
8427
8428 VkDescriptorSet descriptorSet;
8429 VkDescriptorSetAllocateInfo alloc_info = {};
8430 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8431 alloc_info.descriptorSetCount = 1;
8432 alloc_info.descriptorPool = ds_pool;
8433 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008435 ASSERT_VK_SUCCESS(err);
8436
8437 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8438 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8439 pipeline_layout_ci.setLayoutCount = 1;
8440 pipeline_layout_ci.pSetLayouts = &ds_layout;
8441
8442 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008443 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008444 ASSERT_VK_SUCCESS(err);
8445
8446 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8447 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8448 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008449 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008450 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008451 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008452
8453 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8454 // Set scissor as dynamic to avoid that error
8455 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8456 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8457 dyn_state_ci.dynamicStateCount = 1;
8458 dyn_state_ci.pDynamicStates = &vp_state;
8459
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008460 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8461 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8462 pipe_ms_state_ci.pNext = NULL;
8463 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8464 pipe_ms_state_ci.sampleShadingEnable = 0;
8465 pipe_ms_state_ci.minSampleShading = 1.0;
8466 pipe_ms_state_ci.pSampleMask = NULL;
8467
Karl Schultz6addd812016-02-02 17:17:23 -07008468 VkPipelineShaderStageCreateInfo shaderStages[2];
8469 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8470
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008471 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008472 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8473 // 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 -07008474 shaderStages[0] = vs.GetStageCreateInfo();
8475 shaderStages[1] = fs.GetStageCreateInfo();
8476
8477 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8478 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8479 vi_ci.pNext = nullptr;
8480 vi_ci.vertexBindingDescriptionCount = 0;
8481 vi_ci.pVertexBindingDescriptions = nullptr;
8482 vi_ci.vertexAttributeDescriptionCount = 0;
8483 vi_ci.pVertexAttributeDescriptions = nullptr;
8484
8485 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8486 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8487 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8488
8489 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8490 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008491 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008492 rs_ci.pNext = nullptr;
8493
Mark Youngc89c6312016-03-31 16:03:20 -06008494 VkPipelineColorBlendAttachmentState att = {};
8495 att.blendEnable = VK_FALSE;
8496 att.colorWriteMask = 0xf;
8497
Karl Schultz6addd812016-02-02 17:17:23 -07008498 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8499 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8500 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008501 cb_ci.attachmentCount = 1;
8502 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008503
8504 VkGraphicsPipelineCreateInfo gp_ci = {};
8505 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8506 gp_ci.stageCount = 2;
8507 gp_ci.pStages = shaderStages;
8508 gp_ci.pVertexInputState = &vi_ci;
8509 gp_ci.pInputAssemblyState = &ia_ci;
8510 gp_ci.pViewportState = &vp_state_ci;
8511 gp_ci.pRasterizationState = &rs_ci;
8512 gp_ci.pColorBlendState = &cb_ci;
8513 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008514 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008515 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8516 gp_ci.layout = pipeline_layout;
8517 gp_ci.renderPass = renderPass();
8518
8519 VkPipelineCacheCreateInfo pc_ci = {};
8520 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8521
8522 VkPipeline pipeline;
8523 VkPipelineCache pipelineCache;
8524
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008525 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008526 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008527 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008528
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008529 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008530
8531 // Now hit second fail case where we set scissor w/ different count than PSO
8532 // First need to successfully create the PSO from above by setting
8533 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8535 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008536
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008537 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008538 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008539 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008540 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008541 m_commandBuffer->BeginCommandBuffer();
8542 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008543 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008544 VkViewport viewports[1] = {};
8545 viewports[0].width = 8;
8546 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008547 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008548 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008549 Draw(1, 0, 0, 0);
8550
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008551 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008552
Chia-I Wuf7458c52015-10-26 21:10:41 +08008553 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8554 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8555 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8556 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008557 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008558}
8559
Mark Young7394fdd2016-03-31 14:56:43 -06008560TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8561 VkResult err;
8562
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008564
Tony Barbour1fa09702017-03-16 12:09:08 -06008565 ASSERT_NO_FATAL_FAILURE(Init());
Mark Young7394fdd2016-03-31 14:56:43 -06008566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8567
8568 VkDescriptorPoolSize ds_type_count = {};
8569 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8570 ds_type_count.descriptorCount = 1;
8571
8572 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8573 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8574 ds_pool_ci.maxSets = 1;
8575 ds_pool_ci.poolSizeCount = 1;
8576 ds_pool_ci.pPoolSizes = &ds_type_count;
8577
8578 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008579 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008580 ASSERT_VK_SUCCESS(err);
8581
8582 VkDescriptorSetLayoutBinding dsl_binding = {};
8583 dsl_binding.binding = 0;
8584 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8585 dsl_binding.descriptorCount = 1;
8586 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8587
8588 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8589 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8590 ds_layout_ci.bindingCount = 1;
8591 ds_layout_ci.pBindings = &dsl_binding;
8592
8593 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008594 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008595 ASSERT_VK_SUCCESS(err);
8596
8597 VkDescriptorSet descriptorSet;
8598 VkDescriptorSetAllocateInfo alloc_info = {};
8599 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8600 alloc_info.descriptorSetCount = 1;
8601 alloc_info.descriptorPool = ds_pool;
8602 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008603 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008604 ASSERT_VK_SUCCESS(err);
8605
8606 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8607 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8608 pipeline_layout_ci.setLayoutCount = 1;
8609 pipeline_layout_ci.pSetLayouts = &ds_layout;
8610
8611 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008612 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008613 ASSERT_VK_SUCCESS(err);
8614
8615 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8616 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8617 vp_state_ci.scissorCount = 1;
8618 vp_state_ci.pScissors = NULL;
8619 vp_state_ci.viewportCount = 1;
8620 vp_state_ci.pViewports = NULL;
8621
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008622 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008623 // Set scissor as dynamic to avoid that error
8624 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8625 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8626 dyn_state_ci.dynamicStateCount = 2;
8627 dyn_state_ci.pDynamicStates = dynamic_states;
8628
8629 VkPipelineShaderStageCreateInfo shaderStages[2];
8630 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8631
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008632 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8633 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008634 this); // TODO - We shouldn't need a fragment shader
8635 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008636 shaderStages[0] = vs.GetStageCreateInfo();
8637 shaderStages[1] = fs.GetStageCreateInfo();
8638
8639 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8640 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8641 vi_ci.pNext = nullptr;
8642 vi_ci.vertexBindingDescriptionCount = 0;
8643 vi_ci.pVertexBindingDescriptions = nullptr;
8644 vi_ci.vertexAttributeDescriptionCount = 0;
8645 vi_ci.pVertexAttributeDescriptions = nullptr;
8646
8647 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8648 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8649 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8650
8651 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8652 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8653 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008654 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008655
Mark Young47107952016-05-02 15:59:55 -06008656 // Check too low (line width of -1.0f).
8657 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008658
8659 VkPipelineColorBlendAttachmentState att = {};
8660 att.blendEnable = VK_FALSE;
8661 att.colorWriteMask = 0xf;
8662
8663 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8664 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8665 cb_ci.pNext = nullptr;
8666 cb_ci.attachmentCount = 1;
8667 cb_ci.pAttachments = &att;
8668
8669 VkGraphicsPipelineCreateInfo gp_ci = {};
8670 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8671 gp_ci.stageCount = 2;
8672 gp_ci.pStages = shaderStages;
8673 gp_ci.pVertexInputState = &vi_ci;
8674 gp_ci.pInputAssemblyState = &ia_ci;
8675 gp_ci.pViewportState = &vp_state_ci;
8676 gp_ci.pRasterizationState = &rs_ci;
8677 gp_ci.pColorBlendState = &cb_ci;
8678 gp_ci.pDynamicState = &dyn_state_ci;
8679 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8680 gp_ci.layout = pipeline_layout;
8681 gp_ci.renderPass = renderPass();
8682
8683 VkPipelineCacheCreateInfo pc_ci = {};
8684 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8685
8686 VkPipeline pipeline;
8687 VkPipelineCache pipelineCache;
8688
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008689 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008690 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008691 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008692
8693 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008694 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008695
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008697
8698 // Check too high (line width of 65536.0f).
8699 rs_ci.lineWidth = 65536.0f;
8700
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008701 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008702 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008703 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008704
8705 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008706 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008707
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008709
8710 dyn_state_ci.dynamicStateCount = 3;
8711
8712 rs_ci.lineWidth = 1.0f;
8713
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008714 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008715 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008716 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008717 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008718 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008719
8720 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008721 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008722 m_errorMonitor->VerifyFound();
8723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008725
8726 // Check too high with dynamic setting.
8727 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8728 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008729 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008730
8731 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8732 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8733 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8734 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008735 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008736}
8737
Jeremy Hayes37f0cdd2017-05-04 18:08:49 -06008738TEST_F(VkLayerTest, VALIDATION_ERROR_01407) {
8739 TEST_DESCRIPTION("Test VALIDATION_ERROR_01407: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
8740
8741 ASSERT_NO_FATAL_FAILURE(Init());
8742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8743
8744 VkPipelineCache pipeline_cache;
8745 {
8746 VkPipelineCacheCreateInfo create_info{};
8747 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8748
8749 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8750 ASSERT_VK_SUCCESS(err);
8751 }
8752
8753 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8754 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8755
8756 VkPipelineShaderStageCreateInfo stages[2]{{}};
8757 stages[0] = vs.GetStageCreateInfo();
8758 stages[1] = fs.GetStageCreateInfo();
8759
8760 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
8761 VkVertexInputBindingDescription vertex_input_binding_description{};
8762 vertex_input_binding_description.binding = m_device->props.limits.maxVertexInputBindings;
8763
8764 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8765 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8766 vertex_input_state.pNext = nullptr;
8767 vertex_input_state.vertexBindingDescriptionCount = 1;
8768 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8769 vertex_input_state.vertexAttributeDescriptionCount = 0;
8770 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8771
8772 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8773 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8774 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8775
8776 VkViewport viewport{};
8777 VkPipelineViewportStateCreateInfo viewport_state{};
8778 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8779 viewport_state.scissorCount = 1;
8780 viewport_state.viewportCount = 1;
8781 viewport_state.pViewports = &viewport;
8782
8783 VkPipelineMultisampleStateCreateInfo multisample_state{};
8784 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8785 multisample_state.pNext = nullptr;
8786 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8787 multisample_state.sampleShadingEnable = 0;
8788 multisample_state.minSampleShading = 1.0;
8789 multisample_state.pSampleMask = nullptr;
8790
8791 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8792 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8793 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8794 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8795 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8796 rasterization_state.depthClampEnable = VK_FALSE;
8797 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8798 rasterization_state.depthBiasEnable = VK_FALSE;
8799
8800 VkPipelineLayout pipeline_layout;
8801 {
8802 VkPipelineLayoutCreateInfo create_info{};
8803 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8804 create_info.setLayoutCount = 0;
8805 create_info.pSetLayouts = nullptr;
8806
8807 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8808 ASSERT_VK_SUCCESS(err);
8809 }
8810
8811 {
8812 VkGraphicsPipelineCreateInfo create_info{};
8813 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8814 create_info.stageCount = 2;
8815 create_info.pStages = stages;
8816 create_info.pVertexInputState = &vertex_input_state;
8817 create_info.pInputAssemblyState = &input_assembly_state;
8818 create_info.pViewportState = &viewport_state;
8819 create_info.pMultisampleState = &multisample_state;
8820 create_info.pRasterizationState = &rasterization_state;
8821 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8822 create_info.layout = pipeline_layout;
8823 create_info.renderPass = renderPass();
8824
8825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01407);
8826 VkPipeline pipeline;
8827 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8828 m_errorMonitor->VerifyFound();
8829 }
8830
8831 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8832 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8833}
8834
8835TEST_F(VkLayerTest, VALIDATION_ERROR_01408) {
8836 TEST_DESCRIPTION(
8837 "Test VALIDATION_ERROR_01408: stride must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputBindingStride");
8838
8839 ASSERT_NO_FATAL_FAILURE(Init());
8840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8841
8842 VkPipelineCache pipeline_cache;
8843 {
8844 VkPipelineCacheCreateInfo create_info{};
8845 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8846
8847 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8848 ASSERT_VK_SUCCESS(err);
8849 }
8850
8851 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8852 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8853
8854 VkPipelineShaderStageCreateInfo stages[2]{{}};
8855 stages[0] = vs.GetStageCreateInfo();
8856 stages[1] = fs.GetStageCreateInfo();
8857
8858 // Test when stride is greater than VkPhysicalDeviceLimits::maxVertexInputBindingStride.
8859 VkVertexInputBindingDescription vertex_input_binding_description{};
8860 vertex_input_binding_description.stride = m_device->props.limits.maxVertexInputBindingStride + 1;
8861
8862 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8863 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8864 vertex_input_state.pNext = nullptr;
8865 vertex_input_state.vertexBindingDescriptionCount = 1;
8866 vertex_input_state.pVertexBindingDescriptions = &vertex_input_binding_description;
8867 vertex_input_state.vertexAttributeDescriptionCount = 0;
8868 vertex_input_state.pVertexAttributeDescriptions = nullptr;
8869
8870 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8871 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8872 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8873
8874 VkViewport viewport{};
8875 VkPipelineViewportStateCreateInfo viewport_state{};
8876 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8877 viewport_state.scissorCount = 1;
8878 viewport_state.viewportCount = 1;
8879 viewport_state.pViewports = &viewport;
8880
8881 VkPipelineMultisampleStateCreateInfo multisample_state{};
8882 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8883 multisample_state.pNext = nullptr;
8884 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8885 multisample_state.sampleShadingEnable = 0;
8886 multisample_state.minSampleShading = 1.0;
8887 multisample_state.pSampleMask = nullptr;
8888
8889 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8890 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8891 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8892 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8893 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8894 rasterization_state.depthClampEnable = VK_FALSE;
8895 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8896 rasterization_state.depthBiasEnable = VK_FALSE;
8897
8898 VkPipelineLayout pipeline_layout;
8899 {
8900 VkPipelineLayoutCreateInfo create_info{};
8901 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8902 create_info.setLayoutCount = 0;
8903 create_info.pSetLayouts = nullptr;
8904
8905 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
8906 ASSERT_VK_SUCCESS(err);
8907 }
8908
8909 {
8910 VkGraphicsPipelineCreateInfo create_info{};
8911 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8912 create_info.stageCount = 2;
8913 create_info.pStages = stages;
8914 create_info.pVertexInputState = &vertex_input_state;
8915 create_info.pInputAssemblyState = &input_assembly_state;
8916 create_info.pViewportState = &viewport_state;
8917 create_info.pMultisampleState = &multisample_state;
8918 create_info.pRasterizationState = &rasterization_state;
8919 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8920 create_info.layout = pipeline_layout;
8921 create_info.renderPass = renderPass();
8922
8923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01408);
8924 VkPipeline pipeline;
8925 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
8926 m_errorMonitor->VerifyFound();
8927 }
8928
8929 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
8930 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
8931}
8932
Jeremy Hayes091e1ab2017-05-04 18:10:28 -06008933TEST_F(VkLayerTest, VALIDATION_ERROR_01410) {
8934 TEST_DESCRIPTION("Test VALIDATION_ERROR_01410: location must be less than VkPhysicalDeviceLimits::maxVertexInputAttributes");
8935
8936 ASSERT_NO_FATAL_FAILURE(Init());
8937 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8938
8939 VkPipelineCache pipeline_cache;
8940 {
8941 VkPipelineCacheCreateInfo create_info{};
8942 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8943
8944 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
8945 ASSERT_VK_SUCCESS(err);
8946 }
8947
8948 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8949 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8950
8951 VkPipelineShaderStageCreateInfo stages[2]{{}};
8952 stages[0] = vs.GetStageCreateInfo();
8953 stages[1] = fs.GetStageCreateInfo();
8954
8955 // Test when location is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes.
8956 VkVertexInputAttributeDescription vertex_input_attribute_description{};
8957 vertex_input_attribute_description.location = m_device->props.limits.maxVertexInputAttributes;
8958
8959 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
8960 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8961 vertex_input_state.pNext = nullptr;
8962 vertex_input_state.vertexBindingDescriptionCount = 0;
8963 vertex_input_state.pVertexBindingDescriptions = nullptr;
8964 vertex_input_state.vertexAttributeDescriptionCount = 1;
8965 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
8966
8967 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
8968 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8969 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8970
8971 VkViewport viewport{};
8972 VkPipelineViewportStateCreateInfo viewport_state{};
8973 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8974 viewport_state.scissorCount = 1;
8975 viewport_state.viewportCount = 1;
8976 viewport_state.pViewports = &viewport;
8977
8978 VkPipelineMultisampleStateCreateInfo multisample_state{};
8979 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8980 multisample_state.pNext = nullptr;
8981 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8982 multisample_state.sampleShadingEnable = 0;
8983 multisample_state.minSampleShading = 1.0;
8984 multisample_state.pSampleMask = nullptr;
8985
8986 VkPipelineRasterizationStateCreateInfo rasterization_state{};
8987 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8988 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
8989 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
8990 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
8991 rasterization_state.depthClampEnable = VK_FALSE;
8992 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
8993 rasterization_state.depthBiasEnable = VK_FALSE;
8994
8995 VkPipelineLayout pipeline_layout;
8996 {
8997 VkPipelineLayoutCreateInfo create_info{};
8998 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8999 create_info.setLayoutCount = 0;
9000 create_info.pSetLayouts = nullptr;
9001
9002 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9003 ASSERT_VK_SUCCESS(err);
9004 }
9005
9006 {
9007 VkGraphicsPipelineCreateInfo create_info{};
9008 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9009 create_info.stageCount = 2;
9010 create_info.pStages = stages;
9011 create_info.pVertexInputState = &vertex_input_state;
9012 create_info.pInputAssemblyState = &input_assembly_state;
9013 create_info.pViewportState = &viewport_state;
9014 create_info.pMultisampleState = &multisample_state;
9015 create_info.pRasterizationState = &rasterization_state;
9016 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9017 create_info.layout = pipeline_layout;
9018 create_info.renderPass = renderPass();
9019
9020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01410);
9021 VkPipeline pipeline;
9022 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9023 m_errorMonitor->VerifyFound();
9024 }
9025
9026 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9027 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9028}
9029
9030TEST_F(VkLayerTest, VALIDATION_ERROR_01411) {
9031 TEST_DESCRIPTION("Test VALIDATION_ERROR_01411: binding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings");
9032
9033 ASSERT_NO_FATAL_FAILURE(Init());
9034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9035
9036 VkPipelineCache pipeline_cache;
9037 {
9038 VkPipelineCacheCreateInfo create_info{};
9039 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9040
9041 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9042 ASSERT_VK_SUCCESS(err);
9043 }
9044
9045 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9046 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9047
9048 VkPipelineShaderStageCreateInfo stages[2]{{}};
9049 stages[0] = vs.GetStageCreateInfo();
9050 stages[1] = fs.GetStageCreateInfo();
9051
9052 // Test when binding is greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings.
9053 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9054 vertex_input_attribute_description.binding = m_device->props.limits.maxVertexInputBindings;
9055
9056 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9057 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9058 vertex_input_state.pNext = nullptr;
9059 vertex_input_state.vertexBindingDescriptionCount = 0;
9060 vertex_input_state.pVertexBindingDescriptions = nullptr;
9061 vertex_input_state.vertexAttributeDescriptionCount = 1;
9062 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9063
9064 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9065 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9066 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9067
9068 VkViewport viewport{};
9069 VkPipelineViewportStateCreateInfo viewport_state{};
9070 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9071 viewport_state.scissorCount = 1;
9072 viewport_state.viewportCount = 1;
9073 viewport_state.pViewports = &viewport;
9074
9075 VkPipelineMultisampleStateCreateInfo multisample_state{};
9076 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9077 multisample_state.pNext = nullptr;
9078 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9079 multisample_state.sampleShadingEnable = 0;
9080 multisample_state.minSampleShading = 1.0;
9081 multisample_state.pSampleMask = nullptr;
9082
9083 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9084 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9085 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9086 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9087 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9088 rasterization_state.depthClampEnable = VK_FALSE;
9089 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9090 rasterization_state.depthBiasEnable = VK_FALSE;
9091
9092 VkPipelineLayout pipeline_layout;
9093 {
9094 VkPipelineLayoutCreateInfo create_info{};
9095 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9096 create_info.setLayoutCount = 0;
9097 create_info.pSetLayouts = nullptr;
9098
9099 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9100 ASSERT_VK_SUCCESS(err);
9101 }
9102
9103 {
9104 VkGraphicsPipelineCreateInfo create_info{};
9105 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9106 create_info.stageCount = 2;
9107 create_info.pStages = stages;
9108 create_info.pVertexInputState = &vertex_input_state;
9109 create_info.pInputAssemblyState = &input_assembly_state;
9110 create_info.pViewportState = &viewport_state;
9111 create_info.pMultisampleState = &multisample_state;
9112 create_info.pRasterizationState = &rasterization_state;
9113 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9114 create_info.layout = pipeline_layout;
9115 create_info.renderPass = renderPass();
9116
9117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01411);
9118 VkPipeline pipeline;
9119 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9120 m_errorMonitor->VerifyFound();
9121 }
9122
9123 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9124 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9125}
9126
9127TEST_F(VkLayerTest, VALIDATION_ERROR_01412) {
9128 TEST_DESCRIPTION(
9129 "Test VALIDATION_ERROR_01412: offset must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributeOffset");
9130
9131 ASSERT_NO_FATAL_FAILURE(Init());
9132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9133
9134 VkPipelineCache pipeline_cache;
9135 {
9136 VkPipelineCacheCreateInfo create_info{};
9137 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
9138
9139 VkResult err = vkCreatePipelineCache(m_device->device(), &create_info, nullptr, &pipeline_cache);
9140 ASSERT_VK_SUCCESS(err);
9141 }
9142
9143 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
9144 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
9145
9146 VkPipelineShaderStageCreateInfo stages[2]{{}};
9147 stages[0] = vs.GetStageCreateInfo();
9148 stages[1] = fs.GetStageCreateInfo();
9149
9150 // Test when offset is greater than maximum.
9151 VkVertexInputAttributeDescription vertex_input_attribute_description{};
9152 vertex_input_attribute_description.offset = m_device->props.limits.maxVertexInputAttributeOffset + 1;
9153
9154 VkPipelineVertexInputStateCreateInfo vertex_input_state{};
9155 vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
9156 vertex_input_state.pNext = nullptr;
9157 vertex_input_state.vertexBindingDescriptionCount = 0;
9158 vertex_input_state.pVertexBindingDescriptions = nullptr;
9159 vertex_input_state.vertexAttributeDescriptionCount = 1;
9160 vertex_input_state.pVertexAttributeDescriptions = &vertex_input_attribute_description;
9161
9162 VkPipelineInputAssemblyStateCreateInfo input_assembly_state{};
9163 input_assembly_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
9164 input_assembly_state.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
9165
9166 VkViewport viewport{};
9167 VkPipelineViewportStateCreateInfo viewport_state{};
9168 viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
9169 viewport_state.scissorCount = 1;
9170 viewport_state.viewportCount = 1;
9171 viewport_state.pViewports = &viewport;
9172
9173 VkPipelineMultisampleStateCreateInfo multisample_state{};
9174 multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
9175 multisample_state.pNext = nullptr;
9176 multisample_state.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
9177 multisample_state.sampleShadingEnable = 0;
9178 multisample_state.minSampleShading = 1.0;
9179 multisample_state.pSampleMask = nullptr;
9180
9181 VkPipelineRasterizationStateCreateInfo rasterization_state{};
9182 rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
9183 rasterization_state.polygonMode = VK_POLYGON_MODE_FILL;
9184 rasterization_state.cullMode = VK_CULL_MODE_BACK_BIT;
9185 rasterization_state.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
9186 rasterization_state.depthClampEnable = VK_FALSE;
9187 rasterization_state.rasterizerDiscardEnable = VK_FALSE;
9188 rasterization_state.depthBiasEnable = VK_FALSE;
9189
9190 VkPipelineLayout pipeline_layout;
9191 {
9192 VkPipelineLayoutCreateInfo create_info{};
9193 create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9194 create_info.setLayoutCount = 0;
9195 create_info.pSetLayouts = nullptr;
9196
9197 VkResult err = vkCreatePipelineLayout(m_device->device(), &create_info, nullptr, &pipeline_layout);
9198 ASSERT_VK_SUCCESS(err);
9199 }
9200
9201 {
9202 VkGraphicsPipelineCreateInfo create_info{};
9203 create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
9204 create_info.stageCount = 2;
9205 create_info.pStages = stages;
9206 create_info.pVertexInputState = &vertex_input_state;
9207 create_info.pInputAssemblyState = &input_assembly_state;
9208 create_info.pViewportState = &viewport_state;
9209 create_info.pMultisampleState = &multisample_state;
9210 create_info.pRasterizationState = &rasterization_state;
9211 create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
9212 create_info.layout = pipeline_layout;
9213 create_info.renderPass = renderPass();
9214
9215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01412);
9216 VkPipeline pipeline;
9217 vkCreateGraphicsPipelines(m_device->device(), pipeline_cache, 1, &create_info, nullptr, &pipeline);
9218 m_errorMonitor->VerifyFound();
9219 }
9220
9221 vkDestroyPipelineCache(m_device->device(), pipeline_cache, nullptr);
9222 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
9223}
9224
Karl Schultz6addd812016-02-02 17:17:23 -07009225TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009226 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07009228 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009229
Tony Barbour1fa09702017-03-16 12:09:08 -06009230 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009231 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009232
Tony Barbour552f6c02016-12-21 14:34:07 -07009233 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07009234 // Don't care about RenderPass handle b/c error should be flagged before
9235 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009236 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009237
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009238 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06009239}
9240
Karl Schultz6addd812016-02-02 17:17:23 -07009241TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009242 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9244 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009245
Tony Barbour1fa09702017-03-16 12:09:08 -06009246 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009247 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009248
Tony Barbour552f6c02016-12-21 14:34:07 -07009249 m_commandBuffer->BeginCommandBuffer();
9250 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07009251 // Just create a dummy Renderpass that's non-NULL so we can get to the
9252 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009253 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06009254
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009255 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009256}
9257
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009258TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009259 TEST_DESCRIPTION(
9260 "Begin a renderPass where clearValueCount is less than"
9261 "the number of renderPass attachments that use loadOp"
9262 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009263
Tony Barbour1fa09702017-03-16 12:09:08 -06009264 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009265 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9266
9267 // Create a renderPass with a single attachment that uses loadOp CLEAR
9268 VkAttachmentReference attach = {};
9269 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9270 VkSubpassDescription subpass = {};
Cort Stratton7547f772017-05-04 15:18:52 -07009271 subpass.colorAttachmentCount = 1;
9272 subpass.pColorAttachments = &attach;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009273 VkRenderPassCreateInfo rpci = {};
9274 rpci.subpassCount = 1;
9275 rpci.pSubpasses = &subpass;
9276 rpci.attachmentCount = 1;
9277 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07009278 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009279 // Set loadOp to CLEAR
9280 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9281 rpci.pAttachments = &attach_desc;
9282 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9283 VkRenderPass rp;
9284 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9285
9286 VkCommandBufferInheritanceInfo hinfo = {};
9287 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
9288 hinfo.renderPass = VK_NULL_HANDLE;
9289 hinfo.subpass = 0;
9290 hinfo.framebuffer = VK_NULL_HANDLE;
9291 hinfo.occlusionQueryEnable = VK_FALSE;
9292 hinfo.queryFlags = 0;
9293 hinfo.pipelineStatistics = 0;
9294 VkCommandBufferBeginInfo info = {};
9295 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9296 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9297 info.pInheritanceInfo = &hinfo;
9298
9299 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9300 VkRenderPassBeginInfo rp_begin = {};
9301 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9302 rp_begin.pNext = NULL;
9303 rp_begin.renderPass = renderPass();
9304 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009305 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009306
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009308
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009309 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009310
9311 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06009312
9313 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06009314}
9315
Slawomir Cygan0808f392016-11-28 17:53:23 +01009316TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009317 TEST_DESCRIPTION(
9318 "Begin a renderPass where clearValueCount is greater than"
9319 "the number of renderPass attachments that use loadOp"
9320 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01009321
Tony Barbour1fa09702017-03-16 12:09:08 -06009322 ASSERT_NO_FATAL_FAILURE(Init());
Slawomir Cygan0808f392016-11-28 17:53:23 +01009323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9324
9325 // Create a renderPass with a single attachment that uses loadOp CLEAR
9326 VkAttachmentReference attach = {};
9327 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
9328 VkSubpassDescription subpass = {};
Cort Stratton7547f772017-05-04 15:18:52 -07009329 subpass.colorAttachmentCount = 1;
9330 subpass.pColorAttachments = &attach;
Slawomir Cygan0808f392016-11-28 17:53:23 +01009331 VkRenderPassCreateInfo rpci = {};
9332 rpci.subpassCount = 1;
9333 rpci.pSubpasses = &subpass;
9334 rpci.attachmentCount = 1;
9335 VkAttachmentDescription attach_desc = {};
9336 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
9337 // Set loadOp to CLEAR
9338 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
9339 rpci.pAttachments = &attach_desc;
9340 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
9341 VkRenderPass rp;
9342 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
9343
9344 VkCommandBufferBeginInfo info = {};
9345 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
9346 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9347
9348 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
9349 VkRenderPassBeginInfo rp_begin = {};
9350 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
9351 rp_begin.pNext = NULL;
9352 rp_begin.renderPass = renderPass();
9353 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009354 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01009355
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
9357 " has a clearValueCount of"
9358 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01009359
9360 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
9361
9362 m_errorMonitor->VerifyFound();
9363
9364 vkDestroyRenderPass(m_device->device(), rp, NULL);
9365}
9366
Cody Northrop3bb4d962016-05-09 16:15:57 -06009367TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06009368 TEST_DESCRIPTION("End a command buffer with an active render pass");
9369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9371 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06009372
Tony Barbour1fa09702017-03-16 12:09:08 -06009373 ASSERT_NO_FATAL_FAILURE(Init());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9375
Tony Barbour552f6c02016-12-21 14:34:07 -07009376 m_commandBuffer->BeginCommandBuffer();
9377 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
9378 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06009379
9380 m_errorMonitor->VerifyFound();
9381
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009382 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
9383 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06009384}
9385
Karl Schultz6addd812016-02-02 17:17:23 -07009386TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009387 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9389 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009390
Tony Barbour1fa09702017-03-16 12:09:08 -06009391 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009393
Tony Barbour552f6c02016-12-21 14:34:07 -07009394 m_commandBuffer->BeginCommandBuffer();
9395 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009396
9397 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009398 vk_testing::Buffer dstBuffer;
9399 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009400
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009401 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009402
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009403 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009404}
9405
Karl Schultz6addd812016-02-02 17:17:23 -07009406TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009407 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9409 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009410
Tony Barbour1fa09702017-03-16 12:09:08 -06009411 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009413
Tony Barbour552f6c02016-12-21 14:34:07 -07009414 m_commandBuffer->BeginCommandBuffer();
9415 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009416
9417 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009418 vk_testing::Buffer dstBuffer;
9419 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009420
Karl Schultz6addd812016-02-02 17:17:23 -07009421 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07009422 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
9423 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
9424 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009425
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009426 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009427}
9428
Karl Schultz6addd812016-02-02 17:17:23 -07009429TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009430 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9432 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009433
Tony Barbour1fa09702017-03-16 12:09:08 -06009434 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009436
Tony Barbour552f6c02016-12-21 14:34:07 -07009437 m_commandBuffer->BeginCommandBuffer();
9438 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009439
Michael Lentine0a369f62016-02-03 16:51:46 -06009440 VkClearColorValue clear_color;
9441 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07009442 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9443 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
9444 const int32_t tex_width = 32;
9445 const int32_t tex_height = 32;
9446 VkImageCreateInfo image_create_info = {};
9447 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9448 image_create_info.pNext = NULL;
9449 image_create_info.imageType = VK_IMAGE_TYPE_2D;
9450 image_create_info.format = tex_format;
9451 image_create_info.extent.width = tex_width;
9452 image_create_info.extent.height = tex_height;
9453 image_create_info.extent.depth = 1;
9454 image_create_info.mipLevels = 1;
9455 image_create_info.arrayLayers = 1;
9456 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
9457 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07009458 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009459
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009460 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009461 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009462
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009463 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009464
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009465 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009466
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009467 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009468}
9469
Karl Schultz6addd812016-02-02 17:17:23 -07009470TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009471 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9473 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009474
Tony Barbour1fa09702017-03-16 12:09:08 -06009475 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009476 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009477
Dave Houlton1d2022c2017-03-29 11:43:58 -06009478 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009479 if (!depth_format) {
9480 printf(" No Depth + Stencil format found. Skipped.\n");
9481 return;
9482 }
9483
Tony Barbour552f6c02016-12-21 14:34:07 -07009484 m_commandBuffer->BeginCommandBuffer();
9485 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009486
9487 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07009488 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009489 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
9490 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07009491 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07009492 image_create_info.extent.width = 64;
9493 image_create_info.extent.height = 64;
9494 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
9495 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009496
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009497 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009498 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009499
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009500 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009501
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009502 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
9503 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009504
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009505 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009506}
9507
Karl Schultz6addd812016-02-02 17:17:23 -07009508TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009509 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009510 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009511
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9513 "vkCmdClearAttachments(): This call "
9514 "must be issued inside an active "
9515 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009516
Tony Barbour1fa09702017-03-16 12:09:08 -06009517 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009518 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009519
9520 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009521 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009522 ASSERT_VK_SUCCESS(err);
9523
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06009524 VkClearAttachment color_attachment;
9525 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9526 color_attachment.clearValue.color.float32[0] = 0;
9527 color_attachment.clearValue.color.float32[1] = 0;
9528 color_attachment.clearValue.color.float32[2] = 0;
9529 color_attachment.clearValue.color.float32[3] = 0;
9530 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07009531 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009532 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009533
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009534 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06009535}
9536
Chris Forbes3b97e932016-09-07 11:29:24 +12009537TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009538 TEST_DESCRIPTION(
9539 "Test that an error is produced when CmdNextSubpass is "
9540 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12009541
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9543 "vkCmdNextSubpass(): Attempted to advance "
9544 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12009545
Tony Barbour1fa09702017-03-16 12:09:08 -06009546 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3b97e932016-09-07 11:29:24 +12009547 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9548
Tony Barbour552f6c02016-12-21 14:34:07 -07009549 m_commandBuffer->BeginCommandBuffer();
9550 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12009551
9552 // error here.
9553 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
9554 m_errorMonitor->VerifyFound();
9555
Tony Barbour552f6c02016-12-21 14:34:07 -07009556 m_commandBuffer->EndRenderPass();
9557 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12009558}
9559
Chris Forbes6d624702016-09-07 13:57:05 +12009560TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009561 TEST_DESCRIPTION(
9562 "Test that an error is produced when CmdEndRenderPass is "
9563 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12009564
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9566 "vkCmdEndRenderPass(): Called before reaching "
9567 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12009568
Tony Barbour1fa09702017-03-16 12:09:08 -06009569 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009570 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
9571 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12009572
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009573 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12009574
9575 VkRenderPass rp;
9576 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
9577 ASSERT_VK_SUCCESS(err);
9578
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009579 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12009580
9581 VkFramebuffer fb;
9582 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
9583 ASSERT_VK_SUCCESS(err);
9584
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009585 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12009586
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009587 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 +12009588
9589 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
9590
9591 // Error here.
9592 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9593 m_errorMonitor->VerifyFound();
9594
9595 // Clean up.
9596 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
9597 vkDestroyRenderPass(m_device->device(), rp, nullptr);
9598}
9599
Karl Schultz9e66a292016-04-21 15:57:51 -06009600TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
9601 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9603 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06009604
Tony Barbour1fa09702017-03-16 12:09:08 -06009605 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour552f6c02016-12-21 14:34:07 -07009606 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06009607
9608 VkBufferMemoryBarrier buf_barrier = {};
9609 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9610 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9611 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9612 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9613 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9614 buf_barrier.buffer = VK_NULL_HANDLE;
9615 buf_barrier.offset = 0;
9616 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009617 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9618 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06009619
9620 m_errorMonitor->VerifyFound();
9621}
9622
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009623TEST_F(VkLayerTest, InvalidBarriers) {
9624 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
9625
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009627
Tony Barbour1fa09702017-03-16 12:09:08 -06009628 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -06009629 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -07009630 if (!depth_format) {
9631 printf(" No Depth + Stencil format found. Skipped.\n");
9632 return;
9633 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009634 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9635
9636 VkMemoryBarrier mem_barrier = {};
9637 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
9638 mem_barrier.pNext = NULL;
9639 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9640 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07009641 m_commandBuffer->BeginCommandBuffer();
9642 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009643 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009644 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009645 &mem_barrier, 0, nullptr, 0, nullptr);
9646 m_errorMonitor->VerifyFound();
9647
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009649 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009650 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 -06009651 ASSERT_TRUE(image.initialized());
9652 VkImageMemoryBarrier img_barrier = {};
9653 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9654 img_barrier.pNext = NULL;
9655 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9656 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009657 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009658 // New layout can't be UNDEFINED
9659 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
9660 img_barrier.image = image.handle();
9661 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9662 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9663 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9664 img_barrier.subresourceRange.baseArrayLayer = 0;
9665 img_barrier.subresourceRange.baseMipLevel = 0;
9666 img_barrier.subresourceRange.layerCount = 1;
9667 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009668 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9669 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009670 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009671
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009672 // Transition image to color attachment optimal
9673 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9674 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9675 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9676 nullptr, 0, nullptr, 1, &img_barrier);
9677 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009678
Mark Lobodzinski45daf6e2017-05-10 13:19:02 -06009679 // Try to change layout in a renderpass
9680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02080);
9681 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9682 nullptr, 0, nullptr, 1, &img_barrier);
9683 m_errorMonitor->VerifyFound();
9684
9685 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski95512b72017-05-10 12:21:30 -06009686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009687 // baseArrayLayer + layerCount must be <= image's arrayLayers
9688 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009689 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9690 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009691 m_errorMonitor->VerifyFound();
9692 img_barrier.subresourceRange.baseArrayLayer = 0;
9693
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009695 // baseMipLevel + levelCount must be <= image's mipLevels
9696 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009697 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9698 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009699 m_errorMonitor->VerifyFound();
9700 img_barrier.subresourceRange.baseMipLevel = 0;
9701
Mike Weiblen7053aa32017-01-25 15:21:10 -07009702 // levelCount must be non-zero.
9703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
9704 img_barrier.subresourceRange.levelCount = 0;
9705 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9706 nullptr, 0, nullptr, 1, &img_barrier);
9707 m_errorMonitor->VerifyFound();
9708 img_barrier.subresourceRange.levelCount = 1;
9709
9710 // layerCount must be non-zero.
9711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
9712 img_barrier.subresourceRange.layerCount = 0;
9713 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9714 nullptr, 0, nullptr, 1, &img_barrier);
9715 m_errorMonitor->VerifyFound();
9716 img_barrier.subresourceRange.layerCount = 1;
9717
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009718 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 -06009719 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009720 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
9721 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009722 VkBufferMemoryBarrier buf_barrier = {};
9723 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
9724 buf_barrier.pNext = NULL;
9725 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9726 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9727 buf_barrier.buffer = buffer.handle();
9728 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9729 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9730 buf_barrier.offset = 0;
9731 buf_barrier.size = VK_WHOLE_SIZE;
9732 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009733 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9734 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009735 m_errorMonitor->VerifyFound();
9736 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9737
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009739 buf_barrier.offset = 257;
9740 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009741 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9742 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009743 m_errorMonitor->VerifyFound();
9744 buf_barrier.offset = 0;
9745
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009747 buf_barrier.size = 257;
9748 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009749 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9750 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009751 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009752
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009753 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
9755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009756 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009757 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009758 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009759 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9760 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009761 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009762
9763 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009764 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009765 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9766 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009767 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009768
Tobin Ehlis99ab0d22017-04-26 16:53:52 -06009769 // Having only one of depth or stencil set for DS image is an error
9770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00302);
9771 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
9772 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9773 nullptr, 0, nullptr, 1, &img_barrier);
9774 m_errorMonitor->VerifyFound();
9775
9776 // Having anything other than DEPTH and STENCIL is an error
9777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Dave Houltonfbf52152017-01-06 12:55:29 -07009778 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9779 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9780 nullptr, 0, nullptr, 1, &img_barrier);
9781 m_errorMonitor->VerifyFound();
9782
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009783 // Now test depth-only
9784 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009785 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9786 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009787 VkDepthStencilObj d_image(m_device);
9788 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9789 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009790 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009791 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009792 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009793
9794 // DEPTH bit must be set
9795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9796 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009797 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009798 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9799 0, nullptr, 0, nullptr, 1, &img_barrier);
9800 m_errorMonitor->VerifyFound();
9801
9802 // No bits other than DEPTH may be set
9803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9804 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9805 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009806 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9807 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009808 m_errorMonitor->VerifyFound();
9809 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009810
9811 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009812 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9813 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009814 VkDepthStencilObj s_image(m_device);
9815 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9816 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009817 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009818 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009819 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009820 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9822 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009823 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009824 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9825 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009826 m_errorMonitor->VerifyFound();
9827 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009828
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009829 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009830 VkImageObj c_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009831 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 -06009832 ASSERT_TRUE(c_image.initialized());
9833 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9834 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9835 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009836
9837 // COLOR bit must be set
9838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9839 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009840 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009841 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9842 nullptr, 0, nullptr, 1, &img_barrier);
9843 m_errorMonitor->VerifyFound();
9844
9845 // No bits other than COLOR may be set
9846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9847 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9848 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009849 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9850 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009851 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009852
Mike Weiblene6e01172017-03-07 22:18:40 -07009853 // A barrier's new and old VkImageLayout must be compatible with an image's VkImageUsageFlags.
9854 {
9855 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009856 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 -07009857 ASSERT_TRUE(img_color.initialized());
9858
9859 VkImageObj img_ds(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009860 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 -07009861 ASSERT_TRUE(img_ds.initialized());
9862
9863 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009864 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 -07009865 ASSERT_TRUE(img_xfer_src.initialized());
9866
9867 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009868 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 -07009869 ASSERT_TRUE(img_xfer_dst.initialized());
9870
9871 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009872 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 -07009873 ASSERT_TRUE(img_sampled.initialized());
9874
9875 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -06009876 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 -07009877 ASSERT_TRUE(img_input.initialized());
9878
9879 const struct {
9880 VkImageObj &image_obj;
9881 VkImageLayout bad_layout;
9882 UNIQUE_VALIDATION_ERROR_CODE msg_code;
9883 } bad_buffer_layouts[] = {
9884 // clang-format off
9885 // images _without_ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
9886 {img_ds, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9887 {img_xfer_src, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9888 {img_xfer_dst, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9889 {img_sampled, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9890 {img_input, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9891 // images _without_ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
9892 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9893 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9894 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9895 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9896 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9897 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9898 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9899 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9900 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9901 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9902 // images _without_ VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
9903 {img_color, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9904 {img_ds, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9905 {img_xfer_src, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9906 {img_xfer_dst, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9907 // images _without_ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
9908 {img_color, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9909 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9910 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9911 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9912 {img_input, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9913 // images _without_ VK_IMAGE_USAGE_TRANSFER_DST_BIT
9914 {img_color, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9915 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9916 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9917 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9918 {img_input, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9919 // clang-format on
9920 };
9921 const uint32_t layout_count = sizeof(bad_buffer_layouts) / sizeof(bad_buffer_layouts[0]);
9922
9923 for (uint32_t i = 0; i < layout_count; ++i) {
9924 img_barrier.image = bad_buffer_layouts[i].image_obj.handle();
9925 const VkImageUsageFlags usage = bad_buffer_layouts[i].image_obj.usage();
9926 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
9927 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
9928 : VK_IMAGE_ASPECT_COLOR_BIT;
9929
9930 img_barrier.oldLayout = bad_buffer_layouts[i].bad_layout;
9931 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9933 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9934 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9935 m_errorMonitor->VerifyFound();
9936
9937 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9938 img_barrier.newLayout = bad_buffer_layouts[i].bad_layout;
9939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9940 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9941 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9942 m_errorMonitor->VerifyFound();
9943 }
9944
9945 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9946 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9947 }
9948
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009949 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9950
9951 // Create command pool with incompatible queueflags
9952 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mike Schuchardt06304c22017-03-01 17:09:09 -07009953 uint32_t queue_family_index = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_COMPUTE_BIT);
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009954 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009955 printf(" No non-compute queue found; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009956 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009957 }
9958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9959
9960 VkCommandPool command_pool;
9961 VkCommandPoolCreateInfo pool_create_info{};
9962 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9963 pool_create_info.queueFamilyIndex = queue_family_index;
9964 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9965 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9966
9967 // Allocate a command buffer
9968 VkCommandBuffer bad_command_buffer;
9969 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9970 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9971 command_buffer_allocate_info.commandPool = command_pool;
9972 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9973 command_buffer_allocate_info.commandBufferCount = 1;
9974 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9975
9976 VkCommandBufferBeginInfo cbbi = {};
9977 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9978 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9979 buf_barrier.offset = 0;
9980 buf_barrier.size = VK_WHOLE_SIZE;
9981 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9982 &buf_barrier, 0, nullptr);
9983 m_errorMonitor->VerifyFound();
9984
9985 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9986 vkEndCommandBuffer(bad_command_buffer);
9987 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009988 printf(" The non-compute queue does not support graphics; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009989 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009990 }
9991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9992 VkEvent event;
9993 VkEventCreateInfo event_create_info{};
9994 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9995 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9996 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9997 nullptr, 0, nullptr);
9998 m_errorMonitor->VerifyFound();
9999
10000 vkEndCommandBuffer(bad_command_buffer);
10001 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -060010002}
10003
Chris Forbes50223732017-05-01 09:43:35 -070010004TEST_F(VkPositiveLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
10005 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ
10006 // in srcAccessMask.
Tony Barbour18ba25c2016-09-29 13:42:40 -060010007
Chris Forbes50223732017-05-01 09:43:35 -070010008 // The required behavior here was a bit unclear in earlier versions of the
10009 // spec, but there is no memory dependency required here, so this should
10010 // work without warnings.
10011
10012 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060010013 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour18ba25c2016-09-29 13:42:40 -060010014 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060010015 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 -070010016 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -060010017 ASSERT_TRUE(image.initialized());
10018
10019 VkImageMemoryBarrier barrier = {};
10020 VkImageSubresourceRange range;
10021 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tony Barbour18ba25c2016-09-29 13:42:40 -060010022 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
Chris Forbes50223732017-05-01 09:43:35 -070010023 barrier.dstAccessMask = 0;
Tony Barbour18ba25c2016-09-29 13:42:40 -060010024 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10025 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
10026 barrier.image = image.handle();
10027 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10028 range.baseMipLevel = 0;
10029 range.levelCount = 1;
10030 range.baseArrayLayer = 0;
10031 range.layerCount = 1;
10032 barrier.subresourceRange = range;
10033 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
10034 cmdbuf.BeginCommandBuffer();
10035 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10036 &barrier);
10037 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
10038 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10039 barrier.srcAccessMask = 0;
10040 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10041 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
10042 &barrier);
10043
Chris Forbes50223732017-05-01 09:43:35 -070010044 m_errorMonitor->VerifyNotFound();
Tony Barbour18ba25c2016-09-29 13:42:40 -060010045}
10046
Karl Schultz6addd812016-02-02 17:17:23 -070010047TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010048 // Bind a BeginRenderPass within an active RenderPass
Tony Barbour1fa09702017-03-16 12:09:08 -060010049 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010051
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010052 uint32_t const indices[] = {0};
10053 VkBufferCreateInfo buf_info = {};
10054 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10055 buf_info.size = 1024;
10056 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
10057 buf_info.queueFamilyIndexCount = 1;
10058 buf_info.pQueueFamilyIndices = indices;
10059
10060 VkBuffer buffer;
10061 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
10062 ASSERT_VK_SUCCESS(err);
10063
10064 VkMemoryRequirements requirements;
10065 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
10066
10067 VkMemoryAllocateInfo alloc_info{};
10068 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10069 alloc_info.pNext = NULL;
10070 alloc_info.memoryTypeIndex = 0;
10071 alloc_info.allocationSize = requirements.size;
10072 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
10073 ASSERT_TRUE(pass);
10074
10075 VkDeviceMemory memory;
10076 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
10077 ASSERT_VK_SUCCESS(err);
10078
10079 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010080 ASSERT_VK_SUCCESS(err);
10081
Tony Barbour552f6c02016-12-21 14:34:07 -070010082 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010083 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010084
Karl Schultz6addd812016-02-02 17:17:23 -070010085 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
10086 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010087 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
10089 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010090 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010091
Jeremy Hayes483d95d2017-03-08 11:03:01 -070010092 vkFreeMemory(m_device->device(), memory, NULL);
10093 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -060010094}
10095
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010096TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
10097 // Create an out-of-range queueFamilyIndex
Tony Barbour1fa09702017-03-16 12:09:08 -060010098 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010099 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10100 VkBufferCreateInfo buffCI = {};
10101 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10102 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010103 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010104 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010105 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010106 uint32_t qfi[2];
10107 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010108 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010109
10110 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010111 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010112
10113 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -070010114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Petr Kraus97291752017-05-11 01:05:16 +020010115 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (= 777) is not one of the queue "
10116 "families given via VkDeviceQueueCreateInfo structures when the device was created.");
Mark Lobodzinski1f9ebb72017-05-11 15:25:51 -060010117 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010118 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010119
10120 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -070010121 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
10123
10124 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
10125 buffCI.queueFamilyIndexCount = 2;
10126 qfi[0] = 1;
10127 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -070010128 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010129 VkDeviceMemory mem;
10130 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -070010131 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010132
10133 VkMemoryAllocateInfo alloc_info = {};
10134 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10135 alloc_info.allocationSize = 1024;
10136 bool pass = false;
10137 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
10138 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -070010139 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010140 return;
10141 }
10142 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -070010143 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010144
10145 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -070010146 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010147 m_commandBuffer->end();
10148 QueueCommandBuffer(false);
10149 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -070010150 vkDestroyBuffer(m_device->device(), ib2, NULL);
10151 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -070010152 }
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -070010153}
10154
Karl Schultz6addd812016-02-02 17:17:23 -070010155TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010156 TEST_DESCRIPTION(
10157 "Attempt vkCmdExecuteCommands with a primary command buffer"
10158 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010159
Tony Barbour1fa09702017-03-16 12:09:08 -060010160 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010162
Chris Forbesf29a84f2016-10-06 18:39:28 +130010163 // An empty primary command buffer
10164 VkCommandBufferObj cb(m_device, m_commandPool);
10165 cb.BeginCommandBuffer();
10166 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -060010167
Chris Forbesf29a84f2016-10-06 18:39:28 +130010168 m_commandBuffer->BeginCommandBuffer();
10169 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
10170 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010171
Chris Forbesf29a84f2016-10-06 18:39:28 +130010172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
10173 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010174 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010175
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060010176 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be in the pending state");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -060010177}
10178
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010179TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010180 TEST_DESCRIPTION(
10181 "Attempt to update descriptor sets for images and buffers "
10182 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010183 VkResult err;
10184
Tony Barbour1fa09702017-03-16 12:09:08 -060010185 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010186 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10187 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10188 ds_type_count[i].type = VkDescriptorType(i);
10189 ds_type_count[i].descriptorCount = 1;
10190 }
10191 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10192 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10193 ds_pool_ci.pNext = NULL;
10194 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10195 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10196 ds_pool_ci.pPoolSizes = ds_type_count;
10197
10198 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010199 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010200 ASSERT_VK_SUCCESS(err);
10201
10202 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010203 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010204 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10205 dsl_binding[i].binding = 0;
10206 dsl_binding[i].descriptorType = VkDescriptorType(i);
10207 dsl_binding[i].descriptorCount = 1;
10208 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
10209 dsl_binding[i].pImmutableSamplers = NULL;
10210 }
10211
10212 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10213 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10214 ds_layout_ci.pNext = NULL;
10215 ds_layout_ci.bindingCount = 1;
10216 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
10217 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
10218 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010219 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010220 ASSERT_VK_SUCCESS(err);
10221 }
10222 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
10223 VkDescriptorSetAllocateInfo alloc_info = {};
10224 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10225 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
10226 alloc_info.descriptorPool = ds_pool;
10227 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010228 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010229 ASSERT_VK_SUCCESS(err);
10230
10231 // Create a buffer & bufferView to be used for invalid updates
10232 VkBufferCreateInfo buff_ci = {};
10233 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -070010234 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010235 buff_ci.size = 256;
10236 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -070010237 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010238 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10239 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -070010240
10241 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
10242 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
10243 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
10244 ASSERT_VK_SUCCESS(err);
10245
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010246 VkMemoryRequirements mem_reqs;
10247 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
10248 VkMemoryAllocateInfo mem_alloc_info = {};
10249 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10250 mem_alloc_info.pNext = NULL;
10251 mem_alloc_info.memoryTypeIndex = 0;
10252 mem_alloc_info.allocationSize = mem_reqs.size;
10253 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10254 if (!pass) {
10255 vkDestroyBuffer(m_device->device(), buffer, NULL);
10256 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10257 return;
10258 }
10259 VkDeviceMemory mem;
10260 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
10261 ASSERT_VK_SUCCESS(err);
10262 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10263 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010264
10265 VkBufferViewCreateInfo buff_view_ci = {};
10266 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
10267 buff_view_ci.buffer = buffer;
10268 buff_view_ci.format = VK_FORMAT_R8_UNORM;
10269 buff_view_ci.range = VK_WHOLE_SIZE;
10270 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010271 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010272 ASSERT_VK_SUCCESS(err);
10273
Tony Barbour415497c2017-01-24 10:06:09 -070010274 // Now get resources / view for storage_texel_buffer
10275 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
10276 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
10277 if (!pass) {
10278 vkDestroyBuffer(m_device->device(), buffer, NULL);
10279 vkDestroyBufferView(m_device->device(), buff_view, NULL);
10280 vkFreeMemory(m_device->device(), mem, NULL);
10281 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
10282 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10283 return;
10284 }
10285 VkDeviceMemory storage_texel_buffer_mem;
10286 VkBufferView storage_texel_buffer_view;
10287 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
10288 ASSERT_VK_SUCCESS(err);
10289 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
10290 ASSERT_VK_SUCCESS(err);
10291 buff_view_ci.buffer = storage_texel_buffer;
10292 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
10293 ASSERT_VK_SUCCESS(err);
10294
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010295 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -070010296 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010297 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -070010298 image_ci.format = VK_FORMAT_UNDEFINED;
10299 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
10300 VkFormat format = static_cast<VkFormat>(f);
10301 VkFormatProperties fProps = m_device->format_properties(format);
10302 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10303 image_ci.format = format;
10304 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
10305 break;
10306 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
10307 image_ci.format = format;
10308 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
10309 break;
10310 }
10311 }
10312 if (image_ci.format == VK_FORMAT_UNDEFINED) {
10313 return;
10314 }
10315
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010316 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10317 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010318 image_ci.extent.width = 64;
10319 image_ci.extent.height = 64;
10320 image_ci.extent.depth = 1;
10321 image_ci.mipLevels = 1;
10322 image_ci.arrayLayers = 1;
10323 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010324 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010325 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010326 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10327 VkImage image;
10328 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10329 ASSERT_VK_SUCCESS(err);
10330 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010331 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010332
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010333 VkMemoryAllocateInfo mem_alloc = {};
10334 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10335 mem_alloc.pNext = NULL;
10336 mem_alloc.allocationSize = 0;
10337 mem_alloc.memoryTypeIndex = 0;
10338 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10339 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010340 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010341 ASSERT_TRUE(pass);
10342 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10343 ASSERT_VK_SUCCESS(err);
10344 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10345 ASSERT_VK_SUCCESS(err);
10346 // Now create view for image
10347 VkImageViewCreateInfo image_view_ci = {};
10348 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10349 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -070010350 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010351 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10352 image_view_ci.subresourceRange.layerCount = 1;
10353 image_view_ci.subresourceRange.baseArrayLayer = 0;
10354 image_view_ci.subresourceRange.levelCount = 1;
10355 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10356 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010357 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010358 ASSERT_VK_SUCCESS(err);
10359
10360 VkDescriptorBufferInfo buff_info = {};
10361 buff_info.buffer = buffer;
10362 VkDescriptorImageInfo img_info = {};
10363 img_info.imageView = image_view;
10364 VkWriteDescriptorSet descriptor_write = {};
10365 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10366 descriptor_write.dstBinding = 0;
10367 descriptor_write.descriptorCount = 1;
10368 descriptor_write.pTexelBufferView = &buff_view;
10369 descriptor_write.pBufferInfo = &buff_info;
10370 descriptor_write.pImageInfo = &img_info;
10371
10372 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010373 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010374 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
10375 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
10376 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
10377 VALIDATION_ERROR_00943, // STORAGE_IMAGE
10378 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
10379 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
10380 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
10381 VALIDATION_ERROR_00947, // STORAGE_BUFFER
10382 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
10383 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
10384 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010385 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010386 // Start loop at 1 as SAMPLER desc type has no usage bit error
10387 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -070010388 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10389 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
10390 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
10391 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010392 descriptor_write.descriptorType = VkDescriptorType(i);
10393 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010395
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010396 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010397
10398 m_errorMonitor->VerifyFound();
10399 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010400 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
10401 descriptor_write.pTexelBufferView = &buff_view;
10402 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010403 }
Tony Barbour415497c2017-01-24 10:06:09 -070010404
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010405 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
10406 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060010407 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010408 vkDestroyImageView(m_device->device(), image_view, NULL);
10409 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010410 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010411 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010412 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -070010413 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -070010414 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -060010415 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10416}
10417
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010418TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010419 TEST_DESCRIPTION(
10420 "Attempt to update buffer descriptor set that has incorrect "
10421 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010422 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010423 "2. range value of 0\n"
10424 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010425 VkResult err;
10426
Tony Barbour1fa09702017-03-16 12:09:08 -060010427 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010428 VkDescriptorPoolSize ds_type_count = {};
10429 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10430 ds_type_count.descriptorCount = 1;
10431
10432 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10433 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10434 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010435 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010436 ds_pool_ci.maxSets = 1;
10437 ds_pool_ci.poolSizeCount = 1;
10438 ds_pool_ci.pPoolSizes = &ds_type_count;
10439
10440 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010441 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010442 ASSERT_VK_SUCCESS(err);
10443
10444 // Create layout with single uniform buffer descriptor
10445 VkDescriptorSetLayoutBinding dsl_binding = {};
10446 dsl_binding.binding = 0;
10447 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10448 dsl_binding.descriptorCount = 1;
10449 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10450 dsl_binding.pImmutableSamplers = NULL;
10451
10452 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10453 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10454 ds_layout_ci.pNext = NULL;
10455 ds_layout_ci.bindingCount = 1;
10456 ds_layout_ci.pBindings = &dsl_binding;
10457 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010458 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010459 ASSERT_VK_SUCCESS(err);
10460
10461 VkDescriptorSet descriptor_set = {};
10462 VkDescriptorSetAllocateInfo alloc_info = {};
10463 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10464 alloc_info.descriptorSetCount = 1;
10465 alloc_info.descriptorPool = ds_pool;
10466 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010468 ASSERT_VK_SUCCESS(err);
10469
10470 // Create a buffer to be used for invalid updates
10471 VkBufferCreateInfo buff_ci = {};
10472 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10473 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010474 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010475 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10476 VkBuffer buffer;
10477 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
10478 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010479
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010480 // Have to bind memory to buffer before descriptor update
10481 VkMemoryAllocateInfo mem_alloc = {};
10482 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10483 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010484 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010485 mem_alloc.memoryTypeIndex = 0;
10486
10487 VkMemoryRequirements mem_reqs;
10488 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010489 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010490 if (!pass) {
10491 vkDestroyBuffer(m_device->device(), buffer, NULL);
10492 return;
10493 }
10494
10495 VkDeviceMemory mem;
10496 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
10497 ASSERT_VK_SUCCESS(err);
10498 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
10499 ASSERT_VK_SUCCESS(err);
10500
10501 VkDescriptorBufferInfo buff_info = {};
10502 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010503 // Cause error due to offset out of range
10504 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010505 buff_info.range = VK_WHOLE_SIZE;
10506 VkWriteDescriptorSet descriptor_write = {};
10507 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10508 descriptor_write.dstBinding = 0;
10509 descriptor_write.descriptorCount = 1;
10510 descriptor_write.pTexelBufferView = nullptr;
10511 descriptor_write.pBufferInfo = &buff_info;
10512 descriptor_write.pImageInfo = nullptr;
10513
10514 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10515 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010517
10518 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10519
10520 m_errorMonitor->VerifyFound();
10521 // Now cause error due to range of 0
10522 buff_info.offset = 0;
10523 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010525
10526 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10527
10528 m_errorMonitor->VerifyFound();
10529 // Now cause error due to range exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -070010530 buff_info.offset = 0;
10531 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010533
10534 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10535
10536 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -060010537 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -060010538 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10539 vkDestroyBuffer(m_device->device(), buffer, NULL);
10540 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10541 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10542}
10543
Tobin Ehlis845887e2017-02-02 19:01:44 -070010544TEST_F(VkLayerTest, DSBufferLimitErrors) {
10545 TEST_DESCRIPTION(
10546 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
10547 "Test cases include:\n"
10548 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
10549 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
10550 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
10551 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
10552 VkResult err;
10553
Tony Barbour1fa09702017-03-16 12:09:08 -060010554 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis845887e2017-02-02 19:01:44 -070010555 VkDescriptorPoolSize ds_type_count[2] = {};
10556 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10557 ds_type_count[0].descriptorCount = 1;
10558 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10559 ds_type_count[1].descriptorCount = 1;
10560
10561 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10562 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10563 ds_pool_ci.pNext = NULL;
10564 ds_pool_ci.maxSets = 1;
10565 ds_pool_ci.poolSizeCount = 2;
10566 ds_pool_ci.pPoolSizes = ds_type_count;
10567
10568 VkDescriptorPool ds_pool;
10569 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10570 ASSERT_VK_SUCCESS(err);
10571
10572 // Create layout with single uniform buffer & single storage buffer descriptor
10573 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
10574 dsl_binding[0].binding = 0;
10575 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10576 dsl_binding[0].descriptorCount = 1;
10577 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10578 dsl_binding[0].pImmutableSamplers = NULL;
10579 dsl_binding[1].binding = 1;
10580 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10581 dsl_binding[1].descriptorCount = 1;
10582 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10583 dsl_binding[1].pImmutableSamplers = NULL;
10584
10585 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10586 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10587 ds_layout_ci.pNext = NULL;
10588 ds_layout_ci.bindingCount = 2;
10589 ds_layout_ci.pBindings = dsl_binding;
10590 VkDescriptorSetLayout ds_layout;
10591 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10592 ASSERT_VK_SUCCESS(err);
10593
10594 VkDescriptorSet descriptor_set = {};
10595 VkDescriptorSetAllocateInfo alloc_info = {};
10596 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10597 alloc_info.descriptorSetCount = 1;
10598 alloc_info.descriptorPool = ds_pool;
10599 alloc_info.pSetLayouts = &ds_layout;
10600 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10601 ASSERT_VK_SUCCESS(err);
10602
10603 // Create a buffer to be used for invalid updates
10604 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
10605 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
10606 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
10607 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
10608 VkBufferCreateInfo ub_ci = {};
10609 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10610 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
10611 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
10612 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10613 VkBuffer uniform_buffer;
10614 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
10615 ASSERT_VK_SUCCESS(err);
10616 VkBufferCreateInfo sb_ci = {};
10617 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
10618 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
10619 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
10620 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10621 VkBuffer storage_buffer;
10622 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
10623 ASSERT_VK_SUCCESS(err);
10624 // Have to bind memory to buffer before descriptor update
10625 VkMemoryAllocateInfo mem_alloc = {};
10626 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10627 mem_alloc.pNext = NULL;
10628 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
10629 mem_alloc.memoryTypeIndex = 0;
10630
Cort Stratton77a0d592017-02-17 13:14:13 -080010631 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
10632 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
10633 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
10634 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
10635 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010636 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -070010637 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010638 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010639 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10640 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010641 return;
10642 }
10643
10644 VkDeviceMemory mem;
10645 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -070010646 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070010647 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -070010648 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10649 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10650 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10651 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10652 return;
10653 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010654 ASSERT_VK_SUCCESS(err);
10655 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
10656 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -080010657 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -070010658 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
10659 ASSERT_VK_SUCCESS(err);
10660
10661 VkDescriptorBufferInfo buff_info = {};
10662 buff_info.buffer = uniform_buffer;
10663 buff_info.range = ub_ci.size; // This will exceed limit
10664 VkWriteDescriptorSet descriptor_write = {};
10665 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10666 descriptor_write.dstBinding = 0;
10667 descriptor_write.descriptorCount = 1;
10668 descriptor_write.pTexelBufferView = nullptr;
10669 descriptor_write.pBufferInfo = &buff_info;
10670 descriptor_write.pImageInfo = nullptr;
10671
10672 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10673 descriptor_write.dstSet = descriptor_set;
Tony Barbour02d08552017-03-24 16:36:01 -060010674 if (max_ub_range != UINT32_MAX) {
10675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
10676 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10677 m_errorMonitor->VerifyFound();
10678 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010679 // Reduce size of range to acceptable limit & cause offset error
10680 buff_info.range = max_ub_range;
10681 buff_info.offset = min_ub_align - 1;
10682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
10683 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10684 m_errorMonitor->VerifyFound();
10685
10686 // Now break storage updates
10687 buff_info.buffer = storage_buffer;
10688 buff_info.range = sb_ci.size; // This will exceed limit
10689 buff_info.offset = 0; // Reset offset for this update
10690
10691 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
10692 descriptor_write.dstBinding = 1;
Tony Barbour02d08552017-03-24 16:36:01 -060010693 if (max_ub_range != UINT32_MAX) {
10694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
10695 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10696 m_errorMonitor->VerifyFound();
10697 }
Tobin Ehlis845887e2017-02-02 19:01:44 -070010698
10699 // Reduce size of range to acceptable limit & cause offset error
10700 buff_info.range = max_sb_range;
10701 buff_info.offset = min_sb_align - 1;
10702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
10703 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10704 m_errorMonitor->VerifyFound();
10705
10706 vkFreeMemory(m_device->device(), mem, NULL);
10707 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10708 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
10709 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
10710 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10711}
10712
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010713TEST_F(VkLayerTest, DSAspectBitsErrors) {
10714 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
10715 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010716 TEST_DESCRIPTION(
10717 "Attempt to update descriptor sets for images "
10718 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010719 VkResult err;
10720
Tony Barbour1fa09702017-03-16 12:09:08 -060010721 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060010722 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070010723 if (!depth_format) {
10724 printf(" No Depth + Stencil format found. Skipped.\n");
10725 return;
10726 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010727 VkDescriptorPoolSize ds_type_count = {};
10728 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10729 ds_type_count.descriptorCount = 1;
10730
10731 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10732 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10733 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -070010734 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010735 ds_pool_ci.maxSets = 5;
10736 ds_pool_ci.poolSizeCount = 1;
10737 ds_pool_ci.pPoolSizes = &ds_type_count;
10738
10739 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010740 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010741 ASSERT_VK_SUCCESS(err);
10742
10743 VkDescriptorSetLayoutBinding dsl_binding = {};
10744 dsl_binding.binding = 0;
10745 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10746 dsl_binding.descriptorCount = 1;
10747 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10748 dsl_binding.pImmutableSamplers = NULL;
10749
10750 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10751 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10752 ds_layout_ci.pNext = NULL;
10753 ds_layout_ci.bindingCount = 1;
10754 ds_layout_ci.pBindings = &dsl_binding;
10755 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010756 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010757 ASSERT_VK_SUCCESS(err);
10758
10759 VkDescriptorSet descriptor_set = {};
10760 VkDescriptorSetAllocateInfo alloc_info = {};
10761 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10762 alloc_info.descriptorSetCount = 1;
10763 alloc_info.descriptorPool = ds_pool;
10764 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010765 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010766 ASSERT_VK_SUCCESS(err);
10767
10768 // Create an image to be used for invalid updates
10769 VkImageCreateInfo image_ci = {};
10770 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10771 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070010772 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010773 image_ci.extent.width = 64;
10774 image_ci.extent.height = 64;
10775 image_ci.extent.depth = 1;
10776 image_ci.mipLevels = 1;
10777 image_ci.arrayLayers = 1;
10778 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -070010779 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010780 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10781 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10782 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10783 VkImage image;
10784 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10785 ASSERT_VK_SUCCESS(err);
10786 // Bind memory to image
10787 VkMemoryRequirements mem_reqs;
10788 VkDeviceMemory image_mem;
10789 bool pass;
10790 VkMemoryAllocateInfo mem_alloc = {};
10791 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10792 mem_alloc.pNext = NULL;
10793 mem_alloc.allocationSize = 0;
10794 mem_alloc.memoryTypeIndex = 0;
10795 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10796 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010797 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010798 ASSERT_TRUE(pass);
10799 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10800 ASSERT_VK_SUCCESS(err);
10801 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10802 ASSERT_VK_SUCCESS(err);
10803 // Now create view for image
10804 VkImageViewCreateInfo image_view_ci = {};
10805 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10806 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -070010807 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010808 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10809 image_view_ci.subresourceRange.layerCount = 1;
10810 image_view_ci.subresourceRange.baseArrayLayer = 0;
10811 image_view_ci.subresourceRange.levelCount = 1;
10812 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010813 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010814
10815 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010816 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010817 ASSERT_VK_SUCCESS(err);
10818
10819 VkDescriptorImageInfo img_info = {};
10820 img_info.imageView = image_view;
10821 VkWriteDescriptorSet descriptor_write = {};
10822 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10823 descriptor_write.dstBinding = 0;
10824 descriptor_write.descriptorCount = 1;
10825 descriptor_write.pTexelBufferView = NULL;
10826 descriptor_write.pBufferInfo = NULL;
10827 descriptor_write.pImageInfo = &img_info;
10828 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10829 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010830 const char *error_msg =
10831 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10832 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010834
10835 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10836
10837 m_errorMonitor->VerifyFound();
10838 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10839 vkDestroyImage(m_device->device(), image, NULL);
10840 vkFreeMemory(m_device->device(), image_mem, NULL);
10841 vkDestroyImageView(m_device->device(), image_view, NULL);
10842 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10843 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10844}
10845
Karl Schultz6addd812016-02-02 17:17:23 -070010846TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010847 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010848 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010849
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10851 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10852 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010853
Tony Barbour1fa09702017-03-16 12:09:08 -060010854 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070010855 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010856 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010857 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10858 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010859
10860 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010861 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10862 ds_pool_ci.pNext = NULL;
10863 ds_pool_ci.maxSets = 1;
10864 ds_pool_ci.poolSizeCount = 1;
10865 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010866
Tobin Ehlis3b780662015-05-28 12:11:26 -060010867 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010868 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010869 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010870 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010871 dsl_binding.binding = 0;
10872 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10873 dsl_binding.descriptorCount = 1;
10874 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10875 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010876
Tony Barboureb254902015-07-15 12:50:33 -060010877 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010878 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10879 ds_layout_ci.pNext = NULL;
10880 ds_layout_ci.bindingCount = 1;
10881 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010882
Tobin Ehlis3b780662015-05-28 12:11:26 -060010883 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010884 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010885 ASSERT_VK_SUCCESS(err);
10886
10887 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010888 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010889 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010890 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010891 alloc_info.descriptorPool = ds_pool;
10892 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010893 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010894 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010895
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010896 VkSamplerCreateInfo sampler_ci = {};
10897 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10898 sampler_ci.pNext = NULL;
10899 sampler_ci.magFilter = VK_FILTER_NEAREST;
10900 sampler_ci.minFilter = VK_FILTER_NEAREST;
10901 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10902 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10903 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10904 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10905 sampler_ci.mipLodBias = 1.0;
10906 sampler_ci.anisotropyEnable = VK_FALSE;
10907 sampler_ci.maxAnisotropy = 1;
10908 sampler_ci.compareEnable = VK_FALSE;
10909 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10910 sampler_ci.minLod = 1.0;
10911 sampler_ci.maxLod = 1.0;
10912 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10913 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10914 VkSampler sampler;
10915 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10916 ASSERT_VK_SUCCESS(err);
10917
10918 VkDescriptorImageInfo info = {};
10919 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010920
10921 VkWriteDescriptorSet descriptor_write;
10922 memset(&descriptor_write, 0, sizeof(descriptor_write));
10923 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010924 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010925 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010926 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010928 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010929
10930 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10931
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010932 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010933
Chia-I Wuf7458c52015-10-26 21:10:41 +080010934 vkDestroySampler(m_device->device(), sampler, NULL);
10935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10936 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010937}
10938
Karl Schultz6addd812016-02-02 17:17:23 -070010939TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010940 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010941 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010942
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010944
Tony Barbour1fa09702017-03-16 12:09:08 -060010945 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070010946 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010947 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010948 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10949 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010950
10951 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010952 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10953 ds_pool_ci.pNext = NULL;
10954 ds_pool_ci.maxSets = 1;
10955 ds_pool_ci.poolSizeCount = 1;
10956 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010957
Tobin Ehlis3b780662015-05-28 12:11:26 -060010958 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010959 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010960 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010961
Tony Barboureb254902015-07-15 12:50:33 -060010962 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010963 dsl_binding.binding = 0;
10964 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10965 dsl_binding.descriptorCount = 1;
10966 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10967 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010968
10969 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010970 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10971 ds_layout_ci.pNext = NULL;
10972 ds_layout_ci.bindingCount = 1;
10973 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010974
Tobin Ehlis3b780662015-05-28 12:11:26 -060010975 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010977 ASSERT_VK_SUCCESS(err);
10978
10979 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010980 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010981 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010982 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010983 alloc_info.descriptorPool = ds_pool;
10984 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010985 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010986 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010987
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010988 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10989
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010990 // Correctly update descriptor to avoid "NOT_UPDATED" error
10991 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010992 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010993 buff_info.offset = 0;
10994 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010995
10996 VkWriteDescriptorSet descriptor_write;
10997 memset(&descriptor_write, 0, sizeof(descriptor_write));
10998 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010999 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011000 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080011001 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060011002 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11003 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011004
11005 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11006
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011007 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011008
Chia-I Wuf7458c52015-10-26 21:10:41 +080011009 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11010 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011011}
11012
Karl Schultz6addd812016-02-02 17:17:23 -070011013TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070011014 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070011015 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011016
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070011017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011018
Tony Barbour1fa09702017-03-16 12:09:08 -060011019 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011020 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011021 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011022 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11023 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011024
11025 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011026 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11027 ds_pool_ci.pNext = NULL;
11028 ds_pool_ci.maxSets = 1;
11029 ds_pool_ci.poolSizeCount = 1;
11030 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011031
Tobin Ehlis3b780662015-05-28 12:11:26 -060011032 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011033 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011034 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011035
Tony Barboureb254902015-07-15 12:50:33 -060011036 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011037 dsl_binding.binding = 0;
11038 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11039 dsl_binding.descriptorCount = 1;
11040 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11041 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060011042
11043 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011044 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11045 ds_layout_ci.pNext = NULL;
11046 ds_layout_ci.bindingCount = 1;
11047 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011048 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011049 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011050 ASSERT_VK_SUCCESS(err);
11051
11052 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011053 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011054 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011055 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011056 alloc_info.descriptorPool = ds_pool;
11057 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011058 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011059 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011060
Tony Barboureb254902015-07-15 12:50:33 -060011061 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011062 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11063 sampler_ci.pNext = NULL;
11064 sampler_ci.magFilter = VK_FILTER_NEAREST;
11065 sampler_ci.minFilter = VK_FILTER_NEAREST;
11066 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11067 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11068 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11069 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11070 sampler_ci.mipLodBias = 1.0;
11071 sampler_ci.anisotropyEnable = VK_FALSE;
11072 sampler_ci.maxAnisotropy = 1;
11073 sampler_ci.compareEnable = VK_FALSE;
11074 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11075 sampler_ci.minLod = 1.0;
11076 sampler_ci.maxLod = 1.0;
11077 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11078 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060011079
Tobin Ehlis3b780662015-05-28 12:11:26 -060011080 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011081 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011082 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011083
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011084 VkDescriptorImageInfo info = {};
11085 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011086
11087 VkWriteDescriptorSet descriptor_write;
11088 memset(&descriptor_write, 0, sizeof(descriptor_write));
11089 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011090 descriptor_write.dstSet = descriptorSet;
11091 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011092 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011093 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011094 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011095 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011096
11097 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11098
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011099 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011100
Chia-I Wuf7458c52015-10-26 21:10:41 +080011101 vkDestroySampler(m_device->device(), sampler, NULL);
11102 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11103 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011104}
11105
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011106TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
11107 // Create layout w/ empty binding and attempt to update it
11108 VkResult err;
11109
Tony Barbour1fa09702017-03-16 12:09:08 -060011110 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011111
11112 VkDescriptorPoolSize ds_type_count = {};
11113 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11114 ds_type_count.descriptorCount = 1;
11115
11116 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11117 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11118 ds_pool_ci.pNext = NULL;
11119 ds_pool_ci.maxSets = 1;
11120 ds_pool_ci.poolSizeCount = 1;
11121 ds_pool_ci.pPoolSizes = &ds_type_count;
11122
11123 VkDescriptorPool ds_pool;
11124 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11125 ASSERT_VK_SUCCESS(err);
11126
11127 VkDescriptorSetLayoutBinding dsl_binding = {};
11128 dsl_binding.binding = 0;
11129 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11130 dsl_binding.descriptorCount = 0;
11131 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11132 dsl_binding.pImmutableSamplers = NULL;
11133
11134 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11135 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11136 ds_layout_ci.pNext = NULL;
11137 ds_layout_ci.bindingCount = 1;
11138 ds_layout_ci.pBindings = &dsl_binding;
11139 VkDescriptorSetLayout ds_layout;
11140 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11141 ASSERT_VK_SUCCESS(err);
11142
11143 VkDescriptorSet descriptor_set;
11144 VkDescriptorSetAllocateInfo alloc_info = {};
11145 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11146 alloc_info.descriptorSetCount = 1;
11147 alloc_info.descriptorPool = ds_pool;
11148 alloc_info.pSetLayouts = &ds_layout;
11149 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11150 ASSERT_VK_SUCCESS(err);
11151
11152 VkSamplerCreateInfo sampler_ci = {};
11153 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11154 sampler_ci.magFilter = VK_FILTER_NEAREST;
11155 sampler_ci.minFilter = VK_FILTER_NEAREST;
11156 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11157 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11158 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11159 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11160 sampler_ci.mipLodBias = 1.0;
11161 sampler_ci.maxAnisotropy = 1;
11162 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11163 sampler_ci.minLod = 1.0;
11164 sampler_ci.maxLod = 1.0;
11165 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11166
11167 VkSampler sampler;
11168 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11169 ASSERT_VK_SUCCESS(err);
11170
11171 VkDescriptorImageInfo info = {};
11172 info.sampler = sampler;
11173
11174 VkWriteDescriptorSet descriptor_write;
11175 memset(&descriptor_write, 0, sizeof(descriptor_write));
11176 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11177 descriptor_write.dstSet = descriptor_set;
11178 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011179 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070011180 // This is the wrong type, but empty binding error will be flagged first
11181 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11182 descriptor_write.pImageInfo = &info;
11183
11184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
11185 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11186 m_errorMonitor->VerifyFound();
11187
11188 vkDestroySampler(m_device->device(), sampler, NULL);
11189 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11190 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11191}
11192
Karl Schultz6addd812016-02-02 17:17:23 -070011193TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
11194 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
11195 // types
11196 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011197
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011198 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 -060011199
Tony Barbour1fa09702017-03-16 12:09:08 -060011200 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011201
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011202 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011203 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11204 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011205
11206 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011207 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11208 ds_pool_ci.pNext = NULL;
11209 ds_pool_ci.maxSets = 1;
11210 ds_pool_ci.poolSizeCount = 1;
11211 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011212
Tobin Ehlis3b780662015-05-28 12:11:26 -060011213 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011214 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011215 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060011216 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011217 dsl_binding.binding = 0;
11218 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11219 dsl_binding.descriptorCount = 1;
11220 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11221 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011222
Tony Barboureb254902015-07-15 12:50:33 -060011223 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011224 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11225 ds_layout_ci.pNext = NULL;
11226 ds_layout_ci.bindingCount = 1;
11227 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011228
Tobin Ehlis3b780662015-05-28 12:11:26 -060011229 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011230 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011231 ASSERT_VK_SUCCESS(err);
11232
11233 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011234 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011235 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011236 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011237 alloc_info.descriptorPool = ds_pool;
11238 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011239 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011240 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011241
Tony Barboureb254902015-07-15 12:50:33 -060011242 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011243 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11244 sampler_ci.pNext = NULL;
11245 sampler_ci.magFilter = VK_FILTER_NEAREST;
11246 sampler_ci.minFilter = VK_FILTER_NEAREST;
11247 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11248 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11249 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11250 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11251 sampler_ci.mipLodBias = 1.0;
11252 sampler_ci.anisotropyEnable = VK_FALSE;
11253 sampler_ci.maxAnisotropy = 1;
11254 sampler_ci.compareEnable = VK_FALSE;
11255 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11256 sampler_ci.minLod = 1.0;
11257 sampler_ci.maxLod = 1.0;
11258 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11259 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011260 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011261 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011262 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011263
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011264 VkDescriptorImageInfo info = {};
11265 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011266
11267 VkWriteDescriptorSet descriptor_write;
11268 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011269 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011270 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011271 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011272 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011273 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060011274 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080011275
11276 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11277
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011278 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011279
Chia-I Wuf7458c52015-10-26 21:10:41 +080011280 vkDestroySampler(m_device->device(), sampler, NULL);
11281 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11282 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011283}
11284
Karl Schultz6addd812016-02-02 17:17:23 -070011285TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011286 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070011287 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011288
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011290
Tony Barbour1fa09702017-03-16 12:09:08 -060011291 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011292 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
11293 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011294 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011295 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
11296 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011297
11298 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011299 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11300 ds_pool_ci.pNext = NULL;
11301 ds_pool_ci.maxSets = 1;
11302 ds_pool_ci.poolSizeCount = 1;
11303 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011304
11305 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011306 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011307 ASSERT_VK_SUCCESS(err);
11308
11309 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011310 dsl_binding.binding = 0;
11311 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11312 dsl_binding.descriptorCount = 1;
11313 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11314 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011315
11316 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011317 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11318 ds_layout_ci.pNext = NULL;
11319 ds_layout_ci.bindingCount = 1;
11320 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011321 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011322 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011323 ASSERT_VK_SUCCESS(err);
11324
11325 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011326 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011327 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011328 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011329 alloc_info.descriptorPool = ds_pool;
11330 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011331 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011332 ASSERT_VK_SUCCESS(err);
11333
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011334 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011335
11336 VkDescriptorImageInfo descriptor_info;
11337 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11338 descriptor_info.sampler = sampler;
11339
11340 VkWriteDescriptorSet descriptor_write;
11341 memset(&descriptor_write, 0, sizeof(descriptor_write));
11342 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011343 descriptor_write.dstSet = descriptorSet;
11344 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011345 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011346 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11347 descriptor_write.pImageInfo = &descriptor_info;
11348
11349 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11350
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011351 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011352
Chia-I Wuf7458c52015-10-26 21:10:41 +080011353 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11354 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011355}
11356
Karl Schultz6addd812016-02-02 17:17:23 -070011357TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
11358 // Create a single combined Image/Sampler descriptor and send it an invalid
11359 // imageView
11360 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011361
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011363
Tony Barbour1fa09702017-03-16 12:09:08 -060011364 ASSERT_NO_FATAL_FAILURE(Init());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011365 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011366 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11367 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011368
11369 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011370 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11371 ds_pool_ci.pNext = NULL;
11372 ds_pool_ci.maxSets = 1;
11373 ds_pool_ci.poolSizeCount = 1;
11374 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011375
11376 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011377 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011378 ASSERT_VK_SUCCESS(err);
11379
11380 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011381 dsl_binding.binding = 0;
11382 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11383 dsl_binding.descriptorCount = 1;
11384 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11385 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011386
11387 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011388 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11389 ds_layout_ci.pNext = NULL;
11390 ds_layout_ci.bindingCount = 1;
11391 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011392 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011393 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011394 ASSERT_VK_SUCCESS(err);
11395
11396 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011397 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011398 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011399 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011400 alloc_info.descriptorPool = ds_pool;
11401 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011402 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011403 ASSERT_VK_SUCCESS(err);
11404
11405 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011406 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11407 sampler_ci.pNext = NULL;
11408 sampler_ci.magFilter = VK_FILTER_NEAREST;
11409 sampler_ci.minFilter = VK_FILTER_NEAREST;
11410 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11411 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11412 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11413 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11414 sampler_ci.mipLodBias = 1.0;
11415 sampler_ci.anisotropyEnable = VK_FALSE;
11416 sampler_ci.maxAnisotropy = 1;
11417 sampler_ci.compareEnable = VK_FALSE;
11418 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11419 sampler_ci.minLod = 1.0;
11420 sampler_ci.maxLod = 1.0;
11421 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11422 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011423
11424 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011425 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011426 ASSERT_VK_SUCCESS(err);
11427
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011428 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011429
11430 VkDescriptorImageInfo descriptor_info;
11431 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
11432 descriptor_info.sampler = sampler;
11433 descriptor_info.imageView = view;
11434
11435 VkWriteDescriptorSet descriptor_write;
11436 memset(&descriptor_write, 0, sizeof(descriptor_write));
11437 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011438 descriptor_write.dstSet = descriptorSet;
11439 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011440 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011441 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11442 descriptor_write.pImageInfo = &descriptor_info;
11443
11444 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11445
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011446 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011447
Chia-I Wuf7458c52015-10-26 21:10:41 +080011448 vkDestroySampler(m_device->device(), sampler, NULL);
11449 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11450 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060011451}
11452
Karl Schultz6addd812016-02-02 17:17:23 -070011453TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
11454 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
11455 // into the other
11456 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011457
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11459 " binding #1 with type "
11460 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
11461 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011462
Tony Barbour1fa09702017-03-16 12:09:08 -060011463 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultz6addd812016-02-02 17:17:23 -070011464 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011465 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011466 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11467 ds_type_count[0].descriptorCount = 1;
11468 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
11469 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011470
11471 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011472 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11473 ds_pool_ci.pNext = NULL;
11474 ds_pool_ci.maxSets = 1;
11475 ds_pool_ci.poolSizeCount = 2;
11476 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011477
11478 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011479 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011480 ASSERT_VK_SUCCESS(err);
11481 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011482 dsl_binding[0].binding = 0;
11483 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11484 dsl_binding[0].descriptorCount = 1;
11485 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
11486 dsl_binding[0].pImmutableSamplers = NULL;
11487 dsl_binding[1].binding = 1;
11488 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11489 dsl_binding[1].descriptorCount = 1;
11490 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
11491 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011492
11493 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011494 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11495 ds_layout_ci.pNext = NULL;
11496 ds_layout_ci.bindingCount = 2;
11497 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011498
11499 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011500 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011501 ASSERT_VK_SUCCESS(err);
11502
11503 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011504 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011505 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011506 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011507 alloc_info.descriptorPool = ds_pool;
11508 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011509 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011510 ASSERT_VK_SUCCESS(err);
11511
11512 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011513 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11514 sampler_ci.pNext = NULL;
11515 sampler_ci.magFilter = VK_FILTER_NEAREST;
11516 sampler_ci.minFilter = VK_FILTER_NEAREST;
11517 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11518 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11519 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11520 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11521 sampler_ci.mipLodBias = 1.0;
11522 sampler_ci.anisotropyEnable = VK_FALSE;
11523 sampler_ci.maxAnisotropy = 1;
11524 sampler_ci.compareEnable = VK_FALSE;
11525 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11526 sampler_ci.minLod = 1.0;
11527 sampler_ci.maxLod = 1.0;
11528 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11529 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011530
11531 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080011532 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011533 ASSERT_VK_SUCCESS(err);
11534
11535 VkDescriptorImageInfo info = {};
11536 info.sampler = sampler;
11537
11538 VkWriteDescriptorSet descriptor_write;
11539 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
11540 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011541 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011542 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080011543 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060011544 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
11545 descriptor_write.pImageInfo = &info;
11546 // This write update should succeed
11547 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11548 // Now perform a copy update that fails due to type mismatch
11549 VkCopyDescriptorSet copy_ds_update;
11550 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11551 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11552 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011553 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011554 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011555 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
11556 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060011557 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11558
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011559 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011560 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011561 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 -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;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011565 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
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 = 1; // Copy 1 descriptor
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();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011572
Tobin Ehlis04356f92015-10-27 16:35:27 -060011573 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11575 " binding#1 with offset index of 1 plus "
11576 "update array offset of 0 and update of "
11577 "5 descriptors oversteps total number "
11578 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011579
Tobin Ehlis04356f92015-10-27 16:35:27 -060011580 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
11581 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
11582 copy_ds_update.srcSet = descriptorSet;
11583 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011584 copy_ds_update.dstSet = descriptorSet;
11585 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011586 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060011587 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
11588
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011589 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060011590
Chia-I Wuf7458c52015-10-26 21:10:41 +080011591 vkDestroySampler(m_device->device(), sampler, NULL);
11592 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11593 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060011594}
11595
Karl Schultz6addd812016-02-02 17:17:23 -070011596TEST_F(VkLayerTest, NumSamplesMismatch) {
11597 // Create CommandBuffer where MSAA samples doesn't match RenderPass
11598 // sampleCount
11599 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011600
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011602
Tony Barbour1fa09702017-03-16 12:09:08 -060011603 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011604 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011605 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060011606 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011607 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011608
11609 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011610 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11611 ds_pool_ci.pNext = NULL;
11612 ds_pool_ci.maxSets = 1;
11613 ds_pool_ci.poolSizeCount = 1;
11614 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011615
Tobin Ehlis3b780662015-05-28 12:11:26 -060011616 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011617 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011618 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011619
Tony Barboureb254902015-07-15 12:50:33 -060011620 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080011621 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060011622 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080011623 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011624 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11625 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011626
Tony Barboureb254902015-07-15 12:50:33 -060011627 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11628 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11629 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080011630 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070011631 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011632
Tobin Ehlis3b780662015-05-28 12:11:26 -060011633 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011634 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011635 ASSERT_VK_SUCCESS(err);
11636
11637 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011638 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011639 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011640 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011641 alloc_info.descriptorPool = ds_pool;
11642 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011643 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011644 ASSERT_VK_SUCCESS(err);
11645
Tony Barboureb254902015-07-15 12:50:33 -060011646 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011647 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011648 pipe_ms_state_ci.pNext = NULL;
11649 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11650 pipe_ms_state_ci.sampleShadingEnable = 0;
11651 pipe_ms_state_ci.minSampleShading = 1.0;
11652 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011653
Tony Barboureb254902015-07-15 12:50:33 -060011654 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011655 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11656 pipeline_layout_ci.pNext = NULL;
11657 pipeline_layout_ci.setLayoutCount = 1;
11658 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060011659
11660 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011661 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060011662 ASSERT_VK_SUCCESS(err);
11663
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011664 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011665 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 -060011666 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011667 VkPipelineObj pipe(m_device);
11668 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011669 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011670 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011671 pipe.SetMSAA(&pipe_ms_state_ci);
11672 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011673
Tony Barbour552f6c02016-12-21 14:34:07 -070011674 m_commandBuffer->BeginCommandBuffer();
11675 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011676 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060011677
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070011678 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11679 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11680 VkRect2D scissor = {{0, 0}, {16, 16}};
11681 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11682
Mark Young29927482016-05-04 14:38:51 -060011683 // Render triangle (the error should trigger on the attempt to draw).
11684 Draw(3, 1, 0, 0);
11685
11686 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011687 m_commandBuffer->EndRenderPass();
11688 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060011689
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011690 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011691
Chia-I Wuf7458c52015-10-26 21:10:41 +080011692 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11693 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11694 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060011695}
Mark Young29927482016-05-04 14:38:51 -060011696
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011697TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011698 TEST_DESCRIPTION(
11699 "Hit RenderPass incompatible cases. "
11700 "Initial case is drawing with an active renderpass that's "
11701 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011702 VkResult err;
11703
Tony Barbour1fa09702017-03-16 12:09:08 -060011704 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11706
11707 VkDescriptorSetLayoutBinding dsl_binding = {};
11708 dsl_binding.binding = 0;
11709 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11710 dsl_binding.descriptorCount = 1;
11711 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11712 dsl_binding.pImmutableSamplers = NULL;
11713
11714 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11715 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11716 ds_layout_ci.pNext = NULL;
11717 ds_layout_ci.bindingCount = 1;
11718 ds_layout_ci.pBindings = &dsl_binding;
11719
11720 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011721 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011722 ASSERT_VK_SUCCESS(err);
11723
11724 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11725 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11726 pipeline_layout_ci.pNext = NULL;
11727 pipeline_layout_ci.setLayoutCount = 1;
11728 pipeline_layout_ci.pSetLayouts = &ds_layout;
11729
11730 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011731 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011732 ASSERT_VK_SUCCESS(err);
11733
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011734 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011735 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 -060011736 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011737 // Create a renderpass that will be incompatible with default renderpass
11738 VkAttachmentReference attach = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011739 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011740 VkAttachmentReference color_att = {};
Cort Stratton7547f772017-05-04 15:18:52 -070011741 color_att.layout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011742 VkSubpassDescription subpass = {};
11743 subpass.inputAttachmentCount = 1;
11744 subpass.pInputAttachments = &attach;
11745 subpass.colorAttachmentCount = 1;
11746 subpass.pColorAttachments = &color_att;
11747 VkRenderPassCreateInfo rpci = {};
11748 rpci.subpassCount = 1;
11749 rpci.pSubpasses = &subpass;
11750 rpci.attachmentCount = 1;
11751 VkAttachmentDescription attach_desc = {};
11752 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011753 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11754 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011755 rpci.pAttachments = &attach_desc;
11756 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11757 VkRenderPass rp;
11758 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11759 VkPipelineObj pipe(m_device);
11760 pipe.AddShader(&vs);
11761 pipe.AddShader(&fs);
11762 pipe.AddColorAttachment();
11763 VkViewport view_port = {};
11764 m_viewports.push_back(view_port);
11765 pipe.SetViewport(m_viewports);
11766 VkRect2D rect = {};
11767 m_scissors.push_back(rect);
11768 pipe.SetScissor(m_scissors);
11769 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11770
11771 VkCommandBufferInheritanceInfo cbii = {};
11772 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11773 cbii.renderPass = rp;
11774 cbii.subpass = 0;
11775 VkCommandBufferBeginInfo cbbi = {};
11776 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11777 cbbi.pInheritanceInfo = &cbii;
11778 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11779 VkRenderPassBeginInfo rpbi = {};
11780 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11781 rpbi.framebuffer = m_framebuffer;
11782 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011783 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11784 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011785
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011787 // Render triangle (the error should trigger on the attempt to draw).
11788 Draw(3, 1, 0, 0);
11789
11790 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011791 m_commandBuffer->EndRenderPass();
11792 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011793
11794 m_errorMonitor->VerifyFound();
11795
11796 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11797 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11798 vkDestroyRenderPass(m_device->device(), rp, NULL);
11799}
11800
Mark Youngc89c6312016-03-31 16:03:20 -060011801TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11802 // Create Pipeline where the number of blend attachments doesn't match the
11803 // number of color attachments. In this case, we don't add any color
11804 // blend attachments even though we have a color attachment.
11805 VkResult err;
11806
Tobin Ehlis974c0d92017-02-01 13:31:22 -070011807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060011808
Tony Barbour1fa09702017-03-16 12:09:08 -060011809 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc89c6312016-03-31 16:03:20 -060011810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11811 VkDescriptorPoolSize ds_type_count = {};
11812 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11813 ds_type_count.descriptorCount = 1;
11814
11815 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11816 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11817 ds_pool_ci.pNext = NULL;
11818 ds_pool_ci.maxSets = 1;
11819 ds_pool_ci.poolSizeCount = 1;
11820 ds_pool_ci.pPoolSizes = &ds_type_count;
11821
11822 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011823 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011824 ASSERT_VK_SUCCESS(err);
11825
11826 VkDescriptorSetLayoutBinding dsl_binding = {};
11827 dsl_binding.binding = 0;
11828 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11829 dsl_binding.descriptorCount = 1;
11830 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11831 dsl_binding.pImmutableSamplers = NULL;
11832
11833 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11834 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11835 ds_layout_ci.pNext = NULL;
11836 ds_layout_ci.bindingCount = 1;
11837 ds_layout_ci.pBindings = &dsl_binding;
11838
11839 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011840 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011841 ASSERT_VK_SUCCESS(err);
11842
11843 VkDescriptorSet descriptorSet;
11844 VkDescriptorSetAllocateInfo alloc_info = {};
11845 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11846 alloc_info.descriptorSetCount = 1;
11847 alloc_info.descriptorPool = ds_pool;
11848 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011849 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011850 ASSERT_VK_SUCCESS(err);
11851
11852 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011853 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011854 pipe_ms_state_ci.pNext = NULL;
11855 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11856 pipe_ms_state_ci.sampleShadingEnable = 0;
11857 pipe_ms_state_ci.minSampleShading = 1.0;
11858 pipe_ms_state_ci.pSampleMask = NULL;
11859
11860 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11861 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11862 pipeline_layout_ci.pNext = NULL;
11863 pipeline_layout_ci.setLayoutCount = 1;
11864 pipeline_layout_ci.pSetLayouts = &ds_layout;
11865
11866 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011867 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011868 ASSERT_VK_SUCCESS(err);
11869
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011870 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011871 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 -060011872 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011873 VkPipelineObj pipe(m_device);
11874 pipe.AddShader(&vs);
11875 pipe.AddShader(&fs);
11876 pipe.SetMSAA(&pipe_ms_state_ci);
11877 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011878 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011879
11880 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11881 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11882 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11883}
Mark Young29927482016-05-04 14:38:51 -060011884
Mark Muellerd4914412016-06-13 17:52:06 -060011885TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011886 TEST_DESCRIPTION(
11887 "Points to a wrong colorAttachment index in a VkClearAttachment "
11888 "structure passed to vkCmdClearAttachments");
Tony Barbour1fa09702017-03-16 12:09:08 -060011889 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011891
11892 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11893 m_errorMonitor->VerifyFound();
11894}
11895
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011896TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011897 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11898 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011899
Tony Barbour1fa09702017-03-16 12:09:08 -060011900 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011902
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011903 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011904 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11905 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011906
11907 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011908 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11909 ds_pool_ci.pNext = NULL;
11910 ds_pool_ci.maxSets = 1;
11911 ds_pool_ci.poolSizeCount = 1;
11912 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011913
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011914 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011915 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011916 ASSERT_VK_SUCCESS(err);
11917
Tony Barboureb254902015-07-15 12:50:33 -060011918 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011919 dsl_binding.binding = 0;
11920 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11921 dsl_binding.descriptorCount = 1;
11922 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11923 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011924
Tony Barboureb254902015-07-15 12:50:33 -060011925 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011926 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11927 ds_layout_ci.pNext = NULL;
11928 ds_layout_ci.bindingCount = 1;
11929 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011930
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011931 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011932 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011933 ASSERT_VK_SUCCESS(err);
11934
11935 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011936 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011937 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011938 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011939 alloc_info.descriptorPool = ds_pool;
11940 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011941 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011942 ASSERT_VK_SUCCESS(err);
11943
Tony Barboureb254902015-07-15 12:50:33 -060011944 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011945 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011946 pipe_ms_state_ci.pNext = NULL;
11947 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11948 pipe_ms_state_ci.sampleShadingEnable = 0;
11949 pipe_ms_state_ci.minSampleShading = 1.0;
11950 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011951
Tony Barboureb254902015-07-15 12:50:33 -060011952 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011953 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11954 pipeline_layout_ci.pNext = NULL;
11955 pipeline_layout_ci.setLayoutCount = 1;
11956 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011957
11958 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011959 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011960 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011961
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011962 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011963 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011964 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011965 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011966
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011967 VkPipelineObj pipe(m_device);
11968 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011969 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070011970 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011971 pipe.SetMSAA(&pipe_ms_state_ci);
11972 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011973
Tony Barbour552f6c02016-12-21 14:34:07 -070011974 m_commandBuffer->BeginCommandBuffer();
11975 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011976
Karl Schultz6addd812016-02-02 17:17:23 -070011977 // Main thing we care about for this test is that the VkImage obj we're
11978 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011979 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011980 VkClearAttachment color_attachment;
11981 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11982 color_attachment.clearValue.color.float32[0] = 1.0;
11983 color_attachment.clearValue.color.float32[1] = 1.0;
11984 color_attachment.clearValue.color.float32[2] = 1.0;
11985 color_attachment.clearValue.color.float32[3] = 1.0;
11986 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011987 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011988
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011989 // Call for full-sized FB Color attachment prior to issuing a Draw
11990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011991 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011992 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011993 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011994
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011995 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11996 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11998 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11999 m_errorMonitor->VerifyFound();
12000
12001 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
12002 clear_rect.layerCount = 2;
12003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
12004 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012005 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012006
Chia-I Wuf7458c52015-10-26 21:10:41 +080012007 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12008 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12009 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060012010}
12011
Karl Schultz6addd812016-02-02 17:17:23 -070012012TEST_F(VkLayerTest, VtxBufferBadIndex) {
12013 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012014
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12016 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012017
Tony Barbour1fa09702017-03-16 12:09:08 -060012018 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisd332f282015-10-02 11:00:56 -060012019 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060012020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060012021
Chia-I Wu1b99bb22015-10-27 19:25:11 +080012022 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012023 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12024 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060012025
12026 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012027 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12028 ds_pool_ci.pNext = NULL;
12029 ds_pool_ci.maxSets = 1;
12030 ds_pool_ci.poolSizeCount = 1;
12031 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060012032
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060012033 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012034 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012035 ASSERT_VK_SUCCESS(err);
12036
Tony Barboureb254902015-07-15 12:50:33 -060012037 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012038 dsl_binding.binding = 0;
12039 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12040 dsl_binding.descriptorCount = 1;
12041 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
12042 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012043
Tony Barboureb254902015-07-15 12:50:33 -060012044 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012045 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12046 ds_layout_ci.pNext = NULL;
12047 ds_layout_ci.bindingCount = 1;
12048 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060012049
Tobin Ehlis502480b2015-06-24 15:53:07 -060012050 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012051 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012052 ASSERT_VK_SUCCESS(err);
12053
12054 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012055 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080012056 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070012057 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060012058 alloc_info.descriptorPool = ds_pool;
12059 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012060 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012061 ASSERT_VK_SUCCESS(err);
12062
Tony Barboureb254902015-07-15 12:50:33 -060012063 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012064 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070012065 pipe_ms_state_ci.pNext = NULL;
12066 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12067 pipe_ms_state_ci.sampleShadingEnable = 0;
12068 pipe_ms_state_ci.minSampleShading = 1.0;
12069 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012070
Tony Barboureb254902015-07-15 12:50:33 -060012071 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070012072 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12073 pipeline_layout_ci.pNext = NULL;
12074 pipeline_layout_ci.setLayoutCount = 1;
12075 pipeline_layout_ci.pSetLayouts = &ds_layout;
12076 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060012077
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012078 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012079 ASSERT_VK_SUCCESS(err);
12080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012081 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012082 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 -060012083 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012084 VkPipelineObj pipe(m_device);
12085 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060012086 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060012087 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012088 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060012089 pipe.SetViewport(m_viewports);
12090 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060012091 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060012092
Tony Barbour552f6c02016-12-21 14:34:07 -070012093 m_commandBuffer->BeginCommandBuffer();
12094 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012095 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060012096 // Don't care about actual data, just need to get to draw to flag error
12097 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012098 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012099 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060012100 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012101
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012102 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060012103
Chia-I Wuf7458c52015-10-26 21:10:41 +080012104 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12105 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12106 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060012107}
Mark Muellerdfe37552016-07-07 14:47:42 -060012108
Mark Mueller2ee294f2016-08-04 12:59:48 -060012109TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012110 TEST_DESCRIPTION(
12111 "Use an invalid count in a vkEnumeratePhysicalDevices call."
12112 "Use invalid Queue Family Index in vkCreateDevice");
Tony Barbour1fa09702017-03-16 12:09:08 -060012113 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012114
Mark Mueller880fce52016-08-17 15:23:23 -060012115 // The following test fails with recent NVidia drivers.
12116 // By the time core_validation is reached, the NVidia
12117 // driver has sanitized the invalid condition and core_validation
12118 // is not introduced to the failure condition. This is not the case
12119 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012120 // uint32_t count = static_cast<uint32_t>(~0);
12121 // VkPhysicalDevice physical_device;
12122 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
12123 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012124
Mark Mueller2ee294f2016-08-04 12:59:48 -060012125 float queue_priority = 0.0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012126 VkDeviceQueueCreateInfo queue_create_info = {};
12127 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12128 queue_create_info.queueCount = 1;
12129 queue_create_info.pQueuePriorities = &queue_priority;
12130 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
12131
12132 VkPhysicalDeviceFeatures features = m_device->phy().features();
12133 VkDevice testDevice;
12134 VkDeviceCreateInfo device_create_info = {};
12135 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12136 device_create_info.queueCreateInfoCount = 1;
12137 device_create_info.pQueueCreateInfos = &queue_create_info;
12138 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012139
Petr Kraus56ed9192017-05-08 23:45:36 +020012140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00054);
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012141 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms that do
12142 // not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12143 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012144 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12145 m_errorMonitor->VerifyFound();
12146
12147 queue_create_info.queueFamilyIndex = 1;
12148
12149 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
12150 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
12151 for (unsigned i = 0; i < feature_count; i++) {
12152 if (VK_FALSE == feature_array[i]) {
12153 feature_array[i] = VK_TRUE;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012154 device_create_info.pEnabledFeatures = &features;
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12156 "While calling vkCreateDevice(), requesting feature #");
Jeremy Hayes17fd3662017-03-17 11:51:11 -060012157 // The following unexpected error is coming from the LunarG loader. Do not make it a desired message because platforms
12158 // that do not use the LunarG loader (e.g. Android) will not see the message and the test will fail.
12159 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Jeremy Hayesb26fd042017-03-10 09:13:22 -070012160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12161 "You requested features that are unavailable on this device. You should first "
12162 "query feature availability by calling vkGetPhysicalDeviceFeatures().");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012163 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
12164 m_errorMonitor->VerifyFound();
12165 break;
12166 }
12167 }
12168}
12169
Tobin Ehlis16edf082016-11-21 12:33:49 -070012170TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
12171 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
12172
Tony Barbour1fa09702017-03-16 12:09:08 -060012173 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis16edf082016-11-21 12:33:49 -070012174
12175 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
12176 std::vector<VkDeviceQueueCreateInfo> queue_info;
12177 queue_info.reserve(queue_props.size());
12178 std::vector<std::vector<float>> queue_priorities;
12179 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
12180 VkDeviceQueueCreateInfo qi{};
12181 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
12182 qi.queueFamilyIndex = i;
12183 qi.queueCount = queue_props[i].queueCount;
12184 queue_priorities.emplace_back(qi.queueCount, 0.0f);
12185 qi.pQueuePriorities = queue_priorities[i].data();
12186 queue_info.push_back(qi);
12187 }
12188
12189 std::vector<const char *> device_extension_names;
12190
12191 VkDevice local_device;
12192 VkDeviceCreateInfo device_create_info = {};
12193 auto features = m_device->phy().features();
12194 // Intentionally disable pipeline stats
12195 features.pipelineStatisticsQuery = VK_FALSE;
12196 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
12197 device_create_info.pNext = NULL;
12198 device_create_info.queueCreateInfoCount = queue_info.size();
12199 device_create_info.pQueueCreateInfos = queue_info.data();
12200 device_create_info.enabledLayerCount = 0;
12201 device_create_info.ppEnabledLayerNames = NULL;
12202 device_create_info.pEnabledFeatures = &features;
12203 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
12204 ASSERT_VK_SUCCESS(err);
12205
12206 VkQueryPoolCreateInfo qpci{};
12207 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12208 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
12209 qpci.queryCount = 1;
12210 VkQueryPool query_pool;
12211
12212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
12213 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
12214 m_errorMonitor->VerifyFound();
12215
12216 vkDestroyDevice(local_device, nullptr);
12217}
12218
Mark Mueller2ee294f2016-08-04 12:59:48 -060012219TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012220 TEST_DESCRIPTION(
12221 "Use an invalid queue index in a vkCmdWaitEvents call."
12222 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060012223
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012224 const char *invalid_queue_index =
12225 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
12226 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
12227 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012228
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012229 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060012230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012232
Tony Barbour1fa09702017-03-16 12:09:08 -060012233 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller2ee294f2016-08-04 12:59:48 -060012234
12235 VkEvent event;
12236 VkEventCreateInfo event_create_info{};
12237 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12238 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12239
Mark Mueller2ee294f2016-08-04 12:59:48 -060012240 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012241 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012242
Tony Barbour552f6c02016-12-21 14:34:07 -070012243 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060012244
12245 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012246 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 -060012247 ASSERT_TRUE(image.initialized());
12248 VkImageMemoryBarrier img_barrier = {};
12249 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12250 img_barrier.pNext = NULL;
12251 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
12252 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
12253 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12254 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
12255 img_barrier.image = image.handle();
12256 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060012257
12258 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
12259 // that layer validation catches the case when it is not.
12260 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060012261 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12262 img_barrier.subresourceRange.baseArrayLayer = 0;
12263 img_barrier.subresourceRange.baseMipLevel = 0;
12264 img_barrier.subresourceRange.layerCount = 1;
12265 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012266 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
12267 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012268 m_errorMonitor->VerifyFound();
12269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012271
12272 VkQueryPool query_pool;
12273 VkQueryPoolCreateInfo query_pool_create_info = {};
12274 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12275 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
12276 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012277 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012279 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060012280 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
12281
12282 vkEndCommandBuffer(m_commandBuffer->handle());
12283 m_errorMonitor->VerifyFound();
12284
12285 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
12286 vkDestroyEvent(m_device->device(), event, nullptr);
12287}
12288
Mark Muellerdfe37552016-07-07 14:47:42 -060012289TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012290 TEST_DESCRIPTION(
12291 "Submit a command buffer using deleted vertex buffer, "
12292 "delete a buffer twice, use an invalid offset for each "
12293 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060012294
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012295 const char *deleted_buffer_in_command_buffer =
12296 "Cannot submit cmd buffer "
12297 "using deleted buffer ";
12298 const char *invalid_offset_message =
12299 "vkBindBufferMemory(): "
12300 "memoryOffset is 0x";
12301 const char *invalid_storage_buffer_offset_message =
12302 "vkBindBufferMemory(): "
12303 "storage memoryOffset "
12304 "is 0x";
12305 const char *invalid_texel_buffer_offset_message =
12306 "vkBindBufferMemory(): "
12307 "texel memoryOffset "
12308 "is 0x";
12309 const char *invalid_uniform_buffer_offset_message =
12310 "vkBindBufferMemory(): "
12311 "uniform memoryOffset "
12312 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060012313
Tony Barbour1fa09702017-03-16 12:09:08 -060012314 ASSERT_NO_FATAL_FAILURE(Init());
Mark Muellerdfe37552016-07-07 14:47:42 -060012315 ASSERT_NO_FATAL_FAILURE(InitViewport());
12316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12317
12318 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012319 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060012320 pipe_ms_state_ci.pNext = NULL;
12321 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12322 pipe_ms_state_ci.sampleShadingEnable = 0;
12323 pipe_ms_state_ci.minSampleShading = 1.0;
12324 pipe_ms_state_ci.pSampleMask = nullptr;
12325
12326 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12327 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12328 VkPipelineLayout pipeline_layout;
12329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012330 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060012331 ASSERT_VK_SUCCESS(err);
12332
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012333 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12334 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060012335 VkPipelineObj pipe(m_device);
12336 pipe.AddShader(&vs);
12337 pipe.AddShader(&fs);
12338 pipe.AddColorAttachment();
12339 pipe.SetMSAA(&pipe_ms_state_ci);
12340 pipe.SetViewport(m_viewports);
12341 pipe.SetScissor(m_scissors);
12342 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12343
Tony Barbour552f6c02016-12-21 14:34:07 -070012344 m_commandBuffer->BeginCommandBuffer();
12345 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012346 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060012347
12348 {
12349 // Create and bind a vertex buffer in a reduced scope, which will cause
12350 // it to be deleted upon leaving this scope
12351 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012352 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060012353 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
12354 draw_verticies.AddVertexInputToPipe(pipe);
12355 }
12356
12357 Draw(1, 0, 0, 0);
12358
Tony Barbour552f6c02016-12-21 14:34:07 -070012359 m_commandBuffer->EndRenderPass();
12360 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060012361
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060012363 QueueCommandBuffer(false);
12364 m_errorMonitor->VerifyFound();
12365
12366 {
12367 // Create and bind a vertex buffer in a reduced scope, and delete it
12368 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012369 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060012371 buffer_test.TestDoubleDestroy();
12372 }
12373 m_errorMonitor->VerifyFound();
12374
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012375 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012376 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012377 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012379 m_errorMonitor->SetUnexpectedError(
12380 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
12381 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012382 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
12383 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012384 m_errorMonitor->VerifyFound();
12385 }
12386
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012387 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
12388 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012389 // Create and bind a memory buffer with an invalid offset again,
12390 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012392 m_errorMonitor->SetUnexpectedError(
12393 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12394 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012395 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12396 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012397 m_errorMonitor->VerifyFound();
12398 }
12399
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012400 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012401 // Create and bind a memory buffer with an invalid offset again, but
12402 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012404 m_errorMonitor->SetUnexpectedError(
12405 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12406 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012407 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12408 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012409 m_errorMonitor->VerifyFound();
12410 }
12411
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012412 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060012413 // Create and bind a memory buffer with an invalid offset again, but
12414 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012416 m_errorMonitor->SetUnexpectedError(
12417 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
12418 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012419 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
12420 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012421 m_errorMonitor->VerifyFound();
12422 }
12423
12424 {
12425 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012427 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
12428 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012429 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
12430 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012431 m_errorMonitor->VerifyFound();
12432 }
12433
12434 {
12435 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070012436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012437 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
12438 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060012439 }
12440 m_errorMonitor->VerifyFound();
12441
12442 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12443}
12444
Tony Barbourff1351e2017-05-10 11:14:03 -060012445TEST_F(VkLayerTest, BadVertexBufferOffset) {
12446 TEST_DESCRIPTION("Submit an offset past the end of a vertex buffer");
12447
12448 ASSERT_NO_FATAL_FAILURE(Init());
12449 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12450 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Tony Barboure94224e2017-05-11 15:22:43 -060012451 VkConstantBufferObj vbo(m_device, 3, sizeof(float), (const void *)&vbo_data);
Tony Barbourff1351e2017-05-10 11:14:03 -060012452 m_commandBuffer->BeginCommandBuffer();
12453 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
12454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01417);
Tony Barboure94224e2017-05-11 15:22:43 -060012455 BindVertexBuffer(&vbo, (VkDeviceSize)(3 * sizeof(float)), 1); // Offset at the end of the buffer
Tony Barbourff1351e2017-05-10 11:14:03 -060012456 m_errorMonitor->VerifyFound();
12457}
12458
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012459// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
12460TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012461 TEST_DESCRIPTION(
12462 "Hit all possible validation checks associated with the "
12463 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
12464 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012465 // 3 in ValidateCmdBufImageLayouts
12466 // * -1 Attempt to submit cmd buf w/ deleted image
12467 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
12468 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012469
Tony Barbour1fa09702017-03-16 12:09:08 -060012470 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060012471 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070012472 if (!depth_format) {
12473 printf(" No Depth + Stencil format found. Skipped.\n");
12474 return;
12475 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012476 // Create src & dst images to use for copy operations
12477 VkImage src_image;
12478 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080012479 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012480
12481 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
12482 const int32_t tex_width = 32;
12483 const int32_t tex_height = 32;
12484
12485 VkImageCreateInfo image_create_info = {};
12486 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
12487 image_create_info.pNext = NULL;
12488 image_create_info.imageType = VK_IMAGE_TYPE_2D;
12489 image_create_info.format = tex_format;
12490 image_create_info.extent.width = tex_width;
12491 image_create_info.extent.height = tex_height;
12492 image_create_info.extent.depth = 1;
12493 image_create_info.mipLevels = 1;
12494 image_create_info.arrayLayers = 4;
12495 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
12496 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
12497 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080012498 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012499 image_create_info.flags = 0;
12500
12501 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
12502 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012503 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012504 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
12505 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080012506 image_create_info.format = VK_FORMAT_D32_SFLOAT;
12507 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
12508 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
12509 ASSERT_VK_SUCCESS(err);
12510
12511 // Allocate memory
12512 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080012513 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080012514 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080012515 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12516 mem_alloc.pNext = NULL;
12517 mem_alloc.allocationSize = 0;
12518 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080012519
12520 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012521 mem_alloc.allocationSize = img_mem_reqs.size;
12522 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012523 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080012524 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080012525 ASSERT_VK_SUCCESS(err);
12526
12527 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012528 mem_alloc.allocationSize = img_mem_reqs.size;
12529 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012530 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012531 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080012532 ASSERT_VK_SUCCESS(err);
12533
12534 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080012535 mem_alloc.allocationSize = img_mem_reqs.size;
12536 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080012537 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080012538 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080012539 ASSERT_VK_SUCCESS(err);
12540
12541 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
12542 ASSERT_VK_SUCCESS(err);
12543 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
12544 ASSERT_VK_SUCCESS(err);
12545 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
12546 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012547
Tony Barbour552f6c02016-12-21 14:34:07 -070012548 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080012549 VkImageCopy copy_region;
12550 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12551 copy_region.srcSubresource.mipLevel = 0;
12552 copy_region.srcSubresource.baseArrayLayer = 0;
12553 copy_region.srcSubresource.layerCount = 1;
12554 copy_region.srcOffset.x = 0;
12555 copy_region.srcOffset.y = 0;
12556 copy_region.srcOffset.z = 0;
12557 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12558 copy_region.dstSubresource.mipLevel = 0;
12559 copy_region.dstSubresource.baseArrayLayer = 0;
12560 copy_region.dstSubresource.layerCount = 1;
12561 copy_region.dstOffset.x = 0;
12562 copy_region.dstOffset.y = 0;
12563 copy_region.dstOffset.z = 0;
12564 copy_region.extent.width = 1;
12565 copy_region.extent.height = 1;
12566 copy_region.extent.depth = 1;
12567
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12569 "layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12570 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012571
Cort530cf382016-12-08 09:59:47 -080012572 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 -060012573 m_errorMonitor->VerifyFound();
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012574 // The first call hits the expected WARNING and skips the call down the chain, so call a second time to call down chain and
12575 // update layer state
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012576 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
12577 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
Tobin Ehlise35b66a2017-03-15 12:18:31 -060012578 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 -060012579 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012581 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that "
12582 "doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskic61e1da2017-05-15 16:18:13 -060012583 m_errorMonitor->SetUnexpectedError("is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT");
Cort530cf382016-12-08 09:59:47 -080012584 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 -060012585 m_errorMonitor->VerifyFound();
12586 // Final src error is due to bad layout type
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012588 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012589 "VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012590 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012591 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012592 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_UNDEFINED, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012593 m_errorMonitor->VerifyFound();
12594 // Now verify same checks for dst
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12596 "layout should be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL instead of GENERAL.");
12597 m_errorMonitor->SetUnexpectedError("layout should be VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080012598 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 -060012599 m_errorMonitor->VerifyFound();
12600 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012602 "with specific layout VK_IMAGE_LAYOUT_UNDEFINED that doesn't match "
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012603 "the actual current layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012604 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012605 "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 -080012606 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 -060012607 m_errorMonitor->VerifyFound();
Tobin Ehlis74cc6822017-03-14 16:16:51 -060012608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012609 "is VK_IMAGE_LAYOUT_UNDEFINED but can only be VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL "
12610 "or VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012611 m_errorMonitor->SetUnexpectedError(
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012612 "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 -080012613 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 -060012614 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012615
Cort3b021012016-12-07 12:00:57 -080012616 // Convert dst and depth images to TRANSFER_DST for subsequent tests
12617 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
12618 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
12619 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
12620 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
12621 transfer_dst_image_barrier[0].srcAccessMask = 0;
12622 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
12623 transfer_dst_image_barrier[0].image = dst_image;
12624 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12625 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
12626 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12627 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12628 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12629 transfer_dst_image_barrier[0].image = depth_image;
12630 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
12631 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12632 NULL, 0, NULL, 1, transfer_dst_image_barrier);
12633
12634 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080012635 VkClearColorValue color_clear_value = {};
12636 VkImageSubresourceRange clear_range;
12637 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12638 clear_range.baseMipLevel = 0;
12639 clear_range.baseArrayLayer = 0;
12640 clear_range.layerCount = 1;
12641 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012642
Cort3b021012016-12-07 12:00:57 -080012643 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
12644 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
12646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012647 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012648 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012649 // Fail due to provided layout not matching actual current layout for color clear.
12650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080012651 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012652 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080012653
Cort530cf382016-12-08 09:59:47 -080012654 VkClearDepthStencilValue depth_clear_value = {};
12655 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080012656
12657 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
12658 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
12659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
12660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012661 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012662 m_errorMonitor->VerifyFound();
12663 // Fail due to provided layout not matching actual current layout for depth clear.
12664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080012665 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080012666 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010012667
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012668 // Now cause error due to bad image layout transition in PipelineBarrier
12669 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080012670 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012671 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080012672 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012673 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080012674 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
12675 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012676 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012678 "you cannot transition the layout of aspect 1 from "
12679 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when current layout is "
12680 "VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070012681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012682 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
12683 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012684 m_errorMonitor->VerifyFound();
12685
12686 // Finally some layout errors at RenderPass create time
12687 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
12688 VkAttachmentReference attach = {};
12689 // perf warning for GENERAL layout w/ non-DS input attachment
12690 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12691 VkSubpassDescription subpass = {};
12692 subpass.inputAttachmentCount = 1;
12693 subpass.pInputAttachments = &attach;
12694 VkRenderPassCreateInfo rpci = {};
12695 rpci.subpassCount = 1;
12696 rpci.pSubpasses = &subpass;
12697 rpci.attachmentCount = 1;
12698 VkAttachmentDescription attach_desc = {};
12699 attach_desc.format = VK_FORMAT_UNDEFINED;
12700 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012701 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012702 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12704 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012705 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12706 m_errorMonitor->VerifyFound();
12707 // error w/ non-general layout
12708 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12709
12710 m_errorMonitor->SetDesiredFailureMsg(
12711 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12712 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
12713 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12714 m_errorMonitor->VerifyFound();
12715 subpass.inputAttachmentCount = 0;
12716 subpass.colorAttachmentCount = 1;
12717 subpass.pColorAttachments = &attach;
12718 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12719 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12721 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012722 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12723 m_errorMonitor->VerifyFound();
12724 // error w/ non-color opt or GENERAL layout for color attachment
12725 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
12726 m_errorMonitor->SetDesiredFailureMsg(
12727 VK_DEBUG_REPORT_ERROR_BIT_EXT,
12728 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
12729 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12730 m_errorMonitor->VerifyFound();
12731 subpass.colorAttachmentCount = 0;
12732 subpass.pDepthStencilAttachment = &attach;
12733 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
12734 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
12736 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012737 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12738 m_errorMonitor->VerifyFound();
12739 // error w/ non-ds opt or GENERAL layout for color attachment
12740 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12742 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12743 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012744 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12745 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012746 // For this error we need a valid renderpass so create default one
12747 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12748 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070012749 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012750 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12751 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12752 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12753 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12754 // Can't do a CLEAR load on READ_ONLY initialLayout
12755 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12756 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12757 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinski91c28262017-03-22 13:06:12 -060012759 "with invalid first layout VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012760 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12761 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012762
Cort3b021012016-12-07 12:00:57 -080012763 vkFreeMemory(m_device->device(), src_image_mem, NULL);
12764 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
12765 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012766 vkDestroyImage(m_device->device(), src_image, NULL);
12767 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080012768 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012769}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012770
Tobin Ehlise0936662016-10-11 08:10:51 -060012771TEST_F(VkLayerTest, InvalidStorageImageLayout) {
12772 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
12773 VkResult err;
12774
Tony Barbour1fa09702017-03-16 12:09:08 -060012775 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlise0936662016-10-11 08:10:51 -060012776
12777 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
12778 VkImageTiling tiling;
12779 VkFormatProperties format_properties;
12780 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
12781 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12782 tiling = VK_IMAGE_TILING_LINEAR;
12783 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12784 tiling = VK_IMAGE_TILING_OPTIMAL;
12785 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070012786 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060012787 return;
12788 }
12789
12790 VkDescriptorPoolSize ds_type = {};
12791 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12792 ds_type.descriptorCount = 1;
12793
12794 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12795 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12796 ds_pool_ci.maxSets = 1;
12797 ds_pool_ci.poolSizeCount = 1;
12798 ds_pool_ci.pPoolSizes = &ds_type;
12799 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12800
12801 VkDescriptorPool ds_pool;
12802 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12803 ASSERT_VK_SUCCESS(err);
12804
12805 VkDescriptorSetLayoutBinding dsl_binding = {};
12806 dsl_binding.binding = 0;
12807 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12808 dsl_binding.descriptorCount = 1;
12809 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12810 dsl_binding.pImmutableSamplers = NULL;
12811
12812 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12813 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12814 ds_layout_ci.pNext = NULL;
12815 ds_layout_ci.bindingCount = 1;
12816 ds_layout_ci.pBindings = &dsl_binding;
12817
12818 VkDescriptorSetLayout ds_layout;
12819 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12820 ASSERT_VK_SUCCESS(err);
12821
12822 VkDescriptorSetAllocateInfo alloc_info = {};
12823 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12824 alloc_info.descriptorSetCount = 1;
12825 alloc_info.descriptorPool = ds_pool;
12826 alloc_info.pSetLayouts = &ds_layout;
12827 VkDescriptorSet descriptor_set;
12828 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12829 ASSERT_VK_SUCCESS(err);
12830
12831 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12832 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12833 pipeline_layout_ci.pNext = NULL;
12834 pipeline_layout_ci.setLayoutCount = 1;
12835 pipeline_layout_ci.pSetLayouts = &ds_layout;
12836 VkPipelineLayout pipeline_layout;
12837 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12838 ASSERT_VK_SUCCESS(err);
12839
12840 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060012841 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
Tobin Ehlise0936662016-10-11 08:10:51 -060012842 ASSERT_TRUE(image.initialized());
12843 VkImageView view = image.targetView(tex_format);
12844
12845 VkDescriptorImageInfo image_info = {};
12846 image_info.imageView = view;
12847 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12848
12849 VkWriteDescriptorSet descriptor_write = {};
12850 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12851 descriptor_write.dstSet = descriptor_set;
12852 descriptor_write.dstBinding = 0;
12853 descriptor_write.descriptorCount = 1;
12854 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12855 descriptor_write.pImageInfo = &image_info;
12856
12857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12858 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12859 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12860 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12861 m_errorMonitor->VerifyFound();
12862
12863 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12864 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12865 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12866 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12867}
12868
Chris Forbes3fa68552017-05-18 14:34:05 -070012869TEST_F(VkLayerTest, NonSimultaneousSecondaryMarksPrimary) {
Tony Barbour1fa09702017-03-16 12:09:08 -060012870 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fa68552017-05-18 14:34:05 -070012871 const char *simultaneous_use_message =
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012872 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12873 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012874
Chris Forbes3fa68552017-05-18 14:34:05 -070012875 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
Mark Mueller93b938f2016-08-18 10:27:40 -060012876
Chris Forbes3fa68552017-05-18 14:34:05 -070012877 secondary.begin();
12878 secondary.end();
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012879
Chris Forbes3fa68552017-05-18 14:34:05 -070012880 VkCommandBufferBeginInfo cbbi = {
12881 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
12882 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr,
12883 };
Mark Mueller93b938f2016-08-18 10:27:40 -060012884
Chris Forbes3fa68552017-05-18 14:34:05 -070012885 m_commandBuffer->begin(&cbbi);
12886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message);
12887 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012888 m_errorMonitor->VerifyFound();
Chris Forbes3fa68552017-05-18 14:34:05 -070012889 m_commandBuffer->end();
12890}
Mark Mueller93b938f2016-08-18 10:27:40 -060012891
Chris Forbes3fa68552017-05-18 14:34:05 -070012892TEST_F(VkLayerTest, SimultaneousUseSecondaryTwoExecutes) {
12893 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller93b938f2016-08-18 10:27:40 -060012894
Chris Forbes3fa68552017-05-18 14:34:05 -070012895 const char *simultaneous_use_message = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Mueller4042b652016-09-05 22:52:21 -060012896
Chris Forbes3fa68552017-05-18 14:34:05 -070012897 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
12898
12899 VkCommandBufferInheritanceInfo inh = {
12900 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, nullptr,
12901 };
12902 VkCommandBufferBeginInfo cbbi = {
12903 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
12904 0, &inh
12905 };
12906
12907 secondary.begin(&cbbi);
12908 secondary.end();
12909
12910 m_commandBuffer->begin();
12911 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
12912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12913 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary.handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012914 m_errorMonitor->VerifyFound();
Chris Forbes3fa68552017-05-18 14:34:05 -070012915 m_commandBuffer->end();
12916}
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012917
Chris Forbes3fa68552017-05-18 14:34:05 -070012918TEST_F(VkLayerTest, SimultaneousUseSecondarySingleExecute) {
12919 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012920
Chris Forbes3fa68552017-05-18 14:34:05 -070012921 // variation on previous test executing the same CB twice in the same
12922 // CmdExecuteCommands call
12923
12924 const char *simultaneous_use_message = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
12925
12926 VkCommandBufferObj secondary(m_device, m_commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
12927
12928 VkCommandBufferInheritanceInfo inh = {
12929 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, nullptr,
12930 };
12931 VkCommandBufferBeginInfo cbbi = {
12932 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
12933 0, &inh
12934 };
12935
12936 secondary.begin(&cbbi);
12937 secondary.end();
12938
12939 m_commandBuffer->begin();
12940 VkCommandBuffer cbs[] = { secondary.handle(), secondary.handle() };
12941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12942 vkCmdExecuteCommands(m_commandBuffer->handle(), 2, cbs);
12943 m_errorMonitor->VerifyFound();
12944 m_commandBuffer->end();
Mark Mueller93b938f2016-08-18 10:27:40 -060012945}
12946
Tony Barbour626994c2017-02-08 15:29:37 -070012947TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12948 TEST_DESCRIPTION(
12949 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12950 "errors");
12951 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12952 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 -060012953 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070012954
12955 VkCommandBuffer cmd_bufs[2];
12956 VkCommandBufferAllocateInfo alloc_info;
12957 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12958 alloc_info.pNext = NULL;
12959 alloc_info.commandBufferCount = 2;
Mike Schuchardt06304c22017-03-01 17:09:09 -070012960 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070012961 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12962 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12963
12964 VkCommandBufferBeginInfo cb_binfo;
12965 cb_binfo.pNext = NULL;
12966 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12967 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12968 cb_binfo.flags = 0;
12969 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12970 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12971 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12972 vkEndCommandBuffer(cmd_bufs[0]);
12973 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12974
12975 VkSubmitInfo submit_info = {};
12976 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12977 submit_info.commandBufferCount = 2;
12978 submit_info.pCommandBuffers = duplicates;
12979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12980 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12981 m_errorMonitor->VerifyFound();
12982 vkQueueWaitIdle(m_device->m_queue);
12983
12984 // Set one time use and now look for one time submit
12985 duplicates[0] = duplicates[1] = cmd_bufs[1];
12986 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12987 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12988 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12989 vkEndCommandBuffer(cmd_bufs[1]);
12990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12991 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12992 m_errorMonitor->VerifyFound();
12993 vkQueueWaitIdle(m_device->m_queue);
12994}
12995
Tobin Ehlisb093da82017-01-19 12:05:27 -070012996TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012997 TEST_DESCRIPTION(
12998 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12999 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070013000
Tony Barbour1fa09702017-03-16 12:09:08 -060013001 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisb093da82017-01-19 12:05:27 -070013002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13003
13004 std::vector<const char *> device_extension_names;
13005 auto features = m_device->phy().features();
13006 // Make sure gs & ts are disabled
13007 features.geometryShader = false;
13008 features.tessellationShader = false;
13009 // The sacrificial device object
13010 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13011
13012 VkCommandPoolCreateInfo pool_create_info{};
13013 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
13014 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
13015
13016 VkCommandPool command_pool;
13017 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
13018
13019 VkCommandBufferAllocateInfo cmd = {};
13020 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13021 cmd.pNext = NULL;
13022 cmd.commandPool = command_pool;
13023 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
13024 cmd.commandBufferCount = 1;
13025
13026 VkCommandBuffer cmd_buffer;
13027 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
13028 ASSERT_VK_SUCCESS(err);
13029
13030 VkEvent event;
13031 VkEventCreateInfo evci = {};
13032 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13033 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
13034 ASSERT_VK_SUCCESS(result);
13035
13036 VkCommandBufferBeginInfo cbbi = {};
13037 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13038 vkBeginCommandBuffer(cmd_buffer, &cbbi);
13039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
13040 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
13041 m_errorMonitor->VerifyFound();
13042
13043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
13044 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
13045 m_errorMonitor->VerifyFound();
13046
13047 vkDestroyEvent(test_device.handle(), event, NULL);
13048 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
13049}
13050
Chris Forbesd70103a2017-04-13 11:34:09 -070013051TEST_F(VkLayerTest, EventInUseDestroyedSignaled) {
Tony Barbour1fa09702017-03-16 12:09:08 -060013052 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller917f6bc2016-08-30 10:57:19 -060013053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13054
Tony Barbour552f6c02016-12-21 14:34:07 -070013055 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013056
13057 VkEvent event;
13058 VkEventCreateInfo event_create_info = {};
13059 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13060 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013061 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013062
Tony Barbour552f6c02016-12-21 14:34:07 -070013063 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013064 vkDestroyEvent(m_device->device(), event, nullptr);
13065
13066 VkSubmitInfo submit_info = {};
13067 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13068 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013069 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070013070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013071 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13072 m_errorMonitor->VerifyFound();
Chris Forbesd70103a2017-04-13 11:34:09 -070013073}
Mark Muellerc8d441e2016-08-23 17:36:00 -060013074
Chris Forbesd70103a2017-04-13 11:34:09 -070013075TEST_F(VkLayerTest, InUseDestroyedSignaled) {
13076 TEST_DESCRIPTION(
13077 "Use vkCmdExecuteCommands with invalid state "
13078 "in primary and secondary command buffers. "
13079 "Delete objects that are inuse. Call VkQueueSubmit "
13080 "with an event that has been deleted.");
Mark Muellerc8d441e2016-08-23 17:36:00 -060013081
Chris Forbesd70103a2017-04-13 11:34:09 -070013082 ASSERT_NO_FATAL_FAILURE(Init());
13083 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13084
13085 m_errorMonitor->ExpectSuccess();
Mark Muellerc8d441e2016-08-23 17:36:00 -060013086
Mark Mueller917f6bc2016-08-30 10:57:19 -060013087 VkSemaphoreCreateInfo semaphore_create_info = {};
13088 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13089 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013090 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013091 VkFenceCreateInfo fence_create_info = {};
13092 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13093 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013094 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013095
13096 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013097 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013098 descriptor_pool_type_count.descriptorCount = 1;
13099
13100 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13101 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13102 descriptor_pool_create_info.maxSets = 1;
13103 descriptor_pool_create_info.poolSizeCount = 1;
13104 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013105 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013106
13107 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013108 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013109
13110 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060013111 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013112 descriptorset_layout_binding.descriptorCount = 1;
13113 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13114
13115 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013116 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013117 descriptorset_layout_create_info.bindingCount = 1;
13118 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13119
13120 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013121 ASSERT_VK_SUCCESS(
13122 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013123
13124 VkDescriptorSet descriptorset;
13125 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013126 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013127 descriptorset_allocate_info.descriptorSetCount = 1;
13128 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13129 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013130 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013131
Mark Mueller4042b652016-09-05 22:52:21 -060013132 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13133
13134 VkDescriptorBufferInfo buffer_info = {};
13135 buffer_info.buffer = buffer_test.GetBuffer();
13136 buffer_info.offset = 0;
13137 buffer_info.range = 1024;
13138
13139 VkWriteDescriptorSet write_descriptor_set = {};
13140 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13141 write_descriptor_set.dstSet = descriptorset;
13142 write_descriptor_set.descriptorCount = 1;
13143 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13144 write_descriptor_set.pBufferInfo = &buffer_info;
13145
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013146 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060013147
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013148 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13149 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013150
13151 VkPipelineObj pipe(m_device);
13152 pipe.AddColorAttachment();
13153 pipe.AddShader(&vs);
13154 pipe.AddShader(&fs);
13155
13156 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013157 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060013158 pipeline_layout_create_info.setLayoutCount = 1;
13159 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13160
13161 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013162 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060013163
13164 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
13165
Chris Forbesd70103a2017-04-13 11:34:09 -070013166 VkEvent event;
13167 VkEventCreateInfo event_create_info = {};
13168 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13169 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
13170
Tony Barbour552f6c02016-12-21 14:34:07 -070013171 m_commandBuffer->BeginCommandBuffer();
Chris Forbesd70103a2017-04-13 11:34:09 -070013172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013173 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060013174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013175 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13176 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13177 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013178
Tony Barbour552f6c02016-12-21 14:34:07 -070013179 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013180
Chris Forbesd70103a2017-04-13 11:34:09 -070013181 VkSubmitInfo submit_info = {};
13182 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13183 submit_info.commandBufferCount = 1;
13184 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller917f6bc2016-08-30 10:57:19 -060013185 submit_info.signalSemaphoreCount = 1;
13186 submit_info.pSignalSemaphores = &semaphore;
13187 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013188 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060013189
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013191 vkDestroyEvent(m_device->device(), event, nullptr);
13192 m_errorMonitor->VerifyFound();
13193
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013195 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13196 m_errorMonitor->VerifyFound();
13197
Jeremy Hayes08369882017-02-02 10:31:06 -070013198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013199 vkDestroyFence(m_device->device(), fence, nullptr);
13200 m_errorMonitor->VerifyFound();
13201
Tobin Ehlis122207b2016-09-01 08:50:06 -070013202 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013203 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
13204 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013205 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013206 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
13207 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013208 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013209 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
13210 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060013211 vkDestroyEvent(m_device->device(), event, nullptr);
13212 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013213 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060013214 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13215}
13216
Tobin Ehlis2adda372016-09-01 08:51:06 -070013217TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
13218 TEST_DESCRIPTION("Delete in-use query pool.");
13219
Tony Barbour1fa09702017-03-16 12:09:08 -060013220 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis2adda372016-09-01 08:51:06 -070013221 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13222
13223 VkQueryPool query_pool;
13224 VkQueryPoolCreateInfo query_pool_ci{};
13225 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
13226 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
13227 query_pool_ci.queryCount = 1;
13228 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070013229 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013230 // Reset query pool to create binding with cmd buffer
13231 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
13232
Tony Barbour552f6c02016-12-21 14:34:07 -070013233 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070013234
13235 VkSubmitInfo submit_info = {};
13236 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13237 submit_info.commandBufferCount = 1;
13238 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13239 // Submit cmd buffer and then destroy query pool while in-flight
13240 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13241
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070013243 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13244 m_errorMonitor->VerifyFound();
13245
13246 vkQueueWaitIdle(m_device->m_queue);
13247 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013248 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013249 m_errorMonitor->SetUnexpectedError("Unable to remove QueryPool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070013250 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
13251}
13252
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013253TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
13254 TEST_DESCRIPTION("Delete in-use pipeline.");
13255
Tony Barbour1fa09702017-03-16 12:09:08 -060013256 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13258
13259 // Empty pipeline layout used for binding PSO
13260 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13261 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13262 pipeline_layout_ci.setLayoutCount = 0;
13263 pipeline_layout_ci.pSetLayouts = NULL;
13264
13265 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013266 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013267 ASSERT_VK_SUCCESS(err);
13268
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013270 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013271 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13272 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013273 // Store pipeline handle so we can actually delete it before test finishes
13274 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013275 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013276 VkPipelineObj pipe(m_device);
13277 pipe.AddShader(&vs);
13278 pipe.AddShader(&fs);
13279 pipe.AddColorAttachment();
13280 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13281 delete_this_pipeline = pipe.handle();
13282
Tony Barbour552f6c02016-12-21 14:34:07 -070013283 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013284 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013285 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013286
Tony Barbour552f6c02016-12-21 14:34:07 -070013287 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013288
13289 VkSubmitInfo submit_info = {};
13290 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13291 submit_info.commandBufferCount = 1;
13292 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13293 // Submit cmd buffer and then pipeline destroyed while in-flight
13294 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013295 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013296 m_errorMonitor->VerifyFound();
13297 // Make sure queue finished and then actually delete pipeline
13298 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013299 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
13300 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060013301 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
13302 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
13303}
13304
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013305TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
13306 TEST_DESCRIPTION("Delete in-use imageView.");
13307
Tony Barbour1fa09702017-03-16 12:09:08 -060013308 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013309 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13310
13311 VkDescriptorPoolSize ds_type_count;
13312 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13313 ds_type_count.descriptorCount = 1;
13314
13315 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13316 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13317 ds_pool_ci.maxSets = 1;
13318 ds_pool_ci.poolSizeCount = 1;
13319 ds_pool_ci.pPoolSizes = &ds_type_count;
13320
13321 VkDescriptorPool ds_pool;
13322 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13323 ASSERT_VK_SUCCESS(err);
13324
13325 VkSamplerCreateInfo sampler_ci = {};
13326 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13327 sampler_ci.pNext = NULL;
13328 sampler_ci.magFilter = VK_FILTER_NEAREST;
13329 sampler_ci.minFilter = VK_FILTER_NEAREST;
13330 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13331 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13332 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13333 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13334 sampler_ci.mipLodBias = 1.0;
13335 sampler_ci.anisotropyEnable = VK_FALSE;
13336 sampler_ci.maxAnisotropy = 1;
13337 sampler_ci.compareEnable = VK_FALSE;
13338 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13339 sampler_ci.minLod = 1.0;
13340 sampler_ci.maxLod = 1.0;
13341 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13342 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13343 VkSampler sampler;
13344
13345 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13346 ASSERT_VK_SUCCESS(err);
13347
13348 VkDescriptorSetLayoutBinding layout_binding;
13349 layout_binding.binding = 0;
13350 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13351 layout_binding.descriptorCount = 1;
13352 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13353 layout_binding.pImmutableSamplers = NULL;
13354
13355 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13356 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13357 ds_layout_ci.bindingCount = 1;
13358 ds_layout_ci.pBindings = &layout_binding;
13359 VkDescriptorSetLayout ds_layout;
13360 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13361 ASSERT_VK_SUCCESS(err);
13362
13363 VkDescriptorSetAllocateInfo alloc_info = {};
13364 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13365 alloc_info.descriptorSetCount = 1;
13366 alloc_info.descriptorPool = ds_pool;
13367 alloc_info.pSetLayouts = &ds_layout;
13368 VkDescriptorSet descriptor_set;
13369 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13370 ASSERT_VK_SUCCESS(err);
13371
13372 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13373 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13374 pipeline_layout_ci.pNext = NULL;
13375 pipeline_layout_ci.setLayoutCount = 1;
13376 pipeline_layout_ci.pSetLayouts = &ds_layout;
13377
13378 VkPipelineLayout pipeline_layout;
13379 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13380 ASSERT_VK_SUCCESS(err);
13381
13382 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013383 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 -060013384 ASSERT_TRUE(image.initialized());
13385
13386 VkImageView view;
13387 VkImageViewCreateInfo ivci = {};
13388 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13389 ivci.image = image.handle();
13390 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13391 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13392 ivci.subresourceRange.layerCount = 1;
13393 ivci.subresourceRange.baseMipLevel = 0;
13394 ivci.subresourceRange.levelCount = 1;
13395 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13396
13397 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13398 ASSERT_VK_SUCCESS(err);
13399
13400 VkDescriptorImageInfo image_info{};
13401 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13402 image_info.imageView = view;
13403 image_info.sampler = sampler;
13404
13405 VkWriteDescriptorSet descriptor_write = {};
13406 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13407 descriptor_write.dstSet = descriptor_set;
13408 descriptor_write.dstBinding = 0;
13409 descriptor_write.descriptorCount = 1;
13410 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13411 descriptor_write.pImageInfo = &image_info;
13412
13413 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13414
13415 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013416 char const *vsSource =
13417 "#version 450\n"
13418 "\n"
13419 "out gl_PerVertex { \n"
13420 " vec4 gl_Position;\n"
13421 "};\n"
13422 "void main(){\n"
13423 " gl_Position = vec4(1);\n"
13424 "}\n";
13425 char const *fsSource =
13426 "#version 450\n"
13427 "\n"
13428 "layout(set=0, binding=0) uniform sampler2D s;\n"
13429 "layout(location=0) out vec4 x;\n"
13430 "void main(){\n"
13431 " x = texture(s, vec2(1));\n"
13432 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013433 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13434 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13435 VkPipelineObj pipe(m_device);
13436 pipe.AddShader(&vs);
13437 pipe.AddShader(&fs);
13438 pipe.AddColorAttachment();
13439 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13440
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013442
Tony Barbour552f6c02016-12-21 14:34:07 -070013443 m_commandBuffer->BeginCommandBuffer();
13444 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013445 // Bind pipeline to cmd buffer
13446 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13447 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13448 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070013449
13450 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13451 VkRect2D scissor = {{0, 0}, {16, 16}};
13452 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13453 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13454
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013455 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013456 m_commandBuffer->EndRenderPass();
13457 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013458 // Submit cmd buffer then destroy sampler
13459 VkSubmitInfo submit_info = {};
13460 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13461 submit_info.commandBufferCount = 1;
13462 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13463 // Submit cmd buffer and then destroy imageView while in-flight
13464 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13465
13466 vkDestroyImageView(m_device->device(), view, nullptr);
13467 m_errorMonitor->VerifyFound();
13468 vkQueueWaitIdle(m_device->m_queue);
13469 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013470 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013471 m_errorMonitor->SetUnexpectedError("Unable to remove ImageView obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060013472 vkDestroyImageView(m_device->device(), view, NULL);
13473 vkDestroySampler(m_device->device(), sampler, nullptr);
13474 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13475 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13476 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13477}
13478
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013479TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
13480 TEST_DESCRIPTION("Delete in-use bufferView.");
13481
Tony Barbour1fa09702017-03-16 12:09:08 -060013482 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013483 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13484
13485 VkDescriptorPoolSize ds_type_count;
13486 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13487 ds_type_count.descriptorCount = 1;
13488
13489 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13490 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13491 ds_pool_ci.maxSets = 1;
13492 ds_pool_ci.poolSizeCount = 1;
13493 ds_pool_ci.pPoolSizes = &ds_type_count;
13494
13495 VkDescriptorPool ds_pool;
13496 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
13497 ASSERT_VK_SUCCESS(err);
13498
13499 VkDescriptorSetLayoutBinding layout_binding;
13500 layout_binding.binding = 0;
13501 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13502 layout_binding.descriptorCount = 1;
13503 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13504 layout_binding.pImmutableSamplers = NULL;
13505
13506 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13507 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13508 ds_layout_ci.bindingCount = 1;
13509 ds_layout_ci.pBindings = &layout_binding;
13510 VkDescriptorSetLayout ds_layout;
13511 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
13512 ASSERT_VK_SUCCESS(err);
13513
13514 VkDescriptorSetAllocateInfo alloc_info = {};
13515 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13516 alloc_info.descriptorSetCount = 1;
13517 alloc_info.descriptorPool = ds_pool;
13518 alloc_info.pSetLayouts = &ds_layout;
13519 VkDescriptorSet descriptor_set;
13520 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
13521 ASSERT_VK_SUCCESS(err);
13522
13523 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13524 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13525 pipeline_layout_ci.pNext = NULL;
13526 pipeline_layout_ci.setLayoutCount = 1;
13527 pipeline_layout_ci.pSetLayouts = &ds_layout;
13528
13529 VkPipelineLayout pipeline_layout;
13530 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
13531 ASSERT_VK_SUCCESS(err);
13532
13533 VkBuffer buffer;
13534 uint32_t queue_family_index = 0;
13535 VkBufferCreateInfo buffer_create_info = {};
13536 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
13537 buffer_create_info.size = 1024;
13538 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
13539 buffer_create_info.queueFamilyIndexCount = 1;
13540 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
13541
13542 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
13543 ASSERT_VK_SUCCESS(err);
13544
13545 VkMemoryRequirements memory_reqs;
13546 VkDeviceMemory buffer_memory;
13547
13548 VkMemoryAllocateInfo memory_info = {};
13549 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
13550 memory_info.allocationSize = 0;
13551 memory_info.memoryTypeIndex = 0;
13552
13553 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
13554 memory_info.allocationSize = memory_reqs.size;
13555 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
13556 ASSERT_TRUE(pass);
13557
13558 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
13559 ASSERT_VK_SUCCESS(err);
13560 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
13561 ASSERT_VK_SUCCESS(err);
13562
13563 VkBufferView view;
13564 VkBufferViewCreateInfo bvci = {};
13565 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
13566 bvci.buffer = buffer;
13567 bvci.format = VK_FORMAT_R8_UNORM;
13568 bvci.range = VK_WHOLE_SIZE;
13569
13570 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
13571 ASSERT_VK_SUCCESS(err);
13572
13573 VkWriteDescriptorSet descriptor_write = {};
13574 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13575 descriptor_write.dstSet = descriptor_set;
13576 descriptor_write.dstBinding = 0;
13577 descriptor_write.descriptorCount = 1;
13578 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
13579 descriptor_write.pTexelBufferView = &view;
13580
13581 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13582
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013583 char const *vsSource =
13584 "#version 450\n"
13585 "\n"
13586 "out gl_PerVertex { \n"
13587 " vec4 gl_Position;\n"
13588 "};\n"
13589 "void main(){\n"
13590 " gl_Position = vec4(1);\n"
13591 "}\n";
13592 char const *fsSource =
13593 "#version 450\n"
13594 "\n"
13595 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
13596 "layout(location=0) out vec4 x;\n"
13597 "void main(){\n"
13598 " x = imageLoad(s, 0);\n"
13599 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013600 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13601 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13602 VkPipelineObj pipe(m_device);
13603 pipe.AddShader(&vs);
13604 pipe.AddShader(&fs);
13605 pipe.AddColorAttachment();
13606 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13607
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013609
Tony Barbour552f6c02016-12-21 14:34:07 -070013610 m_commandBuffer->BeginCommandBuffer();
13611 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013612 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13613 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13614 VkRect2D scissor = {{0, 0}, {16, 16}};
13615 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13616 // Bind pipeline to cmd buffer
13617 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13618 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13619 &descriptor_set, 0, nullptr);
13620 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013621 m_commandBuffer->EndRenderPass();
13622 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013623
13624 VkSubmitInfo submit_info = {};
13625 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13626 submit_info.commandBufferCount = 1;
13627 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13628 // Submit cmd buffer and then destroy bufferView while in-flight
13629 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13630
13631 vkDestroyBufferView(m_device->device(), view, nullptr);
13632 m_errorMonitor->VerifyFound();
13633 vkQueueWaitIdle(m_device->m_queue);
13634 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013635 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
Mark Lobodzinski74597792017-04-11 15:43:49 -060013636 m_errorMonitor->SetUnexpectedError("Unable to remove BufferView obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060013637 vkDestroyBufferView(m_device->device(), view, NULL);
13638 vkDestroyBuffer(m_device->device(), buffer, NULL);
13639 vkFreeMemory(m_device->device(), buffer_memory, NULL);
13640 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13641 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13642 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13643}
13644
Tobin Ehlis209532e2016-09-07 13:52:18 -060013645TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
13646 TEST_DESCRIPTION("Delete in-use sampler.");
13647
Tony Barbour1fa09702017-03-16 12:09:08 -060013648 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis209532e2016-09-07 13:52:18 -060013649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13650
13651 VkDescriptorPoolSize ds_type_count;
13652 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13653 ds_type_count.descriptorCount = 1;
13654
13655 VkDescriptorPoolCreateInfo ds_pool_ci = {};
13656 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13657 ds_pool_ci.maxSets = 1;
13658 ds_pool_ci.poolSizeCount = 1;
13659 ds_pool_ci.pPoolSizes = &ds_type_count;
13660
13661 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013662 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013663 ASSERT_VK_SUCCESS(err);
13664
13665 VkSamplerCreateInfo sampler_ci = {};
13666 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
13667 sampler_ci.pNext = NULL;
13668 sampler_ci.magFilter = VK_FILTER_NEAREST;
13669 sampler_ci.minFilter = VK_FILTER_NEAREST;
13670 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
13671 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13672 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13673 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
13674 sampler_ci.mipLodBias = 1.0;
13675 sampler_ci.anisotropyEnable = VK_FALSE;
13676 sampler_ci.maxAnisotropy = 1;
13677 sampler_ci.compareEnable = VK_FALSE;
13678 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
13679 sampler_ci.minLod = 1.0;
13680 sampler_ci.maxLod = 1.0;
13681 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
13682 sampler_ci.unnormalizedCoordinates = VK_FALSE;
13683 VkSampler sampler;
13684
13685 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
13686 ASSERT_VK_SUCCESS(err);
13687
13688 VkDescriptorSetLayoutBinding layout_binding;
13689 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060013690 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060013691 layout_binding.descriptorCount = 1;
13692 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13693 layout_binding.pImmutableSamplers = NULL;
13694
13695 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
13696 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13697 ds_layout_ci.bindingCount = 1;
13698 ds_layout_ci.pBindings = &layout_binding;
13699 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013700 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013701 ASSERT_VK_SUCCESS(err);
13702
13703 VkDescriptorSetAllocateInfo alloc_info = {};
13704 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13705 alloc_info.descriptorSetCount = 1;
13706 alloc_info.descriptorPool = ds_pool;
13707 alloc_info.pSetLayouts = &ds_layout;
13708 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013709 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013710 ASSERT_VK_SUCCESS(err);
13711
13712 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13713 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13714 pipeline_layout_ci.pNext = NULL;
13715 pipeline_layout_ci.setLayoutCount = 1;
13716 pipeline_layout_ci.pSetLayouts = &ds_layout;
13717
13718 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013719 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013720 ASSERT_VK_SUCCESS(err);
13721
13722 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013723 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 -060013724 ASSERT_TRUE(image.initialized());
13725
13726 VkImageView view;
13727 VkImageViewCreateInfo ivci = {};
13728 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
13729 ivci.image = image.handle();
13730 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
13731 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
13732 ivci.subresourceRange.layerCount = 1;
13733 ivci.subresourceRange.baseMipLevel = 0;
13734 ivci.subresourceRange.levelCount = 1;
13735 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
13736
13737 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
13738 ASSERT_VK_SUCCESS(err);
13739
13740 VkDescriptorImageInfo image_info{};
13741 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
13742 image_info.imageView = view;
13743 image_info.sampler = sampler;
13744
13745 VkWriteDescriptorSet descriptor_write = {};
13746 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
13747 descriptor_write.dstSet = descriptor_set;
13748 descriptor_write.dstBinding = 0;
13749 descriptor_write.descriptorCount = 1;
13750 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
13751 descriptor_write.pImageInfo = &image_info;
13752
13753 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
13754
13755 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013756 char const *vsSource =
13757 "#version 450\n"
13758 "\n"
13759 "out gl_PerVertex { \n"
13760 " vec4 gl_Position;\n"
13761 "};\n"
13762 "void main(){\n"
13763 " gl_Position = vec4(1);\n"
13764 "}\n";
13765 char const *fsSource =
13766 "#version 450\n"
13767 "\n"
13768 "layout(set=0, binding=0) uniform sampler2D s;\n"
13769 "layout(location=0) out vec4 x;\n"
13770 "void main(){\n"
13771 " x = texture(s, vec2(1));\n"
13772 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060013773 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13774 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13775 VkPipelineObj pipe(m_device);
13776 pipe.AddShader(&vs);
13777 pipe.AddShader(&fs);
13778 pipe.AddColorAttachment();
13779 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13780
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013782
Tony Barbour552f6c02016-12-21 14:34:07 -070013783 m_commandBuffer->BeginCommandBuffer();
13784 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013785 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013786 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13787 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13788 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070013789
13790 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13791 VkRect2D scissor = {{0, 0}, {16, 16}};
13792 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13793 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13794
Tobin Ehlis209532e2016-09-07 13:52:18 -060013795 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013796 m_commandBuffer->EndRenderPass();
13797 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060013798 // Submit cmd buffer then destroy sampler
13799 VkSubmitInfo submit_info = {};
13800 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13801 submit_info.commandBufferCount = 1;
13802 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13803 // Submit cmd buffer and then destroy sampler while in-flight
13804 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13805
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013806 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060013807 m_errorMonitor->VerifyFound();
13808 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070013809
Tobin Ehlis209532e2016-09-07 13:52:18 -060013810 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013811 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
13812 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013813 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060013814 vkDestroyImageView(m_device->device(), view, NULL);
13815 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13816 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13817 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13818}
13819
Mark Mueller1cd9f412016-08-25 13:23:52 -060013820TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013821 TEST_DESCRIPTION(
13822 "Call VkQueueSubmit with a semaphore that is already "
13823 "signaled but not waited on by the queue. Wait on a "
13824 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013825
Tony Barbour1fa09702017-03-16 12:09:08 -060013826 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller96a56d52016-08-24 10:28:05 -060013827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013829 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 -070013830 const char *invalid_fence_wait_message =
13831 " which has not been submitted on a Queue or during "
13832 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013833
Chris Forbese98aec12017-05-18 12:50:14 -070013834 VkCommandBufferObj cb1(m_device, m_commandPool);
13835 cb1.begin();
13836 cb1.end();
Mark Mueller96a56d52016-08-24 10:28:05 -060013837
13838 VkSemaphoreCreateInfo semaphore_create_info = {};
13839 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13840 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013841 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013842 VkSubmitInfo submit_info = {};
13843 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13844 submit_info.commandBufferCount = 1;
Chris Forbese98aec12017-05-18 12:50:14 -070013845 submit_info.pCommandBuffers = &cb1.handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013846 submit_info.signalSemaphoreCount = 1;
13847 submit_info.pSignalSemaphores = &semaphore;
13848 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Chris Forbese98aec12017-05-18 12:50:14 -070013849
Tony Barbour552f6c02016-12-21 14:34:07 -070013850 m_commandBuffer->BeginCommandBuffer();
13851 m_commandBuffer->EndCommandBuffer();
Chris Forbese98aec12017-05-18 12:50:14 -070013852 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013854 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13855 m_errorMonitor->VerifyFound();
13856
Mark Mueller1cd9f412016-08-25 13:23:52 -060013857 VkFenceCreateInfo fence_create_info = {};
13858 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13859 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013860 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013863 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13864 m_errorMonitor->VerifyFound();
13865
Mark Mueller4042b652016-09-05 22:52:21 -060013866 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013867 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013868 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13869}
13870
Tobin Ehlis4af23302016-07-19 10:50:30 -060013871TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013872 TEST_DESCRIPTION(
13873 "Bind a secondary command buffer with with a framebuffer "
13874 "that does not match the framebuffer for the active "
13875 "renderpass.");
Tony Barbour1fa09702017-03-16 12:09:08 -060013876 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis4af23302016-07-19 10:50:30 -060013877 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13878
13879 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013880 VkAttachmentDescription attachment = {0,
13881 VK_FORMAT_B8G8R8A8_UNORM,
13882 VK_SAMPLE_COUNT_1_BIT,
13883 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13884 VK_ATTACHMENT_STORE_OP_STORE,
13885 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13886 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13887 VK_IMAGE_LAYOUT_UNDEFINED,
13888 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013889
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013890 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013891
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013892 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013893
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013894 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013895
13896 VkRenderPass rp;
13897 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13898 ASSERT_VK_SUCCESS(err);
13899
13900 // A compatible framebuffer.
13901 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060013902 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 -060013903 ASSERT_TRUE(image.initialized());
13904
13905 VkImageViewCreateInfo ivci = {
13906 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13907 nullptr,
13908 0,
13909 image.handle(),
13910 VK_IMAGE_VIEW_TYPE_2D,
13911 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013912 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13913 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013914 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13915 };
13916 VkImageView view;
13917 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13918 ASSERT_VK_SUCCESS(err);
13919
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013920 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013921 VkFramebuffer fb;
13922 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13923 ASSERT_VK_SUCCESS(err);
13924
13925 VkCommandBufferAllocateInfo cbai = {};
13926 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070013927 cbai.commandPool = m_commandPool->handle();
Tobin Ehlis4af23302016-07-19 10:50:30 -060013928 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13929 cbai.commandBufferCount = 1;
13930
13931 VkCommandBuffer sec_cb;
13932 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13933 ASSERT_VK_SUCCESS(err);
13934 VkCommandBufferBeginInfo cbbi = {};
13935 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013936 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013937 cbii.renderPass = renderPass();
13938 cbii.framebuffer = fb;
13939 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13940 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013941 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 -060013942 cbbi.pInheritanceInfo = &cbii;
13943 vkBeginCommandBuffer(sec_cb, &cbbi);
13944 vkEndCommandBuffer(sec_cb);
13945
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013946 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013947 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13948 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013949
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013951 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013952 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13953 m_errorMonitor->VerifyFound();
13954 // Cleanup
13955 vkDestroyImageView(m_device->device(), view, NULL);
13956 vkDestroyRenderPass(m_device->device(), rp, NULL);
13957 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13958}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013959
13960TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013961 TEST_DESCRIPTION(
13962 "If logicOp is available on the device, set it to an "
13963 "invalid value. If logicOp is not available, attempt to "
13964 "use it and verify that we see the correct error.");
Tony Barbour1fa09702017-03-16 12:09:08 -060013965 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013966 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13967
13968 auto features = m_device->phy().features();
13969 // Set the expected error depending on whether or not logicOp available
13970 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13972 "If logic operations feature not "
13973 "enabled, logicOpEnable must be "
13974 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013975 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013977 }
13978 // Create a pipeline using logicOp
13979 VkResult err;
13980
13981 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13982 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13983
13984 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013985 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013986 ASSERT_VK_SUCCESS(err);
13987
13988 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13989 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13990 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013991 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013992 vp_state_ci.pViewports = &vp;
13993 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013994 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013995 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013996
13997 VkPipelineShaderStageCreateInfo shaderStages[2];
13998 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13999
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014000 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
14001 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014002 shaderStages[0] = vs.GetStageCreateInfo();
14003 shaderStages[1] = fs.GetStageCreateInfo();
14004
14005 VkPipelineVertexInputStateCreateInfo vi_ci = {};
14006 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14007
14008 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
14009 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14010 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14011
14012 VkPipelineRasterizationStateCreateInfo rs_ci = {};
14013 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130014014 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014015
14016 VkPipelineColorBlendAttachmentState att = {};
14017 att.blendEnable = VK_FALSE;
14018 att.colorWriteMask = 0xf;
14019
14020 VkPipelineColorBlendStateCreateInfo cb_ci = {};
14021 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14022 // Enable logicOp & set logicOp to value 1 beyond allowed entries
14023 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014024 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014025 cb_ci.attachmentCount = 1;
14026 cb_ci.pAttachments = &att;
14027
Chris Forbes8aeacbf2016-10-03 14:25:08 +130014028 VkPipelineMultisampleStateCreateInfo ms_ci = {};
14029 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
14030 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
14031
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014032 VkGraphicsPipelineCreateInfo gp_ci = {};
14033 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14034 gp_ci.stageCount = 2;
14035 gp_ci.pStages = shaderStages;
14036 gp_ci.pVertexInputState = &vi_ci;
14037 gp_ci.pInputAssemblyState = &ia_ci;
14038 gp_ci.pViewportState = &vp_state_ci;
14039 gp_ci.pRasterizationState = &rs_ci;
14040 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130014041 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014042 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14043 gp_ci.layout = pipeline_layout;
14044 gp_ci.renderPass = renderPass();
14045
14046 VkPipelineCacheCreateInfo pc_ci = {};
14047 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14048
14049 VkPipeline pipeline;
14050 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014051 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014052 ASSERT_VK_SUCCESS(err);
14053
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014054 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014055 m_errorMonitor->VerifyFound();
14056 if (VK_SUCCESS == err) {
14057 vkDestroyPipeline(m_device->device(), pipeline, NULL);
14058 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060014059 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
14060 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
14061}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014062
Mike Stroyanaccf7692015-05-12 16:00:45 -060014063#if GTEST_IS_THREADSAFE
14064struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014065 VkCommandBuffer commandBuffer;
Mike Stroyanca855662017-05-02 11:06:27 -060014066 VkDevice device;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014067 VkEvent event;
14068 bool bailout;
14069};
14070
Karl Schultz6addd812016-02-02 17:17:23 -070014071extern "C" void *AddToCommandBuffer(void *arg) {
14072 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014073
Mike Stroyana6d14942016-07-13 15:10:05 -060014074 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014075 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014076 if (data->bailout) {
14077 break;
14078 }
14079 }
14080 return NULL;
14081}
14082
Karl Schultz6addd812016-02-02 17:17:23 -070014083TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014084 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014085
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014087
Tony Barbour1fa09702017-03-16 12:09:08 -060014088 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyanaccf7692015-05-12 16:00:45 -060014089 ASSERT_NO_FATAL_FAILURE(InitViewport());
14090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14091
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014092 // Calls AllocateCommandBuffers
14093 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014094
14095 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014096 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014097
14098 VkEventCreateInfo event_info;
14099 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060014100 VkResult err;
14101
14102 memset(&event_info, 0, sizeof(event_info));
14103 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
14104
Chia-I Wuf7458c52015-10-26 21:10:41 +080014105 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014106 ASSERT_VK_SUCCESS(err);
14107
Mike Stroyanaccf7692015-05-12 16:00:45 -060014108 err = vkResetEvent(device(), event);
14109 ASSERT_VK_SUCCESS(err);
14110
14111 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014112 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014113 data.event = event;
14114 data.bailout = false;
14115 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060014116
14117 // First do some correct operations using multiple threads.
14118 // Add many entries to command buffer from another thread.
14119 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
14120 // Make non-conflicting calls from this thread at the same time.
14121 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060014122 uint32_t count;
14123 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060014124 }
14125 test_platform_thread_join(thread, NULL);
14126
14127 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060014128 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014129 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014130 // Add many entries to command buffer from this thread at the same time.
14131 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060014132
Mike Stroyan4268d1f2015-07-13 14:45:35 -060014133 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014134 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014135
Mike Stroyan10b8cb72016-01-22 15:22:03 -070014136 m_errorMonitor->SetBailout(NULL);
14137
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014138 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060014139
Chia-I Wuf7458c52015-10-26 21:10:41 +080014140 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060014141}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014142#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014143
Karl Schultz6addd812016-02-02 17:17:23 -070014144TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014145 TEST_DESCRIPTION("Test that errors are produced for a spirv modules with invalid code sizes");
Chris Forbes1cc79542016-07-20 11:13:44 +120014146
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014148
Tony Barbour1fa09702017-03-16 12:09:08 -060014149 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14151
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014152 VkShaderModule module;
14153 VkShaderModuleCreateInfo moduleCreateInfo;
14154 struct icd_spv_header spv;
14155
14156 spv.magic = ICD_SPV_MAGIC;
14157 spv.version = ICD_SPV_VERSION;
14158 spv.gen_magic = 0;
14159
14160 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14161 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014162 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014163 moduleCreateInfo.codeSize = 4;
14164 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014165 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014166
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014167 m_errorMonitor->VerifyFound();
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014168
14169 char const *vsSource =
14170 "#version 450\n"
14171 "\n"
14172 "layout(location=0) out float x;\n"
14173 "out gl_PerVertex {\n"
14174 " vec4 gl_Position;\n"
14175 "};\n"
14176 "void main(){\n"
14177 " gl_Position = vec4(1);\n"
14178 " x = 0;\n"
14179 "}\n";
14180
14181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02816);
14182 std::vector<unsigned int> shader;
14183 VkShaderModuleCreateInfo module_create_info;
14184 VkShaderModule shader_module;
14185 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14186 module_create_info.pNext = NULL;
14187 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, shader);
14188 module_create_info.pCode = shader.data();
14189 // Introduce failure by making codeSize a non-multiple of 4
14190 module_create_info.codeSize = shader.size() * sizeof(unsigned int) - 1;
14191 module_create_info.flags = 0;
14192 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
14193
14194 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014195}
14196
Karl Schultz6addd812016-02-02 17:17:23 -070014197TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014198 TEST_DESCRIPTION(
14199 "Test that an error is produced for a spirv module "
14200 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120014201
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014203
Tony Barbour1fa09702017-03-16 12:09:08 -060014204 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014205 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14206
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014207 VkShaderModule module;
14208 VkShaderModuleCreateInfo moduleCreateInfo;
14209 struct icd_spv_header spv;
14210
14211 spv.magic = ~ICD_SPV_MAGIC;
14212 spv.version = ICD_SPV_VERSION;
14213 spv.gen_magic = 0;
14214
14215 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14216 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070014217 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Mark Lobodzinskid742b312017-05-09 16:26:27 -060014218 moduleCreateInfo.codeSize = sizeof(spv) + 16;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014219 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014220 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014221
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014222 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014223}
14224
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014225#if 0
14226// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070014227TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070014228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014229 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014230
Tony Barbour1fa09702017-03-16 12:09:08 -060014231 ASSERT_NO_FATAL_FAILURE(Init());
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014232 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14233
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014234 VkShaderModule module;
14235 VkShaderModuleCreateInfo moduleCreateInfo;
14236 struct icd_spv_header spv;
14237
14238 spv.magic = ICD_SPV_MAGIC;
14239 spv.version = ~ICD_SPV_VERSION;
14240 spv.gen_magic = 0;
14241
14242 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14243 moduleCreateInfo.pNext = NULL;
14244
Karl Schultz6addd812016-02-02 17:17:23 -070014245 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014246 moduleCreateInfo.codeSize = sizeof(spv) + 10;
14247 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014248 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014249
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014250 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014251}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120014252#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060014253
Karl Schultz6addd812016-02-02 17:17:23 -070014254TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014255 TEST_DESCRIPTION(
14256 "Test that a warning is produced for a vertex output that "
14257 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014259
Tony Barbour1fa09702017-03-16 12:09:08 -060014260 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014262
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014263 char const *vsSource =
14264 "#version 450\n"
14265 "\n"
14266 "layout(location=0) out float x;\n"
14267 "out gl_PerVertex {\n"
14268 " vec4 gl_Position;\n"
14269 "};\n"
14270 "void main(){\n"
14271 " gl_Position = vec4(1);\n"
14272 " x = 0;\n"
14273 "}\n";
14274 char const *fsSource =
14275 "#version 450\n"
14276 "\n"
14277 "layout(location=0) out vec4 color;\n"
14278 "void main(){\n"
14279 " color = vec4(1);\n"
14280 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120014281
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014282 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14283 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014284
14285 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014286 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014287 pipe.AddShader(&vs);
14288 pipe.AddShader(&fs);
14289
Chris Forbes9f7ff632015-05-25 11:13:08 +120014290 VkDescriptorSetObj descriptorSet(m_device);
14291 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014292 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120014293
Tony Barbour5781e8f2015-08-04 16:23:11 -060014294 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120014295
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014296 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120014297}
Chris Forbes9f7ff632015-05-25 11:13:08 +120014298
Mark Mueller098c9cb2016-09-08 09:01:57 -060014299TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
14300 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14301
Tony Barbour1fa09702017-03-16 12:09:08 -060014302 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14304
14305 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014306 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014307
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014308 char const *vsSource =
14309 "#version 450\n"
14310 "\n"
14311 "out gl_PerVertex {\n"
14312 " vec4 gl_Position;\n"
14313 "};\n"
14314 "void main(){\n"
14315 " gl_Position = vec4(1);\n"
14316 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014317
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014318 char const *fsSource =
14319 "#version 450\n"
14320 "\n"
14321 "layout (constant_id = 0) const float r = 0.0f;\n"
14322 "layout(location = 0) out vec4 uFragColor;\n"
14323 "void main(){\n"
14324 " uFragColor = vec4(r,1,0,1);\n"
14325 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014326
14327 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14328 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14329
14330 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14331 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14332
14333 VkPipelineLayout pipeline_layout;
14334 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14335
14336 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
14337 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
14338 vp_state_create_info.viewportCount = 1;
14339 VkViewport viewport = {};
14340 vp_state_create_info.pViewports = &viewport;
14341 vp_state_create_info.scissorCount = 1;
14342 VkRect2D scissors = {};
14343 vp_state_create_info.pScissors = &scissors;
14344
14345 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
14346
14347 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
14348 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
14349 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
14350 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
14351
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014352 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060014353
14354 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
14355 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
14356
14357 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
14358 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
14359 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
14360
14361 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
14362 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
14363 rasterization_state_create_info.pNext = nullptr;
14364 rasterization_state_create_info.lineWidth = 1.0f;
14365 rasterization_state_create_info.rasterizerDiscardEnable = true;
14366
14367 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
14368 color_blend_attachment_state.blendEnable = VK_FALSE;
14369 color_blend_attachment_state.colorWriteMask = 0xf;
14370
14371 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
14372 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
14373 color_blend_state_create_info.attachmentCount = 1;
14374 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
14375
14376 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
14377 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
14378 graphicspipe_create_info.stageCount = 2;
14379 graphicspipe_create_info.pStages = shader_stage_create_info;
14380 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
14381 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
14382 graphicspipe_create_info.pViewportState = &vp_state_create_info;
14383 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
14384 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
14385 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
14386 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
14387 graphicspipe_create_info.layout = pipeline_layout;
14388 graphicspipe_create_info.renderPass = renderPass();
14389
14390 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
14391 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
14392
14393 VkPipelineCache pipelineCache;
14394 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
14395
14396 // This structure maps constant ids to data locations.
14397 const VkSpecializationMapEntry entry =
14398 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014399 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014400
14401 uint32_t data = 1;
14402
14403 // Set up the info describing spec map and data
14404 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014405 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060014406 };
14407 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
14408
14409 VkPipeline pipeline;
14410 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
14411 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
14412 m_errorMonitor->VerifyFound();
14413
14414 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
14415 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14416}
14417
14418TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
14419 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
14420
Tony Barbour1fa09702017-03-16 12:09:08 -060014421 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014422 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14423
14424 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
14425
14426 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
14427 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14428 descriptor_pool_type_count[0].descriptorCount = 1;
14429 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14430 descriptor_pool_type_count[1].descriptorCount = 1;
14431
14432 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14433 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14434 descriptor_pool_create_info.maxSets = 1;
14435 descriptor_pool_create_info.poolSizeCount = 2;
14436 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
14437 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14438
14439 VkDescriptorPool descriptorset_pool;
14440 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14441
14442 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14443 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
14444 descriptorset_layout_binding.descriptorCount = 1;
14445 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070014446 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014447
14448 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14449 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14450 descriptorset_layout_create_info.bindingCount = 1;
14451 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14452
14453 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014454 ASSERT_VK_SUCCESS(
14455 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014456
14457 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14458 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14459 descriptorset_allocate_info.descriptorSetCount = 1;
14460 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14461 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14462 VkDescriptorSet descriptorset;
14463 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14464
14465 // Challenge core_validation with a non uniform buffer type.
14466 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
14467
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014468 char const *vsSource =
14469 "#version 450\n"
14470 "\n"
14471 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14472 " mat4 mvp;\n"
14473 "} ubuf;\n"
14474 "out gl_PerVertex {\n"
14475 " vec4 gl_Position;\n"
14476 "};\n"
14477 "void main(){\n"
14478 " gl_Position = ubuf.mvp * vec4(1);\n"
14479 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014480
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014481 char const *fsSource =
14482 "#version 450\n"
14483 "\n"
14484 "layout(location = 0) out vec4 uFragColor;\n"
14485 "void main(){\n"
14486 " uFragColor = vec4(0,1,0,1);\n"
14487 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014488
14489 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14490 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14491
14492 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14493 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14494 pipeline_layout_create_info.setLayoutCount = 1;
14495 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
14496
14497 VkPipelineLayout pipeline_layout;
14498 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14499
14500 VkPipelineObj pipe(m_device);
14501 pipe.AddColorAttachment();
14502 pipe.AddShader(&vs);
14503 pipe.AddShader(&fs);
14504
14505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
14506 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14507 m_errorMonitor->VerifyFound();
14508
14509 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14510 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14511 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14512}
14513
14514TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
14515 TEST_DESCRIPTION(
14516 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
14517
Tony Barbour1fa09702017-03-16 12:09:08 -060014518 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14520
14521 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
14522
14523 VkDescriptorPoolSize descriptor_pool_type_count = {};
14524 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14525 descriptor_pool_type_count.descriptorCount = 1;
14526
14527 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
14528 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
14529 descriptor_pool_create_info.maxSets = 1;
14530 descriptor_pool_create_info.poolSizeCount = 1;
14531 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
14532 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
14533
14534 VkDescriptorPool descriptorset_pool;
14535 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
14536
14537 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
14538 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
14539 descriptorset_layout_binding.descriptorCount = 1;
14540 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
14541 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070014542 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014543
14544 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
14545 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
14546 descriptorset_layout_create_info.bindingCount = 1;
14547 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
14548
14549 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014550 ASSERT_VK_SUCCESS(
14551 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060014552
14553 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
14554 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
14555 descriptorset_allocate_info.descriptorSetCount = 1;
14556 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
14557 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
14558 VkDescriptorSet descriptorset;
14559 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
14560
14561 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
14562
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014563 char const *vsSource =
14564 "#version 450\n"
14565 "\n"
14566 "layout (std140, set = 0, binding = 0) uniform buf {\n"
14567 " mat4 mvp;\n"
14568 "} ubuf;\n"
14569 "out gl_PerVertex {\n"
14570 " vec4 gl_Position;\n"
14571 "};\n"
14572 "void main(){\n"
14573 " gl_Position = ubuf.mvp * vec4(1);\n"
14574 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014575
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014576 char const *fsSource =
14577 "#version 450\n"
14578 "\n"
14579 "layout(location = 0) out vec4 uFragColor;\n"
14580 "void main(){\n"
14581 " uFragColor = vec4(0,1,0,1);\n"
14582 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014583
14584 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14585 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14586
14587 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14588 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14589 pipeline_layout_create_info.setLayoutCount = 1;
14590 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
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, descriptor_not_accessible_message);
14601 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14602 m_errorMonitor->VerifyFound();
14603
14604 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14605 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
14606 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
14607}
14608
14609TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014610 TEST_DESCRIPTION(
14611 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
14612 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014613
Tony Barbour1fa09702017-03-16 12:09:08 -060014614 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014615 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14616
14617 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014618 "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 -060014619
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014620 char const *vsSource =
14621 "#version 450\n"
14622 "\n"
14623 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14624 "out gl_PerVertex {\n"
14625 " vec4 gl_Position;\n"
14626 "};\n"
14627 "void main(){\n"
14628 " gl_Position = vec4(consts.x);\n"
14629 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014630
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014631 char const *fsSource =
14632 "#version 450\n"
14633 "\n"
14634 "layout(location = 0) out vec4 uFragColor;\n"
14635 "void main(){\n"
14636 " uFragColor = vec4(0,1,0,1);\n"
14637 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014638
14639 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14640 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14641
14642 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14643 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14644
14645 // Set up a push constant range
14646 VkPushConstantRange push_constant_ranges = {};
14647 // Set to the wrong stage to challenge core_validation
14648 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
14649 push_constant_ranges.size = 4;
14650
14651 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
14652 pipeline_layout_create_info.pushConstantRangeCount = 1;
14653
14654 VkPipelineLayout pipeline_layout;
14655 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14656
14657 VkPipelineObj pipe(m_device);
14658 pipe.AddColorAttachment();
14659 pipe.AddShader(&vs);
14660 pipe.AddShader(&fs);
14661
14662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
14663 pipe.CreateVKPipeline(pipeline_layout, renderPass());
14664 m_errorMonitor->VerifyFound();
14665
14666 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
14667}
14668
14669TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
14670 TEST_DESCRIPTION(
14671 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
14672
Tony Barbour1fa09702017-03-16 12:09:08 -060014673 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014674 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14675
14676 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014677 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014678
14679 // Some awkward steps are required to test with custom device features.
14680 std::vector<const char *> device_extension_names;
14681 auto features = m_device->phy().features();
14682 // Disable support for 64 bit floats
14683 features.shaderFloat64 = false;
14684 // The sacrificial device object
14685 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
14686
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014687 char const *vsSource =
14688 "#version 450\n"
14689 "\n"
14690 "out gl_PerVertex {\n"
14691 " vec4 gl_Position;\n"
14692 "};\n"
14693 "void main(){\n"
14694 " gl_Position = vec4(1);\n"
14695 "}\n";
14696 char const *fsSource =
14697 "#version 450\n"
14698 "\n"
14699 "layout(location=0) out vec4 color;\n"
14700 "void main(){\n"
14701 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
14702 " color = vec4(green);\n"
14703 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014704
14705 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14706 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14707
14708 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014709
14710 VkPipelineObj pipe(&test_device);
14711 pipe.AddColorAttachment();
14712 pipe.AddShader(&vs);
14713 pipe.AddShader(&fs);
14714
14715 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
14716 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
14717 VkPipelineLayout pipeline_layout;
14718 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
14719
14720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
14721 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
14722 m_errorMonitor->VerifyFound();
14723
14724 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
14725}
14726
Mark Lobodzinski20832822017-03-24 14:49:45 -060014727TEST_F(VkLayerTest, CreateShaderModuleCheckBadCapability) {
14728 TEST_DESCRIPTION("Create a shader in which a capability declared by the shader is not supported.");
14729 // Note that this failure message comes from spirv-tools, specifically the validator.
Mark Mueller098c9cb2016-09-08 09:01:57 -060014730
Tony Barbour1fa09702017-03-16 12:09:08 -060014731 ASSERT_NO_FATAL_FAILURE(Init());
Mark Mueller098c9cb2016-09-08 09:01:57 -060014732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14733
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014734 char const *vsSource =
14735 "#version 450\n"
14736 "\n"
14737 "out gl_PerVertex {\n"
14738 " vec4 gl_Position;\n"
14739 "};\n"
14740 "layout(xfb_buffer = 1) out;"
14741 "void main(){\n"
14742 " gl_Position = vec4(1);\n"
14743 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060014744
Mark Lobodzinski20832822017-03-24 14:49:45 -060014745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Capability value 53 is not allowed by Vulkan");
Mark Mueller098c9cb2016-09-08 09:01:57 -060014746
Mark Lobodzinski20832822017-03-24 14:49:45 -060014747 std::vector<unsigned int> spv;
14748 VkShaderModuleCreateInfo module_create_info;
14749 VkShaderModule shader_module;
14750 module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
14751 module_create_info.pNext = NULL;
14752 this->GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, vsSource, spv);
14753 module_create_info.pCode = spv.data();
14754 module_create_info.codeSize = spv.size() * sizeof(unsigned int);
14755 module_create_info.flags = 0;
Mark Mueller098c9cb2016-09-08 09:01:57 -060014756
Mark Lobodzinski20832822017-03-24 14:49:45 -060014757 vkCreateShaderModule(m_device->handle(), &module_create_info, NULL, &shader_module);
Mark Mueller098c9cb2016-09-08 09:01:57 -060014758
Mark Lobodzinski20832822017-03-24 14:49:45 -060014759 m_errorMonitor->VerifyFound();
Mark Mueller098c9cb2016-09-08 09:01:57 -060014760}
14761
Karl Schultz6addd812016-02-02 17:17:23 -070014762TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014763 TEST_DESCRIPTION(
14764 "Test that an error is produced for a fragment shader input "
14765 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120014766
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014768
Tony Barbour1fa09702017-03-16 12:09:08 -060014769 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014771
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014772 char const *vsSource =
14773 "#version 450\n"
14774 "\n"
14775 "out gl_PerVertex {\n"
14776 " vec4 gl_Position;\n"
14777 "};\n"
14778 "void main(){\n"
14779 " gl_Position = vec4(1);\n"
14780 "}\n";
14781 char const *fsSource =
14782 "#version 450\n"
14783 "\n"
14784 "layout(location=0) in float x;\n"
14785 "layout(location=0) out vec4 color;\n"
14786 "void main(){\n"
14787 " color = vec4(x);\n"
14788 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120014789
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014790 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14791 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014792
14793 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014794 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014795 pipe.AddShader(&vs);
14796 pipe.AddShader(&fs);
14797
Chris Forbes59cb88d2015-05-25 11:13:13 +120014798 VkDescriptorSetObj descriptorSet(m_device);
14799 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014800 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014801
Tony Barbour5781e8f2015-08-04 16:23:11 -060014802 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014803
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014804 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014805}
14806
Karl Schultz6addd812016-02-02 17:17:23 -070014807TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014808 TEST_DESCRIPTION(
14809 "Test that an error is produced for a fragment shader input "
14810 "within an interace block, which is not present in the outputs "
14811 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014813
Tony Barbour1fa09702017-03-16 12:09:08 -060014814 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014815 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14816
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014817 char const *vsSource =
14818 "#version 450\n"
14819 "\n"
14820 "out gl_PerVertex {\n"
14821 " vec4 gl_Position;\n"
14822 "};\n"
14823 "void main(){\n"
14824 " gl_Position = vec4(1);\n"
14825 "}\n";
14826 char const *fsSource =
14827 "#version 450\n"
14828 "\n"
14829 "in block { layout(location=0) float x; } ins;\n"
14830 "layout(location=0) out vec4 color;\n"
14831 "void main(){\n"
14832 " color = vec4(ins.x);\n"
14833 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014834
14835 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14836 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14837
14838 VkPipelineObj pipe(m_device);
14839 pipe.AddColorAttachment();
14840 pipe.AddShader(&vs);
14841 pipe.AddShader(&fs);
14842
14843 VkDescriptorSetObj descriptorSet(m_device);
14844 descriptorSet.AppendDummy();
14845 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14846
14847 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14848
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014849 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014850}
14851
Karl Schultz6addd812016-02-02 17:17:23 -070014852TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014853 TEST_DESCRIPTION(
14854 "Test that an error is produced for mismatched array sizes "
14855 "across the vertex->fragment shader interface");
14856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14857 "Type mismatch on location 0.0: 'ptr to "
14858 "output arr[2] of float32' vs 'ptr to "
14859 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130014860
Tony Barbour1fa09702017-03-16 12:09:08 -060014861 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes0036fd12016-01-26 14:19:49 +130014862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14863
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014864 char const *vsSource =
14865 "#version 450\n"
14866 "\n"
14867 "layout(location=0) out float x[2];\n"
14868 "out gl_PerVertex {\n"
14869 " vec4 gl_Position;\n"
14870 "};\n"
14871 "void main(){\n"
14872 " x[0] = 0; x[1] = 0;\n"
14873 " gl_Position = vec4(1);\n"
14874 "}\n";
14875 char const *fsSource =
14876 "#version 450\n"
14877 "\n"
14878 "layout(location=0) in float x[1];\n"
14879 "layout(location=0) out vec4 color;\n"
14880 "void main(){\n"
14881 " color = vec4(x[0]);\n"
14882 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014883
14884 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14885 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14886
14887 VkPipelineObj pipe(m_device);
14888 pipe.AddColorAttachment();
14889 pipe.AddShader(&vs);
14890 pipe.AddShader(&fs);
14891
14892 VkDescriptorSetObj descriptorSet(m_device);
14893 descriptorSet.AppendDummy();
14894 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14895
14896 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14897
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014898 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014899}
14900
Karl Schultz6addd812016-02-02 17:17:23 -070014901TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014902 TEST_DESCRIPTION(
14903 "Test that an error is produced for mismatched types across "
14904 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014906
Tony Barbour1fa09702017-03-16 12:09:08 -060014907 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014908 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014909
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014910 char const *vsSource =
14911 "#version 450\n"
14912 "\n"
14913 "layout(location=0) out int x;\n"
14914 "out gl_PerVertex {\n"
14915 " vec4 gl_Position;\n"
14916 "};\n"
14917 "void main(){\n"
14918 " x = 0;\n"
14919 " gl_Position = vec4(1);\n"
14920 "}\n";
14921 char const *fsSource =
14922 "#version 450\n"
14923 "\n"
14924 "layout(location=0) in float x;\n" /* VS writes int */
14925 "layout(location=0) out vec4 color;\n"
14926 "void main(){\n"
14927 " color = vec4(x);\n"
14928 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014929
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014930 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14931 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014932
14933 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014934 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014935 pipe.AddShader(&vs);
14936 pipe.AddShader(&fs);
14937
Chris Forbesb56af562015-05-25 11:13:17 +120014938 VkDescriptorSetObj descriptorSet(m_device);
14939 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014940 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014941
Tony Barbour5781e8f2015-08-04 16:23:11 -060014942 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014943
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014944 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014945}
14946
Karl Schultz6addd812016-02-02 17:17:23 -070014947TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014948 TEST_DESCRIPTION(
14949 "Test that an error is produced for mismatched types across "
14950 "the vertex->fragment shader interface, when the variable is contained within "
14951 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014953
Tony Barbour1fa09702017-03-16 12:09:08 -060014954 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa3e85f62016-01-15 14:53:11 +130014955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14956
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014957 char const *vsSource =
14958 "#version 450\n"
14959 "\n"
14960 "out block { layout(location=0) int x; } outs;\n"
14961 "out gl_PerVertex {\n"
14962 " vec4 gl_Position;\n"
14963 "};\n"
14964 "void main(){\n"
14965 " outs.x = 0;\n"
14966 " gl_Position = vec4(1);\n"
14967 "}\n";
14968 char const *fsSource =
14969 "#version 450\n"
14970 "\n"
14971 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14972 "layout(location=0) out vec4 color;\n"
14973 "void main(){\n"
14974 " color = vec4(ins.x);\n"
14975 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014976
14977 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14978 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14979
14980 VkPipelineObj pipe(m_device);
14981 pipe.AddColorAttachment();
14982 pipe.AddShader(&vs);
14983 pipe.AddShader(&fs);
14984
14985 VkDescriptorSetObj descriptorSet(m_device);
14986 descriptorSet.AppendDummy();
14987 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14988
14989 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14990
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014991 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014992}
14993
14994TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014995 TEST_DESCRIPTION(
14996 "Test that an error is produced for location mismatches across "
14997 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14998 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014999 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 +130015000
Tony Barbour1fa09702017-03-16 12:09:08 -060015001 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130015002 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15003
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015004 char const *vsSource =
15005 "#version 450\n"
15006 "\n"
15007 "out block { layout(location=1) float x; } outs;\n"
15008 "out gl_PerVertex {\n"
15009 " vec4 gl_Position;\n"
15010 "};\n"
15011 "void main(){\n"
15012 " outs.x = 0;\n"
15013 " gl_Position = vec4(1);\n"
15014 "}\n";
15015 char const *fsSource =
15016 "#version 450\n"
15017 "\n"
15018 "in block { layout(location=0) float x; } ins;\n"
15019 "layout(location=0) out vec4 color;\n"
15020 "void main(){\n"
15021 " color = vec4(ins.x);\n"
15022 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015023
15024 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15025 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15026
15027 VkPipelineObj pipe(m_device);
15028 pipe.AddColorAttachment();
15029 pipe.AddShader(&vs);
15030 pipe.AddShader(&fs);
15031
15032 VkDescriptorSetObj descriptorSet(m_device);
15033 descriptorSet.AppendDummy();
15034 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15035
15036 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15037
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015038 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130015039}
15040
15041TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015042 TEST_DESCRIPTION(
15043 "Test that an error is produced for component mismatches across the "
15044 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
15045 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015046 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 +130015047
Tony Barbour1fa09702017-03-16 12:09:08 -060015048 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbese9928822016-02-17 14:44:52 +130015049 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15050
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015051 char const *vsSource =
15052 "#version 450\n"
15053 "\n"
15054 "out block { layout(location=0, component=0) float x; } outs;\n"
15055 "out gl_PerVertex {\n"
15056 " vec4 gl_Position;\n"
15057 "};\n"
15058 "void main(){\n"
15059 " outs.x = 0;\n"
15060 " gl_Position = vec4(1);\n"
15061 "}\n";
15062 char const *fsSource =
15063 "#version 450\n"
15064 "\n"
15065 "in block { layout(location=0, component=1) float x; } ins;\n"
15066 "layout(location=0) out vec4 color;\n"
15067 "void main(){\n"
15068 " color = vec4(ins.x);\n"
15069 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130015070
15071 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15072 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15073
15074 VkPipelineObj pipe(m_device);
15075 pipe.AddColorAttachment();
15076 pipe.AddShader(&vs);
15077 pipe.AddShader(&fs);
15078
15079 VkDescriptorSetObj descriptorSet(m_device);
15080 descriptorSet.AppendDummy();
15081 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15082
15083 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15084
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015085 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130015086}
15087
Chris Forbes1f3b0152016-11-30 12:48:40 +130015088TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
15089 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15090
Tony Barbour1fa09702017-03-16 12:09:08 -060015091 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes1f3b0152016-11-30 12:48:40 +130015092 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15093
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015094 char const *vsSource =
15095 "#version 450\n"
15096 "layout(location=0) out mediump float x;\n"
15097 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15098 char const *fsSource =
15099 "#version 450\n"
15100 "layout(location=0) in highp float x;\n"
15101 "layout(location=0) out vec4 color;\n"
15102 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130015103
15104 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15105 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15106
15107 VkPipelineObj pipe(m_device);
15108 pipe.AddColorAttachment();
15109 pipe.AddShader(&vs);
15110 pipe.AddShader(&fs);
15111
15112 VkDescriptorSetObj descriptorSet(m_device);
15113 descriptorSet.AppendDummy();
15114 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15115
15116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15117
15118 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15119
15120 m_errorMonitor->VerifyFound();
15121}
15122
Chris Forbes870a39e2016-11-30 12:55:56 +130015123TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
15124 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
15125
Tony Barbour1fa09702017-03-16 12:09:08 -060015126 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes870a39e2016-11-30 12:55:56 +130015127 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15128
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015129 char const *vsSource =
15130 "#version 450\n"
15131 "out block { layout(location=0) mediump float x; };\n"
15132 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
15133 char const *fsSource =
15134 "#version 450\n"
15135 "in block { layout(location=0) highp float x; };\n"
15136 "layout(location=0) out vec4 color;\n"
15137 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130015138
15139 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15140 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15141
15142 VkPipelineObj pipe(m_device);
15143 pipe.AddColorAttachment();
15144 pipe.AddShader(&vs);
15145 pipe.AddShader(&fs);
15146
15147 VkDescriptorSetObj descriptorSet(m_device);
15148 descriptorSet.AppendDummy();
15149 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15150
15151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
15152
15153 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15154
15155 m_errorMonitor->VerifyFound();
15156}
15157
Karl Schultz6addd812016-02-02 17:17:23 -070015158TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015159 TEST_DESCRIPTION(
15160 "Test that a warning is produced for a vertex attribute which is "
15161 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015163
Tony Barbour1fa09702017-03-16 12:09:08 -060015164 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120015166
15167 VkVertexInputBindingDescription input_binding;
15168 memset(&input_binding, 0, sizeof(input_binding));
15169
15170 VkVertexInputAttributeDescription input_attrib;
15171 memset(&input_attrib, 0, sizeof(input_attrib));
15172 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15173
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015174 char const *vsSource =
15175 "#version 450\n"
15176 "\n"
15177 "out gl_PerVertex {\n"
15178 " vec4 gl_Position;\n"
15179 "};\n"
15180 "void main(){\n"
15181 " gl_Position = vec4(1);\n"
15182 "}\n";
15183 char const *fsSource =
15184 "#version 450\n"
15185 "\n"
15186 "layout(location=0) out vec4 color;\n"
15187 "void main(){\n"
15188 " color = vec4(1);\n"
15189 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120015190
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015191 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15192 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120015193
15194 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015195 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120015196 pipe.AddShader(&vs);
15197 pipe.AddShader(&fs);
15198
15199 pipe.AddVertexInputBindings(&input_binding, 1);
15200 pipe.AddVertexInputAttribs(&input_attrib, 1);
15201
Chris Forbesde136e02015-05-25 11:13:28 +120015202 VkDescriptorSetObj descriptorSet(m_device);
15203 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015204 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120015205
Tony Barbour5781e8f2015-08-04 16:23:11 -060015206 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120015207
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015208 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120015209}
15210
Karl Schultz6addd812016-02-02 17:17:23 -070015211TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015212 TEST_DESCRIPTION(
15213 "Test that a warning is produced for a location mismatch on "
15214 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015216
Tony Barbour1fa09702017-03-16 12:09:08 -060015217 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes7d83cd52016-01-15 11:32:03 +130015218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15219
15220 VkVertexInputBindingDescription input_binding;
15221 memset(&input_binding, 0, sizeof(input_binding));
15222
15223 VkVertexInputAttributeDescription input_attrib;
15224 memset(&input_attrib, 0, sizeof(input_attrib));
15225 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15226
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015227 char const *vsSource =
15228 "#version 450\n"
15229 "\n"
15230 "layout(location=1) in float x;\n"
15231 "out gl_PerVertex {\n"
15232 " vec4 gl_Position;\n"
15233 "};\n"
15234 "void main(){\n"
15235 " gl_Position = vec4(x);\n"
15236 "}\n";
15237 char const *fsSource =
15238 "#version 450\n"
15239 "\n"
15240 "layout(location=0) out vec4 color;\n"
15241 "void main(){\n"
15242 " color = vec4(1);\n"
15243 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130015244
15245 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15246 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15247
15248 VkPipelineObj pipe(m_device);
15249 pipe.AddColorAttachment();
15250 pipe.AddShader(&vs);
15251 pipe.AddShader(&fs);
15252
15253 pipe.AddVertexInputBindings(&input_binding, 1);
15254 pipe.AddVertexInputAttribs(&input_attrib, 1);
15255
15256 VkDescriptorSetObj descriptorSet(m_device);
15257 descriptorSet.AppendDummy();
15258 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15259
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015260 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130015261 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15262
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015263 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130015264}
15265
Karl Schultz6addd812016-02-02 17:17:23 -070015266TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015267 TEST_DESCRIPTION(
15268 "Test that an error is produced for a vertex shader input which is not "
15269 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15271 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015272
Tony Barbour1fa09702017-03-16 12:09:08 -060015273 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015274 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120015275
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015276 char const *vsSource =
15277 "#version 450\n"
15278 "\n"
15279 "layout(location=0) in vec4 x;\n" /* not provided */
15280 "out gl_PerVertex {\n"
15281 " vec4 gl_Position;\n"
15282 "};\n"
15283 "void main(){\n"
15284 " gl_Position = x;\n"
15285 "}\n";
15286 char const *fsSource =
15287 "#version 450\n"
15288 "\n"
15289 "layout(location=0) out vec4 color;\n"
15290 "void main(){\n"
15291 " color = vec4(1);\n"
15292 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120015293
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015294 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15295 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120015296
15297 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015298 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120015299 pipe.AddShader(&vs);
15300 pipe.AddShader(&fs);
15301
Chris Forbes62e8e502015-05-25 11:13:29 +120015302 VkDescriptorSetObj descriptorSet(m_device);
15303 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015304 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120015305
Tony Barbour5781e8f2015-08-04 16:23:11 -060015306 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120015307
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015308 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120015309}
15310
Karl Schultz6addd812016-02-02 17:17:23 -070015311TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015312 TEST_DESCRIPTION(
15313 "Test that an error is produced for a mismatch between the "
15314 "fundamental type (float/int/uint) of an attribute and the "
15315 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060015316 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 -060015317
Tony Barbour1fa09702017-03-16 12:09:08 -060015318 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015320
15321 VkVertexInputBindingDescription input_binding;
15322 memset(&input_binding, 0, sizeof(input_binding));
15323
15324 VkVertexInputAttributeDescription input_attrib;
15325 memset(&input_attrib, 0, sizeof(input_attrib));
15326 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15327
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015328 char const *vsSource =
15329 "#version 450\n"
15330 "\n"
15331 "layout(location=0) in int x;\n" /* attrib provided float */
15332 "out gl_PerVertex {\n"
15333 " vec4 gl_Position;\n"
15334 "};\n"
15335 "void main(){\n"
15336 " gl_Position = vec4(x);\n"
15337 "}\n";
15338 char const *fsSource =
15339 "#version 450\n"
15340 "\n"
15341 "layout(location=0) out vec4 color;\n"
15342 "void main(){\n"
15343 " color = vec4(1);\n"
15344 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120015345
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015346 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15347 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015348
15349 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015350 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015351 pipe.AddShader(&vs);
15352 pipe.AddShader(&fs);
15353
15354 pipe.AddVertexInputBindings(&input_binding, 1);
15355 pipe.AddVertexInputAttribs(&input_attrib, 1);
15356
Chris Forbesc97d98e2015-05-25 11:13:31 +120015357 VkDescriptorSetObj descriptorSet(m_device);
15358 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015359 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120015360
Tony Barbour5781e8f2015-08-04 16:23:11 -060015361 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120015362
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015363 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120015364}
15365
Chris Forbesc68b43c2016-04-06 11:18:47 +120015366TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015367 TEST_DESCRIPTION(
15368 "Test that an error is produced for a pipeline containing multiple "
15369 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15371 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120015372
Tony Barbour1fa09702017-03-16 12:09:08 -060015373 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesc68b43c2016-04-06 11:18:47 +120015374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15375
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015376 char const *vsSource =
15377 "#version 450\n"
15378 "\n"
15379 "out gl_PerVertex {\n"
15380 " vec4 gl_Position;\n"
15381 "};\n"
15382 "void main(){\n"
15383 " gl_Position = vec4(1);\n"
15384 "}\n";
15385 char const *fsSource =
15386 "#version 450\n"
15387 "\n"
15388 "layout(location=0) out vec4 color;\n"
15389 "void main(){\n"
15390 " color = vec4(1);\n"
15391 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120015392
15393 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15394 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15395
15396 VkPipelineObj pipe(m_device);
15397 pipe.AddColorAttachment();
15398 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015399 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120015400 pipe.AddShader(&fs);
15401
15402 VkDescriptorSetObj descriptorSet(m_device);
15403 descriptorSet.AppendDummy();
15404 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15405
15406 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15407
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015408 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120015409}
15410
Chris Forbes82ff92a2016-09-09 10:50:24 +120015411TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120015413
Tony Barbour1fa09702017-03-16 12:09:08 -060015414 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes82ff92a2016-09-09 10:50:24 +120015415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15416
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015417 char const *vsSource =
15418 "#version 450\n"
15419 "out gl_PerVertex {\n"
15420 " vec4 gl_Position;\n"
15421 "};\n"
15422 "void main(){\n"
15423 " gl_Position = vec4(0);\n"
15424 "}\n";
15425 char const *fsSource =
15426 "#version 450\n"
15427 "\n"
15428 "layout(location=0) out vec4 color;\n"
15429 "void main(){\n"
15430 " color = vec4(1);\n"
15431 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120015432
15433 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15434 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
15435
15436 VkPipelineObj pipe(m_device);
15437 pipe.AddColorAttachment();
15438 pipe.AddShader(&vs);
15439 pipe.AddShader(&fs);
15440
15441 VkDescriptorSetObj descriptorSet(m_device);
15442 descriptorSet.AppendDummy();
15443 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15444
15445 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15446
15447 m_errorMonitor->VerifyFound();
15448}
15449
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015450TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15452 "pDepthStencilState is NULL when rasterization is enabled and subpass "
15453 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015454
Tony Barbour1fa09702017-03-16 12:09:08 -060015455 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15457
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015458 char const *vsSource =
15459 "#version 450\n"
15460 "void main(){ gl_Position = vec4(0); }\n";
15461 char const *fsSource =
15462 "#version 450\n"
15463 "\n"
15464 "layout(location=0) out vec4 color;\n"
15465 "void main(){\n"
15466 " color = vec4(1);\n"
15467 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015468
15469 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15470 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15471
15472 VkPipelineObj pipe(m_device);
15473 pipe.AddColorAttachment();
15474 pipe.AddShader(&vs);
15475 pipe.AddShader(&fs);
15476
15477 VkDescriptorSetObj descriptorSet(m_device);
15478 descriptorSet.AppendDummy();
15479 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15480
15481 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015482 {
15483 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15484 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15485 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015486 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015487 {
15488 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
15489 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
15490 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015491 },
15492 };
15493 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015494 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015495 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015496 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
15497 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120015498 VkRenderPass rp;
15499 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15500 ASSERT_VK_SUCCESS(err);
15501
15502 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
15503
15504 m_errorMonitor->VerifyFound();
15505
15506 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15507}
15508
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015509TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015510 TEST_DESCRIPTION(
15511 "Test that an error is produced for a variable output from "
15512 "the TCS without the patch decoration, but consumed in the TES "
15513 "with the decoration.");
15514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15515 "is per-vertex in tessellation control shader stage "
15516 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120015517
Tony Barbour1fa09702017-03-16 12:09:08 -060015518 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa0193bc2016-04-04 19:19:47 +120015519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15520
Chris Forbesc1e852d2016-04-04 19:26:42 +120015521 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070015522 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120015523 return;
15524 }
15525
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015526 char const *vsSource =
15527 "#version 450\n"
15528 "void main(){}\n";
15529 char const *tcsSource =
15530 "#version 450\n"
15531 "layout(location=0) out int x[];\n"
15532 "layout(vertices=3) out;\n"
15533 "void main(){\n"
15534 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15535 " gl_TessLevelInner[0] = 1;\n"
15536 " x[gl_InvocationID] = gl_InvocationID;\n"
15537 "}\n";
15538 char const *tesSource =
15539 "#version 450\n"
15540 "layout(triangles, equal_spacing, cw) in;\n"
15541 "layout(location=0) patch in int x;\n"
15542 "out gl_PerVertex { vec4 gl_Position; };\n"
15543 "void main(){\n"
15544 " gl_Position.xyz = gl_TessCoord;\n"
15545 " gl_Position.w = x;\n"
15546 "}\n";
15547 char const *fsSource =
15548 "#version 450\n"
15549 "layout(location=0) out vec4 color;\n"
15550 "void main(){\n"
15551 " color = vec4(1);\n"
15552 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120015553
15554 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15555 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15556 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15557 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15558
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015559 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15560 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015561
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015562 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120015563
15564 VkPipelineObj pipe(m_device);
15565 pipe.SetInputAssembly(&iasci);
15566 pipe.SetTessellation(&tsci);
15567 pipe.AddColorAttachment();
15568 pipe.AddShader(&vs);
15569 pipe.AddShader(&tcs);
15570 pipe.AddShader(&tes);
15571 pipe.AddShader(&fs);
15572
15573 VkDescriptorSetObj descriptorSet(m_device);
15574 descriptorSet.AppendDummy();
15575 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15576
15577 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15578
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015579 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120015580}
15581
Cort Stratton2bcca1b2017-05-05 16:02:35 -070015582TEST_F(VkLayerTest, CreatePipelineTessErrors) {
15583 TEST_DESCRIPTION("Test various errors when creating a graphics pipeline with tessellation stages active.");
15584
15585 ASSERT_NO_FATAL_FAILURE(Init());
15586 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15587
15588 if (!m_device->phy().features().tessellationShader) {
15589 printf(" Device does not support tessellation shaders; skipped.\n");
15590 return;
15591 }
15592
15593 char const *vsSource =
15594 "#version 450\n"
15595 "void main(){}\n";
15596 char const *tcsSource =
15597 "#version 450\n"
15598 "layout(vertices=3) out;\n"
15599 "void main(){\n"
15600 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
15601 " gl_TessLevelInner[0] = 1;\n"
15602 "}\n";
15603 char const *tesSource =
15604 "#version 450\n"
15605 "layout(triangles, equal_spacing, cw) in;\n"
15606 "out gl_PerVertex { vec4 gl_Position; };\n"
15607 "void main(){\n"
15608 " gl_Position.xyz = gl_TessCoord;\n"
15609 " gl_Position.w = 0;\n"
15610 "}\n";
15611 char const *fsSource =
15612 "#version 450\n"
15613 "layout(location=0) out vec4 color;\n"
15614 "void main(){\n"
15615 " color = vec4(1);\n"
15616 "}\n";
15617
15618 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15619 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
15620 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
15621 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15622
15623 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
15624 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
15625
15626 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
15627
15628 VkDescriptorSetObj descriptorSet(m_device);
15629 descriptorSet.AppendDummy();
15630 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15631
15632 {
15633 VkPipelineObj pipe(m_device);
15634 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15635 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15636 pipe.SetInputAssembly(&iasci_bad);
15637 pipe.AddColorAttachment();
15638 pipe.AddShader(&vs);
15639 pipe.AddShader(&fs);
15640
15641 // Pass a tess control shader without a tess eval shader
15642 pipe.AddShader(&tcs);
15643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00534);
15644 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15645 m_errorMonitor->VerifyFound();
15646 }
15647
15648 {
15649 VkPipelineObj pipe(m_device);
15650 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15651 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; // otherwise we get a failure about invalid topology
15652 pipe.SetInputAssembly(&iasci_bad);
15653 pipe.AddColorAttachment();
15654 pipe.AddShader(&vs);
15655 pipe.AddShader(&fs);
15656
15657 // Pass a tess eval shader without a tess control shader
15658 pipe.AddShader(&tes);
15659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00535);
15660 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15661 m_errorMonitor->VerifyFound();
15662 }
15663
15664 {
15665 VkPipelineObj pipe(m_device);
15666 pipe.SetInputAssembly(&iasci);
15667 pipe.AddColorAttachment();
15668 pipe.AddShader(&vs);
15669 pipe.AddShader(&fs);
15670
15671 // Pass patch topology without tessellation shaders
15672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02100);
15673 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15674 m_errorMonitor->VerifyFound();
15675
15676 pipe.AddShader(&tcs);
15677 pipe.AddShader(&tes);
15678 // Pass a NULL pTessellationState (with active tessellation shader stages)
15679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00536);
15680 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15681 m_errorMonitor->VerifyFound();
15682
15683 // Pass an invalid pTessellationState (bad sType)
15684 VkPipelineTessellationStateCreateInfo tsci_bad = tsci;
15685 tsci_bad.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
15686 pipe.SetTessellation(&tsci_bad);
15687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01427);
15688 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15689 m_errorMonitor->VerifyFound();
15690 // Pass out-of-range patchControlPoints
15691 tsci_bad = tsci;
15692 tsci_bad.patchControlPoints = 0;
15693 pipe.SetTessellation(&tsci);
15694 pipe.SetTessellation(&tsci_bad);
15695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15696 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15697 m_errorMonitor->VerifyFound();
15698 tsci_bad.patchControlPoints = m_device->props.limits.maxTessellationPatchSize + 1;
15699 pipe.SetTessellation(&tsci_bad);
15700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01426);
15701 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15702 m_errorMonitor->VerifyFound();
15703 pipe.SetTessellation(&tsci);
15704
15705 // Pass an invalid primitive topology
15706 VkPipelineInputAssemblyStateCreateInfo iasci_bad = iasci;
15707 iasci_bad.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
15708 pipe.SetInputAssembly(&iasci_bad);
15709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02099);
15710 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15711 m_errorMonitor->VerifyFound();
15712 pipe.SetInputAssembly(&iasci);
15713 }
15714}
15715
Karl Schultz6addd812016-02-02 17:17:23 -070015716TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015717 TEST_DESCRIPTION(
15718 "Test that an error is produced for a vertex attribute setup where multiple "
15719 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15721 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015722
Tony Barbour1fa09702017-03-16 12:09:08 -060015723 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060015724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015725
15726 /* Two binding descriptions for binding 0 */
15727 VkVertexInputBindingDescription input_bindings[2];
15728 memset(input_bindings, 0, sizeof(input_bindings));
15729
15730 VkVertexInputAttributeDescription input_attrib;
15731 memset(&input_attrib, 0, sizeof(input_attrib));
15732 input_attrib.format = VK_FORMAT_R32_SFLOAT;
15733
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015734 char const *vsSource =
15735 "#version 450\n"
15736 "\n"
15737 "layout(location=0) in float x;\n" /* attrib provided float */
15738 "out gl_PerVertex {\n"
15739 " vec4 gl_Position;\n"
15740 "};\n"
15741 "void main(){\n"
15742 " gl_Position = vec4(x);\n"
15743 "}\n";
15744 char const *fsSource =
15745 "#version 450\n"
15746 "\n"
15747 "layout(location=0) out vec4 color;\n"
15748 "void main(){\n"
15749 " color = vec4(1);\n"
15750 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120015751
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015752 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15753 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015754
15755 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080015756 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015757 pipe.AddShader(&vs);
15758 pipe.AddShader(&fs);
15759
15760 pipe.AddVertexInputBindings(input_bindings, 2);
15761 pipe.AddVertexInputAttribs(&input_attrib, 1);
15762
Chris Forbes280ba2c2015-06-12 11:16:41 +120015763 VkDescriptorSetObj descriptorSet(m_device);
15764 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015765 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120015766
Tony Barbour5781e8f2015-08-04 16:23:11 -060015767 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120015768
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015769 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120015770}
Chris Forbes8f68b562015-05-25 11:13:32 +120015771
Karl Schultz6addd812016-02-02 17:17:23 -070015772TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015773 TEST_DESCRIPTION(
15774 "Test that an error is produced for a fragment shader which does not "
15775 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015777
Tony Barbour1fa09702017-03-16 12:09:08 -060015778 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015779
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015780 char const *vsSource =
15781 "#version 450\n"
15782 "\n"
15783 "out gl_PerVertex {\n"
15784 " vec4 gl_Position;\n"
15785 "};\n"
15786 "void main(){\n"
15787 " gl_Position = vec4(1);\n"
15788 "}\n";
15789 char const *fsSource =
15790 "#version 450\n"
15791 "\n"
15792 "void main(){\n"
15793 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015794
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015795 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15796 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015797
15798 VkPipelineObj pipe(m_device);
15799 pipe.AddShader(&vs);
15800 pipe.AddShader(&fs);
15801
Chia-I Wu08accc62015-07-07 11:50:03 +080015802 /* set up CB 0, not written */
15803 pipe.AddColorAttachment();
15804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015805
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015806 VkDescriptorSetObj descriptorSet(m_device);
15807 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015808 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015809
Tony Barbour5781e8f2015-08-04 16:23:11 -060015810 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015811
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015812 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120015813}
15814
Karl Schultz6addd812016-02-02 17:17:23 -070015815TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015816 TEST_DESCRIPTION(
15817 "Test that a warning is produced for a fragment shader which provides a spurious "
15818 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060015820 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015821
Tony Barbour1fa09702017-03-16 12:09:08 -060015822 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015823
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015824 char const *vsSource =
15825 "#version 450\n"
15826 "\n"
15827 "out gl_PerVertex {\n"
15828 " vec4 gl_Position;\n"
15829 "};\n"
15830 "void main(){\n"
15831 " gl_Position = vec4(1);\n"
15832 "}\n";
15833 char const *fsSource =
15834 "#version 450\n"
15835 "\n"
15836 "layout(location=0) out vec4 x;\n"
15837 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
15838 "void main(){\n"
15839 " x = vec4(1);\n"
15840 " y = vec4(1);\n"
15841 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015842
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015843 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15844 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015845
15846 VkPipelineObj pipe(m_device);
15847 pipe.AddShader(&vs);
15848 pipe.AddShader(&fs);
15849
Chia-I Wu08accc62015-07-07 11:50:03 +080015850 /* set up CB 0, not written */
15851 pipe.AddColorAttachment();
15852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015853 /* FS writes CB 1, but we don't configure it */
15854
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015855 VkDescriptorSetObj descriptorSet(m_device);
15856 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015857 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015858
Tony Barbour5781e8f2015-08-04 16:23:11 -060015859 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015860
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015861 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120015862}
15863
Karl Schultz6addd812016-02-02 17:17:23 -070015864TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015865 TEST_DESCRIPTION(
15866 "Test that an error is produced for a mismatch between the fundamental "
15867 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060015868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015869
Tony Barbour1fa09702017-03-16 12:09:08 -060015870 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015871
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015872 char const *vsSource =
15873 "#version 450\n"
15874 "\n"
15875 "out gl_PerVertex {\n"
15876 " vec4 gl_Position;\n"
15877 "};\n"
15878 "void main(){\n"
15879 " gl_Position = vec4(1);\n"
15880 "}\n";
15881 char const *fsSource =
15882 "#version 450\n"
15883 "\n"
15884 "layout(location=0) out ivec4 x;\n" /* not UNORM */
15885 "void main(){\n"
15886 " x = ivec4(1);\n"
15887 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120015888
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015889 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15890 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015891
15892 VkPipelineObj pipe(m_device);
15893 pipe.AddShader(&vs);
15894 pipe.AddShader(&fs);
15895
Chia-I Wu08accc62015-07-07 11:50:03 +080015896 /* set up CB 0; type is UNORM by default */
15897 pipe.AddColorAttachment();
15898 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015899
Chris Forbesa36d69e2015-05-25 11:13:44 +120015900 VkDescriptorSetObj descriptorSet(m_device);
15901 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015902 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120015903
Tony Barbour5781e8f2015-08-04 16:23:11 -060015904 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015905
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015906 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120015907}
Chris Forbes7b1b8932015-06-05 14:43:36 +120015908
Karl Schultz6addd812016-02-02 17:17:23 -070015909TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015910 TEST_DESCRIPTION(
15911 "Test that an error is produced for a shader consuming a uniform "
15912 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015914
Tony Barbour1fa09702017-03-16 12:09:08 -060015915 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes556c76c2015-08-14 12:04:59 +120015916
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015917 char const *vsSource =
15918 "#version 450\n"
15919 "\n"
15920 "out gl_PerVertex {\n"
15921 " vec4 gl_Position;\n"
15922 "};\n"
15923 "void main(){\n"
15924 " gl_Position = vec4(1);\n"
15925 "}\n";
15926 char const *fsSource =
15927 "#version 450\n"
15928 "\n"
15929 "layout(location=0) out vec4 x;\n"
15930 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
15931 "void main(){\n"
15932 " x = vec4(bar.y);\n"
15933 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120015934
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015935 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15936 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120015937
Chris Forbes556c76c2015-08-14 12:04:59 +120015938 VkPipelineObj pipe(m_device);
15939 pipe.AddShader(&vs);
15940 pipe.AddShader(&fs);
15941
15942 /* set up CB 0; type is UNORM by default */
15943 pipe.AddColorAttachment();
15944 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15945
15946 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015947 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120015948
15949 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15950
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015951 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120015952}
15953
Chris Forbes5c59e902016-02-26 16:56:09 +130015954TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015955 TEST_DESCRIPTION(
15956 "Test that an error is produced for a shader consuming push constants "
15957 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130015959
Tony Barbour1fa09702017-03-16 12:09:08 -060015960 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5c59e902016-02-26 16:56:09 +130015961
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015962 char const *vsSource =
15963 "#version 450\n"
15964 "\n"
15965 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
15966 "out gl_PerVertex {\n"
15967 " vec4 gl_Position;\n"
15968 "};\n"
15969 "void main(){\n"
15970 " gl_Position = vec4(consts.x);\n"
15971 "}\n";
15972 char const *fsSource =
15973 "#version 450\n"
15974 "\n"
15975 "layout(location=0) out vec4 x;\n"
15976 "void main(){\n"
15977 " x = vec4(1);\n"
15978 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130015979
15980 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15981 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15982
15983 VkPipelineObj pipe(m_device);
15984 pipe.AddShader(&vs);
15985 pipe.AddShader(&fs);
15986
15987 /* set up CB 0; type is UNORM by default */
15988 pipe.AddColorAttachment();
15989 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15990
15991 VkDescriptorSetObj descriptorSet(m_device);
15992 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15993
15994 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15995
15996 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015997 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015998}
15999
Chris Forbes3fb17902016-08-22 14:57:55 +120016000TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016001 TEST_DESCRIPTION(
16002 "Test that an error is produced for a shader consuming an input attachment "
16003 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120016004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16005 "consumes input attachment index 0 but not provided in subpass");
16006
Tony Barbour1fa09702017-03-16 12:09:08 -060016007 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes3fb17902016-08-22 14:57:55 +120016008
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016009 char const *vsSource =
16010 "#version 450\n"
16011 "\n"
16012 "out gl_PerVertex {\n"
16013 " vec4 gl_Position;\n"
16014 "};\n"
16015 "void main(){\n"
16016 " gl_Position = vec4(1);\n"
16017 "}\n";
16018 char const *fsSource =
16019 "#version 450\n"
16020 "\n"
16021 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16022 "layout(location=0) out vec4 color;\n"
16023 "void main() {\n"
16024 " color = subpassLoad(x);\n"
16025 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120016026
16027 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16028 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16029
16030 VkPipelineObj pipe(m_device);
16031 pipe.AddShader(&vs);
16032 pipe.AddShader(&fs);
16033 pipe.AddColorAttachment();
16034 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016036 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16037 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120016038 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016039 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120016040 ASSERT_VK_SUCCESS(err);
16041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016042 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120016043 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016044 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120016045 ASSERT_VK_SUCCESS(err);
16046
16047 // error here.
16048 pipe.CreateVKPipeline(pl, renderPass());
16049
16050 m_errorMonitor->VerifyFound();
16051
16052 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16053 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16054}
16055
Chris Forbes5a9a0472016-08-22 16:02:09 +120016056TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016057 TEST_DESCRIPTION(
16058 "Test that an error is produced for a shader consuming an input attachment "
16059 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120016060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16061 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
16062
Tony Barbour1fa09702017-03-16 12:09:08 -060016063 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5a9a0472016-08-22 16:02:09 +120016064
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016065 char const *vsSource =
16066 "#version 450\n"
16067 "\n"
16068 "out gl_PerVertex {\n"
16069 " vec4 gl_Position;\n"
16070 "};\n"
16071 "void main(){\n"
16072 " gl_Position = vec4(1);\n"
16073 "}\n";
16074 char const *fsSource =
16075 "#version 450\n"
16076 "\n"
16077 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
16078 "layout(location=0) out vec4 color;\n"
16079 "void main() {\n"
16080 " color = subpassLoad(x);\n"
16081 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120016082
16083 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16084 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16085
16086 VkPipelineObj pipe(m_device);
16087 pipe.AddShader(&vs);
16088 pipe.AddShader(&fs);
16089 pipe.AddColorAttachment();
16090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016092 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16093 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016094 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016095 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016096 ASSERT_VK_SUCCESS(err);
16097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016098 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016099 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016100 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120016101 ASSERT_VK_SUCCESS(err);
16102
16103 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016104 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16105 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16106 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
16107 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
16108 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 +120016109 };
16110 VkAttachmentReference color = {
16111 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
16112 };
16113 VkAttachmentReference input = {
16114 1, VK_IMAGE_LAYOUT_GENERAL,
16115 };
16116
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016117 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016119 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120016120 VkRenderPass rp;
16121 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
16122 ASSERT_VK_SUCCESS(err);
16123
16124 // error here.
16125 pipe.CreateVKPipeline(pl, rp);
16126
16127 m_errorMonitor->VerifyFound();
16128
16129 vkDestroyRenderPass(m_device->device(), rp, nullptr);
16130 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16131 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16132}
16133
Chris Forbes541f7b02016-08-22 15:30:27 +120016134TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016135 TEST_DESCRIPTION(
16136 "Test that an error is produced for a shader consuming an input attachment "
16137 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120016138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070016139 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120016140
Tony Barbour1fa09702017-03-16 12:09:08 -060016141 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes541f7b02016-08-22 15:30:27 +120016142
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016143 char const *vsSource =
16144 "#version 450\n"
16145 "\n"
16146 "out gl_PerVertex {\n"
16147 " vec4 gl_Position;\n"
16148 "};\n"
16149 "void main(){\n"
16150 " gl_Position = vec4(1);\n"
16151 "}\n";
16152 char const *fsSource =
16153 "#version 450\n"
16154 "\n"
16155 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
16156 "layout(location=0) out vec4 color;\n"
16157 "void main() {\n"
16158 " color = subpassLoad(xs[0]);\n"
16159 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120016160
16161 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16162 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16163
16164 VkPipelineObj pipe(m_device);
16165 pipe.AddShader(&vs);
16166 pipe.AddShader(&fs);
16167 pipe.AddColorAttachment();
16168 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16169
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016170 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
16171 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120016172 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016173 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016174 ASSERT_VK_SUCCESS(err);
16175
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016176 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120016177 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016178 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120016179 ASSERT_VK_SUCCESS(err);
16180
16181 // error here.
16182 pipe.CreateVKPipeline(pl, renderPass());
16183
16184 m_errorMonitor->VerifyFound();
16185
16186 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16187 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16188}
16189
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016190TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016191 TEST_DESCRIPTION(
16192 "Test that an error is produced for a compute pipeline consuming a "
16193 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016195
Tony Barbour1fa09702017-03-16 12:09:08 -060016196 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016197
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016198 char const *csSource =
16199 "#version 450\n"
16200 "\n"
16201 "layout(local_size_x=1) in;\n"
16202 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16203 "void main(){\n"
16204 " x = vec4(1);\n"
16205 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016206
16207 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16208
16209 VkDescriptorSetObj descriptorSet(m_device);
16210 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016212 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16213 nullptr,
16214 0,
16215 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16216 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16217 descriptorSet.GetPipelineLayout(),
16218 VK_NULL_HANDLE,
16219 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016220
16221 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016222 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120016223
16224 m_errorMonitor->VerifyFound();
16225
16226 if (err == VK_SUCCESS) {
16227 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16228 }
16229}
16230
Chris Forbes22a9b092016-07-19 14:34:05 +120016231TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016232 TEST_DESCRIPTION(
16233 "Test that an error is produced for a pipeline consuming a "
16234 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16236 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120016237
Tony Barbour1fa09702017-03-16 12:09:08 -060016238 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes22a9b092016-07-19 14:34:05 +120016239
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016240 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
16241 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120016242 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016243 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016244 ASSERT_VK_SUCCESS(err);
16245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016246 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120016247 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016248 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120016249 ASSERT_VK_SUCCESS(err);
16250
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016251 char const *csSource =
16252 "#version 450\n"
16253 "\n"
16254 "layout(local_size_x=1) in;\n"
16255 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
16256 "void main() {\n"
16257 " x.x = 1.0f;\n"
16258 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120016259 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
16260
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016261 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
16262 nullptr,
16263 0,
16264 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
16265 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
16266 pl,
16267 VK_NULL_HANDLE,
16268 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120016269
16270 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016271 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120016272
16273 m_errorMonitor->VerifyFound();
16274
16275 if (err == VK_SUCCESS) {
16276 vkDestroyPipeline(m_device->device(), pipe, nullptr);
16277 }
16278
16279 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
16280 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
16281}
16282
Chris Forbes50020592016-07-27 13:52:41 +120016283TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016284 TEST_DESCRIPTION(
16285 "Test that an error is produced when an image view type "
16286 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120016287
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016288 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 +120016289
Tony Barbour1fa09702017-03-16 12:09:08 -060016290 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes50020592016-07-27 13:52:41 +120016291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16292
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016293 char const *vsSource =
16294 "#version 450\n"
16295 "\n"
16296 "out gl_PerVertex { vec4 gl_Position; };\n"
16297 "void main() { gl_Position = vec4(0); }\n";
16298 char const *fsSource =
16299 "#version 450\n"
16300 "\n"
16301 "layout(set=0, binding=0) uniform sampler3D s;\n"
16302 "layout(location=0) out vec4 color;\n"
16303 "void main() {\n"
16304 " color = texture(s, vec3(0));\n"
16305 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120016306 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16307 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16308
16309 VkPipelineObj pipe(m_device);
16310 pipe.AddShader(&vs);
16311 pipe.AddShader(&fs);
16312 pipe.AddColorAttachment();
16313
16314 VkTextureObj texture(m_device, nullptr);
16315 VkSamplerObj sampler(m_device);
16316
16317 VkDescriptorSetObj descriptorSet(m_device);
16318 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16319 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16320
16321 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16322 ASSERT_VK_SUCCESS(err);
16323
Tony Barbour552f6c02016-12-21 14:34:07 -070016324 m_commandBuffer->BeginCommandBuffer();
16325 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120016326
16327 m_commandBuffer->BindPipeline(pipe);
16328 m_commandBuffer->BindDescriptorSet(descriptorSet);
16329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016330 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120016331 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016332 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120016333 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16334
16335 // error produced here.
16336 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16337
16338 m_errorMonitor->VerifyFound();
16339
Tony Barbour552f6c02016-12-21 14:34:07 -070016340 m_commandBuffer->EndRenderPass();
16341 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120016342}
16343
Chris Forbes5533bfc2016-07-27 14:12:34 +120016344TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016345 TEST_DESCRIPTION(
16346 "Test that an error is produced when a multisampled images "
16347 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016348
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120016350
Tony Barbour1fa09702017-03-16 12:09:08 -060016351 ASSERT_NO_FATAL_FAILURE(Init());
Chris Forbes5533bfc2016-07-27 14:12:34 +120016352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16353
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016354 char const *vsSource =
16355 "#version 450\n"
16356 "\n"
16357 "out gl_PerVertex { vec4 gl_Position; };\n"
16358 "void main() { gl_Position = vec4(0); }\n";
16359 char const *fsSource =
16360 "#version 450\n"
16361 "\n"
16362 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
16363 "layout(location=0) out vec4 color;\n"
16364 "void main() {\n"
16365 " color = texelFetch(s, ivec2(0), 0);\n"
16366 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120016367 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
16368 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
16369
16370 VkPipelineObj pipe(m_device);
16371 pipe.AddShader(&vs);
16372 pipe.AddShader(&fs);
16373 pipe.AddColorAttachment();
16374
16375 VkTextureObj texture(m_device, nullptr);
16376 VkSamplerObj sampler(m_device);
16377
16378 VkDescriptorSetObj descriptorSet(m_device);
16379 descriptorSet.AppendSamplerTexture(&sampler, &texture);
16380 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
16381
16382 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
16383 ASSERT_VK_SUCCESS(err);
16384
Tony Barbour552f6c02016-12-21 14:34:07 -070016385 m_commandBuffer->BeginCommandBuffer();
16386 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120016387
16388 m_commandBuffer->BindPipeline(pipe);
16389 m_commandBuffer->BindDescriptorSet(descriptorSet);
16390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016391 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016392 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016393 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120016394 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16395
16396 // error produced here.
16397 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
16398
16399 m_errorMonitor->VerifyFound();
16400
Tony Barbour552f6c02016-12-21 14:34:07 -070016401 m_commandBuffer->EndRenderPass();
16402 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120016403}
16404
Mark Youngc48c4c12016-04-11 14:26:49 -060016405TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016406 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016407
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016408 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16409 {
16410 VkFormatProperties properties;
16411 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16412 if (properties.optimalTilingFeatures == 0) {
16413 printf(" Image format not supported; skipped.\n");
16414 return;
16415 }
16416 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016417
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016418 VkImageCreateInfo info = {};
16419 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16420 info.pNext = NULL;
16421 info.imageType = VK_IMAGE_TYPE_2D;
16422 info.format = format;
16423 info.extent.height = 32;
16424 info.extent.depth = 1;
16425 info.mipLevels = 1;
16426 info.arrayLayers = 1;
16427 info.samples = VK_SAMPLE_COUNT_1_BIT;
16428 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16429 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16430 info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016431
16432 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016433 {
16434 VkImageFormatProperties properties;
16435 auto const result = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), info.format, info.imageType,
16436 info.tiling, info.usage, info.flags, &properties);
16437 ASSERT_VK_SUCCESS(result);
16438 info.extent.width = properties.maxExtent.width + 1;
16439 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016440
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016441 VkImage image;
16442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
16443 vkCreateImage(m_device->device(), &info, NULL, &image);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016444 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060016445}
16446
Mark Youngc48c4c12016-04-11 14:26:49 -060016447TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016448 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngc48c4c12016-04-11 14:26:49 -060016449
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016450 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
16451 {
16452 VkFormatProperties properties;
16453 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
16454 if (properties.optimalTilingFeatures == 0) {
16455 printf(" Image format not supported; skipped.\n");
16456 return;
16457 }
16458 }
Mark Youngc48c4c12016-04-11 14:26:49 -060016459
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016460 VkImageCreateInfo info = {};
16461 info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16462 info.pNext = NULL;
16463 info.imageType = VK_IMAGE_TYPE_2D;
16464 info.format = format;
16465 info.extent.height = 32;
16466 info.extent.depth = 1;
16467 info.mipLevels = 1;
16468 info.arrayLayers = 1;
16469 info.samples = VK_SAMPLE_COUNT_1_BIT;
16470 info.tiling = VK_IMAGE_TILING_OPTIMAL;
16471 info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16472 info.flags = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016473
16474 // Introduce error by sending down a bogus width extent
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016475 info.extent.width = 0;
Mark Youngc48c4c12016-04-11 14:26:49 -060016476
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016477 VkImage image;
Tobin Ehlisa55b1d42017-04-04 12:23:48 -060016478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02917);
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060016479 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
16480 vkCreateImage(m_device->device(), &info, NULL, &image);
Mark Youngc48c4c12016-04-11 14:26:49 -060016481 m_errorMonitor->VerifyFound();
16482}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070016483
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016484TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016485 TEST_DESCRIPTION(
16486 "Create a render pass with an attachment description "
16487 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016488
Tony Barbour1fa09702017-03-16 12:09:08 -060016489 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016490 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16491
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070016492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060016493
16494 VkAttachmentReference color_attach = {};
16495 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
16496 color_attach.attachment = 0;
16497 VkSubpassDescription subpass = {};
16498 subpass.colorAttachmentCount = 1;
16499 subpass.pColorAttachments = &color_attach;
16500
16501 VkRenderPassCreateInfo rpci = {};
16502 rpci.subpassCount = 1;
16503 rpci.pSubpasses = &subpass;
16504 rpci.attachmentCount = 1;
16505 VkAttachmentDescription attach_desc = {};
16506 attach_desc.format = VK_FORMAT_UNDEFINED;
16507 rpci.pAttachments = &attach_desc;
16508 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
16509 VkRenderPass rp;
16510 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
16511
16512 m_errorMonitor->VerifyFound();
16513
16514 if (result == VK_SUCCESS) {
16515 vkDestroyRenderPass(m_device->device(), rp, NULL);
16516 }
16517}
16518
Karl Schultz6addd812016-02-02 17:17:23 -070016519TEST_F(VkLayerTest, InvalidImageView) {
Tony Barbour1fa09702017-03-16 12:09:08 -060016520 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehliscde08892015-09-22 10:11:37 -060016521
Mike Stroyana3082432015-09-25 13:39:21 -060016522 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070016523 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16524 const int32_t tex_width = 32;
16525 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060016526
16527 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016528 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16529 image_create_info.pNext = NULL;
16530 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16531 image_create_info.format = tex_format;
16532 image_create_info.extent.width = tex_width;
16533 image_create_info.extent.height = tex_height;
16534 image_create_info.extent.depth = 1;
16535 image_create_info.mipLevels = 1;
16536 image_create_info.arrayLayers = 1;
16537 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16538 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16539 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16540 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060016541
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016542 VkImage image;
16543 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060016544 ASSERT_VK_SUCCESS(err);
16545
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016546 VkMemoryRequirements requirements;
16547 vkGetImageMemoryRequirements(m_device->device(), image, &requirements);
16548
16549 VkMemoryAllocateInfo alloc_info{};
16550 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16551 alloc_info.pNext = NULL;
16552 alloc_info.memoryTypeIndex = 0;
16553 alloc_info.allocationSize = requirements.size;
16554 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
16555 ASSERT_TRUE(pass);
16556
16557 VkDeviceMemory memory;
16558 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
16559 ASSERT_VK_SUCCESS(err);
16560
16561 err = vkBindImageMemory(m_device->device(), image, memory, 0);
16562
Tobin Ehliscde08892015-09-22 10:11:37 -060016563 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016564 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016565 image_view_create_info.image = image;
16566 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16567 image_view_create_info.format = tex_format;
16568 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016569 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070016570 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016571 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060016572
16573 VkImageView view;
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016575 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016576 m_errorMonitor->VerifyFound();
Jeremy Hayesa1ffc2b2017-03-10 16:05:37 -070016577
16578 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -060016579 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060016580}
Mike Stroyana3082432015-09-25 13:39:21 -060016581
Mark Youngd339ba32016-05-30 13:28:35 -060016582TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
16583 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060016584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060016585 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060016586
Tony Barbour1fa09702017-03-16 12:09:08 -060016587 ASSERT_NO_FATAL_FAILURE(Init());
Mark Youngd339ba32016-05-30 13:28:35 -060016588
16589 // Create an image and try to create a view with no memory backing the image
16590 VkImage image;
16591
16592 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16593 const int32_t tex_width = 32;
16594 const int32_t tex_height = 32;
16595
16596 VkImageCreateInfo image_create_info = {};
16597 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16598 image_create_info.pNext = NULL;
16599 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16600 image_create_info.format = tex_format;
16601 image_create_info.extent.width = tex_width;
16602 image_create_info.extent.height = tex_height;
16603 image_create_info.extent.depth = 1;
16604 image_create_info.mipLevels = 1;
16605 image_create_info.arrayLayers = 1;
16606 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16607 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16608 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16609 image_create_info.flags = 0;
16610
16611 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16612 ASSERT_VK_SUCCESS(err);
16613
16614 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016615 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060016616 image_view_create_info.image = image;
16617 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16618 image_view_create_info.format = tex_format;
16619 image_view_create_info.subresourceRange.layerCount = 1;
16620 image_view_create_info.subresourceRange.baseMipLevel = 0;
16621 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016622 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060016623
16624 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016625 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060016626
16627 m_errorMonitor->VerifyFound();
16628 vkDestroyImage(m_device->device(), image, NULL);
16629 // If last error is success, it still created the view, so delete it.
16630 if (err == VK_SUCCESS) {
16631 vkDestroyImageView(m_device->device(), view, NULL);
16632 }
Mark Youngd339ba32016-05-30 13:28:35 -060016633}
16634
Karl Schultz6addd812016-02-02 17:17:23 -070016635TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016636 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016638
Tony Barbour1fa09702017-03-16 12:09:08 -060016639 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016640
Karl Schultz6addd812016-02-02 17:17:23 -070016641 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016642 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016643 image.Init(32, 32, 1, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016644 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016645
16646 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016647 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016648 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070016649 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16650 image_view_create_info.format = tex_format;
16651 image_view_create_info.subresourceRange.baseMipLevel = 0;
16652 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016653 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070016654 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016655 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016656
16657 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060016658 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016659
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016660 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060016661}
16662
Mike Weiblena1e13f42017-02-09 21:25:59 -070016663TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
16664 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
16665
Tony Barbour1fa09702017-03-16 12:09:08 -060016666 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblena1e13f42017-02-09 21:25:59 -070016667 VkSubresourceLayout subres_layout = {};
16668
16669 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
16670 {
16671 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
16672 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016673 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016674 ASSERT_TRUE(img.initialized());
16675
16676 VkImageSubresource subres = {};
16677 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16678 subres.mipLevel = 0;
16679 subres.arrayLayer = 0;
16680
16681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
16682 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16683 m_errorMonitor->VerifyFound();
16684 }
16685
16686 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
16687 {
16688 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016689 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016690 ASSERT_TRUE(img.initialized());
16691
16692 VkImageSubresource subres = {};
16693 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
16694 subres.mipLevel = 0;
16695 subres.arrayLayer = 0;
16696
16697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
16698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
16699 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16700 m_errorMonitor->VerifyFound();
16701 }
16702
16703 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
16704 {
16705 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016706 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016707 ASSERT_TRUE(img.initialized());
16708
16709 VkImageSubresource subres = {};
16710 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16711 subres.mipLevel = 1; // ERROR: triggers VU 00739
16712 subres.arrayLayer = 0;
16713
16714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
16715 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16716 m_errorMonitor->VerifyFound();
16717 }
16718
16719 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
16720 {
16721 VkImageObj img(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016722 img.InitNoLayout(32, 32, 1, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mike Weiblena1e13f42017-02-09 21:25:59 -070016723 ASSERT_TRUE(img.initialized());
16724
16725 VkImageSubresource subres = {};
16726 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16727 subres.mipLevel = 0;
16728 subres.arrayLayer = 1; // ERROR: triggers VU 00740
16729
16730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
16731 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
16732 m_errorMonitor->VerifyFound();
16733 }
16734}
16735
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016736TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070016737 VkResult err;
16738 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016739
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016741
Tony Barbour1fa09702017-03-16 12:09:08 -060016742 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060016743
16744 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016745 VkImage srcImage;
16746 VkImage dstImage;
16747 VkDeviceMemory srcMem;
16748 VkDeviceMemory destMem;
16749 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016750
16751 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016752 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16753 image_create_info.pNext = NULL;
16754 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16755 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16756 image_create_info.extent.width = 32;
16757 image_create_info.extent.height = 32;
16758 image_create_info.extent.depth = 1;
16759 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016760 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070016761 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16762 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16763 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16764 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016765
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016766 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016767 ASSERT_VK_SUCCESS(err);
16768
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016769 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016770 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016771 ASSERT_VK_SUCCESS(err);
16772
16773 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016774 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016775 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16776 memAlloc.pNext = NULL;
16777 memAlloc.allocationSize = 0;
16778 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016779
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016780 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016781 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016782 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016783 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016784 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016785 ASSERT_VK_SUCCESS(err);
16786
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016787 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016788 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016789 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016790 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016791 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016792 ASSERT_VK_SUCCESS(err);
16793
16794 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16795 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016796 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016797 ASSERT_VK_SUCCESS(err);
16798
Tony Barbour552f6c02016-12-21 14:34:07 -070016799 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016800 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016801 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016802 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016803 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016804 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016805 copyRegion.srcOffset.x = 0;
16806 copyRegion.srcOffset.y = 0;
16807 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016808 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016809 copyRegion.dstSubresource.mipLevel = 0;
16810 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016811 // Introduce failure by forcing the dst layerCount to differ from src
16812 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016813 copyRegion.dstOffset.x = 0;
16814 copyRegion.dstOffset.y = 0;
16815 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016816 copyRegion.extent.width = 1;
16817 copyRegion.extent.height = 1;
16818 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016819 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016820 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016821
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016822 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016823
Chia-I Wuf7458c52015-10-26 21:10:41 +080016824 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016825 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016826 vkFreeMemory(m_device->device(), srcMem, NULL);
16827 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016828}
16829
Tony Barbourd6673642016-05-05 14:46:39 -060016830TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060016831 TEST_DESCRIPTION("Creating images with unsuported formats ");
16832
Tony Barbour1fa09702017-03-16 12:09:08 -060016833 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060016834 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbourd6673642016-05-05 14:46:39 -060016835
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016836 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130016837 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016838 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016839 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16840 image_create_info.format = VK_FORMAT_UNDEFINED;
16841 image_create_info.extent.width = 32;
16842 image_create_info.extent.height = 32;
16843 image_create_info.extent.depth = 1;
16844 image_create_info.mipLevels = 1;
16845 image_create_info.arrayLayers = 1;
16846 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16847 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16848 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016849
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16851 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016852
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016853 VkImage image;
16854 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016855 m_errorMonitor->VerifyFound();
16856
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016857 // Look for a format that is COMPLETELY unsupported with this hardware
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016858 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Tony Barbourd6673642016-05-05 14:46:39 -060016859 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
16860 VkFormat format = static_cast<VkFormat>(f);
16861 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016862 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060016863 unsupported = format;
16864 break;
16865 }
16866 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060016867
Tony Barbourd6673642016-05-05 14:46:39 -060016868 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060016869 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060016871
Jeremy Hayes96dcd812017-03-14 14:04:19 -060016872 vkCreateImage(m_device->handle(), &image_create_info, NULL, &image);
Tony Barbourd6673642016-05-05 14:46:39 -060016873 m_errorMonitor->VerifyFound();
16874 }
16875}
16876
16877TEST_F(VkLayerTest, ImageLayerViewTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060016878 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
16879
Tony Barbour1fa09702017-03-16 12:09:08 -060016880 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060016881 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070016882 if (!depth_format) {
16883 return;
16884 }
Tony Barbourd6673642016-05-05 14:46:39 -060016885
16886 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016887 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 -060016888 VK_IMAGE_TILING_OPTIMAL, 0);
16889 ASSERT_TRUE(image.initialized());
16890
16891 VkImageView imgView;
16892 VkImageViewCreateInfo imgViewInfo = {};
16893 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16894 imgViewInfo.image = image.handle();
16895 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
16896 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16897 imgViewInfo.subresourceRange.layerCount = 1;
16898 imgViewInfo.subresourceRange.baseMipLevel = 0;
16899 imgViewInfo.subresourceRange.levelCount = 1;
16900 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16901
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016902 // View can't have baseMipLevel >= image's mipLevels - Expect VIEW_CREATE_ERROR
Tony Barbourd6673642016-05-05 14:46:39 -060016903 imgViewInfo.subresourceRange.baseMipLevel = 1;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060016905 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16906 m_errorMonitor->VerifyFound();
16907 imgViewInfo.subresourceRange.baseMipLevel = 0;
16908
Tony Barbourd6673642016-05-05 14:46:39 -060016909 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16910 imgViewInfo.subresourceRange.levelCount = 0;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060016912 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16913 m_errorMonitor->VerifyFound();
16914 imgViewInfo.subresourceRange.levelCount = 1;
16915
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060016916 // View's levelCount can't be > image's mipLevels - Expect VIEW_CREATE_ERROR
16917 imgViewInfo.subresourceRange.levelCount = 2;
16918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
16919 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16920 m_errorMonitor->VerifyFound();
16921 imgViewInfo.subresourceRange.levelCount = 1;
16922
16923 // View can't have baseArrayLayer >= image's arraySize - Expect VIEW_CREATE_ERROR
16924 imgViewInfo.subresourceRange.baseArrayLayer = 1;
16925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
16926 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16927 m_errorMonitor->VerifyFound();
16928 imgViewInfo.subresourceRange.baseArrayLayer = 0;
16929
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016930 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16931 imgViewInfo.subresourceRange.layerCount = 0;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016932 m_errorMonitor->SetDesiredFailureMsg(
16933 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16934 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060016935 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16936 m_errorMonitor->VerifyFound();
16937 imgViewInfo.subresourceRange.layerCount = 1;
16938
Tony Barbourd6673642016-05-05 14:46:39 -060016939 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070016940 imgViewInfo.format = depth_format;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016941 m_errorMonitor->SetDesiredFailureMsg(
16942 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16943 "Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016944 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16945 m_errorMonitor->VerifyFound();
16946 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16947
Tony Barbourd6673642016-05-05 14:46:39 -060016948 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16949 // VIEW_CREATE_ERROR
16950 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060016952 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16953 m_errorMonitor->VerifyFound();
16954 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16955
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016956 // TODO: Update framework to easily passing mutable flag into ImageObj init
16957 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070016958 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
16959 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16960 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060016961 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16962 // VIEW_CREATE_ERROR
16963 VkImageCreateInfo mutImgInfo = image.create_info();
16964 VkImage mutImage;
16965 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016966 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016967 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16968 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016969 VkResult ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
Tony Barbourd6673642016-05-05 14:46:39 -060016970 ASSERT_VK_SUCCESS(ret);
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016971
16972 VkMemoryRequirements requirements;
16973 vkGetImageMemoryRequirements(m_device->device(), mutImage, &requirements);
16974
16975 VkMemoryAllocateInfo alloc_info{};
16976 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16977 alloc_info.pNext = NULL;
16978 alloc_info.memoryTypeIndex = 0;
16979 alloc_info.allocationSize = requirements.size;
16980 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
16981 ASSERT_TRUE(pass);
16982
16983 VkDeviceMemory memory;
16984 ret = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
16985 ASSERT_VK_SUCCESS(ret);
16986
16987 ret = vkBindImageMemory(m_device->device(), mutImage, memory, 0);
16988 ASSERT_VK_SUCCESS(ret);
16989
Tony Barbourd6673642016-05-05 14:46:39 -060016990 imgViewInfo.image = mutImage;
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tony Barbourd6673642016-05-05 14:46:39 -060016992 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16993 m_errorMonitor->VerifyFound();
16994 imgViewInfo.image = image.handle();
Jeremy Hayes2ffbaa72017-03-14 17:05:50 -060016995
16996 vkFreeMemory(m_device->device(), memory, NULL);
Tony Barbourd6673642016-05-05 14:46:39 -060016997 vkDestroyImage(m_device->handle(), mutImage, NULL);
16998}
16999
Dave Houlton75967fc2017-03-06 17:21:16 -070017000TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
17001 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
17002
Tony Barbour1fa09702017-03-16 12:09:08 -060017003 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton75967fc2017-03-06 17:21:16 -070017004
Jamie Madill35127872017-03-15 16:17:46 -040017005 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton75967fc2017-03-06 17:21:16 -070017006 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
17007 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
17008 if (device_features.textureCompressionBC) {
17009 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
17010 } else if (device_features.textureCompressionETC2) {
17011 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
17012 } else if (device_features.textureCompressionASTC_LDR) {
17013 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
17014 } else {
17015 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
17016 return;
17017 }
17018
17019 VkImageCreateInfo ci;
17020 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17021 ci.pNext = NULL;
17022 ci.flags = 0;
17023 ci.imageType = VK_IMAGE_TYPE_2D;
17024 ci.format = compressed_format;
17025 ci.extent = {32, 32, 1};
17026 ci.mipLevels = 6;
17027 ci.arrayLayers = 1;
17028 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17029 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17030 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17031 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17032 ci.queueFamilyIndexCount = 0;
17033 ci.pQueueFamilyIndices = NULL;
17034 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17035
17036 VkImageObj image(m_device);
17037 image.init(&ci);
17038 ASSERT_TRUE(image.initialized());
17039
17040 VkImageObj odd_image(m_device);
17041 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
17042 odd_image.init(&ci);
17043 ASSERT_TRUE(odd_image.initialized());
17044
17045 // Allocate buffers
17046 VkMemoryPropertyFlags reqs = 0;
17047 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
17048 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
17049 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
17050 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
17051 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
17052
17053 VkBufferImageCopy region = {};
17054 region.bufferRowLength = 0;
17055 region.bufferImageHeight = 0;
17056 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17057 region.imageSubresource.layerCount = 1;
17058 region.imageOffset = {0, 0, 0};
17059 region.bufferOffset = 0;
17060
17061 // start recording
17062 m_commandBuffer->BeginCommandBuffer();
17063
17064 // Mip level copies that work - 5 levels
17065 m_errorMonitor->ExpectSuccess();
17066
17067 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
17068 region.imageExtent = {32, 32, 1};
17069 region.imageSubresource.mipLevel = 0;
17070 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
17071 &region);
17072 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17073 &region);
17074
17075 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
17076 region.imageExtent = {8, 8, 1};
17077 region.imageSubresource.mipLevel = 2;
17078 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
17079 &region);
17080 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17081 &region);
17082
17083 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
17084 region.imageExtent = {4, 4, 1};
17085 region.imageSubresource.mipLevel = 3;
17086 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17087 &region);
17088 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17089 &region);
17090
17091 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
17092 region.imageExtent = {2, 2, 1};
17093 region.imageSubresource.mipLevel = 4;
17094 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17095 &region);
17096 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17097 &region);
17098
17099 region.imageExtent = {1, 1, 1};
17100 region.imageSubresource.mipLevel = 5;
17101 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17102 &region);
17103 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17104 &region);
17105 m_errorMonitor->VerifyNotFound();
17106
17107 // Buffer must accomodate a full compressed block, regardless of texel count
17108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17109 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
17110 &region);
17111 m_errorMonitor->VerifyFound();
17112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
17113 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17114 &region);
17115 m_errorMonitor->VerifyFound();
17116
17117 // Copy width < compressed block size, but not the full mip width
17118 region.imageExtent = {1, 2, 1};
17119 region.imageSubresource.mipLevel = 4;
17120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17121 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17122 &region);
17123 m_errorMonitor->VerifyFound();
17124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17125 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17126 &region);
17127 m_errorMonitor->VerifyFound();
17128
17129 // Copy height < compressed block size but not the full mip height
17130 region.imageExtent = {2, 1, 1};
17131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17132 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17133 &region);
17134 m_errorMonitor->VerifyFound();
17135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17136 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17137 &region);
17138 m_errorMonitor->VerifyFound();
17139
17140 // Offsets must be multiple of compressed block size
17141 region.imageOffset = {1, 1, 0};
17142 region.imageExtent = {1, 1, 1};
17143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17144 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17145 &region);
17146 m_errorMonitor->VerifyFound();
17147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
17148 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17149 &region);
17150 m_errorMonitor->VerifyFound();
17151
17152 // Offset + extent width = mip width - should succeed
17153 region.imageOffset = {4, 4, 0};
17154 region.imageExtent = {3, 4, 1};
17155 region.imageSubresource.mipLevel = 2;
17156 m_errorMonitor->ExpectSuccess();
17157 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17158 &region);
17159 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17160 &region);
17161 m_errorMonitor->VerifyNotFound();
17162
17163 // Offset + extent width > mip width, but still within the final compressed block - should succeed
17164 region.imageExtent = {4, 4, 1};
17165 m_errorMonitor->ExpectSuccess();
17166 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17167 &region);
17168 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17169 &region);
17170 m_errorMonitor->VerifyNotFound();
17171
17172 // Offset + extent width < mip width and not a multiple of block width - should fail
17173 region.imageExtent = {3, 3, 1};
17174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17175 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
17176 &region);
17177 m_errorMonitor->VerifyFound();
17178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
17179 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17180 &region);
17181 m_errorMonitor->VerifyFound();
17182}
17183
Dave Houlton59a20702017-02-02 17:26:23 -070017184TEST_F(VkLayerTest, ImageBufferCopyTests) {
17185 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
17186
Tony Barbour1fa09702017-03-16 12:09:08 -060017187 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourf887b162017-03-09 10:06:46 -070017188 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
17189 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
17190 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
17191 return;
17192 }
Dave Houlton584d51e2017-02-16 12:52:54 -070017193
17194 // Bail if any dimension of transfer granularity is 0.
17195 auto index = m_device->graphics_queue_node_index_;
17196 auto queue_family_properties = m_device->phy().queue_properties();
17197 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
17198 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
17199 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
17200 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
17201 return;
17202 }
17203
Dave Houlton59a20702017-02-02 17:26:23 -070017204 VkImageObj image_64k(m_device); // 128^2 texels, 64k
17205 VkImageObj image_16k(m_device); // 64^2 texels, 16k
17206 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070017207 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
17208 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
17209 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
17210 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
17211
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017212 image_64k.Init(128, 128, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017213 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17214 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017215 image_16k.Init(64, 64, 1, VK_FORMAT_R8G8B8A8_UINT,
Dave Houlton59a20702017-02-02 17:26:23 -070017216 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
17217 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017218 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 -070017219 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070017220 ASSERT_TRUE(image_64k.initialized());
17221 ASSERT_TRUE(image_16k.initialized());
17222 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017223
Dave Houltonf3229d52017-02-21 15:59:08 -070017224 // Verify all needed Depth/Stencil formats are supported
17225 bool missing_ds_support = false;
17226 VkFormatProperties props = {0, 0, 0};
17227 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
17228 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17229 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
17230 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17231 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
17232 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17233 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
17234 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
17235
17236 if (!missing_ds_support) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017237 ds_image_4D_1S.Init(
17238 256, 256, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017239 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17240 VK_IMAGE_TILING_OPTIMAL, 0);
17241 ASSERT_TRUE(ds_image_4D_1S.initialized());
17242
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017243 ds_image_3D_1S.Init(
17244 256, 256, 1, VK_FORMAT_D24_UNORM_S8_UINT,
Dave Houltonf3229d52017-02-21 15:59:08 -070017245 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17246 VK_IMAGE_TILING_OPTIMAL, 0);
17247 ASSERT_TRUE(ds_image_3D_1S.initialized());
17248
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017249 ds_image_2D.Init(
17250 256, 256, 1, VK_FORMAT_D16_UNORM,
17251 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17252 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017253 ASSERT_TRUE(ds_image_2D.initialized());
17254
Dave Houlton11dcd5e2017-04-25 16:00:10 -060017255 ds_image_1S.Init(
17256 256, 256, 1, VK_FORMAT_S8_UINT,
17257 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
17258 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houltonf3229d52017-02-21 15:59:08 -070017259 ASSERT_TRUE(ds_image_1S.initialized());
17260 }
17261
17262 // Allocate buffers
17263 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070017264 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070017265 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
17266 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
17267 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
17268 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070017269
17270 VkBufferImageCopy region = {};
17271 region.bufferRowLength = 0;
17272 region.bufferImageHeight = 0;
17273 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17274 region.imageSubresource.layerCount = 1;
17275 region.imageOffset = {0, 0, 0};
17276 region.imageExtent = {64, 64, 1};
17277 region.bufferOffset = 0;
17278
17279 // attempt copies before putting command buffer in recording state
17280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
17281 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17282 &region);
17283 m_errorMonitor->VerifyFound();
17284
17285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
17286 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17287 &region);
17288 m_errorMonitor->VerifyFound();
17289
17290 // start recording
17291 m_commandBuffer->BeginCommandBuffer();
17292
17293 // successful copies
17294 m_errorMonitor->ExpectSuccess();
17295 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17296 &region);
17297 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17298 &region);
17299 region.imageOffset.x = 16; // 16k copy, offset requires larger image
17300 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17301 &region);
17302 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
17303 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17304 &region);
17305 region.imageOffset.x = 0;
17306 region.imageExtent.height = 64;
17307 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
17308 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17309 &region);
17310 m_errorMonitor->VerifyNotFound();
17311
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017312 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070017313 region.imageExtent = {65, 64, 1};
17314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17315 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17316 &region);
17317 m_errorMonitor->VerifyFound();
17318
17319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17320 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17321 &region);
17322 m_errorMonitor->VerifyFound();
17323
17324 // image/buffer too small (offset) on copy to image
17325 region.imageExtent = {64, 64, 1};
17326 region.imageOffset = {0, 4, 0};
17327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
17328 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17329 &region);
17330 m_errorMonitor->VerifyFound();
17331
17332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
17333 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
17334 &region);
17335 m_errorMonitor->VerifyFound();
17336
17337 // image/buffer too small on copy to buffer
17338 region.imageExtent = {64, 64, 1};
17339 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070017340 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
17342 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17343 &region);
17344 m_errorMonitor->VerifyFound();
17345
17346 region.imageExtent = {64, 65, 1};
17347 region.bufferOffset = 0;
17348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
17349 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
17350 &region);
17351 m_errorMonitor->VerifyFound();
17352
17353 // buffer size ok but rowlength causes loose packing
17354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17355 region.imageExtent = {64, 64, 1};
17356 region.bufferRowLength = 68;
17357 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17358 &region);
17359 m_errorMonitor->VerifyFound();
17360
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017361 // An extent with zero area should produce a warning, but no error
17362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
17363 region.imageExtent.width = 0;
17364 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17365 &region);
17366 m_errorMonitor->VerifyFound();
17367
Dave Houlton59a20702017-02-02 17:26:23 -070017368 // aspect bits
17369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
17370 region.imageExtent = {64, 64, 1};
17371 region.bufferRowLength = 0;
17372 region.bufferImageHeight = 0;
17373 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17374 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17375 buffer_16k.handle(), 1, &region);
17376 m_errorMonitor->VerifyFound();
17377
17378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
17379 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17380 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
17381 &region);
17382 m_errorMonitor->VerifyFound();
17383
17384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
17385 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17386 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
17387 buffer_16k.handle(), 1, &region);
17388 m_errorMonitor->VerifyFound();
17389
Dave Houltonf3229d52017-02-21 15:59:08 -070017390 // Test Depth/Stencil copies
17391 if (missing_ds_support) {
17392 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
17393 } else {
17394 VkBufferImageCopy ds_region = {};
17395 ds_region.bufferOffset = 0;
17396 ds_region.bufferRowLength = 0;
17397 ds_region.bufferImageHeight = 0;
17398 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
17399 ds_region.imageSubresource.mipLevel = 0;
17400 ds_region.imageSubresource.baseArrayLayer = 0;
17401 ds_region.imageSubresource.layerCount = 1;
17402 ds_region.imageOffset = {0, 0, 0};
17403 ds_region.imageExtent = {256, 256, 1};
17404
17405 // Depth copies that should succeed
17406 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
17407 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17408 buffer_256k.handle(), 1, &ds_region);
17409 m_errorMonitor->VerifyNotFound();
17410
17411 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
17412 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17413 buffer_256k.handle(), 1, &ds_region);
17414 m_errorMonitor->VerifyNotFound();
17415
17416 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
17417 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17418 buffer_128k.handle(), 1, &ds_region);
17419 m_errorMonitor->VerifyNotFound();
17420
17421 // Depth copies that should fail
17422 ds_region.bufferOffset = 4;
17423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17424 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
17425 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17426 buffer_256k.handle(), 1, &ds_region);
17427 m_errorMonitor->VerifyFound();
17428
17429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17430 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
17431 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17432 buffer_256k.handle(), 1, &ds_region);
17433 m_errorMonitor->VerifyFound();
17434
17435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17436 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
17437 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17438 buffer_128k.handle(), 1, &ds_region);
17439 m_errorMonitor->VerifyFound();
17440
17441 // Stencil copies that should succeed
17442 ds_region.bufferOffset = 0;
17443 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
17444 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17445 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17446 buffer_64k.handle(), 1, &ds_region);
17447 m_errorMonitor->VerifyNotFound();
17448
17449 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
17450 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17451 buffer_64k.handle(), 1, &ds_region);
17452 m_errorMonitor->VerifyNotFound();
17453
17454 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
17455 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17456 buffer_64k.handle(), 1, &ds_region);
17457 m_errorMonitor->VerifyNotFound();
17458
17459 // Stencil copies that should fail
17460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17461 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17462 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17463 buffer_16k.handle(), 1, &ds_region);
17464 m_errorMonitor->VerifyFound();
17465
17466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17467 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
17468 ds_region.bufferRowLength = 260;
17469 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17470 buffer_64k.handle(), 1, &ds_region);
17471 m_errorMonitor->VerifyFound();
17472
17473 ds_region.bufferRowLength = 0;
17474 ds_region.bufferOffset = 4;
17475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17476 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
17477 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
17478 buffer_64k.handle(), 1, &ds_region);
17479 m_errorMonitor->VerifyFound();
17480 }
17481
Dave Houlton584d51e2017-02-16 12:52:54 -070017482 // Test compressed formats, if supported
Jamie Madill35127872017-03-15 16:17:46 -040017483 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton584d51e2017-02-16 12:52:54 -070017484 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070017485 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
17486 device_features.textureCompressionASTC_LDR)) {
17487 printf(" No compressed formats supported - block compression tests skipped.\n");
17488 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070017489 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
17490 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070017491 if (device_features.textureCompressionBC) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017492 image_16k_4x4comp.Init(128, 128, 1, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
17493 0);
17494 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 -070017495 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017496 } else if (device_features.textureCompressionETC2) {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017497 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 -070017498 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017499 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 -070017500 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017501 } else {
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017502 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 -070017503 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017504 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 -070017505 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070017506 }
17507 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070017508
Dave Houlton584d51e2017-02-16 12:52:54 -070017509 // Just fits
17510 m_errorMonitor->ExpectSuccess();
17511 region.imageExtent = {128, 128, 1};
17512 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17513 buffer_16k.handle(), 1, &region);
17514 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017515
Dave Houlton584d51e2017-02-16 12:52:54 -070017516 // with offset, too big for buffer
17517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
17518 region.bufferOffset = 16;
17519 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17520 buffer_16k.handle(), 1, &region);
17521 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017522 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017523
Dave Houlton67e9b532017-03-02 17:00:10 -070017524 // extents that are not a multiple of compressed block size
17525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
17526 region.imageExtent.width = 66;
17527 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17528 buffer_16k.handle(), 1, &region);
17529 m_errorMonitor->VerifyFound();
17530 region.imageExtent.width = 128;
17531
17532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017533 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070017534 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17535 buffer_16k.handle(), 1, &region);
17536 m_errorMonitor->VerifyFound();
17537 region.imageExtent.height = 128;
17538
17539 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
17540
17541 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
17542 m_errorMonitor->ExpectSuccess();
17543 region.imageExtent.width = 66;
17544 region.imageOffset.x = 64;
17545 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17546 buffer_16k.handle(), 1, &region);
17547 region.imageExtent.width = 16;
17548 region.imageOffset.x = 0;
17549 region.imageExtent.height = 2;
17550 region.imageOffset.y = 128;
17551 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017552 buffer_16k.handle(), 1, &region);
17553 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070017554 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017555
Dave Houlton584d51e2017-02-16 12:52:54 -070017556 // buffer offset must be a multiple of texel block size (16)
17557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
17558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
17559 region.imageExtent = {64, 64, 1};
17560 region.bufferOffset = 24;
17561 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17562 buffer_16k.handle(), 1, &region);
17563 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017564
Dave Houlton584d51e2017-02-16 12:52:54 -070017565 // rowlength not a multiple of block width (4)
17566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
17567 region.bufferOffset = 0;
17568 region.bufferRowLength = 130;
17569 region.bufferImageHeight = 0;
17570 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17571 buffer_64k.handle(), 1, &region);
17572 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070017573
Dave Houlton584d51e2017-02-16 12:52:54 -070017574 // imageheight not a multiple of block height (4)
17575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
17576 region.bufferRowLength = 0;
17577 region.bufferImageHeight = 130;
17578 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
17579 buffer_64k.handle(), 1, &region);
17580 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070017581 }
Dave Houlton59a20702017-02-02 17:26:23 -070017582}
17583
Tony Barbourd6673642016-05-05 14:46:39 -060017584TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070017585 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060017586
Tony Barbour1fa09702017-03-16 12:09:08 -060017587 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourd6673642016-05-05 14:46:39 -060017588
Rene Lindsay135204f2016-12-22 17:11:09 -070017589 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060017590 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017591 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 -070017592 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060017593 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060017594 vk_testing::Buffer buffer;
17595 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070017596 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060017597 VkBufferImageCopy region = {};
17598 region.bufferRowLength = 128;
17599 region.bufferImageHeight = 128;
17600 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17601 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070017602 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017603 region.imageExtent.height = 4;
17604 region.imageExtent.width = 4;
17605 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070017606
17607 VkImageObj image2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017608 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 -070017609 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070017610 ASSERT_TRUE(image2.initialized());
17611 vk_testing::Buffer buffer2;
17612 VkMemoryPropertyFlags reqs2 = 0;
17613 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
17614 VkBufferImageCopy region2 = {};
17615 region2.bufferRowLength = 128;
17616 region2.bufferImageHeight = 128;
17617 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17618 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
17619 region2.imageSubresource.layerCount = 1;
17620 region2.imageExtent.height = 4;
17621 region2.imageExtent.width = 4;
17622 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017623 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060017624
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017625 // Image must have offset.z of 0 and extent.depth of 1
17626 // Introduce failure by setting imageExtent.depth to 0
17627 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070017628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017629 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017630 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017631 m_errorMonitor->VerifyFound();
17632
17633 region.imageExtent.depth = 1;
17634
17635 // Image must have offset.z of 0 and extent.depth of 1
17636 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017637 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017638 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070017639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070017640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017641 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017642 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070017643 m_errorMonitor->VerifyFound();
17644
17645 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017646 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
17647 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070017648 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017650 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17651 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017652 m_errorMonitor->VerifyFound();
17653
17654 // BufferOffset must be a multiple of 4
17655 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070017656 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070017658 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
17659 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017660 m_errorMonitor->VerifyFound();
17661
17662 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
17663 region.bufferOffset = 0;
17664 region.imageExtent.height = 128;
17665 region.imageExtent.width = 128;
17666 // Introduce failure by setting bufferRowLength > 0 but less than width
17667 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017669 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17670 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017671 m_errorMonitor->VerifyFound();
17672
17673 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
17674 region.bufferRowLength = 128;
17675 // Introduce failure by setting bufferRowHeight > 0 but less than height
17676 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070017677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017678 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
17679 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060017680 m_errorMonitor->VerifyFound();
17681
17682 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060017683 VkImageObj intImage1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017684 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 -070017685 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017686 VkImageObj intImage2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017687 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 -070017688 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060017689 VkImageBlit blitRegion = {};
17690 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17691 blitRegion.srcSubresource.baseArrayLayer = 0;
17692 blitRegion.srcSubresource.layerCount = 1;
17693 blitRegion.srcSubresource.mipLevel = 0;
17694 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17695 blitRegion.dstSubresource.baseArrayLayer = 0;
17696 blitRegion.dstSubresource.layerCount = 1;
17697 blitRegion.dstSubresource.mipLevel = 0;
17698
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017699 // Look for NULL-blit warning
Jeremy Hayesf8e749f2017-03-15 09:40:27 -060017700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17701 "vkCmdBlitImage: pRegions[0].srcOffsets specify a zero-volume area.");
17702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
17703 "vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060017704 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.Layout(), intImage2.handle(),
17705 intImage2.Layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060017706 m_errorMonitor->VerifyFound();
17707
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070017708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060017709 VkImageMemoryBarrier img_barrier;
17710 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17711 img_barrier.pNext = NULL;
17712 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17713 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17714 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17715 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17716 img_barrier.image = image.handle();
17717 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17718 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17719 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17720 img_barrier.subresourceRange.baseArrayLayer = 0;
17721 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060017722 img_barrier.subresourceRange.layerCount = 0;
17723 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017724 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
17725 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060017726 m_errorMonitor->VerifyFound();
17727 img_barrier.subresourceRange.layerCount = 1;
17728}
17729
17730TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060017731 TEST_DESCRIPTION("Exceed the limits of image format ");
17732
Tony Barbour1fa09702017-03-16 12:09:08 -060017733 ASSERT_NO_FATAL_FAILURE(Init());
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017734
17735 VkFormat const format = VK_FORMAT_B8G8R8A8_UNORM;
17736 {
17737 VkFormatProperties properties;
17738 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), format, &properties);
17739 if (properties.linearTilingFeatures == 0) {
17740 printf(" Image format not supported; skipped.\n");
17741 return;
17742 }
17743 }
17744
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060017746 VkImageCreateInfo image_create_info = {};
17747 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17748 image_create_info.pNext = NULL;
17749 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Jeremy Hayesbb63cc12017-03-20 15:33:01 -060017750 image_create_info.format = format;
Tony Barbourd6673642016-05-05 14:46:39 -060017751 image_create_info.extent.width = 32;
17752 image_create_info.extent.height = 32;
17753 image_create_info.extent.depth = 1;
17754 image_create_info.mipLevels = 1;
17755 image_create_info.arrayLayers = 1;
17756 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17757 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17758 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17759 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17760 image_create_info.flags = 0;
17761
17762 VkImage nullImg;
17763 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017764 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
17765 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070017766 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017767 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17768 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17769 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070017770 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060017771
Tony Barbour0907e362017-03-09 15:05:30 -070017772 uint32_t maxDim =
17773 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
17774 // If max mip levels exceeds image extents, skip the max mip levels test
17775 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
17776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
17777 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
17778 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17779 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17780 m_errorMonitor->VerifyFound();
17781 image_create_info.mipLevels = 1;
17782 }
Tony Barbourd6673642016-05-05 14:46:39 -060017783
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060017785 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
17786 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17787 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17788 m_errorMonitor->VerifyFound();
17789 image_create_info.arrayLayers = 1;
17790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060017792 int samples = imgFmtProps.sampleCounts >> 1;
17793 image_create_info.samples = (VkSampleCountFlagBits)samples;
17794 // Expect INVALID_FORMAT_LIMITS_VIOLATION
17795 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17796 m_errorMonitor->VerifyFound();
17797 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17798
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17800 "pCreateInfo->initialLayout, must be "
17801 "VK_IMAGE_LAYOUT_UNDEFINED or "
17802 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060017803 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
17804 // Expect INVALID_LAYOUT
17805 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
17806 m_errorMonitor->VerifyFound();
17807 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17808}
17809
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017810TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017811 // Image copy with source region specified greater than src image size
Tony Barbour1fa09702017-03-16 12:09:08 -060017812 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017813
Dave Houltonfc1a4052017-04-27 14:32:45 -060017814 // Create images with full mip chain
17815 VkImageCreateInfo ci;
17816 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17817 ci.pNext = NULL;
17818 ci.flags = 0;
17819 ci.imageType = VK_IMAGE_TYPE_3D;
17820 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
17821 ci.extent = {32, 32, 8};
17822 ci.mipLevels = 6;
17823 ci.arrayLayers = 1;
17824 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17825 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17826 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17827 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17828 ci.queueFamilyIndexCount = 0;
17829 ci.pQueueFamilyIndices = NULL;
17830 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17831
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017832 VkImageObj src_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017833 src_image.init(&ci);
17834 ASSERT_TRUE(src_image.initialized());
17835
17836 // Dest image with one more mip level
17837 ci.extent = {64, 64, 16};
17838 ci.mipLevels = 7;
17839 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017840 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017841 dst_image.init(&ci);
17842 ASSERT_TRUE(dst_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017843
Tony Barbour552f6c02016-12-21 14:34:07 -070017844 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017845
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017846 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017847 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017848 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017849 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060017850 copy_region.srcSubresource.mipLevel = 0;
17851 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017852 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017853 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017854 copy_region.srcSubresource.layerCount = 1;
17855 copy_region.dstSubresource.layerCount = 1;
17856 copy_region.srcOffset = {0, 0, 0};
17857 copy_region.dstOffset = {0, 0, 0};
17858
17859 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017860 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17861 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017862 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017863
Dave Houltonfc1a4052017-04-27 14:32:45 -060017864 // Source exceeded in x-dim, VU 01202
17865 copy_region.srcOffset.x = 4;
17866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175); // General "contained within" VU
17867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01202);
17868 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17869 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017870 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017871
17872 // Source exceeded in y-dim, VU 01203
17873 copy_region.srcOffset.x = 0;
17874 copy_region.extent.height = 48;
17875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
17876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01203);
17877 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17878 &copy_region);
17879 m_errorMonitor->VerifyFound();
17880
17881 // Source exceeded in z-dim, VU 01204
17882 copy_region.extent = {4, 4, 4};
17883 copy_region.srcSubresource.mipLevel = 2;
17884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
17885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01204);
17886 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17887 &copy_region);
17888 m_errorMonitor->VerifyFound();
17889
17890 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017891}
17892
17893TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017894 // Image copy with dest region specified greater than dest image size
Tony Barbour1fa09702017-03-16 12:09:08 -060017895 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017896
Dave Houltonfc1a4052017-04-27 14:32:45 -060017897 // Create images with full mip chain
17898 VkImageCreateInfo ci;
17899 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17900 ci.pNext = NULL;
17901 ci.flags = 0;
17902 ci.imageType = VK_IMAGE_TYPE_3D;
17903 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
17904 ci.extent = {32, 32, 8};
17905 ci.mipLevels = 6;
17906 ci.arrayLayers = 1;
17907 ci.samples = VK_SAMPLE_COUNT_1_BIT;
17908 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
17909 ci.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17910 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17911 ci.queueFamilyIndexCount = 0;
17912 ci.pQueueFamilyIndices = NULL;
17913 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17914
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017915 VkImageObj dst_image(m_device);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017916 dst_image.init(&ci);
17917 ASSERT_TRUE(dst_image.initialized());
17918
17919 // Src image with one more mip level
17920 ci.extent = {64, 64, 16};
17921 ci.mipLevels = 7;
17922 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17923 VkImageObj src_image(m_device);
17924 src_image.init(&ci);
17925 ASSERT_TRUE(src_image.initialized());
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017926
Tony Barbour552f6c02016-12-21 14:34:07 -070017927 m_commandBuffer->BeginCommandBuffer();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017928
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017929 VkImageCopy copy_region;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017930 copy_region.extent = {32, 32, 8};
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017931 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017932 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Dave Houltoncee81d02017-05-02 11:00:10 -060017933 copy_region.srcSubresource.mipLevel = 0;
17934 copy_region.dstSubresource.mipLevel = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017935 copy_region.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017936 copy_region.dstSubresource.baseArrayLayer = 0;
Dave Houltonfc1a4052017-04-27 14:32:45 -060017937 copy_region.srcSubresource.layerCount = 1;
17938 copy_region.dstSubresource.layerCount = 1;
17939 copy_region.srcOffset = {0, 0, 0};
17940 copy_region.dstOffset = {0, 0, 0};
17941
17942 m_errorMonitor->ExpectSuccess();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017943 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17944 &copy_region);
Dave Houltonfc1a4052017-04-27 14:32:45 -060017945 m_errorMonitor->VerifyNotFound();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017946
Dave Houltonfc1a4052017-04-27 14:32:45 -060017947 // Dest exceeded in x-dim, VU 01205
17948 copy_region.dstOffset.x = 4;
17949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176); // General "contained within" VU
17950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01205);
17951 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17952 &copy_region);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017953 m_errorMonitor->VerifyFound();
Dave Houltonfc1a4052017-04-27 14:32:45 -060017954
17955 // Dest exceeded in y-dim, VU 01206
17956 copy_region.dstOffset.x = 0;
17957 copy_region.extent.height = 48;
17958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
17959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01206);
17960 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17961 &copy_region);
17962 m_errorMonitor->VerifyFound();
17963
17964 // Dest exceeded in z-dim, VU 01207
17965 copy_region.extent = {4, 4, 4};
17966 copy_region.dstSubresource.mipLevel = 2;
17967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
17968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01207);
17969 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
17970 &copy_region);
17971 m_errorMonitor->VerifyFound();
17972
17973 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060017974}
17975
Karl Schultz6addd812016-02-02 17:17:23 -070017976TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060017977 VkResult err;
17978 bool pass;
17979
17980 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070017981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060017982
Tony Barbour1fa09702017-03-16 12:09:08 -060017983 ASSERT_NO_FATAL_FAILURE(Init());
Karl Schultzbdb75952016-04-19 11:36:49 -060017984
17985 // Create two images of different types and try to copy between them
17986 VkImage srcImage;
17987 VkImage dstImage;
17988 VkDeviceMemory srcMem;
17989 VkDeviceMemory destMem;
17990 VkMemoryRequirements memReqs;
17991
17992 VkImageCreateInfo image_create_info = {};
17993 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17994 image_create_info.pNext = NULL;
17995 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17996 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17997 image_create_info.extent.width = 32;
17998 image_create_info.extent.height = 32;
17999 image_create_info.extent.depth = 1;
18000 image_create_info.mipLevels = 1;
18001 image_create_info.arrayLayers = 1;
18002 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18003 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
18004 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18005 image_create_info.flags = 0;
18006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018007 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060018008 ASSERT_VK_SUCCESS(err);
18009
18010 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18011 // Introduce failure by creating second image with a different-sized format.
18012 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018013 VkFormatProperties properties;
18014 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18015 if (properties.optimalTilingFeatures == 0) {
18016 printf(" Image format not supported; skipped.\n");
18017 return;
18018 }
Karl Schultzbdb75952016-04-19 11:36:49 -060018019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018020 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060018021 ASSERT_VK_SUCCESS(err);
18022
18023 // Allocate memory
18024 VkMemoryAllocateInfo memAlloc = {};
18025 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18026 memAlloc.pNext = NULL;
18027 memAlloc.allocationSize = 0;
18028 memAlloc.memoryTypeIndex = 0;
18029
18030 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
18031 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018032 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060018033 ASSERT_TRUE(pass);
18034 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
18035 ASSERT_VK_SUCCESS(err);
18036
18037 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
18038 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018039 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060018040 ASSERT_TRUE(pass);
18041 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
18042 ASSERT_VK_SUCCESS(err);
18043
18044 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18045 ASSERT_VK_SUCCESS(err);
18046 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
18047 ASSERT_VK_SUCCESS(err);
18048
Tony Barbour552f6c02016-12-21 14:34:07 -070018049 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018050 VkImageCopy copyRegion;
18051 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18052 copyRegion.srcSubresource.mipLevel = 0;
18053 copyRegion.srcSubresource.baseArrayLayer = 0;
18054 copyRegion.srcSubresource.layerCount = 0;
18055 copyRegion.srcOffset.x = 0;
18056 copyRegion.srcOffset.y = 0;
18057 copyRegion.srcOffset.z = 0;
18058 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18059 copyRegion.dstSubresource.mipLevel = 0;
18060 copyRegion.dstSubresource.baseArrayLayer = 0;
18061 copyRegion.dstSubresource.layerCount = 0;
18062 copyRegion.dstOffset.x = 0;
18063 copyRegion.dstOffset.y = 0;
18064 copyRegion.dstOffset.z = 0;
18065 copyRegion.extent.width = 1;
18066 copyRegion.extent.height = 1;
18067 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018068 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018069 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060018070
18071 m_errorMonitor->VerifyFound();
18072
18073 vkDestroyImage(m_device->device(), srcImage, NULL);
18074 vkDestroyImage(m_device->device(), dstImage, NULL);
18075 vkFreeMemory(m_device->device(), srcMem, NULL);
18076 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018077}
18078
Karl Schultz6addd812016-02-02 17:17:23 -070018079TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
18080 VkResult err;
18081 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018082
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018083 // Create a depth image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18085 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018086
Tony Barbour1fa09702017-03-16 12:09:08 -060018087 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018088 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018089 if (!depth_format) {
18090 return;
18091 }
Mike Stroyana3082432015-09-25 13:39:21 -060018092
18093 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018094 VkImage srcImage;
18095 VkImage dstImage;
18096 VkDeviceMemory srcMem;
18097 VkDeviceMemory destMem;
18098 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018099
18100 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018101 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18102 image_create_info.pNext = NULL;
18103 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018104 image_create_info.format = VK_FORMAT_D32_SFLOAT;
Karl Schultz6addd812016-02-02 17:17:23 -070018105 image_create_info.extent.width = 32;
18106 image_create_info.extent.height = 32;
18107 image_create_info.extent.depth = 1;
18108 image_create_info.mipLevels = 1;
18109 image_create_info.arrayLayers = 1;
18110 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Youngad61f4b2017-04-07 08:59:56 -060018111 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -070018112 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18113 image_create_info.flags = 0;
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018114 VkFormatProperties properties;
18115 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), image_create_info.format, &properties);
18116 if (properties.optimalTilingFeatures == 0) {
18117 printf(" Image format not supported; skipped.\n");
18118 return;
18119 }
Mike Stroyana3082432015-09-25 13:39:21 -060018120
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018121 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018122 ASSERT_VK_SUCCESS(err);
18123
Karl Schultzbdb75952016-04-19 11:36:49 -060018124 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18125
Mark Lobodzinskidb117632016-03-31 10:45:56 -060018126 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070018127 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070018128 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060018129 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018131 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018132 ASSERT_VK_SUCCESS(err);
18133
18134 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018135 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018136 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18137 memAlloc.pNext = NULL;
18138 memAlloc.allocationSize = 0;
18139 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018140
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018141 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018142 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018143 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018144 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018145 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018146 ASSERT_VK_SUCCESS(err);
18147
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018148 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018149 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018150 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018151 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018152 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018153 ASSERT_VK_SUCCESS(err);
18154
18155 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18156 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018157 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018158 ASSERT_VK_SUCCESS(err);
18159
Tony Barbour552f6c02016-12-21 14:34:07 -070018160 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018161 VkImageCopy copyRegion;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018162 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018163 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018164 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018165 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018166 copyRegion.srcOffset.x = 0;
18167 copyRegion.srcOffset.y = 0;
18168 copyRegion.srcOffset.z = 0;
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018169 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018170 copyRegion.dstSubresource.mipLevel = 0;
18171 copyRegion.dstSubresource.baseArrayLayer = 0;
18172 copyRegion.dstSubresource.layerCount = 0;
18173 copyRegion.dstOffset.x = 0;
18174 copyRegion.dstOffset.y = 0;
18175 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018176 copyRegion.extent.width = 1;
18177 copyRegion.extent.height = 1;
18178 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018179 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018180 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018181
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018182 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018183
Chia-I Wuf7458c52015-10-26 21:10:41 +080018184 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018185 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018186 vkFreeMemory(m_device->device(), srcMem, NULL);
18187 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018188}
18189
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018190TEST_F(VkLayerTest, CopyImageSampleCountMismatch) {
18191 TEST_DESCRIPTION("Image copies with sample count mis-matches");
Dave Houlton33c22b72017-02-28 13:16:02 -070018192
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018193 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton33c22b72017-02-28 13:16:02 -070018194
18195 VkImageFormatProperties image_format_properties;
18196 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
18197 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
18198 &image_format_properties);
18199
18200 if ((0 == (VK_SAMPLE_COUNT_2_BIT & image_format_properties.sampleCounts)) ||
18201 (0 == (VK_SAMPLE_COUNT_4_BIT & image_format_properties.sampleCounts))) {
18202 printf(" Image multi-sample support not found; skipped.\n");
18203 return;
18204 }
18205
18206 VkImageCreateInfo ci;
18207 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18208 ci.pNext = NULL;
18209 ci.flags = 0;
18210 ci.imageType = VK_IMAGE_TYPE_2D;
18211 ci.format = VK_FORMAT_R8G8B8A8_UNORM;
18212 ci.extent = {128, 128, 1};
18213 ci.mipLevels = 1;
18214 ci.arrayLayers = 1;
18215 ci.samples = VK_SAMPLE_COUNT_1_BIT;
18216 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
18217 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
18218 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18219 ci.queueFamilyIndexCount = 0;
18220 ci.pQueueFamilyIndices = NULL;
18221 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18222
18223 VkImageObj image1(m_device);
18224 image1.init(&ci);
18225 ASSERT_TRUE(image1.initialized());
18226
18227 ci.samples = VK_SAMPLE_COUNT_2_BIT;
18228 VkImageObj image2(m_device);
18229 image2.init(&ci);
18230 ASSERT_TRUE(image2.initialized());
18231
18232 ci.samples = VK_SAMPLE_COUNT_4_BIT;
18233 VkImageObj image4(m_device);
18234 image4.init(&ci);
18235 ASSERT_TRUE(image4.initialized());
18236
18237 m_commandBuffer->BeginCommandBuffer();
18238
18239 VkImageCopy copyRegion;
18240 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_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_COLOR_BIT;
18246 copyRegion.dstSubresource.mipLevel = 0;
18247 copyRegion.dstSubresource.baseArrayLayer = 0;
18248 copyRegion.dstSubresource.layerCount = 1;
18249 copyRegion.dstOffset = {0, 0, 0};
18250 copyRegion.extent = {128, 128, 1};
18251
18252 // Copy a single sample image to/from a multi-sample image
18253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18254 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image1.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18255 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18256 m_errorMonitor->VerifyFound();
18257
18258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18259 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image1.handle(),
18260 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18261 m_errorMonitor->VerifyFound();
18262
18263 // Copy between multi-sample images with different sample counts
18264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18265 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image2.handle(), VK_IMAGE_LAYOUT_GENERAL, image4.handle(),
18266 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18267 m_errorMonitor->VerifyFound();
18268
18269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01185);
18270 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), image4.handle(), VK_IMAGE_LAYOUT_GENERAL, image2.handle(),
18271 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18272 m_errorMonitor->VerifyFound();
18273
18274 m_commandBuffer->EndCommandBuffer();
18275}
18276
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018277TEST_F(VkLayerTest, CopyImageAspectMismatch) {
18278 TEST_DESCRIPTION("Image copies with aspect mask errors");
Mark Lobodzinski77e590c2017-03-17 12:05:16 -060018279 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018280 auto ds_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060018281 if (!ds_format) {
18282 return;
18283 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018284
Tobin Ehlis6d4d1d52017-04-05 12:06:10 -060018285 VkFormatProperties properties;
18286 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT, &properties);
18287 if (properties.optimalTilingFeatures == 0) {
18288 printf(" Image format VK_FORMAT_D32_SFLOAT not supported; skipped.\n");
18289 return;
18290 }
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018291 VkImageObj color_image(m_device), ds_image(m_device), depth_image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018292 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 -060018293 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 -060018294 VK_IMAGE_TILING_OPTIMAL, 0);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060018295 ds_image.Init(128, 128, 1, ds_format, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
18296 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018297 ASSERT_TRUE(color_image.initialized());
18298 ASSERT_TRUE(depth_image.initialized());
18299 ASSERT_TRUE(ds_image.initialized());
18300
18301 VkImageCopy copyRegion;
18302 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18303 copyRegion.srcSubresource.mipLevel = 0;
18304 copyRegion.srcSubresource.baseArrayLayer = 0;
18305 copyRegion.srcSubresource.layerCount = 1;
18306 copyRegion.srcOffset = {0, 0, 0};
18307 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18308 copyRegion.dstSubresource.mipLevel = 0;
18309 copyRegion.dstSubresource.baseArrayLayer = 0;
18310 copyRegion.dstSubresource.layerCount = 1;
18311 copyRegion.dstOffset = {64, 0, 0};
18312 copyRegion.extent = {64, 128, 1};
18313
18314 // Submitting command before command buffer is in recording state
Dave Houlton3c9fca72017-03-27 17:25:54 -060018315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18316 "You must call vkBeginCommandBuffer"); // VALIDATION_ERROR_01192);
18317 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), depth_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18318 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018319 m_errorMonitor->VerifyFound();
18320
18321 m_commandBuffer->BeginCommandBuffer();
18322
18323 // Src and dest aspect masks don't match
18324 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
18325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01197);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018326 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, ds_image.handle(),
18327 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018328 m_errorMonitor->VerifyFound();
18329 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18330
18331 // Illegal combinations of aspect bits - VU 01221
Dave Houlton3c9fca72017-03-27 17:25:54 -060018332 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; // color must be alone
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018333 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
18334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01221);
18335 // These aspect/format mismatches are redundant but unavoidable here
18336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
Dave Houlton3c9fca72017-03-27 17:25:54 -060018338 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18339 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018340 m_errorMonitor->VerifyFound();
18341 // Metadata aspect is illegal - VU 01222
18342 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18343 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
18344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01222);
18345 // These aspect/format mismatches are redundant but unavoidable here
Dave Houlton3c9fca72017-03-27 17:25:54 -060018346 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, color_image.handle(),
18347 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Dave Houlton4eaaf3a2017-03-14 11:31:20 -060018348 m_errorMonitor->VerifyFound();
18349
18350 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18351 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
18352
18353 // Aspect mask doesn't match source image format - VU 01200
18354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01200);
18355 // Again redundant but unavoidable when provoking vu01200 w/o vu01201
18356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18357 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18358 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18359 m_errorMonitor->VerifyFound();
18360
18361 // Aspect mask doesn't match dest image format - VU 01201
18362 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18363 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01201);
18365 // Again redundant but unavoidable when provoking vu01201 w/o vu01200
18366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "unmatched source and dest image depth/stencil formats");
18367 vkCmdCopyImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, depth_image.handle(),
18368 VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
18369 m_errorMonitor->VerifyFound();
18370
18371 m_commandBuffer->EndCommandBuffer();
18372}
18373
Karl Schultz6addd812016-02-02 17:17:23 -070018374TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
18375 VkResult err;
18376 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018377
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18379 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018380
Tony Barbour1fa09702017-03-16 12:09:08 -060018381 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018382
18383 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018384 VkImage srcImage;
18385 VkImage dstImage;
18386 VkDeviceMemory srcMem;
18387 VkDeviceMemory destMem;
18388 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018389
18390 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018391 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18392 image_create_info.pNext = NULL;
18393 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18394 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18395 image_create_info.extent.width = 32;
18396 image_create_info.extent.height = 1;
18397 image_create_info.extent.depth = 1;
18398 image_create_info.mipLevels = 1;
18399 image_create_info.arrayLayers = 1;
18400 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18401 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18402 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18403 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018405 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018406 ASSERT_VK_SUCCESS(err);
18407
Karl Schultz6addd812016-02-02 17:17:23 -070018408 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018409
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018410 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018411 ASSERT_VK_SUCCESS(err);
18412
18413 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018414 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018415 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18416 memAlloc.pNext = NULL;
18417 memAlloc.allocationSize = 0;
18418 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018419
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018420 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018421 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018422 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018423 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018424 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018425 ASSERT_VK_SUCCESS(err);
18426
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018427 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018428 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018429 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018430 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018431 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018432 ASSERT_VK_SUCCESS(err);
18433
18434 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18435 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018436 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018437 ASSERT_VK_SUCCESS(err);
18438
Tony Barbour552f6c02016-12-21 14:34:07 -070018439 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018440 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018441 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18442 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018443 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018444 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018445 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018446 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018447 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018448 resolveRegion.srcOffset.x = 0;
18449 resolveRegion.srcOffset.y = 0;
18450 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018451 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018452 resolveRegion.dstSubresource.mipLevel = 0;
18453 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018454 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018455 resolveRegion.dstOffset.x = 0;
18456 resolveRegion.dstOffset.y = 0;
18457 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018458 resolveRegion.extent.width = 1;
18459 resolveRegion.extent.height = 1;
18460 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018461 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018462 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018463
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018464 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018465
Chia-I Wuf7458c52015-10-26 21:10:41 +080018466 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018467 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018468 vkFreeMemory(m_device->device(), srcMem, NULL);
18469 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018470}
18471
Karl Schultz6addd812016-02-02 17:17:23 -070018472TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
18473 VkResult err;
18474 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018475
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18477 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018478
Tony Barbour1fa09702017-03-16 12:09:08 -060018479 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018480
Chris Forbesa7530692016-05-08 12:35:39 +120018481 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070018482 VkImage srcImage;
18483 VkImage dstImage;
18484 VkDeviceMemory srcMem;
18485 VkDeviceMemory destMem;
18486 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018487
18488 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018489 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18490 image_create_info.pNext = NULL;
18491 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18492 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18493 image_create_info.extent.width = 32;
18494 image_create_info.extent.height = 1;
18495 image_create_info.extent.depth = 1;
18496 image_create_info.mipLevels = 1;
18497 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120018498 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018499 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18500 // Note: Some implementations expect color attachment usage for any
18501 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018502 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018503 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018504
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018505 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018506 ASSERT_VK_SUCCESS(err);
18507
Karl Schultz6addd812016-02-02 17:17:23 -070018508 // Note: Some implementations expect color attachment usage for any
18509 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018510 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018511
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018512 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018513 ASSERT_VK_SUCCESS(err);
18514
18515 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018516 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018517 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18518 memAlloc.pNext = NULL;
18519 memAlloc.allocationSize = 0;
18520 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018521
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018522 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018523 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018524 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018525 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018526 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018527 ASSERT_VK_SUCCESS(err);
18528
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018529 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018530 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018531 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018532 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018533 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018534 ASSERT_VK_SUCCESS(err);
18535
18536 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18537 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018538 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018539 ASSERT_VK_SUCCESS(err);
18540
Tony Barbour552f6c02016-12-21 14:34:07 -070018541 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018542 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018543 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18544 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018545 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018546 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018547 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018548 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018549 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018550 resolveRegion.srcOffset.x = 0;
18551 resolveRegion.srcOffset.y = 0;
18552 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018553 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018554 resolveRegion.dstSubresource.mipLevel = 0;
18555 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018556 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018557 resolveRegion.dstOffset.x = 0;
18558 resolveRegion.dstOffset.y = 0;
18559 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018560 resolveRegion.extent.width = 1;
18561 resolveRegion.extent.height = 1;
18562 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018563 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018564 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018565
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018566 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018567
Chia-I Wuf7458c52015-10-26 21:10:41 +080018568 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018569 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018570 vkFreeMemory(m_device->device(), srcMem, NULL);
18571 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018572}
18573
Karl Schultz6addd812016-02-02 17:17:23 -070018574TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
18575 VkResult err;
18576 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018577
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018579 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018580
Tony Barbour1fa09702017-03-16 12:09:08 -060018581 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018582
18583 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018584 VkImage srcImage;
18585 VkImage dstImage;
18586 VkDeviceMemory srcMem;
18587 VkDeviceMemory destMem;
18588 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018589
18590 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018591 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18592 image_create_info.pNext = NULL;
18593 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18594 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18595 image_create_info.extent.width = 32;
18596 image_create_info.extent.height = 1;
18597 image_create_info.extent.depth = 1;
18598 image_create_info.mipLevels = 1;
18599 image_create_info.arrayLayers = 1;
18600 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18601 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18602 // Note: Some implementations expect color attachment usage for any
18603 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018604 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018605 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018606
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018607 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018608 ASSERT_VK_SUCCESS(err);
18609
Karl Schultz6addd812016-02-02 17:17:23 -070018610 // Set format to something other than source image
18611 image_create_info.format = VK_FORMAT_R32_SFLOAT;
18612 // Note: Some implementations expect color attachment usage for any
18613 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018614 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018615 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018616
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018617 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018618 ASSERT_VK_SUCCESS(err);
18619
18620 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018621 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018622 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18623 memAlloc.pNext = NULL;
18624 memAlloc.allocationSize = 0;
18625 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018626
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018627 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018628 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018629 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018630 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018631 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018632 ASSERT_VK_SUCCESS(err);
18633
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018634 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018635 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018636 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018637 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018638 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018639 ASSERT_VK_SUCCESS(err);
18640
18641 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18642 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018643 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018644 ASSERT_VK_SUCCESS(err);
18645
Tony Barbour552f6c02016-12-21 14:34:07 -070018646 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018647 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018648 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18649 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018650 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018651 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018652 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018653 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018654 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018655 resolveRegion.srcOffset.x = 0;
18656 resolveRegion.srcOffset.y = 0;
18657 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018658 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018659 resolveRegion.dstSubresource.mipLevel = 0;
18660 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018661 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018662 resolveRegion.dstOffset.x = 0;
18663 resolveRegion.dstOffset.y = 0;
18664 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018665 resolveRegion.extent.width = 1;
18666 resolveRegion.extent.height = 1;
18667 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018668 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018669 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018670
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018671 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018672
Chia-I Wuf7458c52015-10-26 21:10:41 +080018673 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018674 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018675 vkFreeMemory(m_device->device(), srcMem, NULL);
18676 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018677}
18678
Karl Schultz6addd812016-02-02 17:17:23 -070018679TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
18680 VkResult err;
18681 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060018682
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070018683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018684 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018685
Tony Barbour1fa09702017-03-16 12:09:08 -060018686 ASSERT_NO_FATAL_FAILURE(Init());
Mike Stroyana3082432015-09-25 13:39:21 -060018687
18688 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070018689 VkImage srcImage;
18690 VkImage dstImage;
18691 VkDeviceMemory srcMem;
18692 VkDeviceMemory destMem;
18693 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060018694
18695 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018696 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18697 image_create_info.pNext = NULL;
18698 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18699 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18700 image_create_info.extent.width = 32;
18701 image_create_info.extent.height = 1;
18702 image_create_info.extent.depth = 1;
18703 image_create_info.mipLevels = 1;
18704 image_create_info.arrayLayers = 1;
18705 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
18706 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18707 // Note: Some implementations expect color attachment usage for any
18708 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018709 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018710 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018711
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018712 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018713 ASSERT_VK_SUCCESS(err);
18714
Karl Schultz6addd812016-02-02 17:17:23 -070018715 image_create_info.imageType = VK_IMAGE_TYPE_1D;
18716 // Note: Some implementations expect color attachment usage for any
18717 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018718 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018719 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018721 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060018722 ASSERT_VK_SUCCESS(err);
18723
18724 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018725 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018726 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18727 memAlloc.pNext = NULL;
18728 memAlloc.allocationSize = 0;
18729 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018730
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060018731 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018732 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018733 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018734 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018735 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018736 ASSERT_VK_SUCCESS(err);
18737
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018738 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060018739 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018740 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060018741 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018742 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060018743 ASSERT_VK_SUCCESS(err);
18744
18745 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
18746 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018747 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060018748 ASSERT_VK_SUCCESS(err);
18749
Tony Barbour552f6c02016-12-21 14:34:07 -070018750 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018751 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070018752 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
18753 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060018754 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018755 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060018756 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060018757 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018758 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060018759 resolveRegion.srcOffset.x = 0;
18760 resolveRegion.srcOffset.y = 0;
18761 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080018762 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018763 resolveRegion.dstSubresource.mipLevel = 0;
18764 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130018765 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018766 resolveRegion.dstOffset.x = 0;
18767 resolveRegion.dstOffset.y = 0;
18768 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060018769 resolveRegion.extent.width = 1;
18770 resolveRegion.extent.height = 1;
18771 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018772 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070018773 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060018774
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018775 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060018776
Chia-I Wuf7458c52015-10-26 21:10:41 +080018777 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018778 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018779 vkFreeMemory(m_device->device(), srcMem, NULL);
18780 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060018781}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018782
Karl Schultz6addd812016-02-02 17:17:23 -070018783TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018784 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070018785 // to using a DS format, then cause it to hit error due to COLOR_BIT not
18786 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018787 // The image format check comes 2nd in validation so we trigger it first,
18788 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070018789 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18792 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018793
Tony Barbour1fa09702017-03-16 12:09:08 -060018794 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018795 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018796 if (!depth_format) {
18797 return;
18798 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018799
Chia-I Wu1b99bb22015-10-27 19:25:11 +080018800 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018801 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18802 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018803
18804 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018805 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18806 ds_pool_ci.pNext = NULL;
18807 ds_pool_ci.maxSets = 1;
18808 ds_pool_ci.poolSizeCount = 1;
18809 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018810
18811 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018812 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018813 ASSERT_VK_SUCCESS(err);
18814
18815 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018816 dsl_binding.binding = 0;
18817 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18818 dsl_binding.descriptorCount = 1;
18819 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18820 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018821
18822 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018823 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18824 ds_layout_ci.pNext = NULL;
18825 ds_layout_ci.bindingCount = 1;
18826 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018827 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018828 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018829 ASSERT_VK_SUCCESS(err);
18830
18831 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080018832 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080018833 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070018834 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018835 alloc_info.descriptorPool = ds_pool;
18836 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018837 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018838 ASSERT_VK_SUCCESS(err);
18839
Karl Schultz6addd812016-02-02 17:17:23 -070018840 VkImage image_bad;
18841 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018842 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070018843 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018844 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070018845 const int32_t tex_width = 32;
18846 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018847
18848 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070018849 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18850 image_create_info.pNext = NULL;
18851 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18852 image_create_info.format = tex_format_bad;
18853 image_create_info.extent.width = tex_width;
18854 image_create_info.extent.height = tex_height;
18855 image_create_info.extent.depth = 1;
18856 image_create_info.mipLevels = 1;
18857 image_create_info.arrayLayers = 1;
18858 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18859 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018860 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070018861 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018862
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018863 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018864 ASSERT_VK_SUCCESS(err);
18865 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018866 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
18867 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018868 ASSERT_VK_SUCCESS(err);
18869
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018870 // ---Bind image memory---
18871 VkMemoryRequirements img_mem_reqs;
18872 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
18873 VkMemoryAllocateInfo image_alloc_info = {};
18874 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18875 image_alloc_info.pNext = NULL;
18876 image_alloc_info.memoryTypeIndex = 0;
18877 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018878 bool pass =
18879 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 -070018880 ASSERT_TRUE(pass);
18881 VkDeviceMemory mem;
18882 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
18883 ASSERT_VK_SUCCESS(err);
18884 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
18885 ASSERT_VK_SUCCESS(err);
18886 // -----------------------
18887
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018888 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130018889 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070018890 image_view_create_info.image = image_bad;
18891 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18892 image_view_create_info.format = tex_format_bad;
18893 image_view_create_info.subresourceRange.baseArrayLayer = 0;
18894 image_view_create_info.subresourceRange.baseMipLevel = 0;
18895 image_view_create_info.subresourceRange.layerCount = 1;
18896 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018897 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018898
18899 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018900 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060018901
Chris Forbes8f36a8a2016-04-07 13:21:07 +120018902 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018903
Chia-I Wuf7458c52015-10-26 21:10:41 +080018904 vkDestroyImage(m_device->device(), image_bad, NULL);
18905 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080018906 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18907 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070018908
18909 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060018910}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018911
18912TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018913 TEST_DESCRIPTION(
18914 "Call ClearColorImage w/ a depth|stencil image and "
18915 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018916
Tony Barbour1fa09702017-03-16 12:09:08 -060018917 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060018918 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070018919 if (!depth_format) {
18920 return;
18921 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18923
Tony Barbour552f6c02016-12-21 14:34:07 -070018924 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018925
18926 // Color image
18927 VkClearColorValue clear_color;
18928 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
18929 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
18930 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
18931 const int32_t img_width = 32;
18932 const int32_t img_height = 32;
18933 VkImageCreateInfo image_create_info = {};
18934 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18935 image_create_info.pNext = NULL;
18936 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18937 image_create_info.format = color_format;
18938 image_create_info.extent.width = img_width;
18939 image_create_info.extent.height = img_height;
18940 image_create_info.extent.depth = 1;
18941 image_create_info.mipLevels = 1;
18942 image_create_info.arrayLayers = 1;
18943 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18944 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
18945 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18946
18947 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018948 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018949
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018950 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018951
18952 // Depth/Stencil image
18953 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018954 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018955 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
18956 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070018957 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018958 ds_image_create_info.extent.width = 64;
18959 ds_image_create_info.extent.height = 64;
18960 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070018961 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 -060018962
18963 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018964 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018965
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018966 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 -060018967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018969
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018970 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018971 &color_range);
18972
18973 m_errorMonitor->VerifyFound();
18974
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18976 "vkCmdClearColorImage called with "
18977 "image created without "
18978 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060018979
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070018980 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060018981 &color_range);
18982
18983 m_errorMonitor->VerifyFound();
18984
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018985 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060018986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18987 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018988
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018989 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
18990 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060018991
18992 m_errorMonitor->VerifyFound();
18993}
Tobin Ehliscde08892015-09-22 10:11:37 -060018994
Mike Schuchardt35fece12017-03-07 14:40:28 -070018995TEST_F(VkLayerTest, CommandQueueFlags) {
18996 TEST_DESCRIPTION(
18997 "Allocate a command buffer on a queue that does not support graphics and try to issue a "
18998 "graphics-only command");
18999
19000 ASSERT_NO_FATAL_FAILURE(Init());
19001
19002 uint32_t queueFamilyIndex = m_device->QueueFamilyWithoutCapabilities(VK_QUEUE_GRAPHICS_BIT);
Dave Houlton3c9fca72017-03-27 17:25:54 -060019003 if (queueFamilyIndex == UINT32_MAX) {
Mike Schuchardt35fece12017-03-07 14:40:28 -070019004 printf(" Non-graphics queue family not found; skipped.\n");
19005 return;
19006 } else {
19007 // Create command pool on a non-graphics queue
19008 VkCommandPoolObj command_pool(m_device, queueFamilyIndex);
19009
19010 // Setup command buffer on pool
19011 VkCommandBufferObj command_buffer(m_device, &command_pool);
19012 command_buffer.BeginCommandBuffer();
19013
19014 // Issue a graphics only command
19015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01446);
19016 VkViewport viewport = {0, 0, 16, 16, 0, 1};
19017 command_buffer.SetViewport(0, 1, &viewport);
19018 m_errorMonitor->VerifyFound();
19019 }
19020}
19021
Mark Lobodzinskib8359282017-05-16 09:17:51 -060019022TEST_F(VkLayerTest, ExecuteUnrecordedCBs) {
19023 TEST_DESCRIPTION(
19024 "Attempt vkCmdExecuteCommands and then QueueSubmit with an unrecorded secondary and primary command buffer, respectively");
19025
19026 ASSERT_NO_FATAL_FAILURE(Init());
19027 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00155);
19029 // Allocate a secondary command buffer
19030 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19031 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19032 command_buffer_allocate_info.commandPool = m_commandPool->handle();
19033 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19034 command_buffer_allocate_info.commandBufferCount = 1;
19035 VkCommandBuffer secondary_command_buffer;
19036 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19037 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19038 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19039 command_buffer_begin_info.flags =
19040 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19041 command_buffer_begin_info.pInheritanceInfo = nullptr;
19042
19043 // Now update primary cmd buffer to execute unrecorded secondary
19044 VkResult err = vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
19045 ASSERT_VK_SUCCESS(err);
19046 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19047 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
19048 vkCmdEndRenderPass(m_commandBuffer->handle());
19049 err = vkEndCommandBuffer(m_commandBuffer->handle());
19050 ASSERT_VK_SUCCESS(err);
19051 m_errorMonitor->VerifyFound();
19052
19053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00134);
19054 // Allocate a primary command buffer
19055 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19056 command_buffer_allocate_info.commandBufferCount = 1;
19057 VkCommandBuffer primary_command_buffer;
19058 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19059
19060 // And submit the unrecorded command buffer
19061 VkSubmitInfo submit_info = {};
19062 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19063 submit_info.commandBufferCount = 1;
19064 submit_info.pCommandBuffers = &primary_command_buffer;
19065 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19066 m_errorMonitor->VerifyFound();
19067}
19068
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019069// WSI Enabled Tests
19070//
Chris Forbes09368e42016-10-13 11:59:22 +130019071#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019072TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
19073
19074#if defined(VK_USE_PLATFORM_XCB_KHR)
19075 VkSurfaceKHR surface = VK_NULL_HANDLE;
19076
19077 VkResult err;
19078 bool pass;
19079 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
19080 VkSwapchainCreateInfoKHR swapchain_create_info = {};
19081 // uint32_t swapchain_image_count = 0;
19082 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
19083 // uint32_t image_index = 0;
19084 // VkPresentInfoKHR present_info = {};
19085
Tony Barbour1fa09702017-03-16 12:09:08 -060019086 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019087
19088 // Use the create function from one of the VK_KHR_*_surface extension in
19089 // order to create a surface, testing all known errors in the process,
19090 // before successfully creating a surface:
19091 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
19092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
19093 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
19094 pass = (err != VK_SUCCESS);
19095 ASSERT_TRUE(pass);
19096 m_errorMonitor->VerifyFound();
19097
19098 // Next, try to create a surface with the wrong
19099 // VkXcbSurfaceCreateInfoKHR::sType:
19100 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
19101 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19103 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19104 pass = (err != VK_SUCCESS);
19105 ASSERT_TRUE(pass);
19106 m_errorMonitor->VerifyFound();
19107
19108 // Create a native window, and then correctly create a surface:
19109 xcb_connection_t *connection;
19110 xcb_screen_t *screen;
19111 xcb_window_t xcb_window;
19112 xcb_intern_atom_reply_t *atom_wm_delete_window;
19113
19114 const xcb_setup_t *setup;
19115 xcb_screen_iterator_t iter;
19116 int scr;
19117 uint32_t value_mask, value_list[32];
19118 int width = 1;
19119 int height = 1;
19120
19121 connection = xcb_connect(NULL, &scr);
19122 ASSERT_TRUE(connection != NULL);
19123 setup = xcb_get_setup(connection);
19124 iter = xcb_setup_roots_iterator(setup);
19125 while (scr-- > 0)
19126 xcb_screen_next(&iter);
19127 screen = iter.data;
19128
19129 xcb_window = xcb_generate_id(connection);
19130
19131 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
19132 value_list[0] = screen->black_pixel;
19133 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
19134
19135 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
19136 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
19137
19138 /* Magic code that will send notification when window is destroyed */
19139 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
19140 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
19141
19142 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
19143 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
19144 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
19145 free(reply);
19146
19147 xcb_map_window(connection, xcb_window);
19148
19149 // Force the x/y coordinates to 100,100 results are identical in consecutive
19150 // runs
19151 const uint32_t coords[] = { 100, 100 };
19152 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
19153
19154 // Finally, try to correctly create a surface:
19155 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
19156 xcb_create_info.pNext = NULL;
19157 xcb_create_info.flags = 0;
19158 xcb_create_info.connection = connection;
19159 xcb_create_info.window = xcb_window;
19160 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
19161 pass = (err == VK_SUCCESS);
19162 ASSERT_TRUE(pass);
19163
19164 // Check if surface supports presentation:
19165
19166 // 1st, do so without having queried the queue families:
19167 VkBool32 supported = false;
19168 // TODO: Get the following error to come out:
19169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19170 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
19171 "function");
19172 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19173 pass = (err != VK_SUCCESS);
19174 // ASSERT_TRUE(pass);
19175 // m_errorMonitor->VerifyFound();
19176
19177 // Next, query a queue family index that's too large:
19178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19179 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
19180 pass = (err != VK_SUCCESS);
19181 ASSERT_TRUE(pass);
19182 m_errorMonitor->VerifyFound();
19183
19184 // Finally, do so correctly:
19185 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19186 // SUPPORTED
19187 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
19188 pass = (err == VK_SUCCESS);
19189 ASSERT_TRUE(pass);
19190
19191 // Before proceeding, try to create a swapchain without having called
19192 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
19193 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19194 swapchain_create_info.pNext = NULL;
19195 swapchain_create_info.flags = 0;
19196 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
19197 swapchain_create_info.surface = surface;
19198 swapchain_create_info.imageArrayLayers = 1;
19199 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
19200 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
19201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19202 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
19203 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19204 pass = (err != VK_SUCCESS);
19205 ASSERT_TRUE(pass);
19206 m_errorMonitor->VerifyFound();
19207
19208 // Get the surface capabilities:
19209 VkSurfaceCapabilitiesKHR surface_capabilities;
19210
19211 // Do so correctly (only error logged by this entrypoint is if the
19212 // extension isn't enabled):
19213 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
19214 pass = (err == VK_SUCCESS);
19215 ASSERT_TRUE(pass);
19216
19217 // Get the surface formats:
19218 uint32_t surface_format_count;
19219
19220 // First, try without a pointer to surface_format_count:
19221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
19222 "specified as NULL");
19223 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
19224 pass = (err == VK_SUCCESS);
19225 ASSERT_TRUE(pass);
19226 m_errorMonitor->VerifyFound();
19227
19228 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
19229 // correctly done a 1st try (to get the count):
19230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19231 surface_format_count = 0;
19232 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
19233 pass = (err == VK_SUCCESS);
19234 ASSERT_TRUE(pass);
19235 m_errorMonitor->VerifyFound();
19236
19237 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19238 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19239 pass = (err == VK_SUCCESS);
19240 ASSERT_TRUE(pass);
19241
19242 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19243 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
19244
19245 // Next, do a 2nd try with surface_format_count being set too high:
19246 surface_format_count += 5;
19247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19248 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19249 pass = (err == VK_SUCCESS);
19250 ASSERT_TRUE(pass);
19251 m_errorMonitor->VerifyFound();
19252
19253 // Finally, do a correct 1st and 2nd try:
19254 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
19255 pass = (err == VK_SUCCESS);
19256 ASSERT_TRUE(pass);
19257 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
19258 pass = (err == VK_SUCCESS);
19259 ASSERT_TRUE(pass);
19260
19261 // Get the surface present modes:
19262 uint32_t surface_present_mode_count;
19263
19264 // First, try without a pointer to surface_format_count:
19265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
19266 "specified as NULL");
19267
19268 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
19269 pass = (err == VK_SUCCESS);
19270 ASSERT_TRUE(pass);
19271 m_errorMonitor->VerifyFound();
19272
19273 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
19274 // correctly done a 1st try (to get the count):
19275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
19276 surface_present_mode_count = 0;
19277 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
19278 (VkPresentModeKHR *)&surface_present_mode_count);
19279 pass = (err == VK_SUCCESS);
19280 ASSERT_TRUE(pass);
19281 m_errorMonitor->VerifyFound();
19282
19283 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
19284 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19285 pass = (err == VK_SUCCESS);
19286 ASSERT_TRUE(pass);
19287
19288 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
19289 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
19290
19291 // Next, do a 2nd try with surface_format_count being set too high:
19292 surface_present_mode_count += 5;
19293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
19294 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19295 pass = (err == VK_SUCCESS);
19296 ASSERT_TRUE(pass);
19297 m_errorMonitor->VerifyFound();
19298
19299 // Finally, do a correct 1st and 2nd try:
19300 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
19301 pass = (err == VK_SUCCESS);
19302 ASSERT_TRUE(pass);
19303 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
19304 pass = (err == VK_SUCCESS);
19305 ASSERT_TRUE(pass);
19306
19307 // Create a swapchain:
19308
19309 // First, try without a pointer to swapchain_create_info:
19310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
19311 "specified as NULL");
19312
19313 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
19314 pass = (err != VK_SUCCESS);
19315 ASSERT_TRUE(pass);
19316 m_errorMonitor->VerifyFound();
19317
19318 // Next, call with a non-NULL swapchain_create_info, that has the wrong
19319 // sType:
19320 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
19321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
19322
19323 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19324 pass = (err != VK_SUCCESS);
19325 ASSERT_TRUE(pass);
19326 m_errorMonitor->VerifyFound();
19327
19328 // Next, call with a NULL swapchain pointer:
19329 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
19330 swapchain_create_info.pNext = NULL;
19331 swapchain_create_info.flags = 0;
19332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
19333 "specified as NULL");
19334
19335 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
19336 pass = (err != VK_SUCCESS);
19337 ASSERT_TRUE(pass);
19338 m_errorMonitor->VerifyFound();
19339
19340 // TODO: Enhance swapchain layer so that
19341 // swapchain_create_info.queueFamilyIndexCount is checked against something?
19342
19343 // Next, call with a queue family index that's too large:
19344 uint32_t queueFamilyIndex[2] = { 100000, 0 };
19345 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19346 swapchain_create_info.queueFamilyIndexCount = 2;
19347 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
19348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
19349 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19350 pass = (err != VK_SUCCESS);
19351 ASSERT_TRUE(pass);
19352 m_errorMonitor->VerifyFound();
19353
19354 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
19355 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
19356 swapchain_create_info.queueFamilyIndexCount = 1;
19357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19358 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
19359 "pCreateInfo->pQueueFamilyIndices).");
19360 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19361 pass = (err != VK_SUCCESS);
19362 ASSERT_TRUE(pass);
19363 m_errorMonitor->VerifyFound();
19364
19365 // Next, call with an invalid imageSharingMode:
19366 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
19367 swapchain_create_info.queueFamilyIndexCount = 1;
19368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19369 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
19370 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
19371 pass = (err != VK_SUCCESS);
19372 ASSERT_TRUE(pass);
19373 m_errorMonitor->VerifyFound();
19374 // Fix for the future:
19375 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
19376 // SUPPORTED
19377 swapchain_create_info.queueFamilyIndexCount = 0;
19378 queueFamilyIndex[0] = 0;
19379 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
19380
19381 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
19382 // Get the images from a swapchain:
19383 // Acquire an image from a swapchain:
19384 // Present an image to a swapchain:
19385 // Destroy the swapchain:
19386
19387 // TODOs:
19388 //
19389 // - Try destroying the device without first destroying the swapchain
19390 //
19391 // - Try destroying the device without first destroying the surface
19392 //
19393 // - Try destroying the surface without first destroying the swapchain
19394
19395 // Destroy the surface:
19396 vkDestroySurfaceKHR(instance(), surface, NULL);
19397
19398 // Tear down the window:
19399 xcb_destroy_window(connection, xcb_window);
19400 xcb_disconnect(connection);
19401
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019402#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019403 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019404#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019405}
Chris Forbes09368e42016-10-13 11:59:22 +130019406#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019407
19408//
19409// POSITIVE VALIDATION TESTS
19410//
19411// These tests do not expect to encounter ANY validation errors pass only if this is true
19412
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019413TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
19414 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
Tony Barbour1fa09702017-03-16 12:09:08 -060019415 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019416 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19417
19418 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19419 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019420 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070019421 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19422 command_buffer_allocate_info.commandBufferCount = 1;
19423
19424 VkCommandBuffer secondary_command_buffer;
19425 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19426 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19427 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19428 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19429 command_buffer_inheritance_info.renderPass = m_renderPass;
19430 command_buffer_inheritance_info.framebuffer = m_framebuffer;
19431
19432 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19433 command_buffer_begin_info.flags =
19434 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
19435 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19436
19437 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19438 VkClearAttachment color_attachment;
19439 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19440 color_attachment.clearValue.color.float32[0] = 0;
19441 color_attachment.clearValue.color.float32[1] = 0;
19442 color_attachment.clearValue.color.float32[2] = 0;
19443 color_attachment.clearValue.color.float32[3] = 0;
19444 color_attachment.colorAttachment = 0;
19445 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
19446 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
19447}
19448
Tobin Ehlise0006882016-11-03 10:14:28 -060019449TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019450 TEST_DESCRIPTION(
19451 "Perform an image layout transition in a secondary command buffer followed "
19452 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060019453 VkResult err;
19454 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060019455 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060019456 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070019457 if (!depth_format) {
19458 return;
19459 }
Tobin Ehlise0006882016-11-03 10:14:28 -060019460 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19461 // Allocate a secondary and primary cmd buffer
19462 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
19463 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mike Schuchardt06304c22017-03-01 17:09:09 -070019464 command_buffer_allocate_info.commandPool = m_commandPool->handle();
Tobin Ehlise0006882016-11-03 10:14:28 -060019465 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19466 command_buffer_allocate_info.commandBufferCount = 1;
19467
19468 VkCommandBuffer secondary_command_buffer;
19469 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
19470 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19471 VkCommandBuffer primary_command_buffer;
19472 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
19473 VkCommandBufferBeginInfo command_buffer_begin_info = {};
19474 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
19475 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19476 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19477 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
19478 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
19479
19480 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
19481 ASSERT_VK_SUCCESS(err);
19482 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060019483 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 -060019484 ASSERT_TRUE(image.initialized());
19485 VkImageMemoryBarrier img_barrier = {};
19486 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19487 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19488 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19489 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19490 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19491 img_barrier.image = image.handle();
19492 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19493 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19494 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19495 img_barrier.subresourceRange.baseArrayLayer = 0;
19496 img_barrier.subresourceRange.baseMipLevel = 0;
19497 img_barrier.subresourceRange.layerCount = 1;
19498 img_barrier.subresourceRange.levelCount = 1;
19499 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
19500 0, nullptr, 1, &img_barrier);
19501 err = vkEndCommandBuffer(secondary_command_buffer);
19502 ASSERT_VK_SUCCESS(err);
19503
19504 // Now update primary cmd buffer to execute secondary and transitions image
19505 command_buffer_begin_info.pInheritanceInfo = nullptr;
19506 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
19507 ASSERT_VK_SUCCESS(err);
19508 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
19509 VkImageMemoryBarrier img_barrier2 = {};
19510 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19511 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19512 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19513 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19514 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19515 img_barrier2.image = image.handle();
19516 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19517 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19518 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19519 img_barrier2.subresourceRange.baseArrayLayer = 0;
19520 img_barrier2.subresourceRange.baseMipLevel = 0;
19521 img_barrier2.subresourceRange.layerCount = 1;
19522 img_barrier2.subresourceRange.levelCount = 1;
19523 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
19524 nullptr, 1, &img_barrier2);
19525 err = vkEndCommandBuffer(primary_command_buffer);
19526 ASSERT_VK_SUCCESS(err);
19527 VkSubmitInfo submit_info = {};
19528 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19529 submit_info.commandBufferCount = 1;
19530 submit_info.pCommandBuffers = &primary_command_buffer;
19531 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19532 ASSERT_VK_SUCCESS(err);
19533 m_errorMonitor->VerifyNotFound();
19534 err = vkDeviceWaitIdle(m_device->device());
19535 ASSERT_VK_SUCCESS(err);
Mike Schuchardt06304c22017-03-01 17:09:09 -070019536 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &secondary_command_buffer);
19537 vkFreeCommandBuffers(m_device->device(), m_commandPool->handle(), 1, &primary_command_buffer);
Tobin Ehlise0006882016-11-03 10:14:28 -060019538}
19539
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019540// This is a positive test. No failures are expected.
19541TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019542 TEST_DESCRIPTION(
19543 "Ensure that the vkUpdateDescriptorSets validation code "
19544 "is ignoring VkWriteDescriptorSet members that are not "
19545 "related to the descriptor type specified by "
19546 "VkWriteDescriptorSet::descriptorType. Correct "
19547 "validation behavior will result in the test running to "
19548 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019549
19550 const uintptr_t invalid_ptr = 0xcdcdcdcd;
19551
Tony Barbour1fa09702017-03-16 12:09:08 -060019552 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019553
19554 // Image Case
19555 {
19556 m_errorMonitor->ExpectSuccess();
19557
19558 VkImage image;
19559 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
19560 const int32_t tex_width = 32;
19561 const int32_t tex_height = 32;
19562 VkImageCreateInfo image_create_info = {};
19563 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19564 image_create_info.pNext = NULL;
19565 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19566 image_create_info.format = tex_format;
19567 image_create_info.extent.width = tex_width;
19568 image_create_info.extent.height = tex_height;
19569 image_create_info.extent.depth = 1;
19570 image_create_info.mipLevels = 1;
19571 image_create_info.arrayLayers = 1;
19572 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19573 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19574 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
19575 image_create_info.flags = 0;
19576 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19577 ASSERT_VK_SUCCESS(err);
19578
19579 VkMemoryRequirements memory_reqs;
19580 VkDeviceMemory image_memory;
19581 bool pass;
19582 VkMemoryAllocateInfo memory_info = {};
19583 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19584 memory_info.pNext = NULL;
19585 memory_info.allocationSize = 0;
19586 memory_info.memoryTypeIndex = 0;
19587 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19588 memory_info.allocationSize = memory_reqs.size;
19589 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19590 ASSERT_TRUE(pass);
19591 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
19592 ASSERT_VK_SUCCESS(err);
19593 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
19594 ASSERT_VK_SUCCESS(err);
19595
19596 VkImageViewCreateInfo image_view_create_info = {};
19597 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19598 image_view_create_info.image = image;
19599 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
19600 image_view_create_info.format = tex_format;
19601 image_view_create_info.subresourceRange.layerCount = 1;
19602 image_view_create_info.subresourceRange.baseMipLevel = 0;
19603 image_view_create_info.subresourceRange.levelCount = 1;
19604 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19605
19606 VkImageView view;
19607 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
19608 ASSERT_VK_SUCCESS(err);
19609
19610 VkDescriptorPoolSize ds_type_count = {};
19611 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19612 ds_type_count.descriptorCount = 1;
19613
19614 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19615 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19616 ds_pool_ci.pNext = NULL;
19617 ds_pool_ci.maxSets = 1;
19618 ds_pool_ci.poolSizeCount = 1;
19619 ds_pool_ci.pPoolSizes = &ds_type_count;
19620
19621 VkDescriptorPool ds_pool;
19622 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19623 ASSERT_VK_SUCCESS(err);
19624
19625 VkDescriptorSetLayoutBinding dsl_binding = {};
19626 dsl_binding.binding = 0;
19627 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
19628 dsl_binding.descriptorCount = 1;
19629 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19630 dsl_binding.pImmutableSamplers = NULL;
19631
19632 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19633 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19634 ds_layout_ci.pNext = NULL;
19635 ds_layout_ci.bindingCount = 1;
19636 ds_layout_ci.pBindings = &dsl_binding;
19637 VkDescriptorSetLayout ds_layout;
19638 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19639 ASSERT_VK_SUCCESS(err);
19640
19641 VkDescriptorSet descriptor_set;
19642 VkDescriptorSetAllocateInfo alloc_info = {};
19643 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19644 alloc_info.descriptorSetCount = 1;
19645 alloc_info.descriptorPool = ds_pool;
19646 alloc_info.pSetLayouts = &ds_layout;
19647 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19648 ASSERT_VK_SUCCESS(err);
19649
19650 VkDescriptorImageInfo image_info = {};
19651 image_info.imageView = view;
19652 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
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_SAMPLED_IMAGE;
19661 descriptor_write.pImageInfo = &image_info;
19662
19663 // Set pBufferInfo and pTexelBufferView to invalid values, which should
19664 // be
19665 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
19666 // This will most likely produce a crash if the parameter_validation
19667 // layer
19668 // does not correctly ignore pBufferInfo.
19669 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(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
19676 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19677 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19678 vkDestroyImageView(m_device->device(), view, NULL);
19679 vkDestroyImage(m_device->device(), image, NULL);
19680 vkFreeMemory(m_device->device(), image_memory, NULL);
19681 }
19682
19683 // Buffer Case
19684 {
19685 m_errorMonitor->ExpectSuccess();
19686
19687 VkBuffer buffer;
19688 uint32_t queue_family_index = 0;
19689 VkBufferCreateInfo buffer_create_info = {};
19690 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19691 buffer_create_info.size = 1024;
19692 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19693 buffer_create_info.queueFamilyIndexCount = 1;
19694 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19695
19696 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19697 ASSERT_VK_SUCCESS(err);
19698
19699 VkMemoryRequirements memory_reqs;
19700 VkDeviceMemory buffer_memory;
19701 bool pass;
19702 VkMemoryAllocateInfo memory_info = {};
19703 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19704 memory_info.pNext = NULL;
19705 memory_info.allocationSize = 0;
19706 memory_info.memoryTypeIndex = 0;
19707
19708 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19709 memory_info.allocationSize = memory_reqs.size;
19710 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19711 ASSERT_TRUE(pass);
19712
19713 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19714 ASSERT_VK_SUCCESS(err);
19715 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19716 ASSERT_VK_SUCCESS(err);
19717
19718 VkDescriptorPoolSize ds_type_count = {};
19719 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19720 ds_type_count.descriptorCount = 1;
19721
19722 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19723 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19724 ds_pool_ci.pNext = NULL;
19725 ds_pool_ci.maxSets = 1;
19726 ds_pool_ci.poolSizeCount = 1;
19727 ds_pool_ci.pPoolSizes = &ds_type_count;
19728
19729 VkDescriptorPool ds_pool;
19730 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19731 ASSERT_VK_SUCCESS(err);
19732
19733 VkDescriptorSetLayoutBinding dsl_binding = {};
19734 dsl_binding.binding = 0;
19735 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19736 dsl_binding.descriptorCount = 1;
19737 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19738 dsl_binding.pImmutableSamplers = NULL;
19739
19740 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19741 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19742 ds_layout_ci.pNext = NULL;
19743 ds_layout_ci.bindingCount = 1;
19744 ds_layout_ci.pBindings = &dsl_binding;
19745 VkDescriptorSetLayout ds_layout;
19746 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19747 ASSERT_VK_SUCCESS(err);
19748
19749 VkDescriptorSet descriptor_set;
19750 VkDescriptorSetAllocateInfo alloc_info = {};
19751 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19752 alloc_info.descriptorSetCount = 1;
19753 alloc_info.descriptorPool = ds_pool;
19754 alloc_info.pSetLayouts = &ds_layout;
19755 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19756 ASSERT_VK_SUCCESS(err);
19757
19758 VkDescriptorBufferInfo buffer_info = {};
19759 buffer_info.buffer = buffer;
19760 buffer_info.offset = 0;
19761 buffer_info.range = 1024;
19762
19763 VkWriteDescriptorSet descriptor_write;
19764 memset(&descriptor_write, 0, sizeof(descriptor_write));
19765 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19766 descriptor_write.dstSet = descriptor_set;
19767 descriptor_write.dstBinding = 0;
19768 descriptor_write.descriptorCount = 1;
19769 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
19770 descriptor_write.pBufferInfo = &buffer_info;
19771
19772 // Set pImageInfo and pTexelBufferView to invalid values, which should
19773 // be
19774 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
19775 // This will most likely produce a crash if the parameter_validation
19776 // layer
19777 // does not correctly ignore pImageInfo.
19778 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
19779 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
19780
19781 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19782
19783 m_errorMonitor->VerifyNotFound();
19784
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019785 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19786 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19787 vkDestroyBuffer(m_device->device(), buffer, NULL);
19788 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19789 }
19790
19791 // Texel Buffer Case
19792 {
19793 m_errorMonitor->ExpectSuccess();
19794
19795 VkBuffer buffer;
19796 uint32_t queue_family_index = 0;
19797 VkBufferCreateInfo buffer_create_info = {};
19798 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19799 buffer_create_info.size = 1024;
19800 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
19801 buffer_create_info.queueFamilyIndexCount = 1;
19802 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
19803
19804 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
19805 ASSERT_VK_SUCCESS(err);
19806
19807 VkMemoryRequirements memory_reqs;
19808 VkDeviceMemory buffer_memory;
19809 bool pass;
19810 VkMemoryAllocateInfo memory_info = {};
19811 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19812 memory_info.pNext = NULL;
19813 memory_info.allocationSize = 0;
19814 memory_info.memoryTypeIndex = 0;
19815
19816 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
19817 memory_info.allocationSize = memory_reqs.size;
19818 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19819 ASSERT_TRUE(pass);
19820
19821 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
19822 ASSERT_VK_SUCCESS(err);
19823 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
19824 ASSERT_VK_SUCCESS(err);
19825
19826 VkBufferViewCreateInfo buff_view_ci = {};
19827 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
19828 buff_view_ci.buffer = buffer;
19829 buff_view_ci.format = VK_FORMAT_R8_UNORM;
19830 buff_view_ci.range = VK_WHOLE_SIZE;
19831 VkBufferView buffer_view;
19832 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
19833
19834 VkDescriptorPoolSize ds_type_count = {};
19835 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19836 ds_type_count.descriptorCount = 1;
19837
19838 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19839 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19840 ds_pool_ci.pNext = NULL;
19841 ds_pool_ci.maxSets = 1;
19842 ds_pool_ci.poolSizeCount = 1;
19843 ds_pool_ci.pPoolSizes = &ds_type_count;
19844
19845 VkDescriptorPool ds_pool;
19846 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19847 ASSERT_VK_SUCCESS(err);
19848
19849 VkDescriptorSetLayoutBinding dsl_binding = {};
19850 dsl_binding.binding = 0;
19851 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19852 dsl_binding.descriptorCount = 1;
19853 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
19854 dsl_binding.pImmutableSamplers = NULL;
19855
19856 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19857 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19858 ds_layout_ci.pNext = NULL;
19859 ds_layout_ci.bindingCount = 1;
19860 ds_layout_ci.pBindings = &dsl_binding;
19861 VkDescriptorSetLayout ds_layout;
19862 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19863 ASSERT_VK_SUCCESS(err);
19864
19865 VkDescriptorSet descriptor_set;
19866 VkDescriptorSetAllocateInfo alloc_info = {};
19867 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19868 alloc_info.descriptorSetCount = 1;
19869 alloc_info.descriptorPool = ds_pool;
19870 alloc_info.pSetLayouts = &ds_layout;
19871 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19872 ASSERT_VK_SUCCESS(err);
19873
19874 VkWriteDescriptorSet descriptor_write;
19875 memset(&descriptor_write, 0, sizeof(descriptor_write));
19876 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19877 descriptor_write.dstSet = descriptor_set;
19878 descriptor_write.dstBinding = 0;
19879 descriptor_write.descriptorCount = 1;
19880 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
19881 descriptor_write.pTexelBufferView = &buffer_view;
19882
19883 // Set pImageInfo and pBufferInfo to invalid values, which should be
19884 // ignored for descriptorType ==
19885 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
19886 // This will most likely produce a crash if the parameter_validation
19887 // layer
19888 // does not correctly ignore pImageInfo and pBufferInfo.
19889 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
19890 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
19891
19892 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19893
19894 m_errorMonitor->VerifyNotFound();
19895
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019896 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19897 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19898 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
19899 vkDestroyBuffer(m_device->device(), buffer, NULL);
19900 vkFreeMemory(m_device->device(), buffer_memory, NULL);
19901 }
19902}
19903
Tobin Ehlis8893af82017-05-08 12:52:25 -060019904TEST_F(VkPositiveLayerTest, ImmutableSamplerOnlyDescriptor) {
19905 TEST_DESCRIPTION(
19906 "Bind a DescriptorSet with only an immutable sampler"
19907 "and make sure that we don't warn for no update.");
19908
19909 ASSERT_NO_FATAL_FAILURE(Init());
19910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19911
19912 VkDescriptorPoolSize ds_type_count = {};
19913 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
19914 ds_type_count.descriptorCount = 1;
19915
19916 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19917 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19918 ds_pool_ci.maxSets = 1;
19919 ds_pool_ci.poolSizeCount = 1;
19920 ds_pool_ci.pPoolSizes = &ds_type_count;
19921
19922 VkDescriptorPool ds_pool;
19923 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19924 ASSERT_VK_SUCCESS(err);
19925
19926 VkSamplerCreateInfo sampler_ci = {};
19927 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
19928 sampler_ci.pNext = NULL;
19929 sampler_ci.magFilter = VK_FILTER_NEAREST;
19930 sampler_ci.minFilter = VK_FILTER_NEAREST;
19931 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
19932 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
19933 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
19934 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
19935 sampler_ci.mipLodBias = 1.0;
19936 sampler_ci.anisotropyEnable = VK_FALSE;
19937 sampler_ci.maxAnisotropy = 1;
19938 sampler_ci.compareEnable = VK_FALSE;
19939 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
19940 sampler_ci.minLod = 1.0;
19941 sampler_ci.maxLod = 1.0;
19942 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
19943 sampler_ci.unnormalizedCoordinates = VK_FALSE;
19944 VkSampler sampler;
19945
19946 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
19947 ASSERT_VK_SUCCESS(err);
19948
19949 VkDescriptorSetLayoutBinding layout_binding = {};
19950 layout_binding.binding = 0;
19951 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
19952 layout_binding.descriptorCount = 1;
19953 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19954 layout_binding.pImmutableSamplers = static_cast<VkSampler *>(&sampler);
19955
19956 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19957 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19958 ds_layout_ci.bindingCount = 1;
19959 ds_layout_ci.pBindings = &layout_binding;
19960 VkDescriptorSetLayout ds_layout;
19961 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19962 ASSERT_VK_SUCCESS(err);
19963
19964 VkDescriptorSetAllocateInfo alloc_info = {};
19965 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19966 alloc_info.descriptorSetCount = 1;
19967 alloc_info.descriptorPool = ds_pool;
19968 alloc_info.pSetLayouts = &ds_layout;
19969 VkDescriptorSet descriptor_set;
19970 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19971 ASSERT_VK_SUCCESS(err);
19972
19973 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19974 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19975 pipeline_layout_ci.pNext = NULL;
19976 pipeline_layout_ci.setLayoutCount = 1;
19977 pipeline_layout_ci.pSetLayouts = &ds_layout;
19978
19979 VkPipelineLayout pipeline_layout;
19980 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19981 ASSERT_VK_SUCCESS(err);
19982
19983 m_errorMonitor->ExpectSuccess();
19984 m_commandBuffer->BeginCommandBuffer();
19985 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
19986
19987 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
19988 &descriptor_set, 0, nullptr);
19989 m_errorMonitor->VerifyNotFound();
19990
19991 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19992 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19993 vkDestroySampler(m_device->device(), sampler, NULL);
19994 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19995}
19996
Tobin Ehlisf7428442016-10-25 07:58:24 -060019997TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
19998 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
19999
Tony Barbour1fa09702017-03-16 12:09:08 -060020000 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlisf7428442016-10-25 07:58:24 -060020001 // Create layout where two binding #s are "1"
20002 static const uint32_t NUM_BINDINGS = 3;
20003 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
20004 dsl_binding[0].binding = 1;
20005 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20006 dsl_binding[0].descriptorCount = 1;
20007 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20008 dsl_binding[0].pImmutableSamplers = NULL;
20009 dsl_binding[1].binding = 0;
20010 dsl_binding[1].descriptorCount = 1;
20011 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20012 dsl_binding[1].descriptorCount = 1;
20013 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20014 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020015 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060020016 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20017 dsl_binding[2].descriptorCount = 1;
20018 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20019 dsl_binding[2].pImmutableSamplers = NULL;
20020
20021 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20022 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20023 ds_layout_ci.pNext = NULL;
20024 ds_layout_ci.bindingCount = NUM_BINDINGS;
20025 ds_layout_ci.pBindings = dsl_binding;
20026 VkDescriptorSetLayout ds_layout;
20027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
20028 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20029 m_errorMonitor->VerifyFound();
20030}
20031
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060020032TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020033 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
20034
Tony Barbour1fa09702017-03-16 12:09:08 -060020035 ASSERT_NO_FATAL_FAILURE(Init());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020036
Tony Barbour552f6c02016-12-21 14:34:07 -070020037 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020038
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060020039 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
20040
20041 {
20042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
20043 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
20044 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20045 m_errorMonitor->VerifyFound();
20046 }
20047
20048 {
20049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
20050 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
20051 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20052 m_errorMonitor->VerifyFound();
20053 }
20054
20055 {
20056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
20057 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
20058 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20059 m_errorMonitor->VerifyFound();
20060 }
20061
20062 {
20063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
20064 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
20065 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20066 m_errorMonitor->VerifyFound();
20067 }
20068
20069 {
20070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
20071 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
20072 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20073 m_errorMonitor->VerifyFound();
20074 }
20075
20076 {
20077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
20078 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
20079 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
20080 m_errorMonitor->VerifyFound();
20081 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020082
20083 {
20084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
20085 VkRect2D scissor = {{-1, 0}, {16, 16}};
20086 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20087 m_errorMonitor->VerifyFound();
20088 }
20089
20090 {
20091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
20092 VkRect2D scissor = {{0, -2}, {16, 16}};
20093 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20094 m_errorMonitor->VerifyFound();
20095 }
20096
20097 {
20098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
20099 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
20100 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20101 m_errorMonitor->VerifyFound();
20102 }
20103
20104 {
20105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
20106 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
20107 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
20108 m_errorMonitor->VerifyFound();
20109 }
20110
Tony Barbour552f6c02016-12-21 14:34:07 -070020111 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060020112}
20113
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020114// This is a positive test. No failures are expected.
20115TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
20116 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
20117 VkResult err;
20118
Tony Barbour1fa09702017-03-16 12:09:08 -060020119 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020120 m_errorMonitor->ExpectSuccess();
20121 VkDescriptorPoolSize ds_type_count = {};
20122 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20123 ds_type_count.descriptorCount = 2;
20124
20125 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20126 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20127 ds_pool_ci.pNext = NULL;
20128 ds_pool_ci.maxSets = 1;
20129 ds_pool_ci.poolSizeCount = 1;
20130 ds_pool_ci.pPoolSizes = &ds_type_count;
20131
20132 VkDescriptorPool ds_pool;
20133 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20134 ASSERT_VK_SUCCESS(err);
20135
20136 // Create layout with two uniform buffer descriptors w/ empty binding between them
20137 static const uint32_t NUM_BINDINGS = 3;
20138 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
20139 dsl_binding[0].binding = 0;
20140 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20141 dsl_binding[0].descriptorCount = 1;
20142 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
20143 dsl_binding[0].pImmutableSamplers = NULL;
20144 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020145 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020146 dsl_binding[2].binding = 2;
20147 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20148 dsl_binding[2].descriptorCount = 1;
20149 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
20150 dsl_binding[2].pImmutableSamplers = NULL;
20151
20152 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20153 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20154 ds_layout_ci.pNext = NULL;
20155 ds_layout_ci.bindingCount = NUM_BINDINGS;
20156 ds_layout_ci.pBindings = dsl_binding;
20157 VkDescriptorSetLayout ds_layout;
20158 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20159 ASSERT_VK_SUCCESS(err);
20160
20161 VkDescriptorSet descriptor_set = {};
20162 VkDescriptorSetAllocateInfo alloc_info = {};
20163 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20164 alloc_info.descriptorSetCount = 1;
20165 alloc_info.descriptorPool = ds_pool;
20166 alloc_info.pSetLayouts = &ds_layout;
20167 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20168 ASSERT_VK_SUCCESS(err);
20169
20170 // Create a buffer to be used for update
20171 VkBufferCreateInfo buff_ci = {};
20172 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20173 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20174 buff_ci.size = 256;
20175 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20176 VkBuffer buffer;
20177 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
20178 ASSERT_VK_SUCCESS(err);
20179 // Have to bind memory to buffer before descriptor update
20180 VkMemoryAllocateInfo mem_alloc = {};
20181 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20182 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020183 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020184 mem_alloc.memoryTypeIndex = 0;
20185
20186 VkMemoryRequirements mem_reqs;
20187 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20188 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
20189 if (!pass) {
20190 vkDestroyBuffer(m_device->device(), buffer, NULL);
20191 return;
20192 }
20193
20194 VkDeviceMemory mem;
20195 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20196 ASSERT_VK_SUCCESS(err);
20197 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20198 ASSERT_VK_SUCCESS(err);
20199
20200 // Only update the descriptor at binding 2
20201 VkDescriptorBufferInfo buff_info = {};
20202 buff_info.buffer = buffer;
20203 buff_info.offset = 0;
20204 buff_info.range = VK_WHOLE_SIZE;
20205 VkWriteDescriptorSet descriptor_write = {};
20206 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20207 descriptor_write.dstBinding = 2;
20208 descriptor_write.descriptorCount = 1;
20209 descriptor_write.pTexelBufferView = nullptr;
20210 descriptor_write.pBufferInfo = &buff_info;
20211 descriptor_write.pImageInfo = nullptr;
20212 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
20213 descriptor_write.dstSet = descriptor_set;
20214
20215 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20216
20217 m_errorMonitor->VerifyNotFound();
20218 // Cleanup
20219 vkFreeMemory(m_device->device(), mem, NULL);
20220 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20221 vkDestroyBuffer(m_device->device(), buffer, NULL);
20222 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20223}
20224
20225// This is a positive test. No failures are expected.
20226TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
20227 VkResult err;
20228 bool pass;
20229
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020230 TEST_DESCRIPTION(
20231 "Create a buffer, allocate memory, bind memory, destroy "
20232 "the buffer, create an image, and bind the same memory to "
20233 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020234
20235 m_errorMonitor->ExpectSuccess();
20236
Tony Barbour1fa09702017-03-16 12:09:08 -060020237 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020238
20239 VkBuffer buffer;
20240 VkImage image;
20241 VkDeviceMemory mem;
20242 VkMemoryRequirements mem_reqs;
20243
20244 VkBufferCreateInfo buf_info = {};
20245 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20246 buf_info.pNext = NULL;
20247 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20248 buf_info.size = 256;
20249 buf_info.queueFamilyIndexCount = 0;
20250 buf_info.pQueueFamilyIndices = NULL;
20251 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20252 buf_info.flags = 0;
20253 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
20254 ASSERT_VK_SUCCESS(err);
20255
20256 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
20257
20258 VkMemoryAllocateInfo alloc_info = {};
20259 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20260 alloc_info.pNext = NULL;
20261 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020262
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020263 // Ensure memory is big enough for both bindings
20264 alloc_info.allocationSize = 0x10000;
20265
20266 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20267 if (!pass) {
20268 vkDestroyBuffer(m_device->device(), buffer, NULL);
20269 return;
20270 }
20271
20272 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20273 ASSERT_VK_SUCCESS(err);
20274
20275 uint8_t *pData;
20276 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
20277 ASSERT_VK_SUCCESS(err);
20278
20279 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
20280
20281 vkUnmapMemory(m_device->device(), mem);
20282
20283 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20284 ASSERT_VK_SUCCESS(err);
20285
20286 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
20287 // memory. In fact, it was never used by the GPU.
20288 // Just be be sure, wait for idle.
20289 vkDestroyBuffer(m_device->device(), buffer, NULL);
20290 vkDeviceWaitIdle(m_device->device());
20291
Tobin Ehlis6a005702016-12-28 15:25:56 -070020292 // Use optimal as some platforms report linear support but then fail image creation
20293 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
20294 VkImageFormatProperties image_format_properties;
20295 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
20296 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
20297 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020298 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070020299 vkFreeMemory(m_device->device(), mem, NULL);
20300 return;
20301 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020302 VkImageCreateInfo image_create_info = {};
20303 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
20304 image_create_info.pNext = NULL;
20305 image_create_info.imageType = VK_IMAGE_TYPE_2D;
20306 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
20307 image_create_info.extent.width = 64;
20308 image_create_info.extent.height = 64;
20309 image_create_info.extent.depth = 1;
20310 image_create_info.mipLevels = 1;
20311 image_create_info.arrayLayers = 1;
20312 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070020313 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020314 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
20315 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
20316 image_create_info.queueFamilyIndexCount = 0;
20317 image_create_info.pQueueFamilyIndices = NULL;
20318 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
20319 image_create_info.flags = 0;
20320
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020321 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070020322 * to be textures or it will be the staging image if they are not.
20323 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020324 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
20325 ASSERT_VK_SUCCESS(err);
20326
20327 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
20328
Tobin Ehlis6a005702016-12-28 15:25:56 -070020329 VkMemoryAllocateInfo mem_alloc = {};
20330 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20331 mem_alloc.pNext = NULL;
20332 mem_alloc.allocationSize = 0;
20333 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020334 mem_alloc.allocationSize = mem_reqs.size;
20335
20336 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
20337 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070020338 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020339 vkDestroyImage(m_device->device(), image, NULL);
20340 return;
20341 }
20342
20343 // VALIDATION FAILURE:
20344 err = vkBindImageMemory(m_device->device(), image, mem, 0);
20345 ASSERT_VK_SUCCESS(err);
20346
20347 m_errorMonitor->VerifyNotFound();
20348
20349 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020350 vkDestroyImage(m_device->device(), image, NULL);
20351}
20352
Tony Barbourab713912017-02-02 14:17:35 -070020353// This is a positive test. No failures are expected.
20354TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
20355 VkResult err;
20356
20357 TEST_DESCRIPTION(
20358 "Call all applicable destroy and free routines with NULL"
20359 "handles, expecting no validation errors");
20360
20361 m_errorMonitor->ExpectSuccess();
20362
Tony Barbour1fa09702017-03-16 12:09:08 -060020363 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbourab713912017-02-02 14:17:35 -070020364 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20365 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
20366 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
20367 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
20368 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20369 vkDestroyDevice(VK_NULL_HANDLE, NULL);
20370 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
20371 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
20372 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
20373 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
20374 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
20375 vkDestroyInstance(VK_NULL_HANDLE, NULL);
20376 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
20377 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
20378 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
20379 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
20380 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
20381 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
20382 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
20383 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
20384
20385 VkCommandPool command_pool;
20386 VkCommandPoolCreateInfo pool_create_info{};
20387 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20388 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20389 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20390 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20391 VkCommandBuffer command_buffers[3] = {};
20392 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20393 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20394 command_buffer_allocate_info.commandPool = command_pool;
20395 command_buffer_allocate_info.commandBufferCount = 1;
20396 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20397 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
20398 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
20399 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20400
20401 VkDescriptorPoolSize ds_type_count = {};
20402 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20403 ds_type_count.descriptorCount = 1;
20404
20405 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20406 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20407 ds_pool_ci.pNext = NULL;
20408 ds_pool_ci.maxSets = 1;
20409 ds_pool_ci.poolSizeCount = 1;
20410 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
20411 ds_pool_ci.pPoolSizes = &ds_type_count;
20412
20413 VkDescriptorPool ds_pool;
20414 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20415 ASSERT_VK_SUCCESS(err);
20416
20417 VkDescriptorSetLayoutBinding dsl_binding = {};
20418 dsl_binding.binding = 2;
20419 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20420 dsl_binding.descriptorCount = 1;
20421 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20422 dsl_binding.pImmutableSamplers = NULL;
20423 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20424 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20425 ds_layout_ci.pNext = NULL;
20426 ds_layout_ci.bindingCount = 1;
20427 ds_layout_ci.pBindings = &dsl_binding;
20428 VkDescriptorSetLayout ds_layout;
20429 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20430 ASSERT_VK_SUCCESS(err);
20431
20432 VkDescriptorSet descriptor_sets[3] = {};
20433 VkDescriptorSetAllocateInfo alloc_info = {};
20434 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20435 alloc_info.descriptorSetCount = 1;
20436 alloc_info.descriptorPool = ds_pool;
20437 alloc_info.pSetLayouts = &ds_layout;
20438 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
20439 ASSERT_VK_SUCCESS(err);
20440 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
20441 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20442 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20443
20444 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
20445
20446 m_errorMonitor->VerifyNotFound();
20447}
20448
Tony Barbour626994c2017-02-08 15:29:37 -070020449TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070020450 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070020451
20452 m_errorMonitor->ExpectSuccess();
20453
Tony Barbour1fa09702017-03-16 12:09:08 -060020454 ASSERT_NO_FATAL_FAILURE(Init());
Tony Barbour626994c2017-02-08 15:29:37 -070020455 VkCommandBuffer cmd_bufs[4];
20456 VkCommandBufferAllocateInfo alloc_info;
20457 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20458 alloc_info.pNext = NULL;
20459 alloc_info.commandBufferCount = 4;
Mike Schuchardt06304c22017-03-01 17:09:09 -070020460 alloc_info.commandPool = m_commandPool->handle();
Tony Barbour626994c2017-02-08 15:29:37 -070020461 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20462 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
20463 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020464 image.Init(128, 128, 1, VK_FORMAT_B8G8R8A8_UNORM,
Mike Weiblen62d08a32017-03-07 22:18:27 -070020465 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
20466 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070020467 ASSERT_TRUE(image.initialized());
20468 VkCommandBufferBeginInfo cb_binfo;
20469 cb_binfo.pNext = NULL;
20470 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20471 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
20472 cb_binfo.flags = 0;
20473 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
20474 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
20475 VkImageMemoryBarrier img_barrier = {};
20476 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20477 img_barrier.pNext = NULL;
20478 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20479 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20480 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20481 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
20482 img_barrier.image = image.handle();
20483 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20484 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20485 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20486 img_barrier.subresourceRange.baseArrayLayer = 0;
20487 img_barrier.subresourceRange.baseMipLevel = 0;
20488 img_barrier.subresourceRange.layerCount = 1;
20489 img_barrier.subresourceRange.levelCount = 1;
20490 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20491 &img_barrier);
20492 vkEndCommandBuffer(cmd_bufs[0]);
20493 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
20494 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
20495 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20496 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20497 &img_barrier);
20498 vkEndCommandBuffer(cmd_bufs[1]);
20499 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
20500 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20501 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20502 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20503 &img_barrier);
20504 vkEndCommandBuffer(cmd_bufs[2]);
20505 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
20506 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20507 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20508 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
20509 &img_barrier);
20510 vkEndCommandBuffer(cmd_bufs[3]);
20511
20512 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
20513 VkSemaphore semaphore1, semaphore2;
20514 VkSemaphoreCreateInfo semaphore_create_info{};
20515 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20516 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
20517 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
20518 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
20519 VkSubmitInfo submit_info[3];
20520 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20521 submit_info[0].pNext = nullptr;
20522 submit_info[0].commandBufferCount = 1;
20523 submit_info[0].pCommandBuffers = &cmd_bufs[0];
20524 submit_info[0].signalSemaphoreCount = 1;
20525 submit_info[0].pSignalSemaphores = &semaphore1;
20526 submit_info[0].waitSemaphoreCount = 0;
20527 submit_info[0].pWaitDstStageMask = nullptr;
20528 submit_info[0].pWaitDstStageMask = flags;
20529 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20530 submit_info[1].pNext = nullptr;
20531 submit_info[1].commandBufferCount = 1;
20532 submit_info[1].pCommandBuffers = &cmd_bufs[1];
20533 submit_info[1].waitSemaphoreCount = 1;
20534 submit_info[1].pWaitSemaphores = &semaphore1;
20535 submit_info[1].signalSemaphoreCount = 1;
20536 submit_info[1].pSignalSemaphores = &semaphore2;
20537 submit_info[1].pWaitDstStageMask = flags;
20538 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20539 submit_info[2].pNext = nullptr;
20540 submit_info[2].commandBufferCount = 2;
20541 submit_info[2].pCommandBuffers = &cmd_bufs[2];
20542 submit_info[2].waitSemaphoreCount = 1;
20543 submit_info[2].pWaitSemaphores = &semaphore2;
20544 submit_info[2].signalSemaphoreCount = 0;
20545 submit_info[2].pSignalSemaphores = nullptr;
20546 submit_info[2].pWaitDstStageMask = flags;
20547 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
20548 vkQueueWaitIdle(m_device->m_queue);
20549
20550 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
20551 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
20552 m_errorMonitor->VerifyNotFound();
20553}
20554
Tobin Ehlis953e8392016-11-17 10:54:13 -070020555TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
20556 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
20557 // We previously had a bug where dynamic offset of inactive bindings was still being used
20558 VkResult err;
20559 m_errorMonitor->ExpectSuccess();
20560
Tony Barbour1fa09702017-03-16 12:09:08 -060020561 ASSERT_NO_FATAL_FAILURE(Init());
Tobin Ehlis953e8392016-11-17 10:54:13 -070020562 ASSERT_NO_FATAL_FAILURE(InitViewport());
20563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20564
20565 VkDescriptorPoolSize ds_type_count = {};
20566 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20567 ds_type_count.descriptorCount = 3;
20568
20569 VkDescriptorPoolCreateInfo ds_pool_ci = {};
20570 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
20571 ds_pool_ci.pNext = NULL;
20572 ds_pool_ci.maxSets = 1;
20573 ds_pool_ci.poolSizeCount = 1;
20574 ds_pool_ci.pPoolSizes = &ds_type_count;
20575
20576 VkDescriptorPool ds_pool;
20577 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
20578 ASSERT_VK_SUCCESS(err);
20579
20580 const uint32_t BINDING_COUNT = 3;
20581 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020582 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020583 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20584 dsl_binding[0].descriptorCount = 1;
20585 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20586 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020587 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020588 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20589 dsl_binding[1].descriptorCount = 1;
20590 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20591 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070020592 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070020593 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20594 dsl_binding[2].descriptorCount = 1;
20595 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
20596 dsl_binding[2].pImmutableSamplers = NULL;
20597
20598 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
20599 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
20600 ds_layout_ci.pNext = NULL;
20601 ds_layout_ci.bindingCount = BINDING_COUNT;
20602 ds_layout_ci.pBindings = dsl_binding;
20603 VkDescriptorSetLayout ds_layout;
20604 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
20605 ASSERT_VK_SUCCESS(err);
20606
20607 VkDescriptorSet descriptor_set;
20608 VkDescriptorSetAllocateInfo alloc_info = {};
20609 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
20610 alloc_info.descriptorSetCount = 1;
20611 alloc_info.descriptorPool = ds_pool;
20612 alloc_info.pSetLayouts = &ds_layout;
20613 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
20614 ASSERT_VK_SUCCESS(err);
20615
20616 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20617 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20618 pipeline_layout_ci.pNext = NULL;
20619 pipeline_layout_ci.setLayoutCount = 1;
20620 pipeline_layout_ci.pSetLayouts = &ds_layout;
20621
20622 VkPipelineLayout pipeline_layout;
20623 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20624 ASSERT_VK_SUCCESS(err);
20625
20626 // Create two buffers to update the descriptors with
20627 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
20628 uint32_t qfi = 0;
20629 VkBufferCreateInfo buffCI = {};
20630 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20631 buffCI.size = 2048;
20632 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20633 buffCI.queueFamilyIndexCount = 1;
20634 buffCI.pQueueFamilyIndices = &qfi;
20635
20636 VkBuffer dyub1;
20637 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
20638 ASSERT_VK_SUCCESS(err);
20639 // buffer2
20640 buffCI.size = 1024;
20641 VkBuffer dyub2;
20642 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
20643 ASSERT_VK_SUCCESS(err);
20644 // Allocate memory and bind to buffers
20645 VkMemoryAllocateInfo mem_alloc[2] = {};
20646 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20647 mem_alloc[0].pNext = NULL;
20648 mem_alloc[0].memoryTypeIndex = 0;
20649 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20650 mem_alloc[1].pNext = NULL;
20651 mem_alloc[1].memoryTypeIndex = 0;
20652
20653 VkMemoryRequirements mem_reqs1;
20654 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
20655 VkMemoryRequirements mem_reqs2;
20656 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
20657 mem_alloc[0].allocationSize = mem_reqs1.size;
20658 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
20659 mem_alloc[1].allocationSize = mem_reqs2.size;
20660 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
20661 if (!pass) {
20662 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20663 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20664 return;
20665 }
20666
20667 VkDeviceMemory mem1;
20668 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
20669 ASSERT_VK_SUCCESS(err);
20670 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
20671 ASSERT_VK_SUCCESS(err);
20672 VkDeviceMemory mem2;
20673 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
20674 ASSERT_VK_SUCCESS(err);
20675 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
20676 ASSERT_VK_SUCCESS(err);
20677 // Update descriptors
20678 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
20679 buff_info[0].buffer = dyub1;
20680 buff_info[0].offset = 0;
20681 buff_info[0].range = 256;
20682 buff_info[1].buffer = dyub1;
20683 buff_info[1].offset = 256;
20684 buff_info[1].range = 512;
20685 buff_info[2].buffer = dyub2;
20686 buff_info[2].offset = 0;
20687 buff_info[2].range = 512;
20688
20689 VkWriteDescriptorSet descriptor_write;
20690 memset(&descriptor_write, 0, sizeof(descriptor_write));
20691 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
20692 descriptor_write.dstSet = descriptor_set;
20693 descriptor_write.dstBinding = 0;
20694 descriptor_write.descriptorCount = BINDING_COUNT;
20695 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
20696 descriptor_write.pBufferInfo = buff_info;
20697
20698 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
20699
Tony Barbour552f6c02016-12-21 14:34:07 -070020700 m_commandBuffer->BeginCommandBuffer();
20701 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070020702
20703 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020704 char const *vsSource =
20705 "#version 450\n"
20706 "\n"
20707 "out gl_PerVertex { \n"
20708 " vec4 gl_Position;\n"
20709 "};\n"
20710 "void main(){\n"
20711 " gl_Position = vec4(1);\n"
20712 "}\n";
20713 char const *fsSource =
20714 "#version 450\n"
20715 "\n"
20716 "layout(location=0) out vec4 x;\n"
20717 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
20718 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
20719 "void main(){\n"
20720 " x = vec4(bar1.y) + vec4(bar2.y);\n"
20721 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070020722 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20723 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20724 VkPipelineObj pipe(m_device);
20725 pipe.SetViewport(m_viewports);
20726 pipe.SetScissor(m_scissors);
20727 pipe.AddShader(&vs);
20728 pipe.AddShader(&fs);
20729 pipe.AddColorAttachment();
20730 pipe.CreateVKPipeline(pipeline_layout, renderPass());
20731
20732 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
20733 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
20734 // we used to have a bug in this case.
20735 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
20736 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
20737 &descriptor_set, BINDING_COUNT, dyn_off);
20738 Draw(1, 0, 0, 0);
20739 m_errorMonitor->VerifyNotFound();
20740
20741 vkDestroyBuffer(m_device->device(), dyub1, NULL);
20742 vkDestroyBuffer(m_device->device(), dyub2, NULL);
20743 vkFreeMemory(m_device->device(), mem1, NULL);
20744 vkFreeMemory(m_device->device(), mem2, NULL);
20745
20746 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20747 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
20748 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
20749}
20750
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020751TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020752 TEST_DESCRIPTION(
20753 "Ensure that validations handling of non-coherent memory "
20754 "mapping while using VK_WHOLE_SIZE does not cause access "
20755 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020756 VkResult err;
20757 uint8_t *pData;
Tony Barbour1fa09702017-03-16 12:09:08 -060020758 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020759
20760 VkDeviceMemory mem;
20761 VkMemoryRequirements mem_reqs;
20762 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020763 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020764 VkMemoryAllocateInfo alloc_info = {};
20765 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20766 alloc_info.pNext = NULL;
20767 alloc_info.memoryTypeIndex = 0;
20768
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020769 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020770 alloc_info.allocationSize = allocation_size;
20771
20772 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
20773 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 -070020774 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020775 if (!pass) {
20776 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020777 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
20778 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020779 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020780 pass = m_device->phy().set_memory_type(
20781 mem_reqs.memoryTypeBits, &alloc_info,
20782 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
20783 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020784 if (!pass) {
20785 return;
20786 }
20787 }
20788 }
20789
20790 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
20791 ASSERT_VK_SUCCESS(err);
20792
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020793 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020794 m_errorMonitor->ExpectSuccess();
20795 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
20796 ASSERT_VK_SUCCESS(err);
20797 VkMappedMemoryRange mmr = {};
20798 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20799 mmr.memory = mem;
20800 mmr.offset = 0;
20801 mmr.size = VK_WHOLE_SIZE;
20802 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20803 ASSERT_VK_SUCCESS(err);
20804 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20805 ASSERT_VK_SUCCESS(err);
20806 m_errorMonitor->VerifyNotFound();
20807 vkUnmapMemory(m_device->device(), mem);
20808
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020809 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020810 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020811 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020812 ASSERT_VK_SUCCESS(err);
20813 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20814 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020815 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020816 mmr.size = VK_WHOLE_SIZE;
20817 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20818 ASSERT_VK_SUCCESS(err);
20819 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20820 ASSERT_VK_SUCCESS(err);
20821 m_errorMonitor->VerifyNotFound();
20822 vkUnmapMemory(m_device->device(), mem);
20823
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020824 // Map with offset and size
20825 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020826 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020827 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020828 ASSERT_VK_SUCCESS(err);
20829 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20830 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020831 mmr.offset = 4 * atom_size;
20832 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020833 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20834 ASSERT_VK_SUCCESS(err);
20835 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
20836 ASSERT_VK_SUCCESS(err);
20837 m_errorMonitor->VerifyNotFound();
20838 vkUnmapMemory(m_device->device(), mem);
20839
20840 // Map without offset and flush WHOLE_SIZE with two separate offsets
20841 m_errorMonitor->ExpectSuccess();
20842 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
20843 ASSERT_VK_SUCCESS(err);
20844 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
20845 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020846 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020847 mmr.size = VK_WHOLE_SIZE;
20848 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20849 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070020850 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020851 mmr.size = VK_WHOLE_SIZE;
20852 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
20853 ASSERT_VK_SUCCESS(err);
20854 m_errorMonitor->VerifyNotFound();
20855 vkUnmapMemory(m_device->device(), mem);
20856
20857 vkFreeMemory(m_device->device(), mem, NULL);
20858}
20859
20860// This is a positive test. We used to expect error in this case but spec now allows it
20861TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
20862 m_errorMonitor->ExpectSuccess();
20863 vk_testing::Fence testFence;
20864 VkFenceCreateInfo fenceInfo = {};
20865 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20866 fenceInfo.pNext = NULL;
20867
Tony Barbour1fa09702017-03-16 12:09:08 -060020868 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020869 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020870 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020871 VkResult result = vkResetFences(m_device->device(), 1, fences);
20872 ASSERT_VK_SUCCESS(result);
20873
20874 m_errorMonitor->VerifyNotFound();
20875}
20876
20877TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
20878 m_errorMonitor->ExpectSuccess();
20879
Tony Barbour1fa09702017-03-16 12:09:08 -060020880 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020881 VkResult err;
20882
20883 // Record (empty!) command buffer that can be submitted multiple times
20884 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020885 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
20886 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020887 m_commandBuffer->BeginCommandBuffer(&cbbi);
20888 m_commandBuffer->EndCommandBuffer();
20889
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020890 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020891 VkFence fence;
20892 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20893 ASSERT_VK_SUCCESS(err);
20894
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020895 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020896 VkSemaphore s1, s2;
20897 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
20898 ASSERT_VK_SUCCESS(err);
20899 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
20900 ASSERT_VK_SUCCESS(err);
20901
20902 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020903 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020904 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20905 ASSERT_VK_SUCCESS(err);
20906
20907 // Submit CB again, signaling s2.
20908 si.pSignalSemaphores = &s2;
20909 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
20910 ASSERT_VK_SUCCESS(err);
20911
20912 // Wait for fence.
20913 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20914 ASSERT_VK_SUCCESS(err);
20915
20916 // CB is still in flight from second submission, but semaphore s1 is no
20917 // longer in flight. delete it.
20918 vkDestroySemaphore(m_device->device(), s1, nullptr);
20919
20920 m_errorMonitor->VerifyNotFound();
20921
20922 // Force device idle and clean up remaining objects
20923 vkDeviceWaitIdle(m_device->device());
20924 vkDestroySemaphore(m_device->device(), s2, nullptr);
20925 vkDestroyFence(m_device->device(), fence, nullptr);
20926}
20927
20928TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
20929 m_errorMonitor->ExpectSuccess();
20930
Tony Barbour1fa09702017-03-16 12:09:08 -060020931 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020932 VkResult err;
20933
20934 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020935 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020936 VkFence f1;
20937 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
20938 ASSERT_VK_SUCCESS(err);
20939
20940 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020941 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020942 VkFence f2;
20943 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
20944 ASSERT_VK_SUCCESS(err);
20945
20946 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020947 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020948 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
20949
20950 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020951 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020952 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
20953
20954 // Should have both retired!
20955 vkDestroyFence(m_device->device(), f1, nullptr);
20956 vkDestroyFence(m_device->device(), f2, nullptr);
20957
20958 m_errorMonitor->VerifyNotFound();
20959}
20960
20961TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020962 TEST_DESCRIPTION(
20963 "Verify that creating an image view from an image with valid usage "
20964 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020965
Tony Barbour1fa09702017-03-16 12:09:08 -060020966 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020967
20968 m_errorMonitor->ExpectSuccess();
20969 // Verify that we can create a view with usage INPUT_ATTACHMENT
20970 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060020971 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 -060020972 ASSERT_TRUE(image.initialized());
20973 VkImageView imageView;
20974 VkImageViewCreateInfo ivci = {};
20975 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
20976 ivci.image = image.handle();
20977 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
20978 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
20979 ivci.subresourceRange.layerCount = 1;
20980 ivci.subresourceRange.baseMipLevel = 0;
20981 ivci.subresourceRange.levelCount = 1;
20982 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20983
20984 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
20985 m_errorMonitor->VerifyNotFound();
20986 vkDestroyImageView(m_device->device(), imageView, NULL);
20987}
20988
20989// This is a positive test. No failures are expected.
20990TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020991 TEST_DESCRIPTION(
20992 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
20993 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020994
Tony Barbour1fa09702017-03-16 12:09:08 -060020995 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020996
20997 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020998 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Tony Barbour623721f2017-03-24 15:00:21 -060020999 if (!m_device->phy().features().sparseBinding) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021000
21001 m_errorMonitor->ExpectSuccess();
21002
21003 VkImage image;
21004 VkImageCreateInfo image_create_info = {};
21005 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
21006 image_create_info.pNext = NULL;
21007 image_create_info.imageType = VK_IMAGE_TYPE_2D;
21008 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
21009 image_create_info.extent.width = 64;
21010 image_create_info.extent.height = 64;
21011 image_create_info.extent.depth = 1;
21012 image_create_info.mipLevels = 1;
21013 image_create_info.arrayLayers = 1;
21014 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
21015 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
21016 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
21017 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
21018 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
21019 ASSERT_VK_SUCCESS(err);
21020
21021 VkMemoryRequirements memory_reqs;
21022 VkDeviceMemory memory_one, memory_two;
21023 bool pass;
21024 VkMemoryAllocateInfo memory_info = {};
21025 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21026 memory_info.pNext = NULL;
21027 memory_info.allocationSize = 0;
21028 memory_info.memoryTypeIndex = 0;
21029 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
21030 // Find an image big enough to allow sparse mapping of 2 memory regions
21031 // Increase the image size until it is at least twice the
21032 // size of the required alignment, to ensure we can bind both
21033 // allocated memory blocks to the image on aligned offsets.
21034 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
21035 vkDestroyImage(m_device->device(), image, nullptr);
21036 image_create_info.extent.width *= 2;
21037 image_create_info.extent.height *= 2;
21038 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
21039 ASSERT_VK_SUCCESS(err);
21040 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
21041 }
21042 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
21043 // at the end of the first
21044 memory_info.allocationSize = memory_reqs.alignment;
21045 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
21046 ASSERT_TRUE(pass);
21047 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
21048 ASSERT_VK_SUCCESS(err);
21049 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
21050 ASSERT_VK_SUCCESS(err);
21051 VkSparseMemoryBind binds[2];
21052 binds[0].flags = 0;
21053 binds[0].memory = memory_one;
21054 binds[0].memoryOffset = 0;
21055 binds[0].resourceOffset = 0;
21056 binds[0].size = memory_info.allocationSize;
21057 binds[1].flags = 0;
21058 binds[1].memory = memory_two;
21059 binds[1].memoryOffset = 0;
21060 binds[1].resourceOffset = memory_info.allocationSize;
21061 binds[1].size = memory_info.allocationSize;
21062
21063 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
21064 opaqueBindInfo.image = image;
21065 opaqueBindInfo.bindCount = 2;
21066 opaqueBindInfo.pBinds = binds;
21067
21068 VkFence fence = VK_NULL_HANDLE;
21069 VkBindSparseInfo bindSparseInfo = {};
21070 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
21071 bindSparseInfo.imageOpaqueBindCount = 1;
21072 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
21073
21074 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
21075 vkQueueWaitIdle(m_device->m_queue);
21076 vkDestroyImage(m_device->device(), image, NULL);
21077 vkFreeMemory(m_device->device(), memory_one, NULL);
21078 vkFreeMemory(m_device->device(), memory_two, NULL);
21079 m_errorMonitor->VerifyNotFound();
21080}
21081
21082TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021083 TEST_DESCRIPTION(
21084 "Ensure that CmdBeginRenderPass with an attachment's "
21085 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
21086 "the command buffer has prior knowledge of that "
21087 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021088
21089 m_errorMonitor->ExpectSuccess();
21090
Tony Barbour1fa09702017-03-16 12:09:08 -060021091 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021092
21093 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021094 VkAttachmentDescription attachment = {0,
21095 VK_FORMAT_R8G8B8A8_UNORM,
21096 VK_SAMPLE_COUNT_1_BIT,
21097 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21098 VK_ATTACHMENT_STORE_OP_STORE,
21099 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21100 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21101 VK_IMAGE_LAYOUT_UNDEFINED,
21102 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021103
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021104 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021105
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021106 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021107
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021108 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021109
21110 VkRenderPass rp;
21111 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21112 ASSERT_VK_SUCCESS(err);
21113
21114 // A compatible framebuffer.
21115 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021116 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 -060021117 ASSERT_TRUE(image.initialized());
21118
21119 VkImageViewCreateInfo ivci = {
21120 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21121 nullptr,
21122 0,
21123 image.handle(),
21124 VK_IMAGE_VIEW_TYPE_2D,
21125 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021126 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21127 VK_COMPONENT_SWIZZLE_IDENTITY},
21128 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021129 };
21130 VkImageView view;
21131 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21132 ASSERT_VK_SUCCESS(err);
21133
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021134 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021135 VkFramebuffer fb;
21136 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21137 ASSERT_VK_SUCCESS(err);
21138
21139 // Record a single command buffer which uses this renderpass twice. The
21140 // bug is triggered at the beginning of the second renderpass, when the
21141 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021142 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 -070021143 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021144 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21145 vkCmdEndRenderPass(m_commandBuffer->handle());
21146 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21147
21148 m_errorMonitor->VerifyNotFound();
21149
21150 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070021151 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021152
21153 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21154 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21155 vkDestroyImageView(m_device->device(), view, nullptr);
21156}
21157
21158TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021159 TEST_DESCRIPTION(
21160 "This test should pass. Create a Framebuffer and "
21161 "command buffer, bind them together, then destroy "
21162 "command pool and framebuffer and verify there are no "
21163 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021164
21165 m_errorMonitor->ExpectSuccess();
21166
Tony Barbour1fa09702017-03-16 12:09:08 -060021167 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021168
21169 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021170 VkAttachmentDescription attachment = {0,
21171 VK_FORMAT_R8G8B8A8_UNORM,
21172 VK_SAMPLE_COUNT_1_BIT,
21173 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21174 VK_ATTACHMENT_STORE_OP_STORE,
21175 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21176 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21177 VK_IMAGE_LAYOUT_UNDEFINED,
21178 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021179
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021180 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021181
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021182 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021183
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021184 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021185
21186 VkRenderPass rp;
21187 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21188 ASSERT_VK_SUCCESS(err);
21189
21190 // A compatible framebuffer.
21191 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021192 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 -060021193 ASSERT_TRUE(image.initialized());
21194
21195 VkImageViewCreateInfo ivci = {
21196 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21197 nullptr,
21198 0,
21199 image.handle(),
21200 VK_IMAGE_VIEW_TYPE_2D,
21201 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021202 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21203 VK_COMPONENT_SWIZZLE_IDENTITY},
21204 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021205 };
21206 VkImageView view;
21207 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21208 ASSERT_VK_SUCCESS(err);
21209
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021210 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021211 VkFramebuffer fb;
21212 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21213 ASSERT_VK_SUCCESS(err);
21214
21215 // Explicitly create a command buffer to bind the FB to so that we can then
21216 // destroy the command pool in order to implicitly free command buffer
21217 VkCommandPool command_pool;
21218 VkCommandPoolCreateInfo pool_create_info{};
21219 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21220 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21221 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21222 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21223
21224 VkCommandBuffer command_buffer;
21225 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21226 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21227 command_buffer_allocate_info.commandPool = command_pool;
21228 command_buffer_allocate_info.commandBufferCount = 1;
21229 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21230 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21231
21232 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021233 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 -060021234 VkCommandBufferBeginInfo begin_info{};
21235 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21236 vkBeginCommandBuffer(command_buffer, &begin_info);
21237
21238 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21239 vkCmdEndRenderPass(command_buffer);
21240 vkEndCommandBuffer(command_buffer);
21241 vkDestroyImageView(m_device->device(), view, nullptr);
21242 // Destroy command pool to implicitly free command buffer
21243 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21244 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21245 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21246 m_errorMonitor->VerifyNotFound();
21247}
21248
21249TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021250 TEST_DESCRIPTION(
21251 "Ensure that CmdBeginRenderPass applies the layout "
21252 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021253
21254 m_errorMonitor->ExpectSuccess();
21255
Tony Barbour1fa09702017-03-16 12:09:08 -060021256 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021257
21258 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021259 VkAttachmentDescription attachment = {0,
21260 VK_FORMAT_R8G8B8A8_UNORM,
21261 VK_SAMPLE_COUNT_1_BIT,
21262 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21263 VK_ATTACHMENT_STORE_OP_STORE,
21264 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21265 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21266 VK_IMAGE_LAYOUT_UNDEFINED,
21267 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021268
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021269 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021270
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021271 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021272
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021273 VkSubpassDependency dep = {0,
21274 0,
21275 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21276 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21277 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21278 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21279 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021280
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021281 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021282
21283 VkResult err;
21284 VkRenderPass rp;
21285 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21286 ASSERT_VK_SUCCESS(err);
21287
21288 // A compatible framebuffer.
21289 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021290 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 -060021291 ASSERT_TRUE(image.initialized());
21292
21293 VkImageViewCreateInfo ivci = {
21294 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21295 nullptr,
21296 0,
21297 image.handle(),
21298 VK_IMAGE_VIEW_TYPE_2D,
21299 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021300 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21301 VK_COMPONENT_SWIZZLE_IDENTITY},
21302 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021303 };
21304 VkImageView view;
21305 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21306 ASSERT_VK_SUCCESS(err);
21307
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021308 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021309 VkFramebuffer fb;
21310 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21311 ASSERT_VK_SUCCESS(err);
21312
21313 // Record a single command buffer which issues a pipeline barrier w/
21314 // image memory barrier for the attachment. This detects the previously
21315 // missing tracking of the subpass layout by throwing a validation error
21316 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021317 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 -070021318 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021319 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21320
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021321 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
21322 nullptr,
21323 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21324 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21325 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21326 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21327 VK_QUEUE_FAMILY_IGNORED,
21328 VK_QUEUE_FAMILY_IGNORED,
21329 image.handle(),
21330 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021331 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021332 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21333 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021334
21335 vkCmdEndRenderPass(m_commandBuffer->handle());
21336 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021337 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021338
21339 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21340 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21341 vkDestroyImageView(m_device->device(), view, nullptr);
21342}
21343
21344TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021345 TEST_DESCRIPTION(
21346 "Validate that when an imageView of a depth/stencil image "
21347 "is used as a depth/stencil framebuffer attachment, the "
21348 "aspectMask is ignored and both depth and stencil image "
21349 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021350
Tony Barbour1fa09702017-03-16 12:09:08 -060021351 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021352 VkFormatProperties format_properties;
21353 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
21354 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
21355 return;
21356 }
21357
21358 m_errorMonitor->ExpectSuccess();
21359
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021360 VkAttachmentDescription attachment = {0,
21361 VK_FORMAT_D32_SFLOAT_S8_UINT,
21362 VK_SAMPLE_COUNT_1_BIT,
21363 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21364 VK_ATTACHMENT_STORE_OP_STORE,
21365 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21366 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21367 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
21368 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021369
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021370 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021371
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021372 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021373
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021374 VkSubpassDependency dep = {0,
21375 0,
21376 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21377 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
21378 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21379 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
21380 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021381
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021382 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021383
21384 VkResult err;
21385 VkRenderPass rp;
21386 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21387 ASSERT_VK_SUCCESS(err);
21388
21389 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021390 image.InitNoLayout(32, 32, 1, VK_FORMAT_D32_SFLOAT_S8_UINT,
21391 0x26, // usage
21392 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021393 ASSERT_TRUE(image.initialized());
21394 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
21395
21396 VkImageViewCreateInfo ivci = {
21397 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21398 nullptr,
21399 0,
21400 image.handle(),
21401 VK_IMAGE_VIEW_TYPE_2D,
21402 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021403 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
21404 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021405 };
21406 VkImageView view;
21407 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21408 ASSERT_VK_SUCCESS(err);
21409
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021410 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021411 VkFramebuffer fb;
21412 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21413 ASSERT_VK_SUCCESS(err);
21414
Tony Barbour552f6c02016-12-21 14:34:07 -070021415 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021416
21417 VkImageMemoryBarrier imb = {};
21418 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21419 imb.pNext = nullptr;
21420 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21421 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21422 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21423 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
21424 imb.srcQueueFamilyIndex = 0;
21425 imb.dstQueueFamilyIndex = 0;
21426 imb.image = image.handle();
21427 imb.subresourceRange.aspectMask = 0x6;
21428 imb.subresourceRange.baseMipLevel = 0;
21429 imb.subresourceRange.levelCount = 0x1;
21430 imb.subresourceRange.baseArrayLayer = 0;
21431 imb.subresourceRange.layerCount = 0x1;
21432
21433 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021434 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
21435 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021436
Tony Barbour552f6c02016-12-21 14:34:07 -070021437 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021438 QueueCommandBuffer(false);
21439 m_errorMonitor->VerifyNotFound();
21440
21441 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21442 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21443 vkDestroyImageView(m_device->device(), view, nullptr);
21444}
21445
21446TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021447 TEST_DESCRIPTION(
21448 "Ensure that layout transitions work correctly without "
21449 "errors, when an attachment reference is "
21450 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021451
21452 m_errorMonitor->ExpectSuccess();
21453
Tony Barbour1fa09702017-03-16 12:09:08 -060021454 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021455
21456 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021457 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021458
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021459 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021460
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021461 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021462
21463 VkRenderPass rp;
21464 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21465 ASSERT_VK_SUCCESS(err);
21466
21467 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021468 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021469 VkFramebuffer fb;
21470 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21471 ASSERT_VK_SUCCESS(err);
21472
21473 // Record a command buffer which just begins and ends the renderpass. The
21474 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021475 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 -070021476 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021477 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21478 vkCmdEndRenderPass(m_commandBuffer->handle());
21479 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070021480 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021481
21482 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21483 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21484}
21485
21486// This is a positive test. No errors are expected.
21487TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021488 TEST_DESCRIPTION(
21489 "Create a stencil-only attachment with a LOAD_OP set to "
21490 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021491 VkResult result = VK_SUCCESS;
Tony Barbour1fa09702017-03-16 12:09:08 -060021492 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021493 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070021494 if (!depth_format) {
21495 printf(" No Depth + Stencil format found. Skipped.\n");
21496 return;
21497 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021498 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070021499 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021500 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
21501 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021502 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
21503 return;
21504 }
21505
Tony Barbourf887b162017-03-09 10:06:46 -070021506 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021507 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021508 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021509 VkAttachmentDescription att = {};
21510 VkAttachmentReference ref = {};
21511 att.format = depth_stencil_fmt;
21512 att.samples = VK_SAMPLE_COUNT_1_BIT;
21513 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
21514 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21515 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21516 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
21517 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21518 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21519
21520 VkClearValue clear;
21521 clear.depthStencil.depth = 1.0;
21522 clear.depthStencil.stencil = 0;
21523 ref.attachment = 0;
21524 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21525
21526 VkSubpassDescription subpass = {};
21527 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
21528 subpass.flags = 0;
21529 subpass.inputAttachmentCount = 0;
21530 subpass.pInputAttachments = NULL;
21531 subpass.colorAttachmentCount = 0;
21532 subpass.pColorAttachments = NULL;
21533 subpass.pResolveAttachments = NULL;
21534 subpass.pDepthStencilAttachment = &ref;
21535 subpass.preserveAttachmentCount = 0;
21536 subpass.pPreserveAttachments = NULL;
21537
21538 VkRenderPass rp;
21539 VkRenderPassCreateInfo rp_info = {};
21540 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21541 rp_info.attachmentCount = 1;
21542 rp_info.pAttachments = &att;
21543 rp_info.subpassCount = 1;
21544 rp_info.pSubpasses = &subpass;
21545 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
21546 ASSERT_VK_SUCCESS(result);
21547
21548 VkImageView *depthView = m_depthStencil->BindInfo();
21549 VkFramebufferCreateInfo fb_info = {};
21550 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
21551 fb_info.pNext = NULL;
21552 fb_info.renderPass = rp;
21553 fb_info.attachmentCount = 1;
21554 fb_info.pAttachments = depthView;
21555 fb_info.width = 100;
21556 fb_info.height = 100;
21557 fb_info.layers = 1;
21558 VkFramebuffer fb;
21559 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
21560 ASSERT_VK_SUCCESS(result);
21561
21562 VkRenderPassBeginInfo rpbinfo = {};
21563 rpbinfo.clearValueCount = 1;
21564 rpbinfo.pClearValues = &clear;
21565 rpbinfo.pNext = NULL;
21566 rpbinfo.renderPass = rp;
21567 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
21568 rpbinfo.renderArea.extent.width = 100;
21569 rpbinfo.renderArea.extent.height = 100;
21570 rpbinfo.renderArea.offset.x = 0;
21571 rpbinfo.renderArea.offset.y = 0;
21572 rpbinfo.framebuffer = fb;
21573
21574 VkFence fence = {};
21575 VkFenceCreateInfo fence_ci = {};
21576 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21577 fence_ci.pNext = nullptr;
21578 fence_ci.flags = 0;
21579 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
21580 ASSERT_VK_SUCCESS(result);
21581
21582 m_commandBuffer->BeginCommandBuffer();
21583 m_commandBuffer->BeginRenderPass(rpbinfo);
21584 m_commandBuffer->EndRenderPass();
21585 m_commandBuffer->EndCommandBuffer();
21586 m_commandBuffer->QueueCommandBuffer(fence);
21587
21588 VkImageObj destImage(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021589 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 -070021590 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021591 VkImageMemoryBarrier barrier = {};
21592 VkImageSubresourceRange range;
21593 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21594 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21595 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
21596 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21597 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
21598 barrier.image = m_depthStencil->handle();
21599 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21600 range.baseMipLevel = 0;
21601 range.levelCount = 1;
21602 range.baseArrayLayer = 0;
21603 range.layerCount = 1;
21604 barrier.subresourceRange = range;
21605 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21606 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
21607 cmdbuf.BeginCommandBuffer();
21608 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 -070021609 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021610 barrier.srcAccessMask = 0;
21611 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
21612 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
21613 barrier.image = destImage.handle();
21614 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
21615 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 -070021616 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021617 VkImageCopy cregion;
21618 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21619 cregion.srcSubresource.mipLevel = 0;
21620 cregion.srcSubresource.baseArrayLayer = 0;
21621 cregion.srcSubresource.layerCount = 1;
21622 cregion.srcOffset.x = 0;
21623 cregion.srcOffset.y = 0;
21624 cregion.srcOffset.z = 0;
21625 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
21626 cregion.dstSubresource.mipLevel = 0;
21627 cregion.dstSubresource.baseArrayLayer = 0;
21628 cregion.dstSubresource.layerCount = 1;
21629 cregion.dstOffset.x = 0;
21630 cregion.dstOffset.y = 0;
21631 cregion.dstOffset.z = 0;
21632 cregion.extent.width = 100;
21633 cregion.extent.height = 100;
21634 cregion.extent.depth = 1;
21635 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021636 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021637 cmdbuf.EndCommandBuffer();
21638
21639 VkSubmitInfo submit_info;
21640 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21641 submit_info.pNext = NULL;
21642 submit_info.waitSemaphoreCount = 0;
21643 submit_info.pWaitSemaphores = NULL;
21644 submit_info.pWaitDstStageMask = NULL;
21645 submit_info.commandBufferCount = 1;
21646 submit_info.pCommandBuffers = &cmdbuf.handle();
21647 submit_info.signalSemaphoreCount = 0;
21648 submit_info.pSignalSemaphores = NULL;
21649
21650 m_errorMonitor->ExpectSuccess();
21651 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21652 m_errorMonitor->VerifyNotFound();
21653
21654 vkQueueWaitIdle(m_device->m_queue);
21655 vkDestroyFence(m_device->device(), fence, nullptr);
21656 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21657 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
21658}
21659
21660// This is a positive test. No errors should be generated.
Mike Weiblene4e225d2017-03-07 23:15:43 -070021661TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) {
21662 TEST_DESCRIPTION("Ensure barriers' new and old VkImageLayout are compatible with their images' VkImageUsageFlags");
21663
21664 m_errorMonitor->ExpectSuccess();
21665
Tony Barbour1fa09702017-03-16 12:09:08 -060021666 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060021667 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbour9357d542017-03-24 15:42:21 -060021668 if (!depth_format) {
21669 printf(" No Depth + Stencil format found. Skipped.\n");
21670 return;
21671 }
Mike Weiblene4e225d2017-03-07 23:15:43 -070021672 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21673
21674 VkImageMemoryBarrier img_barrier = {};
21675 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
21676 img_barrier.pNext = NULL;
21677 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
21678 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
21679 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21680 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
21681 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21682 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
21683 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
21684 img_barrier.subresourceRange.baseArrayLayer = 0;
21685 img_barrier.subresourceRange.baseMipLevel = 0;
21686 img_barrier.subresourceRange.layerCount = 1;
21687 img_barrier.subresourceRange.levelCount = 1;
21688
21689 {
21690 VkImageObj img_color(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021691 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 -070021692 ASSERT_TRUE(img_color.initialized());
21693
21694 VkImageObj img_ds1(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021695 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 -070021696 ASSERT_TRUE(img_ds1.initialized());
21697
21698 VkImageObj img_ds2(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021699 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 -070021700 ASSERT_TRUE(img_ds2.initialized());
21701
21702 VkImageObj img_xfer_src(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021703 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 -070021704 ASSERT_TRUE(img_xfer_src.initialized());
21705
21706 VkImageObj img_xfer_dst(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021707 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 -070021708 ASSERT_TRUE(img_xfer_dst.initialized());
21709
21710 VkImageObj img_sampled(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021711 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 -070021712 ASSERT_TRUE(img_sampled.initialized());
21713
21714 VkImageObj img_input(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060021715 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 -070021716 ASSERT_TRUE(img_input.initialized());
21717
21718 const struct {
21719 VkImageObj &image_obj;
21720 VkImageLayout old_layout;
21721 VkImageLayout new_layout;
21722 } buffer_layouts[] = {
21723 // clang-format off
21724 {img_color, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21725 {img_ds1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21726 {img_ds2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21727 {img_sampled, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21728 {img_input, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21729 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21730 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
21731 // clang-format on
21732 };
21733 const uint32_t layout_count = sizeof(buffer_layouts) / sizeof(buffer_layouts[0]);
21734
21735 m_commandBuffer->BeginCommandBuffer();
21736 for (uint32_t i = 0; i < layout_count; ++i) {
21737 img_barrier.image = buffer_layouts[i].image_obj.handle();
21738 const VkImageUsageFlags usage = buffer_layouts[i].image_obj.usage();
21739 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
21740 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
21741 : VK_IMAGE_ASPECT_COLOR_BIT;
21742
21743 img_barrier.oldLayout = buffer_layouts[i].old_layout;
21744 img_barrier.newLayout = buffer_layouts[i].new_layout;
21745 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21746 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21747
21748 img_barrier.oldLayout = buffer_layouts[i].new_layout;
21749 img_barrier.newLayout = buffer_layouts[i].old_layout;
21750 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
21751 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
21752 }
21753 m_commandBuffer->EndCommandBuffer();
21754
21755 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
21756 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
21757 }
21758 m_errorMonitor->VerifyNotFound();
21759}
21760
21761// This is a positive test. No errors should be generated.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021762TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
21763 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
21764
21765 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060021766 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021767
21768 VkEvent event;
21769 VkEventCreateInfo event_create_info{};
21770 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
21771 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
21772
21773 VkCommandPool command_pool;
21774 VkCommandPoolCreateInfo pool_create_info{};
21775 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21776 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21777 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21778 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21779
21780 VkCommandBuffer command_buffer;
21781 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21782 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21783 command_buffer_allocate_info.commandPool = command_pool;
21784 command_buffer_allocate_info.commandBufferCount = 1;
21785 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21786 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21787
21788 VkQueue queue = VK_NULL_HANDLE;
21789 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
21790
21791 {
21792 VkCommandBufferBeginInfo begin_info{};
21793 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21794 vkBeginCommandBuffer(command_buffer, &begin_info);
21795
21796 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 -070021797 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021798 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
21799 vkEndCommandBuffer(command_buffer);
21800 }
21801 {
21802 VkSubmitInfo submit_info{};
21803 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21804 submit_info.commandBufferCount = 1;
21805 submit_info.pCommandBuffers = &command_buffer;
21806 submit_info.signalSemaphoreCount = 0;
21807 submit_info.pSignalSemaphores = nullptr;
21808 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21809 }
21810 { vkSetEvent(m_device->device(), event); }
21811
21812 vkQueueWaitIdle(queue);
21813
21814 vkDestroyEvent(m_device->device(), event, nullptr);
21815 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21816 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21817
21818 m_errorMonitor->VerifyNotFound();
21819}
21820// This is a positive test. No errors should be generated.
21821TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
21822 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
21823
Tony Barbour1fa09702017-03-16 12:09:08 -060021824 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021825 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021826
21827 m_errorMonitor->ExpectSuccess();
21828
21829 VkQueryPool query_pool;
21830 VkQueryPoolCreateInfo query_pool_create_info{};
21831 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
21832 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
21833 query_pool_create_info.queryCount = 1;
21834 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
21835
21836 VkCommandPool command_pool;
21837 VkCommandPoolCreateInfo pool_create_info{};
21838 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21839 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21840 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21841 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21842
21843 VkCommandBuffer command_buffer;
21844 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21845 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21846 command_buffer_allocate_info.commandPool = command_pool;
21847 command_buffer_allocate_info.commandBufferCount = 1;
21848 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21849 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
21850
21851 VkCommandBuffer secondary_command_buffer;
21852 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
21853 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
21854
21855 VkQueue queue = VK_NULL_HANDLE;
21856 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21857
21858 uint32_t qfi = 0;
21859 VkBufferCreateInfo buff_create_info = {};
21860 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21861 buff_create_info.size = 1024;
21862 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
21863 buff_create_info.queueFamilyIndexCount = 1;
21864 buff_create_info.pQueueFamilyIndices = &qfi;
21865
21866 VkResult err;
21867 VkBuffer buffer;
21868 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
21869 ASSERT_VK_SUCCESS(err);
21870 VkMemoryAllocateInfo mem_alloc = {};
21871 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21872 mem_alloc.pNext = NULL;
21873 mem_alloc.allocationSize = 1024;
21874 mem_alloc.memoryTypeIndex = 0;
21875
21876 VkMemoryRequirements memReqs;
21877 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
21878 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
21879 if (!pass) {
21880 vkDestroyBuffer(m_device->device(), buffer, NULL);
21881 return;
21882 }
21883
21884 VkDeviceMemory mem;
21885 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
21886 ASSERT_VK_SUCCESS(err);
21887 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
21888 ASSERT_VK_SUCCESS(err);
21889
21890 VkCommandBufferInheritanceInfo hinfo = {};
21891 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
21892 hinfo.renderPass = VK_NULL_HANDLE;
21893 hinfo.subpass = 0;
21894 hinfo.framebuffer = VK_NULL_HANDLE;
21895 hinfo.occlusionQueryEnable = VK_FALSE;
21896 hinfo.queryFlags = 0;
21897 hinfo.pipelineStatistics = 0;
21898
21899 {
21900 VkCommandBufferBeginInfo begin_info{};
21901 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21902 begin_info.pInheritanceInfo = &hinfo;
21903 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
21904
21905 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
21906 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
21907
21908 vkEndCommandBuffer(secondary_command_buffer);
21909
21910 begin_info.pInheritanceInfo = nullptr;
21911 vkBeginCommandBuffer(command_buffer, &begin_info);
21912
21913 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
21914 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
21915
21916 vkEndCommandBuffer(command_buffer);
21917 }
21918 {
21919 VkSubmitInfo submit_info{};
21920 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21921 submit_info.commandBufferCount = 1;
21922 submit_info.pCommandBuffers = &command_buffer;
21923 submit_info.signalSemaphoreCount = 0;
21924 submit_info.pSignalSemaphores = nullptr;
21925 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21926 }
21927
21928 vkQueueWaitIdle(queue);
21929
21930 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
21931 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
21932 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
21933 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21934 vkDestroyBuffer(m_device->device(), buffer, NULL);
21935 vkFreeMemory(m_device->device(), mem, NULL);
21936
21937 m_errorMonitor->VerifyNotFound();
21938}
21939
21940// This is a positive test. No errors should be generated.
21941TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
21942 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
21943
Tony Barbour1fa09702017-03-16 12:09:08 -060021944 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021945 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021946
21947 m_errorMonitor->ExpectSuccess();
21948
21949 VkQueryPool query_pool;
21950 VkQueryPoolCreateInfo query_pool_create_info{};
21951 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
21952 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
21953 query_pool_create_info.queryCount = 1;
21954 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
21955
21956 VkCommandPool command_pool;
21957 VkCommandPoolCreateInfo pool_create_info{};
21958 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21959 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21960 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21961 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21962
21963 VkCommandBuffer command_buffer[2];
21964 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21965 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21966 command_buffer_allocate_info.commandPool = command_pool;
21967 command_buffer_allocate_info.commandBufferCount = 2;
21968 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21969 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21970
21971 VkQueue queue = VK_NULL_HANDLE;
21972 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21973
21974 uint32_t qfi = 0;
21975 VkBufferCreateInfo buff_create_info = {};
21976 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21977 buff_create_info.size = 1024;
21978 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
21979 buff_create_info.queueFamilyIndexCount = 1;
21980 buff_create_info.pQueueFamilyIndices = &qfi;
21981
21982 VkResult err;
21983 VkBuffer buffer;
21984 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
21985 ASSERT_VK_SUCCESS(err);
21986 VkMemoryAllocateInfo mem_alloc = {};
21987 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21988 mem_alloc.pNext = NULL;
21989 mem_alloc.allocationSize = 1024;
21990 mem_alloc.memoryTypeIndex = 0;
21991
21992 VkMemoryRequirements memReqs;
21993 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
21994 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
21995 if (!pass) {
21996 vkDestroyBuffer(m_device->device(), buffer, NULL);
21997 return;
21998 }
21999
22000 VkDeviceMemory mem;
22001 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
22002 ASSERT_VK_SUCCESS(err);
22003 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
22004 ASSERT_VK_SUCCESS(err);
22005
22006 {
22007 VkCommandBufferBeginInfo begin_info{};
22008 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22009 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22010
22011 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
22012 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
22013
22014 vkEndCommandBuffer(command_buffer[0]);
22015
22016 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22017
22018 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
22019
22020 vkEndCommandBuffer(command_buffer[1]);
22021 }
22022 {
22023 VkSubmitInfo submit_info{};
22024 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22025 submit_info.commandBufferCount = 2;
22026 submit_info.pCommandBuffers = command_buffer;
22027 submit_info.signalSemaphoreCount = 0;
22028 submit_info.pSignalSemaphores = nullptr;
22029 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22030 }
22031
22032 vkQueueWaitIdle(queue);
22033
22034 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
22035 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
22036 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22037 vkDestroyBuffer(m_device->device(), buffer, NULL);
22038 vkFreeMemory(m_device->device(), mem, NULL);
22039
22040 m_errorMonitor->VerifyNotFound();
22041}
22042
Tony Barbourc46924f2016-11-04 11:49:52 -060022043TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022044 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
22045
Tony Barbour1fa09702017-03-16 12:09:08 -060022046 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022047 VkEvent event;
22048 VkEventCreateInfo event_create_info{};
22049 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
22050 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
22051
22052 VkCommandPool command_pool;
22053 VkCommandPoolCreateInfo pool_create_info{};
22054 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22055 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22056 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22057 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22058
22059 VkCommandBuffer command_buffer;
22060 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22061 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22062 command_buffer_allocate_info.commandPool = command_pool;
22063 command_buffer_allocate_info.commandBufferCount = 1;
22064 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22065 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
22066
22067 VkQueue queue = VK_NULL_HANDLE;
22068 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
22069
22070 {
22071 VkCommandBufferBeginInfo begin_info{};
22072 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22073 vkBeginCommandBuffer(command_buffer, &begin_info);
22074
22075 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022076 vkEndCommandBuffer(command_buffer);
22077 }
22078 {
22079 VkSubmitInfo submit_info{};
22080 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22081 submit_info.commandBufferCount = 1;
22082 submit_info.pCommandBuffers = &command_buffer;
22083 submit_info.signalSemaphoreCount = 0;
22084 submit_info.pSignalSemaphores = nullptr;
22085 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22086 }
22087 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
22089 "that is already in use by a "
22090 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022091 vkSetEvent(m_device->device(), event);
22092 m_errorMonitor->VerifyFound();
22093 }
22094
22095 vkQueueWaitIdle(queue);
22096
22097 vkDestroyEvent(m_device->device(), event, nullptr);
22098 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
22099 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22100}
22101
22102// This is a positive test. No errors should be generated.
22103TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022104 TEST_DESCRIPTION(
22105 "Two command buffers with two separate fences are each "
22106 "run through a Submit & WaitForFences cycle 3 times. This "
22107 "previously revealed a bug so running this positive test "
22108 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022109 m_errorMonitor->ExpectSuccess();
22110
Tony Barbour1fa09702017-03-16 12:09:08 -060022111 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022112 VkQueue queue = VK_NULL_HANDLE;
22113 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
22114
22115 static const uint32_t NUM_OBJECTS = 2;
22116 static const uint32_t NUM_FRAMES = 3;
22117 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
22118 VkFence fences[NUM_OBJECTS] = {};
22119
22120 VkCommandPool cmd_pool;
22121 VkCommandPoolCreateInfo cmd_pool_ci = {};
22122 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22123 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
22124 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22125 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
22126 ASSERT_VK_SUCCESS(err);
22127
22128 VkCommandBufferAllocateInfo cmd_buf_info = {};
22129 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22130 cmd_buf_info.commandPool = cmd_pool;
22131 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22132 cmd_buf_info.commandBufferCount = 1;
22133
22134 VkFenceCreateInfo fence_ci = {};
22135 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22136 fence_ci.pNext = nullptr;
22137 fence_ci.flags = 0;
22138
22139 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22140 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
22141 ASSERT_VK_SUCCESS(err);
22142 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
22143 ASSERT_VK_SUCCESS(err);
22144 }
22145
22146 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
22147 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
22148 // Create empty cmd buffer
22149 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
22150 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22151
22152 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
22153 ASSERT_VK_SUCCESS(err);
22154 err = vkEndCommandBuffer(cmd_buffers[obj]);
22155 ASSERT_VK_SUCCESS(err);
22156
22157 VkSubmitInfo submit_info = {};
22158 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22159 submit_info.commandBufferCount = 1;
22160 submit_info.pCommandBuffers = &cmd_buffers[obj];
22161 // Submit cmd buffer and wait for fence
22162 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
22163 ASSERT_VK_SUCCESS(err);
22164 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
22165 ASSERT_VK_SUCCESS(err);
22166 err = vkResetFences(m_device->device(), 1, &fences[obj]);
22167 ASSERT_VK_SUCCESS(err);
22168 }
22169 }
22170 m_errorMonitor->VerifyNotFound();
22171 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
22172 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
22173 vkDestroyFence(m_device->device(), fences[i], nullptr);
22174 }
22175}
22176// This is a positive test. No errors should be generated.
22177TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022178 TEST_DESCRIPTION(
22179 "Two command buffers, each in a separate QueueSubmit call "
22180 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022181
Tony Barbour1fa09702017-03-16 12:09:08 -060022182 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022183 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022184
22185 m_errorMonitor->ExpectSuccess();
22186
22187 VkSemaphore semaphore;
22188 VkSemaphoreCreateInfo semaphore_create_info{};
22189 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22190 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22191
22192 VkCommandPool command_pool;
22193 VkCommandPoolCreateInfo pool_create_info{};
22194 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22195 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22196 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22197 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22198
22199 VkCommandBuffer command_buffer[2];
22200 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22201 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22202 command_buffer_allocate_info.commandPool = command_pool;
22203 command_buffer_allocate_info.commandBufferCount = 2;
22204 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22205 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22206
22207 VkQueue queue = VK_NULL_HANDLE;
22208 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22209
22210 {
22211 VkCommandBufferBeginInfo begin_info{};
22212 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22213 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22214
22215 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 -070022216 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022217
22218 VkViewport viewport{};
22219 viewport.maxDepth = 1.0f;
22220 viewport.minDepth = 0.0f;
22221 viewport.width = 512;
22222 viewport.height = 512;
22223 viewport.x = 0;
22224 viewport.y = 0;
22225 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22226 vkEndCommandBuffer(command_buffer[0]);
22227 }
22228 {
22229 VkCommandBufferBeginInfo begin_info{};
22230 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22231 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22232
22233 VkViewport viewport{};
22234 viewport.maxDepth = 1.0f;
22235 viewport.minDepth = 0.0f;
22236 viewport.width = 512;
22237 viewport.height = 512;
22238 viewport.x = 0;
22239 viewport.y = 0;
22240 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22241 vkEndCommandBuffer(command_buffer[1]);
22242 }
22243 {
22244 VkSubmitInfo submit_info{};
22245 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22246 submit_info.commandBufferCount = 1;
22247 submit_info.pCommandBuffers = &command_buffer[0];
22248 submit_info.signalSemaphoreCount = 1;
22249 submit_info.pSignalSemaphores = &semaphore;
22250 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22251 }
22252 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022253 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022254 VkSubmitInfo submit_info{};
22255 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22256 submit_info.commandBufferCount = 1;
22257 submit_info.pCommandBuffers = &command_buffer[1];
22258 submit_info.waitSemaphoreCount = 1;
22259 submit_info.pWaitSemaphores = &semaphore;
22260 submit_info.pWaitDstStageMask = flags;
22261 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22262 }
22263
22264 vkQueueWaitIdle(m_device->m_queue);
22265
22266 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22267 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22268 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22269
22270 m_errorMonitor->VerifyNotFound();
22271}
22272
22273// This is a positive test. No errors should be generated.
22274TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022275 TEST_DESCRIPTION(
22276 "Two command buffers, each in a separate QueueSubmit call "
22277 "submitted on separate queues, the second having a fence"
22278 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022279
Tony Barbour1fa09702017-03-16 12:09:08 -060022280 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022281 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022282
22283 m_errorMonitor->ExpectSuccess();
22284
22285 VkFence fence;
22286 VkFenceCreateInfo fence_create_info{};
22287 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22288 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22289
22290 VkSemaphore semaphore;
22291 VkSemaphoreCreateInfo semaphore_create_info{};
22292 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22293 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22294
22295 VkCommandPool command_pool;
22296 VkCommandPoolCreateInfo pool_create_info{};
22297 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22298 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22299 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22300 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22301
22302 VkCommandBuffer command_buffer[2];
22303 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22304 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22305 command_buffer_allocate_info.commandPool = command_pool;
22306 command_buffer_allocate_info.commandBufferCount = 2;
22307 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22308 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22309
22310 VkQueue queue = VK_NULL_HANDLE;
22311 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22312
22313 {
22314 VkCommandBufferBeginInfo begin_info{};
22315 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22316 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22317
22318 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 -070022319 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022320
22321 VkViewport viewport{};
22322 viewport.maxDepth = 1.0f;
22323 viewport.minDepth = 0.0f;
22324 viewport.width = 512;
22325 viewport.height = 512;
22326 viewport.x = 0;
22327 viewport.y = 0;
22328 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22329 vkEndCommandBuffer(command_buffer[0]);
22330 }
22331 {
22332 VkCommandBufferBeginInfo begin_info{};
22333 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22334 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22335
22336 VkViewport viewport{};
22337 viewport.maxDepth = 1.0f;
22338 viewport.minDepth = 0.0f;
22339 viewport.width = 512;
22340 viewport.height = 512;
22341 viewport.x = 0;
22342 viewport.y = 0;
22343 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22344 vkEndCommandBuffer(command_buffer[1]);
22345 }
22346 {
22347 VkSubmitInfo submit_info{};
22348 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22349 submit_info.commandBufferCount = 1;
22350 submit_info.pCommandBuffers = &command_buffer[0];
22351 submit_info.signalSemaphoreCount = 1;
22352 submit_info.pSignalSemaphores = &semaphore;
22353 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22354 }
22355 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022356 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022357 VkSubmitInfo submit_info{};
22358 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22359 submit_info.commandBufferCount = 1;
22360 submit_info.pCommandBuffers = &command_buffer[1];
22361 submit_info.waitSemaphoreCount = 1;
22362 submit_info.pWaitSemaphores = &semaphore;
22363 submit_info.pWaitDstStageMask = flags;
22364 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22365 }
22366
22367 vkQueueWaitIdle(m_device->m_queue);
22368
22369 vkDestroyFence(m_device->device(), fence, nullptr);
22370 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22371 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22372 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22373
22374 m_errorMonitor->VerifyNotFound();
22375}
22376
22377// This is a positive test. No errors should be generated.
22378TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022379 TEST_DESCRIPTION(
22380 "Two command buffers, each in a separate QueueSubmit call "
22381 "submitted on separate queues, the second having a fence"
22382 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022383
Tony Barbour1fa09702017-03-16 12:09:08 -060022384 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022385 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022386
22387 m_errorMonitor->ExpectSuccess();
22388
22389 VkFence fence;
22390 VkFenceCreateInfo fence_create_info{};
22391 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22392 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22393
22394 VkSemaphore semaphore;
22395 VkSemaphoreCreateInfo semaphore_create_info{};
22396 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22397 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22398
22399 VkCommandPool command_pool;
22400 VkCommandPoolCreateInfo pool_create_info{};
22401 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22402 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22403 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22404 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22405
22406 VkCommandBuffer command_buffer[2];
22407 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22408 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22409 command_buffer_allocate_info.commandPool = command_pool;
22410 command_buffer_allocate_info.commandBufferCount = 2;
22411 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22412 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22413
22414 VkQueue queue = VK_NULL_HANDLE;
22415 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22416
22417 {
22418 VkCommandBufferBeginInfo begin_info{};
22419 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22420 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22421
22422 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 -070022423 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022424
22425 VkViewport viewport{};
22426 viewport.maxDepth = 1.0f;
22427 viewport.minDepth = 0.0f;
22428 viewport.width = 512;
22429 viewport.height = 512;
22430 viewport.x = 0;
22431 viewport.y = 0;
22432 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22433 vkEndCommandBuffer(command_buffer[0]);
22434 }
22435 {
22436 VkCommandBufferBeginInfo begin_info{};
22437 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22438 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22439
22440 VkViewport viewport{};
22441 viewport.maxDepth = 1.0f;
22442 viewport.minDepth = 0.0f;
22443 viewport.width = 512;
22444 viewport.height = 512;
22445 viewport.x = 0;
22446 viewport.y = 0;
22447 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22448 vkEndCommandBuffer(command_buffer[1]);
22449 }
22450 {
22451 VkSubmitInfo submit_info{};
22452 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22453 submit_info.commandBufferCount = 1;
22454 submit_info.pCommandBuffers = &command_buffer[0];
22455 submit_info.signalSemaphoreCount = 1;
22456 submit_info.pSignalSemaphores = &semaphore;
22457 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22458 }
22459 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022460 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022461 VkSubmitInfo submit_info{};
22462 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22463 submit_info.commandBufferCount = 1;
22464 submit_info.pCommandBuffers = &command_buffer[1];
22465 submit_info.waitSemaphoreCount = 1;
22466 submit_info.pWaitSemaphores = &semaphore;
22467 submit_info.pWaitDstStageMask = flags;
22468 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22469 }
22470
22471 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22472 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22473
22474 vkDestroyFence(m_device->device(), fence, nullptr);
22475 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22476 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22477 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22478
22479 m_errorMonitor->VerifyNotFound();
22480}
22481
22482TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Tony Barbour1fa09702017-03-16 12:09:08 -060022483 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022484 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022485 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022486 return;
22487 }
22488
22489 VkResult err;
22490
22491 m_errorMonitor->ExpectSuccess();
22492
22493 VkQueue q0 = m_device->m_queue;
22494 VkQueue q1 = nullptr;
22495 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
22496 ASSERT_NE(q1, nullptr);
22497
22498 // An (empty) command buffer. We must have work in the first submission --
22499 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022500 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022501 VkCommandPool pool;
22502 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
22503 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022504 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
22505 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022506 VkCommandBuffer cb;
22507 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
22508 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022509 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022510 err = vkBeginCommandBuffer(cb, &cbbi);
22511 ASSERT_VK_SUCCESS(err);
22512 err = vkEndCommandBuffer(cb);
22513 ASSERT_VK_SUCCESS(err);
22514
22515 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022516 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022517 VkSemaphore s;
22518 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
22519 ASSERT_VK_SUCCESS(err);
22520
22521 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022522 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022523
22524 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
22525 ASSERT_VK_SUCCESS(err);
22526
22527 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022528 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022529 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022530
22531 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
22532 ASSERT_VK_SUCCESS(err);
22533
22534 // Wait for q0 idle
22535 err = vkQueueWaitIdle(q0);
22536 ASSERT_VK_SUCCESS(err);
22537
22538 // Command buffer should have been completed (it was on q0); reset the pool.
22539 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
22540
22541 m_errorMonitor->VerifyNotFound();
22542
22543 // Force device completely idle and clean up resources
22544 vkDeviceWaitIdle(m_device->device());
22545 vkDestroyCommandPool(m_device->device(), pool, nullptr);
22546 vkDestroySemaphore(m_device->device(), s, nullptr);
22547}
22548
22549// This is a positive test. No errors should be generated.
22550TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022551 TEST_DESCRIPTION(
22552 "Two command buffers, each in a separate QueueSubmit call "
22553 "submitted on separate queues, the second having a fence, "
22554 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022555
Tony Barbour1fa09702017-03-16 12:09:08 -060022556 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022557 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022558
22559 m_errorMonitor->ExpectSuccess();
22560
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022561 VkFence fence;
22562 VkFenceCreateInfo fence_create_info{};
22563 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22564 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22565
22566 VkSemaphore semaphore;
22567 VkSemaphoreCreateInfo semaphore_create_info{};
22568 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22569 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22570
22571 VkCommandPool command_pool;
22572 VkCommandPoolCreateInfo pool_create_info{};
22573 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22574 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22575 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22576 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22577
22578 VkCommandBuffer command_buffer[2];
22579 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22580 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22581 command_buffer_allocate_info.commandPool = command_pool;
22582 command_buffer_allocate_info.commandBufferCount = 2;
22583 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22584 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22585
22586 VkQueue queue = VK_NULL_HANDLE;
22587 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
22588
22589 {
22590 VkCommandBufferBeginInfo begin_info{};
22591 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22592 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22593
22594 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 -070022595 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022596
22597 VkViewport viewport{};
22598 viewport.maxDepth = 1.0f;
22599 viewport.minDepth = 0.0f;
22600 viewport.width = 512;
22601 viewport.height = 512;
22602 viewport.x = 0;
22603 viewport.y = 0;
22604 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22605 vkEndCommandBuffer(command_buffer[0]);
22606 }
22607 {
22608 VkCommandBufferBeginInfo begin_info{};
22609 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22610 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22611
22612 VkViewport viewport{};
22613 viewport.maxDepth = 1.0f;
22614 viewport.minDepth = 0.0f;
22615 viewport.width = 512;
22616 viewport.height = 512;
22617 viewport.x = 0;
22618 viewport.y = 0;
22619 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22620 vkEndCommandBuffer(command_buffer[1]);
22621 }
22622 {
22623 VkSubmitInfo submit_info{};
22624 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22625 submit_info.commandBufferCount = 1;
22626 submit_info.pCommandBuffers = &command_buffer[0];
22627 submit_info.signalSemaphoreCount = 1;
22628 submit_info.pSignalSemaphores = &semaphore;
22629 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
22630 }
22631 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022632 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022633 VkSubmitInfo submit_info{};
22634 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22635 submit_info.commandBufferCount = 1;
22636 submit_info.pCommandBuffers = &command_buffer[1];
22637 submit_info.waitSemaphoreCount = 1;
22638 submit_info.pWaitSemaphores = &semaphore;
22639 submit_info.pWaitDstStageMask = flags;
22640 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22641 }
22642
22643 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22644
22645 vkDestroyFence(m_device->device(), fence, nullptr);
22646 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22647 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22648 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22649
22650 m_errorMonitor->VerifyNotFound();
22651}
22652
22653// This is a positive test. No errors should be generated.
22654TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022655 TEST_DESCRIPTION(
22656 "Two command buffers, each in a separate QueueSubmit call "
22657 "on the same queue, sharing a signal/wait semaphore, the "
22658 "second having a fence, "
22659 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022660
22661 m_errorMonitor->ExpectSuccess();
22662
Tony Barbour1fa09702017-03-16 12:09:08 -060022663 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022664 VkFence fence;
22665 VkFenceCreateInfo fence_create_info{};
22666 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22667 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22668
22669 VkSemaphore semaphore;
22670 VkSemaphoreCreateInfo semaphore_create_info{};
22671 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22672 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22673
22674 VkCommandPool command_pool;
22675 VkCommandPoolCreateInfo pool_create_info{};
22676 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22677 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22678 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22679 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22680
22681 VkCommandBuffer command_buffer[2];
22682 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22683 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22684 command_buffer_allocate_info.commandPool = command_pool;
22685 command_buffer_allocate_info.commandBufferCount = 2;
22686 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22687 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22688
22689 {
22690 VkCommandBufferBeginInfo begin_info{};
22691 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22692 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22693
22694 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 -070022695 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022696
22697 VkViewport viewport{};
22698 viewport.maxDepth = 1.0f;
22699 viewport.minDepth = 0.0f;
22700 viewport.width = 512;
22701 viewport.height = 512;
22702 viewport.x = 0;
22703 viewport.y = 0;
22704 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22705 vkEndCommandBuffer(command_buffer[0]);
22706 }
22707 {
22708 VkCommandBufferBeginInfo begin_info{};
22709 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22710 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22711
22712 VkViewport viewport{};
22713 viewport.maxDepth = 1.0f;
22714 viewport.minDepth = 0.0f;
22715 viewport.width = 512;
22716 viewport.height = 512;
22717 viewport.x = 0;
22718 viewport.y = 0;
22719 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22720 vkEndCommandBuffer(command_buffer[1]);
22721 }
22722 {
22723 VkSubmitInfo submit_info{};
22724 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22725 submit_info.commandBufferCount = 1;
22726 submit_info.pCommandBuffers = &command_buffer[0];
22727 submit_info.signalSemaphoreCount = 1;
22728 submit_info.pSignalSemaphores = &semaphore;
22729 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22730 }
22731 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022732 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022733 VkSubmitInfo submit_info{};
22734 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22735 submit_info.commandBufferCount = 1;
22736 submit_info.pCommandBuffers = &command_buffer[1];
22737 submit_info.waitSemaphoreCount = 1;
22738 submit_info.pWaitSemaphores = &semaphore;
22739 submit_info.pWaitDstStageMask = flags;
22740 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22741 }
22742
22743 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22744
22745 vkDestroyFence(m_device->device(), fence, nullptr);
22746 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
22747 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22748 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22749
22750 m_errorMonitor->VerifyNotFound();
22751}
22752
22753// This is a positive test. No errors should be generated.
22754TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022755 TEST_DESCRIPTION(
22756 "Two command buffers, each in a separate QueueSubmit call "
22757 "on the same queue, no fences, followed by a third QueueSubmit with NO "
22758 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022759
22760 m_errorMonitor->ExpectSuccess();
22761
Tony Barbour1fa09702017-03-16 12:09:08 -060022762 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022763 VkFence fence;
22764 VkFenceCreateInfo fence_create_info{};
22765 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22766 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22767
22768 VkCommandPool command_pool;
22769 VkCommandPoolCreateInfo pool_create_info{};
22770 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22771 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22772 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22773 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22774
22775 VkCommandBuffer command_buffer[2];
22776 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22777 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22778 command_buffer_allocate_info.commandPool = command_pool;
22779 command_buffer_allocate_info.commandBufferCount = 2;
22780 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22781 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22782
22783 {
22784 VkCommandBufferBeginInfo begin_info{};
22785 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22786 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22787
22788 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 -070022789 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022790
22791 VkViewport viewport{};
22792 viewport.maxDepth = 1.0f;
22793 viewport.minDepth = 0.0f;
22794 viewport.width = 512;
22795 viewport.height = 512;
22796 viewport.x = 0;
22797 viewport.y = 0;
22798 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22799 vkEndCommandBuffer(command_buffer[0]);
22800 }
22801 {
22802 VkCommandBufferBeginInfo begin_info{};
22803 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22804 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22805
22806 VkViewport viewport{};
22807 viewport.maxDepth = 1.0f;
22808 viewport.minDepth = 0.0f;
22809 viewport.width = 512;
22810 viewport.height = 512;
22811 viewport.x = 0;
22812 viewport.y = 0;
22813 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22814 vkEndCommandBuffer(command_buffer[1]);
22815 }
22816 {
22817 VkSubmitInfo submit_info{};
22818 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22819 submit_info.commandBufferCount = 1;
22820 submit_info.pCommandBuffers = &command_buffer[0];
22821 submit_info.signalSemaphoreCount = 0;
22822 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
22823 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22824 }
22825 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022826 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022827 VkSubmitInfo submit_info{};
22828 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22829 submit_info.commandBufferCount = 1;
22830 submit_info.pCommandBuffers = &command_buffer[1];
22831 submit_info.waitSemaphoreCount = 0;
22832 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
22833 submit_info.pWaitDstStageMask = flags;
22834 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22835 }
22836
22837 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
22838
22839 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22840 ASSERT_VK_SUCCESS(err);
22841
22842 vkDestroyFence(m_device->device(), fence, nullptr);
22843 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22844 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22845
22846 m_errorMonitor->VerifyNotFound();
22847}
22848
22849// This is a positive test. No errors should be generated.
22850TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022851 TEST_DESCRIPTION(
22852 "Two command buffers, each in a separate QueueSubmit call "
22853 "on the same queue, the second having a fence, followed "
22854 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022855
22856 m_errorMonitor->ExpectSuccess();
22857
Tony Barbour1fa09702017-03-16 12:09:08 -060022858 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022859 VkFence fence;
22860 VkFenceCreateInfo fence_create_info{};
22861 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22862 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22863
22864 VkCommandPool command_pool;
22865 VkCommandPoolCreateInfo pool_create_info{};
22866 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22867 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22868 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22869 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22870
22871 VkCommandBuffer command_buffer[2];
22872 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22873 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22874 command_buffer_allocate_info.commandPool = command_pool;
22875 command_buffer_allocate_info.commandBufferCount = 2;
22876 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22877 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22878
22879 {
22880 VkCommandBufferBeginInfo begin_info{};
22881 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22882 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22883
22884 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 -070022885 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022886
22887 VkViewport viewport{};
22888 viewport.maxDepth = 1.0f;
22889 viewport.minDepth = 0.0f;
22890 viewport.width = 512;
22891 viewport.height = 512;
22892 viewport.x = 0;
22893 viewport.y = 0;
22894 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22895 vkEndCommandBuffer(command_buffer[0]);
22896 }
22897 {
22898 VkCommandBufferBeginInfo begin_info{};
22899 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22900 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22901
22902 VkViewport viewport{};
22903 viewport.maxDepth = 1.0f;
22904 viewport.minDepth = 0.0f;
22905 viewport.width = 512;
22906 viewport.height = 512;
22907 viewport.x = 0;
22908 viewport.y = 0;
22909 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
22910 vkEndCommandBuffer(command_buffer[1]);
22911 }
22912 {
22913 VkSubmitInfo submit_info{};
22914 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22915 submit_info.commandBufferCount = 1;
22916 submit_info.pCommandBuffers = &command_buffer[0];
22917 submit_info.signalSemaphoreCount = 0;
22918 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
22919 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
22920 }
22921 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022922 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022923 VkSubmitInfo submit_info{};
22924 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
22925 submit_info.commandBufferCount = 1;
22926 submit_info.pCommandBuffers = &command_buffer[1];
22927 submit_info.waitSemaphoreCount = 0;
22928 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
22929 submit_info.pWaitDstStageMask = flags;
22930 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
22931 }
22932
22933 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
22934
22935 vkDestroyFence(m_device->device(), fence, nullptr);
22936 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
22937 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
22938
22939 m_errorMonitor->VerifyNotFound();
22940}
22941
22942// This is a positive test. No errors should be generated.
22943TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022944 TEST_DESCRIPTION(
22945 "Two command buffers each in a separate SubmitInfo sent in a single "
22946 "QueueSubmit call followed by a WaitForFences call.");
Tony Barbour1fa09702017-03-16 12:09:08 -060022947 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022948
22949 m_errorMonitor->ExpectSuccess();
22950
22951 VkFence fence;
22952 VkFenceCreateInfo fence_create_info{};
22953 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
22954 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
22955
22956 VkSemaphore semaphore;
22957 VkSemaphoreCreateInfo semaphore_create_info{};
22958 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
22959 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
22960
22961 VkCommandPool command_pool;
22962 VkCommandPoolCreateInfo pool_create_info{};
22963 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
22964 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
22965 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
22966 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
22967
22968 VkCommandBuffer command_buffer[2];
22969 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
22970 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22971 command_buffer_allocate_info.commandPool = command_pool;
22972 command_buffer_allocate_info.commandBufferCount = 2;
22973 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22974 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
22975
22976 {
22977 VkCommandBufferBeginInfo begin_info{};
22978 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22979 vkBeginCommandBuffer(command_buffer[0], &begin_info);
22980
22981 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 -070022982 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022983
22984 VkViewport viewport{};
22985 viewport.maxDepth = 1.0f;
22986 viewport.minDepth = 0.0f;
22987 viewport.width = 512;
22988 viewport.height = 512;
22989 viewport.x = 0;
22990 viewport.y = 0;
22991 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
22992 vkEndCommandBuffer(command_buffer[0]);
22993 }
22994 {
22995 VkCommandBufferBeginInfo begin_info{};
22996 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22997 vkBeginCommandBuffer(command_buffer[1], &begin_info);
22998
22999 VkViewport viewport{};
23000 viewport.maxDepth = 1.0f;
23001 viewport.minDepth = 0.0f;
23002 viewport.width = 512;
23003 viewport.height = 512;
23004 viewport.x = 0;
23005 viewport.y = 0;
23006 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
23007 vkEndCommandBuffer(command_buffer[1]);
23008 }
23009 {
23010 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023011 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023012
23013 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23014 submit_info[0].pNext = NULL;
23015 submit_info[0].commandBufferCount = 1;
23016 submit_info[0].pCommandBuffers = &command_buffer[0];
23017 submit_info[0].signalSemaphoreCount = 1;
23018 submit_info[0].pSignalSemaphores = &semaphore;
23019 submit_info[0].waitSemaphoreCount = 0;
23020 submit_info[0].pWaitSemaphores = NULL;
23021 submit_info[0].pWaitDstStageMask = 0;
23022
23023 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
23024 submit_info[1].pNext = NULL;
23025 submit_info[1].commandBufferCount = 1;
23026 submit_info[1].pCommandBuffers = &command_buffer[1];
23027 submit_info[1].waitSemaphoreCount = 1;
23028 submit_info[1].pWaitSemaphores = &semaphore;
23029 submit_info[1].pWaitDstStageMask = flags;
23030 submit_info[1].signalSemaphoreCount = 0;
23031 submit_info[1].pSignalSemaphores = NULL;
23032 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
23033 }
23034
23035 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
23036
23037 vkDestroyFence(m_device->device(), fence, nullptr);
23038 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
23039 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
23040 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
23041
23042 m_errorMonitor->VerifyNotFound();
23043}
23044
23045TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
23046 m_errorMonitor->ExpectSuccess();
23047
Tony Barbour1fa09702017-03-16 12:09:08 -060023048 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023049 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23050
Tony Barbour552f6c02016-12-21 14:34:07 -070023051 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023052
23053 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
23054 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
23055 m_errorMonitor->VerifyNotFound();
23056 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
23057 m_errorMonitor->VerifyNotFound();
23058 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
23059 m_errorMonitor->VerifyNotFound();
23060
23061 m_commandBuffer->EndCommandBuffer();
23062 m_errorMonitor->VerifyNotFound();
23063}
23064
23065TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023066 TEST_DESCRIPTION(
23067 "Positive test where we create a renderpass with an "
23068 "attachment that uses LOAD_OP_CLEAR, the first subpass "
23069 "has a valid layout, and a second subpass then uses a "
23070 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023071 m_errorMonitor->ExpectSuccess();
Tony Barbour1fa09702017-03-16 12:09:08 -060023072 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023073 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023074 if (!depth_format) {
23075 printf(" No Depth + Stencil format found. Skipped.\n");
23076 return;
23077 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023078
23079 VkAttachmentReference attach[2] = {};
23080 attach[0].attachment = 0;
23081 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
23082 attach[1].attachment = 0;
23083 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
23084 VkSubpassDescription subpasses[2] = {};
23085 // First subpass clears DS attach on load
23086 subpasses[0].pDepthStencilAttachment = &attach[0];
23087 // 2nd subpass reads in DS as input attachment
23088 subpasses[1].inputAttachmentCount = 1;
23089 subpasses[1].pInputAttachments = &attach[1];
23090 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070023091 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023092 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
23093 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
23094 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
23095 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
23096 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
23097 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
23098 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
23099 VkRenderPassCreateInfo rpci = {};
23100 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
23101 rpci.attachmentCount = 1;
23102 rpci.pAttachments = &attach_desc;
23103 rpci.subpassCount = 2;
23104 rpci.pSubpasses = subpasses;
23105
23106 // Now create RenderPass and verify no errors
23107 VkRenderPass rp;
23108 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
23109 m_errorMonitor->VerifyNotFound();
23110
23111 vkDestroyRenderPass(m_device->device(), rp, NULL);
23112}
23113
Tobin Ehlis01103de2017-02-16 13:22:47 -070023114TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
23115 TEST_DESCRIPTION(
23116 "Create a render pass with depth-stencil attachment where layout transition "
23117 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
23118 "transition has correctly occurred at queue submit time with no validation errors.");
23119
Tony Barbour1fa09702017-03-16 12:09:08 -060023120 ASSERT_NO_FATAL_FAILURE(Init());
Dave Houlton1d2022c2017-03-29 11:43:58 -060023121 auto depth_format = FindSupportedDepthStencilFormat(gpu());
Tony Barbourf887b162017-03-09 10:06:46 -070023122 if (!depth_format) {
23123 printf(" No Depth + Stencil format found. Skipped.\n");
23124 return;
23125 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070023126 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070023127 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023128 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
23129 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070023130 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070023131 return;
23132 }
23133
23134 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070023135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23136
23137 // A renderpass with one depth/stencil attachment.
23138 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070023139 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023140 VK_SAMPLE_COUNT_1_BIT,
23141 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23142 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23143 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
23144 VK_ATTACHMENT_STORE_OP_DONT_CARE,
23145 VK_IMAGE_LAYOUT_UNDEFINED,
23146 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23147
23148 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
23149
23150 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
23151
23152 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
23153
23154 VkRenderPass rp;
23155 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23156 ASSERT_VK_SUCCESS(err);
23157 // A compatible ds image.
23158 VkImageObj image(m_device);
Jeremy Hayesf6bfa6b2017-04-04 15:05:52 -060023159 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 -070023160 ASSERT_TRUE(image.initialized());
23161
23162 VkImageViewCreateInfo ivci = {
23163 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
23164 nullptr,
23165 0,
23166 image.handle(),
23167 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070023168 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070023169 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
23170 VK_COMPONENT_SWIZZLE_IDENTITY},
23171 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
23172 };
23173 VkImageView view;
23174 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
23175 ASSERT_VK_SUCCESS(err);
23176
23177 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
23178 VkFramebuffer fb;
23179 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
23180 ASSERT_VK_SUCCESS(err);
23181
23182 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
23183 m_commandBuffer->BeginCommandBuffer();
23184 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
23185 vkCmdEndRenderPass(m_commandBuffer->handle());
23186 m_commandBuffer->EndCommandBuffer();
23187 QueueCommandBuffer(false);
23188 m_errorMonitor->VerifyNotFound();
23189
23190 // Cleanup
23191 vkDestroyImageView(m_device->device(), view, NULL);
23192 vkDestroyRenderPass(m_device->device(), rp, NULL);
23193 vkDestroyFramebuffer(m_device->device(), fb, NULL);
23194}
23195
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023196TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023197 TEST_DESCRIPTION(
23198 "Test that pipeline validation accepts matrices passed "
23199 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023200 m_errorMonitor->ExpectSuccess();
23201
Tony Barbour1fa09702017-03-16 12:09:08 -060023202 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023203 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23204
23205 VkVertexInputBindingDescription input_binding;
23206 memset(&input_binding, 0, sizeof(input_binding));
23207
23208 VkVertexInputAttributeDescription input_attribs[2];
23209 memset(input_attribs, 0, sizeof(input_attribs));
23210
23211 for (int i = 0; i < 2; i++) {
23212 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23213 input_attribs[i].location = i;
23214 }
23215
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023216 char const *vsSource =
23217 "#version 450\n"
23218 "\n"
23219 "layout(location=0) in mat2x4 x;\n"
23220 "out gl_PerVertex {\n"
23221 " vec4 gl_Position;\n"
23222 "};\n"
23223 "void main(){\n"
23224 " gl_Position = x[0] + x[1];\n"
23225 "}\n";
23226 char const *fsSource =
23227 "#version 450\n"
23228 "\n"
23229 "layout(location=0) out vec4 color;\n"
23230 "void main(){\n"
23231 " color = vec4(1);\n"
23232 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023233
23234 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23235 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23236
23237 VkPipelineObj pipe(m_device);
23238 pipe.AddColorAttachment();
23239 pipe.AddShader(&vs);
23240 pipe.AddShader(&fs);
23241
23242 pipe.AddVertexInputBindings(&input_binding, 1);
23243 pipe.AddVertexInputAttribs(input_attribs, 2);
23244
23245 VkDescriptorSetObj descriptorSet(m_device);
23246 descriptorSet.AppendDummy();
23247 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23248
23249 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23250
23251 /* expect success */
23252 m_errorMonitor->VerifyNotFound();
23253}
23254
23255TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
23256 m_errorMonitor->ExpectSuccess();
23257
Tony Barbour1fa09702017-03-16 12:09:08 -060023258 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23260
23261 VkVertexInputBindingDescription input_binding;
23262 memset(&input_binding, 0, sizeof(input_binding));
23263
23264 VkVertexInputAttributeDescription input_attribs[2];
23265 memset(input_attribs, 0, sizeof(input_attribs));
23266
23267 for (int i = 0; i < 2; i++) {
23268 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23269 input_attribs[i].location = i;
23270 }
23271
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023272 char const *vsSource =
23273 "#version 450\n"
23274 "\n"
23275 "layout(location=0) in vec4 x[2];\n"
23276 "out gl_PerVertex {\n"
23277 " vec4 gl_Position;\n"
23278 "};\n"
23279 "void main(){\n"
23280 " gl_Position = x[0] + x[1];\n"
23281 "}\n";
23282 char const *fsSource =
23283 "#version 450\n"
23284 "\n"
23285 "layout(location=0) out vec4 color;\n"
23286 "void main(){\n"
23287 " color = vec4(1);\n"
23288 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023289
23290 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23291 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23292
23293 VkPipelineObj pipe(m_device);
23294 pipe.AddColorAttachment();
23295 pipe.AddShader(&vs);
23296 pipe.AddShader(&fs);
23297
23298 pipe.AddVertexInputBindings(&input_binding, 1);
23299 pipe.AddVertexInputAttribs(input_attribs, 2);
23300
23301 VkDescriptorSetObj descriptorSet(m_device);
23302 descriptorSet.AppendDummy();
23303 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23304
23305 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23306
23307 m_errorMonitor->VerifyNotFound();
23308}
23309
23310TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023311 TEST_DESCRIPTION(
23312 "Test that pipeline validation accepts consuming a vertex attribute "
23313 "through multiple vertex shader inputs, each consuming a different "
23314 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023315 m_errorMonitor->ExpectSuccess();
23316
Tony Barbour1fa09702017-03-16 12:09:08 -060023317 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023318 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23319
23320 VkVertexInputBindingDescription input_binding;
23321 memset(&input_binding, 0, sizeof(input_binding));
23322
23323 VkVertexInputAttributeDescription input_attribs[3];
23324 memset(input_attribs, 0, sizeof(input_attribs));
23325
23326 for (int i = 0; i < 3; i++) {
23327 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
23328 input_attribs[i].location = i;
23329 }
23330
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023331 char const *vsSource =
23332 "#version 450\n"
23333 "\n"
23334 "layout(location=0) in vec4 x;\n"
23335 "layout(location=1) in vec3 y1;\n"
23336 "layout(location=1, component=3) in float y2;\n"
23337 "layout(location=2) in vec4 z;\n"
23338 "out gl_PerVertex {\n"
23339 " vec4 gl_Position;\n"
23340 "};\n"
23341 "void main(){\n"
23342 " gl_Position = x + vec4(y1, y2) + z;\n"
23343 "}\n";
23344 char const *fsSource =
23345 "#version 450\n"
23346 "\n"
23347 "layout(location=0) out vec4 color;\n"
23348 "void main(){\n"
23349 " color = vec4(1);\n"
23350 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023351
23352 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23353 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23354
23355 VkPipelineObj pipe(m_device);
23356 pipe.AddColorAttachment();
23357 pipe.AddShader(&vs);
23358 pipe.AddShader(&fs);
23359
23360 pipe.AddVertexInputBindings(&input_binding, 1);
23361 pipe.AddVertexInputAttribs(input_attribs, 3);
23362
23363 VkDescriptorSetObj descriptorSet(m_device);
23364 descriptorSet.AppendDummy();
23365 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23366
23367 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23368
23369 m_errorMonitor->VerifyNotFound();
23370}
23371
23372TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
23373 m_errorMonitor->ExpectSuccess();
23374
Tony Barbour1fa09702017-03-16 12:09:08 -060023375 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23377
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023378 char const *vsSource =
23379 "#version 450\n"
23380 "out gl_PerVertex {\n"
23381 " vec4 gl_Position;\n"
23382 "};\n"
23383 "void main(){\n"
23384 " gl_Position = vec4(0);\n"
23385 "}\n";
23386 char const *fsSource =
23387 "#version 450\n"
23388 "\n"
23389 "layout(location=0) out vec4 color;\n"
23390 "void main(){\n"
23391 " color = vec4(1);\n"
23392 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023393
23394 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23395 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23396
23397 VkPipelineObj pipe(m_device);
23398 pipe.AddColorAttachment();
23399 pipe.AddShader(&vs);
23400 pipe.AddShader(&fs);
23401
23402 VkDescriptorSetObj descriptorSet(m_device);
23403 descriptorSet.AppendDummy();
23404 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23405
23406 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23407
23408 m_errorMonitor->VerifyNotFound();
23409}
23410
23411TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023412 TEST_DESCRIPTION(
23413 "Test that pipeline validation accepts the relaxed type matching rules "
23414 "set out in 14.1.3: fundamental type must match, and producer side must "
23415 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023416 m_errorMonitor->ExpectSuccess();
23417
23418 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
23419
Tony Barbour1fa09702017-03-16 12:09:08 -060023420 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023421 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23422
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023423 char const *vsSource =
23424 "#version 450\n"
23425 "out gl_PerVertex {\n"
23426 " vec4 gl_Position;\n"
23427 "};\n"
23428 "layout(location=0) out vec3 x;\n"
23429 "layout(location=1) out ivec3 y;\n"
23430 "layout(location=2) out vec3 z;\n"
23431 "void main(){\n"
23432 " gl_Position = vec4(0);\n"
23433 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
23434 "}\n";
23435 char const *fsSource =
23436 "#version 450\n"
23437 "\n"
23438 "layout(location=0) out vec4 color;\n"
23439 "layout(location=0) in float x;\n"
23440 "layout(location=1) flat in int y;\n"
23441 "layout(location=2) in vec2 z;\n"
23442 "void main(){\n"
23443 " color = vec4(1 + x + y + z.x);\n"
23444 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023445
23446 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23447 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23448
23449 VkPipelineObj pipe(m_device);
23450 pipe.AddColorAttachment();
23451 pipe.AddShader(&vs);
23452 pipe.AddShader(&fs);
23453
23454 VkDescriptorSetObj descriptorSet(m_device);
23455 descriptorSet.AppendDummy();
23456 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23457
23458 VkResult err = VK_SUCCESS;
23459 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23460 ASSERT_VK_SUCCESS(err);
23461
23462 m_errorMonitor->VerifyNotFound();
23463}
23464
23465TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023466 TEST_DESCRIPTION(
23467 "Test that pipeline validation accepts per-vertex variables "
23468 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023469 m_errorMonitor->ExpectSuccess();
23470
Tony Barbour1fa09702017-03-16 12:09:08 -060023471 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023472 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23473
23474 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023475 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023476 return;
23477 }
23478
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023479 char const *vsSource =
23480 "#version 450\n"
23481 "void main(){}\n";
23482 char const *tcsSource =
23483 "#version 450\n"
23484 "layout(location=0) out int x[];\n"
23485 "layout(vertices=3) out;\n"
23486 "void main(){\n"
23487 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
23488 " gl_TessLevelInner[0] = 1;\n"
23489 " x[gl_InvocationID] = gl_InvocationID;\n"
23490 "}\n";
23491 char const *tesSource =
23492 "#version 450\n"
23493 "layout(triangles, equal_spacing, cw) in;\n"
23494 "layout(location=0) in int x[];\n"
23495 "out gl_PerVertex { vec4 gl_Position; };\n"
23496 "void main(){\n"
23497 " gl_Position.xyz = gl_TessCoord;\n"
23498 " gl_Position.w = x[0] + x[1] + x[2];\n"
23499 "}\n";
23500 char const *fsSource =
23501 "#version 450\n"
23502 "layout(location=0) out vec4 color;\n"
23503 "void main(){\n"
23504 " color = vec4(1);\n"
23505 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023506
23507 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23508 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
23509 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
23510 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23511
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023512 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
23513 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023514
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023515 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023516
23517 VkPipelineObj pipe(m_device);
23518 pipe.SetInputAssembly(&iasci);
23519 pipe.SetTessellation(&tsci);
23520 pipe.AddColorAttachment();
23521 pipe.AddShader(&vs);
23522 pipe.AddShader(&tcs);
23523 pipe.AddShader(&tes);
23524 pipe.AddShader(&fs);
23525
23526 VkDescriptorSetObj descriptorSet(m_device);
23527 descriptorSet.AppendDummy();
23528 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23529
23530 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23531
23532 m_errorMonitor->VerifyNotFound();
23533}
23534
23535TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023536 TEST_DESCRIPTION(
23537 "Test that pipeline validation accepts a user-defined "
23538 "interface block passed into the geometry shader. This "
23539 "is interesting because the 'extra' array level is not "
23540 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023541 m_errorMonitor->ExpectSuccess();
23542
Tony Barbour1fa09702017-03-16 12:09:08 -060023543 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023544 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23545
23546 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023547 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023548 return;
23549 }
23550
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023551 char const *vsSource =
23552 "#version 450\n"
23553 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
23554 "void main(){\n"
23555 " vs_out.x = vec4(1);\n"
23556 "}\n";
23557 char const *gsSource =
23558 "#version 450\n"
23559 "layout(triangles) in;\n"
23560 "layout(triangle_strip, max_vertices=3) out;\n"
23561 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
23562 "out gl_PerVertex { vec4 gl_Position; };\n"
23563 "void main() {\n"
23564 " gl_Position = gs_in[0].x;\n"
23565 " EmitVertex();\n"
23566 "}\n";
23567 char const *fsSource =
23568 "#version 450\n"
23569 "layout(location=0) out vec4 color;\n"
23570 "void main(){\n"
23571 " color = vec4(1);\n"
23572 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023573
23574 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23575 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
23576 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23577
23578 VkPipelineObj pipe(m_device);
23579 pipe.AddColorAttachment();
23580 pipe.AddShader(&vs);
23581 pipe.AddShader(&gs);
23582 pipe.AddShader(&fs);
23583
23584 VkDescriptorSetObj descriptorSet(m_device);
23585 descriptorSet.AppendDummy();
23586 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23587
23588 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23589
23590 m_errorMonitor->VerifyNotFound();
23591}
23592
23593TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023594 TEST_DESCRIPTION(
23595 "Test that pipeline validation accepts basic use of 64bit vertex "
23596 "attributes. This is interesting because they consume multiple "
23597 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023598 m_errorMonitor->ExpectSuccess();
23599
Tony Barbour1fa09702017-03-16 12:09:08 -060023600 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023601 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23602
23603 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070023604 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023605 return;
23606 }
23607
23608 VkVertexInputBindingDescription input_bindings[1];
23609 memset(input_bindings, 0, sizeof(input_bindings));
23610
23611 VkVertexInputAttributeDescription input_attribs[4];
23612 memset(input_attribs, 0, sizeof(input_attribs));
23613 input_attribs[0].location = 0;
23614 input_attribs[0].offset = 0;
23615 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23616 input_attribs[1].location = 2;
23617 input_attribs[1].offset = 32;
23618 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23619 input_attribs[2].location = 4;
23620 input_attribs[2].offset = 64;
23621 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23622 input_attribs[3].location = 6;
23623 input_attribs[3].offset = 96;
23624 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
23625
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023626 char const *vsSource =
23627 "#version 450\n"
23628 "\n"
23629 "layout(location=0) in dmat4 x;\n"
23630 "out gl_PerVertex {\n"
23631 " vec4 gl_Position;\n"
23632 "};\n"
23633 "void main(){\n"
23634 " gl_Position = vec4(x[0][0]);\n"
23635 "}\n";
23636 char const *fsSource =
23637 "#version 450\n"
23638 "\n"
23639 "layout(location=0) out vec4 color;\n"
23640 "void main(){\n"
23641 " color = vec4(1);\n"
23642 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023643
23644 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23645 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23646
23647 VkPipelineObj pipe(m_device);
23648 pipe.AddColorAttachment();
23649 pipe.AddShader(&vs);
23650 pipe.AddShader(&fs);
23651
23652 pipe.AddVertexInputBindings(input_bindings, 1);
23653 pipe.AddVertexInputAttribs(input_attribs, 4);
23654
23655 VkDescriptorSetObj descriptorSet(m_device);
23656 descriptorSet.AppendDummy();
23657 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23658
23659 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
23660
23661 m_errorMonitor->VerifyNotFound();
23662}
23663
23664TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
23665 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
23666 m_errorMonitor->ExpectSuccess();
23667
Tony Barbour1fa09702017-03-16 12:09:08 -060023668 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023669
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023670 char const *vsSource =
23671 "#version 450\n"
23672 "\n"
23673 "out gl_PerVertex {\n"
23674 " vec4 gl_Position;\n"
23675 "};\n"
23676 "void main(){\n"
23677 " gl_Position = vec4(1);\n"
23678 "}\n";
23679 char const *fsSource =
23680 "#version 450\n"
23681 "\n"
23682 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
23683 "layout(location=0) out vec4 color;\n"
23684 "void main() {\n"
23685 " color = subpassLoad(x);\n"
23686 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023687
23688 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
23689 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
23690
23691 VkPipelineObj pipe(m_device);
23692 pipe.AddShader(&vs);
23693 pipe.AddShader(&fs);
23694 pipe.AddColorAttachment();
23695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
23696
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023697 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
23698 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023699 VkDescriptorSetLayout dsl;
23700 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23701 ASSERT_VK_SUCCESS(err);
23702
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023703 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023704 VkPipelineLayout pl;
23705 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23706 ASSERT_VK_SUCCESS(err);
23707
23708 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023709 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23710 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23711 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
23712 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
23713 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 -060023714 };
23715 VkAttachmentReference color = {
23716 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
23717 };
23718 VkAttachmentReference input = {
23719 1, VK_IMAGE_LAYOUT_GENERAL,
23720 };
23721
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023722 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023723
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023724 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023725 VkRenderPass rp;
23726 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
23727 ASSERT_VK_SUCCESS(err);
23728
23729 // should be OK. would go wrong here if it's going to...
23730 pipe.CreateVKPipeline(pl, rp);
23731
23732 m_errorMonitor->VerifyNotFound();
23733
23734 vkDestroyRenderPass(m_device->device(), rp, nullptr);
23735 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23736 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23737}
23738
23739TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023740 TEST_DESCRIPTION(
23741 "Test that pipeline validation accepts a compute pipeline which declares a "
23742 "descriptor-backed resource which is not provided, but the shader does not "
23743 "statically use it. This is interesting because it requires compute pipelines "
23744 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023745 m_errorMonitor->ExpectSuccess();
23746
Tony Barbour1fa09702017-03-16 12:09:08 -060023747 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023748
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023749 char const *csSource =
23750 "#version 450\n"
23751 "\n"
23752 "layout(local_size_x=1) in;\n"
23753 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
23754 "void main(){\n"
23755 " // x is not used.\n"
23756 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023757
23758 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23759
23760 VkDescriptorSetObj descriptorSet(m_device);
23761 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
23762
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023763 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23764 nullptr,
23765 0,
23766 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23767 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23768 descriptorSet.GetPipelineLayout(),
23769 VK_NULL_HANDLE,
23770 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023771
23772 VkPipeline pipe;
23773 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23774
23775 m_errorMonitor->VerifyNotFound();
23776
23777 if (err == VK_SUCCESS) {
23778 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23779 }
23780}
23781
23782TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023783 TEST_DESCRIPTION(
23784 "Test that pipeline validation accepts a shader consuming only the "
23785 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023786 m_errorMonitor->ExpectSuccess();
23787
Tony Barbour1fa09702017-03-16 12:09:08 -060023788 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023789
23790 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023791 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23792 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23793 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023794 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023795 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023796 VkDescriptorSetLayout dsl;
23797 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23798 ASSERT_VK_SUCCESS(err);
23799
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023800 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023801 VkPipelineLayout pl;
23802 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23803 ASSERT_VK_SUCCESS(err);
23804
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023805 char const *csSource =
23806 "#version 450\n"
23807 "\n"
23808 "layout(local_size_x=1) in;\n"
23809 "layout(set=0, binding=0) uniform sampler s;\n"
23810 "layout(set=0, binding=1) uniform texture2D t;\n"
23811 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
23812 "void main() {\n"
23813 " x = texture(sampler2D(t, s), vec2(0));\n"
23814 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023815 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23816
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023817 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23818 nullptr,
23819 0,
23820 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23821 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23822 pl,
23823 VK_NULL_HANDLE,
23824 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023825
23826 VkPipeline pipe;
23827 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23828
23829 m_errorMonitor->VerifyNotFound();
23830
23831 if (err == VK_SUCCESS) {
23832 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23833 }
23834
23835 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23836 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23837}
23838
23839TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023840 TEST_DESCRIPTION(
23841 "Test that pipeline validation accepts a shader consuming only the "
23842 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023843 m_errorMonitor->ExpectSuccess();
23844
Tony Barbour1fa09702017-03-16 12:09:08 -060023845 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023846
23847 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023848 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23849 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23850 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023851 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023852 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023853 VkDescriptorSetLayout dsl;
23854 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23855 ASSERT_VK_SUCCESS(err);
23856
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023857 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023858 VkPipelineLayout pl;
23859 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23860 ASSERT_VK_SUCCESS(err);
23861
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023862 char const *csSource =
23863 "#version 450\n"
23864 "\n"
23865 "layout(local_size_x=1) in;\n"
23866 "layout(set=0, binding=0) uniform texture2D t;\n"
23867 "layout(set=0, binding=1) uniform sampler s;\n"
23868 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
23869 "void main() {\n"
23870 " x = texture(sampler2D(t, s), vec2(0));\n"
23871 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023872 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23873
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023874 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23875 nullptr,
23876 0,
23877 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23878 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23879 pl,
23880 VK_NULL_HANDLE,
23881 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023882
23883 VkPipeline pipe;
23884 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23885
23886 m_errorMonitor->VerifyNotFound();
23887
23888 if (err == VK_SUCCESS) {
23889 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23890 }
23891
23892 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23893 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23894}
23895
23896TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023897 TEST_DESCRIPTION(
23898 "Test that pipeline validation accepts a shader consuming "
23899 "both the sampler and the image of a combined image+sampler "
23900 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023901 m_errorMonitor->ExpectSuccess();
23902
Tony Barbour1fa09702017-03-16 12:09:08 -060023903 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023904
23905 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023906 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
23907 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023908 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023909 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023910 VkDescriptorSetLayout dsl;
23911 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
23912 ASSERT_VK_SUCCESS(err);
23913
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023914 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023915 VkPipelineLayout pl;
23916 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
23917 ASSERT_VK_SUCCESS(err);
23918
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070023919 char const *csSource =
23920 "#version 450\n"
23921 "\n"
23922 "layout(local_size_x=1) in;\n"
23923 "layout(set=0, binding=0) uniform texture2D t;\n"
23924 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
23925 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
23926 "void main() {\n"
23927 " x = texture(sampler2D(t, s), vec2(0));\n"
23928 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023929 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
23930
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070023931 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
23932 nullptr,
23933 0,
23934 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
23935 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
23936 pl,
23937 VK_NULL_HANDLE,
23938 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060023939
23940 VkPipeline pipe;
23941 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
23942
23943 m_errorMonitor->VerifyNotFound();
23944
23945 if (err == VK_SUCCESS) {
23946 vkDestroyPipeline(m_device->device(), pipe, nullptr);
23947 }
23948
23949 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
23950 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
23951}
23952
Tony Barbour3ed87a02017-03-15 16:19:02 -060023953TEST_F(VkPositiveLayerTest, Maintenance1Tests) {
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023954 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
23955
Tony Barbour3ed87a02017-03-15 16:19:02 -060023956 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
Tony Barbour73c0f352017-03-16 15:55:38 -060023957 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour3ed87a02017-03-15 16:19:02 -060023958
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023959 // Ensure that extension is available and enabled.
23960 uint32_t extension_count = 0;
23961 bool supports_maintenance1_extension = false;
23962 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
23963 ASSERT_VK_SUCCESS(err);
23964 if (extension_count > 0) {
23965 std::vector<VkExtensionProperties> available_extensions(extension_count);
23966
23967 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
23968 ASSERT_VK_SUCCESS(err);
23969 for (const auto &extension_props : available_extensions) {
23970 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
23971 supports_maintenance1_extension = true;
23972 }
23973 }
23974 }
23975
23976 // Proceed if extension is supported by hardware
23977 if (!supports_maintenance1_extension) {
23978 printf(" Maintenance1 Extension not supported, skipping tests\n");
23979 return;
23980 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023981
23982 m_errorMonitor->ExpectSuccess();
Dave Houlton8e0fe7a2017-03-30 10:32:10 -060023983 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023984 VkCommandBuffer cmd_buf;
23985 VkCommandBufferAllocateInfo alloc_info;
23986 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
23987 alloc_info.pNext = NULL;
23988 alloc_info.commandBufferCount = 1;
Mike Schuchardt06304c22017-03-01 17:09:09 -070023989 alloc_info.commandPool = m_commandPool->handle();
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060023990 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
23991 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
23992
23993 VkCommandBufferBeginInfo cb_binfo;
23994 cb_binfo.pNext = NULL;
23995 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
23996 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
23997 cb_binfo.flags = 0;
23998 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
23999 // Set Negative height, should give error if Maintenance 1 is not enabled
24000 VkViewport viewport = {0, 0, 16, -16, 0, 1};
24001 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
24002 vkEndCommandBuffer(cmd_buf);
24003
24004 m_errorMonitor->VerifyNotFound();
24005}
24006
Mark Lobodzinski35ecad32017-03-27 13:09:07 -060024007TEST_F(VkLayerTest, DuplicateValidPNextStructures) {
24008 TEST_DESCRIPTION("Create a pNext chain containing valid strutures, but with a duplicate structure type");
24009
24010 ASSERT_NO_FATAL_FAILURE(Init());
24011
24012 uint32_t extension_count = 0;
24013 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24014 ASSERT_VK_SUCCESS(err);
24015
24016 if (extension_count > 0) {
24017 std::vector<VkExtensionProperties> available_extensions(extension_count);
24018 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24019 ASSERT_VK_SUCCESS(err);
24020
24021 for (const auto &extension_props : available_extensions) {
24022 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
24023 // Create two pNext structures which by themselves would be valid
24024 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
24025 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info_2 = {};
24026 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24027 dedicated_buffer_create_info.pNext = &dedicated_buffer_create_info_2;
24028 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
24029
24030 dedicated_buffer_create_info_2.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24031 dedicated_buffer_create_info_2.pNext = nullptr;
24032 dedicated_buffer_create_info_2.dedicatedAllocation = VK_TRUE;
24033
24034 uint32_t queue_family_index = 0;
24035 VkBufferCreateInfo buffer_create_info = {};
24036 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
24037 buffer_create_info.pNext = &dedicated_buffer_create_info;
24038 buffer_create_info.size = 1024;
24039 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
24040 buffer_create_info.queueFamilyIndexCount = 1;
24041 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
24042
24043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "chain contains duplicate structure types");
24044 VkBuffer buffer;
24045 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
24046 m_errorMonitor->VerifyFound();
24047 }
24048 }
24049 }
24050}
24051
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024052TEST_F(VkPositiveLayerTest, ValidStructPNext) {
24053 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
24054
Tony Barbour1fa09702017-03-16 12:09:08 -060024055 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024056
24057 // Positive test to check parameter_validation and unique_objects support
24058 // for NV_dedicated_allocation
24059 uint32_t extension_count = 0;
24060 bool supports_nv_dedicated_allocation = false;
24061 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
24062 ASSERT_VK_SUCCESS(err);
24063
24064 if (extension_count > 0) {
24065 std::vector<VkExtensionProperties> available_extensions(extension_count);
24066
24067 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
24068 ASSERT_VK_SUCCESS(err);
24069
24070 for (const auto &extension_props : available_extensions) {
24071 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
24072 supports_nv_dedicated_allocation = true;
24073 }
24074 }
24075 }
24076
24077 if (supports_nv_dedicated_allocation) {
24078 m_errorMonitor->ExpectSuccess();
24079
24080 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
24081 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
24082 dedicated_buffer_create_info.pNext = nullptr;
24083 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
24084
24085 uint32_t queue_family_index = 0;
24086 VkBufferCreateInfo buffer_create_info = {};
24087 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
24088 buffer_create_info.pNext = &dedicated_buffer_create_info;
24089 buffer_create_info.size = 1024;
24090 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
24091 buffer_create_info.queueFamilyIndexCount = 1;
24092 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
24093
24094 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070024095 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024096 ASSERT_VK_SUCCESS(err);
24097
24098 VkMemoryRequirements memory_reqs;
24099 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
24100
24101 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
24102 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
24103 dedicated_memory_info.pNext = nullptr;
24104 dedicated_memory_info.buffer = buffer;
24105 dedicated_memory_info.image = VK_NULL_HANDLE;
24106
24107 VkMemoryAllocateInfo memory_info = {};
24108 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
24109 memory_info.pNext = &dedicated_memory_info;
24110 memory_info.allocationSize = memory_reqs.size;
24111
24112 bool pass;
24113 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
24114 ASSERT_TRUE(pass);
24115
24116 VkDeviceMemory buffer_memory;
24117 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
24118 ASSERT_VK_SUCCESS(err);
24119
24120 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
24121 ASSERT_VK_SUCCESS(err);
24122
24123 vkDestroyBuffer(m_device->device(), buffer, NULL);
24124 vkFreeMemory(m_device->device(), buffer_memory, NULL);
24125
24126 m_errorMonitor->VerifyNotFound();
24127 }
24128}
24129
24130TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
24131 VkResult err;
24132
24133 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
24134
Tony Barbour1fa09702017-03-16 12:09:08 -060024135 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024136 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
24137
24138 std::vector<const char *> device_extension_names;
24139 auto features = m_device->phy().features();
24140 // Artificially disable support for non-solid fill modes
24141 features.fillModeNonSolid = false;
24142 // The sacrificial device object
24143 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
24144
24145 VkRenderpassObj render_pass(&test_device);
24146
24147 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
24148 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
24149 pipeline_layout_ci.setLayoutCount = 0;
24150 pipeline_layout_ci.pSetLayouts = NULL;
24151
24152 VkPipelineLayout pipeline_layout;
24153 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
24154 ASSERT_VK_SUCCESS(err);
24155
24156 VkPipelineRasterizationStateCreateInfo rs_ci = {};
24157 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
24158 rs_ci.pNext = nullptr;
24159 rs_ci.lineWidth = 1.0f;
24160 rs_ci.rasterizerDiscardEnable = true;
24161
24162 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
24163 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
24164
24165 // Set polygonMode=FILL. No error is expected
24166 m_errorMonitor->ExpectSuccess();
24167 {
24168 VkPipelineObj pipe(&test_device);
24169 pipe.AddShader(&vs);
24170 pipe.AddShader(&fs);
24171 pipe.AddColorAttachment();
24172 // Set polygonMode to a good value
24173 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
24174 pipe.SetRasterization(&rs_ci);
24175 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
24176 }
24177 m_errorMonitor->VerifyNotFound();
24178
24179 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
24180}
24181
Dave Houlton1150cf52017-04-27 14:38:11 -060024182TEST_F(VkPositiveLayerTest, LongSemaphoreChain) {
Chris Forbes94196952017-04-06 16:30:59 -070024183 m_errorMonitor->ExpectSuccess();
24184
24185 ASSERT_NO_FATAL_FAILURE(Init());
24186 VkResult err;
24187
24188 std::vector<VkSemaphore> semaphores;
24189
24190 const int chainLength = 32768;
24191 VkPipelineStageFlags flags = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
24192
24193 for (int i = 0; i < chainLength; i++) {
Dave Houlton1150cf52017-04-27 14:38:11 -060024194 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024195 VkSemaphore semaphore;
24196 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &semaphore);
24197 ASSERT_VK_SUCCESS(err);
24198
24199 semaphores.push_back(semaphore);
24200
Chris Forbesfc50aaa2017-05-01 10:20:17 -070024201 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO,
24202 nullptr,
24203 semaphores.size() > 1 ? 1u : 0u,
24204 semaphores.size() > 1 ? &semaphores[semaphores.size() - 2] : nullptr,
24205 &flags,
24206 0,
24207 nullptr,
24208 1,
24209 &semaphores[semaphores.size() - 1]};
Chris Forbes94196952017-04-06 16:30:59 -070024210 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
24211 ASSERT_VK_SUCCESS(err);
24212 }
24213
Dave Houlton1150cf52017-04-27 14:38:11 -060024214 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Chris Forbes94196952017-04-06 16:30:59 -070024215 VkFence fence;
24216 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24217 ASSERT_VK_SUCCESS(err);
Dave Houlton1150cf52017-04-27 14:38:11 -060024218 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &semaphores.back(), &flags, 0, nullptr, 0, nullptr};
Chris Forbes94196952017-04-06 16:30:59 -070024219 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24220 ASSERT_VK_SUCCESS(err);
24221
24222 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
24223
Dave Houlton1150cf52017-04-27 14:38:11 -060024224 for (auto semaphore : semaphores) vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Chris Forbes94196952017-04-06 16:30:59 -070024225
24226 vkDestroyFence(m_device->device(), fence, nullptr);
24227
24228 m_errorMonitor->VerifyNotFound();
24229}
24230
Mike Stroyanca855662017-05-02 11:06:27 -060024231extern "C" void *ReleaseNullFence(void *arg) {
24232 struct thread_data_struct *data = (struct thread_data_struct *)arg;
24233
24234 for (int i = 0; i < 40000; i++) {
24235 vkDestroyFence(data->device, VK_NULL_HANDLE, NULL);
24236 if (data->bailout) {
24237 break;
24238 }
24239 }
24240 return NULL;
24241}
24242
24243TEST_F(VkPositiveLayerTest, ThreadNullFenceCollision) {
24244 test_platform_thread thread;
24245
24246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
24247
24248 ASSERT_NO_FATAL_FAILURE(Init());
24249
24250 struct thread_data_struct data;
24251 data.device = m_device->device();
24252 data.bailout = false;
24253 m_errorMonitor->SetBailout(&data.bailout);
24254
24255 // Call vkDestroyFence of VK_NULL_HANDLE repeatedly using multiple threads.
24256 // There should be no validation error from collision of that non-object.
24257 test_platform_thread_create(&thread, ReleaseNullFence, (void *)&data);
24258 for (int i = 0; i < 40000; i++) {
24259 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
24260 }
24261 test_platform_thread_join(thread, NULL);
24262
24263 m_errorMonitor->SetBailout(NULL);
24264
24265 m_errorMonitor->VerifyNotFound();
24266}
24267
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024268#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024269TEST_F(VkPositiveLayerTest, LongFenceChain)
24270{
24271 m_errorMonitor->ExpectSuccess();
24272
Tony Barbour1fa09702017-03-16 12:09:08 -060024273 ASSERT_NO_FATAL_FAILURE(Init());
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060024274 VkResult err;
24275
24276 std::vector<VkFence> fences;
24277
24278 const int chainLength = 32768;
24279
24280 for (int i = 0; i < chainLength; i++) {
24281 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
24282 VkFence fence;
24283 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
24284 ASSERT_VK_SUCCESS(err);
24285
24286 fences.push_back(fence);
24287
24288 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
24289 0, nullptr, 0, nullptr };
24290 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
24291 ASSERT_VK_SUCCESS(err);
24292
24293 }
24294
24295 // BOOM, stack overflow.
24296 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
24297
24298 for (auto fence : fences)
24299 vkDestroyFence(m_device->device(), fence, nullptr);
24300
24301 m_errorMonitor->VerifyNotFound();
24302}
24303#endif
24304
Cody Northrop1242dfd2016-07-13 17:24:59 -060024305#if defined(ANDROID) && defined(VALIDATION_APK)
Cody Northropb94529f2017-04-05 13:05:51 -060024306const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060024307static bool initialized = false;
24308static bool active = false;
24309
24310// Convert Intents to argv
24311// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024312std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024313 std::vector<std::string> args;
24314 JavaVM &vm = *app.activity->vm;
24315 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024316 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024317
24318 JNIEnv &env = *p_env;
24319 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024320 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024321 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024322 jmethodID get_string_extra_method =
24323 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060024324 jvalue get_string_extra_args;
24325 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024326 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060024327
24328 std::string args_str;
24329 if (extra_str) {
24330 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
24331 args_str = extra_utf;
24332 env.ReleaseStringUTFChars(extra_str, extra_utf);
24333 env.DeleteLocalRef(extra_str);
24334 }
24335
24336 env.DeleteLocalRef(get_string_extra_args.l);
24337 env.DeleteLocalRef(intent);
24338 vm.DetachCurrentThread();
24339
24340 // split args_str
24341 std::stringstream ss(args_str);
24342 std::string arg;
24343 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024344 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024345 }
24346
24347 return args;
24348}
24349
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024350void addFullTestCommentIfPresent(const ::testing::TestInfo &test_info, std::string &error_message) {
24351 const char *const type_param = test_info.type_param();
24352 const char *const value_param = test_info.value_param();
Cody Northropb94529f2017-04-05 13:05:51 -060024353
24354 if (type_param != NULL || value_param != NULL) {
24355 error_message.append(", where ");
24356 if (type_param != NULL) {
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024357 error_message.append("TypeParam = ").append(type_param);
24358 if (value_param != NULL) error_message.append(" and ");
Cody Northropb94529f2017-04-05 13:05:51 -060024359 }
24360 if (value_param != NULL) {
24361 error_message.append("GetParam() = ").append(value_param);
24362 }
24363 }
24364}
24365
24366// Inspired by https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md
24367class LogcatPrinter : public ::testing::EmptyTestEventListener {
24368 // Called before a test starts.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024369 virtual void OnTestStart(const ::testing::TestInfo &test_info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024370 __android_log_print(ANDROID_LOG_INFO, appTag, "[ RUN ] %s.%s", test_info.test_case_name(), test_info.name());
24371 }
24372
24373 // Called after a failed assertion or a SUCCEED() invocation.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024374 virtual void OnTestPartResult(const ::testing::TestPartResult &result) {
Cody Northropb94529f2017-04-05 13:05:51 -060024375 // If the test part succeeded, we don't need to do anything.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024376 if (result.type() == ::testing::TestPartResult::kSuccess) return;
Cody Northropb94529f2017-04-05 13:05:51 -060024377
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024378 __android_log_print(ANDROID_LOG_INFO, appTag, "%s in %s:%d %s", result.failed() ? "*** Failure" : "Success",
24379 result.file_name(), result.line_number(), result.summary());
Cody Northropb94529f2017-04-05 13:05:51 -060024380 }
24381
24382 // Called after a test ends.
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024383 virtual void OnTestEnd(const ::testing::TestInfo &info) {
Cody Northropb94529f2017-04-05 13:05:51 -060024384 std::string result;
24385 if (info.result()->Passed()) {
24386 result.append("[ OK ]");
24387 } else {
24388 result.append("[ FAILED ]");
24389 }
24390 result.append(info.test_case_name()).append(".").append(info.name());
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024391 if (info.result()->Failed()) addFullTestCommentIfPresent(info, result);
Cody Northropb94529f2017-04-05 13:05:51 -060024392
24393 if (::testing::GTEST_FLAG(print_time)) {
24394 std::ostringstream os;
24395 os << info.result()->elapsed_time();
24396 result.append(" (").append(os.str()).append(" ms)");
24397 }
24398
24399 __android_log_print(ANDROID_LOG_INFO, appTag, "%s", result.c_str());
24400 };
24401};
24402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024403static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024405static void processCommand(struct android_app *app, int32_t cmd) {
24406 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024407 case APP_CMD_INIT_WINDOW: {
24408 if (app->window) {
24409 initialized = true;
24410 }
24411 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024412 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024413 case APP_CMD_GAINED_FOCUS: {
24414 active = true;
24415 break;
24416 }
24417 case APP_CMD_LOST_FOCUS: {
24418 active = false;
24419 break;
24420 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024421 }
24422}
24423
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024424void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024425 app_dummy();
24426
Cody Northrop1242dfd2016-07-13 17:24:59 -060024427 int vulkanSupport = InitVulkan();
24428 if (vulkanSupport == 0) {
24429 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
24430 return;
24431 }
24432
24433 app->onAppCmd = processCommand;
24434 app->onInputEvent = processInput;
24435
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024436 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024437 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024438 struct android_poll_source *source;
24439 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060024440 if (source) {
24441 source->process(app, source);
24442 }
24443
24444 if (app->destroyRequested != 0) {
24445 VkTestFramework::Finish();
24446 return;
24447 }
24448 }
24449
24450 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024451 // Use the following key to send arguments to gtest, i.e.
24452 // --es args "--gtest_filter=-VkLayerTest.foo"
24453 const char key[] = "args";
24454 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024456 std::string filter = "";
24457 if (args.size() > 0) {
24458 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
24459 filter += args[0];
24460 } else {
24461 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
24462 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024463
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024464 int argc = 2;
24465 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
24466 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024467
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024468 // Route output to files until we can override the gtest output
24469 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
24470 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024471
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024472 ::testing::InitGoogleTest(&argc, argv);
Cody Northropb94529f2017-04-05 13:05:51 -060024473
Dave Houlton11dcd5e2017-04-25 16:00:10 -060024474 ::testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
Cody Northropb94529f2017-04-05 13:05:51 -060024475 listeners.Append(new LogcatPrinter);
24476
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024477 VkTestFramework::InitArgs(&argc, argv);
24478 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024479
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024480 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024481
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024482 if (result != 0) {
24483 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
24484 } else {
24485 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
24486 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060024487
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024488 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060024489
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024490 fclose(stdout);
24491 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060024492
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024493 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060024494 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060024495 }
24496 }
24497}
24498#endif
24499
Tony Barbour300a6082015-04-07 13:44:53 -060024500int main(int argc, char **argv) {
24501 int result;
24502
Cody Northrop8e54a402016-03-08 22:25:52 -070024503#ifdef ANDROID
24504 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070024505 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070024506#endif
24507
Tony Barbour300a6082015-04-07 13:44:53 -060024508 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060024509 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060024510
24511 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
24512
24513 result = RUN_ALL_TESTS();
24514
Tony Barbour6918cd52015-04-09 12:58:51 -060024515 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060024516 return result;
24517}