blob: 0d2547c00be6d0ee102e60d81e614fd987a468f5 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 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>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070059 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070087static const char bindStateVertShaderText[] =
88 "#version 450\n"
89 "vec2 vertices[3];\n"
90 "out gl_PerVertex {\n"
91 " vec4 gl_Position;\n"
92 "};\n"
93 "void main() {\n"
94 " vertices[0] = vec2(-1.0, -1.0);\n"
95 " vertices[1] = vec2( 1.0, -1.0);\n"
96 " vertices[2] = vec2( 0.0, 1.0);\n"
97 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
98 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050099
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700100static const char bindStateFragShaderText[] =
101 "#version 450\n"
102 "\n"
103 "layout(location = 0) out vec4 uFragColor;\n"
104 "void main(){\n"
105 " uFragColor = vec4(0,1,0,1);\n"
106 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500107
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600108static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
109 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
110 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600111
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600112// ErrorMonitor Usage:
113//
Dave Houltonfbf52152017-01-06 12:55:29 -0700114// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600115// encountered log messages, or a validation error enum identifying
116// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
117// will match all log messages. logMsg will return true for skipCall
118// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600119//
Dave Houltonfbf52152017-01-06 12:55:29 -0700120// Call VerifyFound to determine if all desired failure messages
121// were encountered. Call VerifyNotFound to determine if any unexpected
122// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600123class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700124 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700125 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700126 test_platform_thread_create_mutex(&mutex_);
127 test_platform_thread_lock_mutex(&mutex_);
128 Reset();
129 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600130 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600131
Dave Houltonfbf52152017-01-06 12:55:29 -0700132 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600133
Dave Houltonfbf52152017-01-06 12:55:29 -0700134 // Set monitor to pristine state
135 void Reset() {
136 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
137 bailout_ = NULL;
138 message_found_ = VK_FALSE;
139 failure_message_strings_.clear();
140 desired_message_strings_.clear();
141 desired_message_ids_.clear();
142 other_messages_.clear();
143 message_outstanding_count_ = 0;
144 }
145
146 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700147 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700148 test_platform_thread_lock_mutex(&mutex_);
149 desired_message_strings_.insert(msgString);
150 message_flags_ |= msgFlags;
151 message_outstanding_count_++;
152 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600153 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600154
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700155 // ErrorMonitor will look for an error message containing the specified string(s)
156 template <typename Iter>
157 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
158 for (; iter != end; ++iter) {
159 SetDesiredFailureMsg(msgFlags, *iter);
160 }
161 }
162
Dave Houltonfbf52152017-01-06 12:55:29 -0700163 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700164 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700165 test_platform_thread_lock_mutex(&mutex_);
166 desired_message_ids_.insert(msg_id);
167 message_flags_ |= msgFlags;
168 message_outstanding_count_++;
169 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600170 }
171
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700172 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600173 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700174 test_platform_thread_lock_mutex(&mutex_);
175 if (bailout_ != NULL) {
176 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600177 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600178 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600179 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600180
Dave Houltonfbf52152017-01-06 12:55:29 -0700181 for (auto desired_msg : desired_message_strings_) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600182 if (desired_msg.length() == 0) {
183 // An empty desired_msg string "" indicates a positive test - not expecting an error.
184 // Return true to avoid calling layers/driver with this error.
185 // And don't erase the "" string, so it remains if another error is found.
186 result = VK_TRUE;
Tony Barbourae58dba2016-12-13 16:30:36 -0700187 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700188 message_found_ = VK_TRUE;
189 failure_message_strings_.insert(errorString);
Karl Schultz05cc4e32016-10-12 13:25:23 -0600190 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600191 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700192 message_outstanding_count_--;
193 failure_message_strings_.insert(errorString);
194 message_found_ = VK_TRUE;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600195 result = VK_TRUE;
196 // We only want one match for each expected error so remove from set here
197 // Since we're about the break the loop it's ok to remove from set we're iterating over
Dave Houltonfbf52152017-01-06 12:55:29 -0700198 desired_message_strings_.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600199 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600200 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600201 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700202 for (auto desired_id : desired_message_ids_) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600203 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
204 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
205 // Return true to avoid calling layers/driver with this error.
206 result = VK_TRUE;
207 } else if (desired_id == message_code) {
208 // Double-check that the string matches the error enum
209 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
210 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700211 message_outstanding_count_--;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600212 result = VK_TRUE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700213 message_found_ = VK_TRUE;
214 desired_message_ids_.erase(desired_id);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600215 break;
216 } else {
217 // Treat this message as a regular unexpected error, but print a warning jic
218 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
219 errorString.c_str(), desired_id, validation_error_map[desired_id]);
220 }
221 }
222 }
223
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600224 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200225 printf("Unexpected: %s\n", msgString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700226 other_messages_.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600227 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700228 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600229 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600230 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600231
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700232 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600233
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700234 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600235
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700236 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600237
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700238 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700239
240 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600241
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700242 void DumpFailureMsgs(void) const {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600243 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600244 if (otherMsgs.size()) {
245 cout << "Other error messages logged for this test were:" << endl;
246 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
247 cout << " " << *iter << endl;
248 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600249 }
250 }
251
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600252 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200253
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600254 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700255 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600256 // Match ANY message matching specified type
257 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700258 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200259 }
260
261 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600262 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700263 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200264 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700265 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700266 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600267 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700268 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700269 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600270 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200271 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700272 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200273 }
274
275 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600276 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700277 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200278 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700279 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700280 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600281 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200282 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700283 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200284 }
285
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700286 private:
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700287 VkFlags message_flags_;
288 std::unordered_set<uint32_t> desired_message_ids_;
289 std::unordered_set<string> desired_message_strings_;
290 std::unordered_set<string> failure_message_strings_;
291 vector<string> other_messages_;
292 test_platform_thread_mutex mutex_;
293 bool *bailout_;
294 VkBool32 message_found_;
295 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600296};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500297
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600298static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
299 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
300 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600301 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
302 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600303 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600304 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600305 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600306}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500307
Karl Schultz6addd812016-02-02 17:17:23 -0700308class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700309 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600310 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
311 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700312 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600313 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
314 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700315 }
Tony Barbour300a6082015-04-07 13:44:53 -0600316
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600317 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
318 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700319 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600320 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700321 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600322 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700323 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600324 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
325 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
326 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700327 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
328 }
329 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
330 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
331 }
332
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700333 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700334 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600335 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600336
337 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600338 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600339 std::vector<const char *> instance_extension_names;
340 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600341
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700342 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600343 /*
344 * Since CreateDbgMsgCallback is an instance level extension call
345 * any extension / layer that utilizes that feature also needs
346 * to be enabled at create instance time.
347 */
Karl Schultz6addd812016-02-02 17:17:23 -0700348 // Use Threading layer first to protect others from
349 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700350 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600351 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800352 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700353 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800354 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600355 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700356 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600357
Ian Elliott2c1daf52016-05-12 09:41:46 -0600358 if (m_enableWSI) {
359 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
360 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
361#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
362#if defined(VK_USE_PLATFORM_ANDROID_KHR)
363 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700364#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600365#if defined(VK_USE_PLATFORM_MIR_KHR)
366 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700367#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600368#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
369 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700370#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600371#if defined(VK_USE_PLATFORM_WIN32_KHR)
372 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700373#endif // VK_USE_PLATFORM_WIN32_KHR
374#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600375#if defined(VK_USE_PLATFORM_XCB_KHR)
376 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
377#elif defined(VK_USE_PLATFORM_XLIB_KHR)
378 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700379#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600380 }
381
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600382 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600383 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800384 this->app_info.pApplicationName = "layer_tests";
385 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600386 this->app_info.pEngineName = "unittest";
387 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600388 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600389
Tony Barbour15524c32015-04-29 17:34:29 -0600390 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600391 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600392 }
393
394 virtual void TearDown() {
395 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600396 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600397 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600398 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600399
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600400 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600401};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500402
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600403void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500404 // Create identity matrix
405 int i;
406 struct vktriangle_vs_uniform data;
407
408 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700409 glm::mat4 View = glm::mat4(1.0f);
410 glm::mat4 Model = glm::mat4(1.0f);
411 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500412 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700413 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500414
415 memcpy(&data.mvp, &MVP[0][0], matrixSize);
416
Karl Schultz6addd812016-02-02 17:17:23 -0700417 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600418 {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 -0500419 };
420
Karl Schultz6addd812016-02-02 17:17:23 -0700421 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500422 data.position[i][0] = tri_data[i].posX;
423 data.position[i][1] = tri_data[i].posY;
424 data.position[i][2] = tri_data[i].posZ;
425 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700426 data.color[i][0] = tri_data[i].r;
427 data.color[i][1] = tri_data[i].g;
428 data.color[i][2] = tri_data[i].b;
429 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500430 }
431
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500432 ASSERT_NO_FATAL_FAILURE(InitViewport());
433
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200434 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
435 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500436
Karl Schultz6addd812016-02-02 17:17:23 -0700437 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600438 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500439
440 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800441 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500442 pipelineobj.AddShader(&vs);
443 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600444 if (failMask & BsoFailLineWidth) {
445 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600446 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600447 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600448 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
449 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600450 }
451 if (failMask & BsoFailDepthBias) {
452 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600453 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600454 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600455 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600456 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600457 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600458 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700459 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700460 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600461 if (failMask & BsoFailViewport) {
462 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
463 }
464 if (failMask & BsoFailScissor) {
465 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
466 }
467 if (failMask & BsoFailBlend) {
468 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 VkPipelineColorBlendAttachmentState att_state = {};
470 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
471 att_state.blendEnable = VK_TRUE;
472 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600473 }
474 if (failMask & BsoFailDepthBounds) {
475 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
476 }
477 if (failMask & BsoFailStencilReadMask) {
478 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
479 }
480 if (failMask & BsoFailStencilWriteMask) {
481 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
482 }
483 if (failMask & BsoFailStencilReference) {
484 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
485 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500486
487 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600488 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500489
490 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700491 m_commandBuffer->BeginCommandBuffer();
492 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500493
Tony Barbourfe3351b2015-07-28 10:17:20 -0600494 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500495
496 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600497 if (failMask & BsoFailIndexBuffer) {
498 // Use DrawIndexed w/o an index buffer bound
499 DrawIndexed(3, 1, 0, 0, 0);
500 } else {
501 Draw(3, 1, 0, 0);
502 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503
Mark Muellerd4914412016-06-13 17:52:06 -0600504 if (failMask & BsoFailCmdClearAttachments) {
505 VkClearAttachment color_attachment = {};
506 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700507 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600508 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
509
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600510 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600511 }
512
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700514 m_commandBuffer->EndRenderPass();
515 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600516 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500517}
518
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600519void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
520 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500521 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600522 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500523 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600524 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500525 }
526
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800527 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700528 // Make sure depthWriteEnable is set so that Depth fail test will work
529 // correctly
530 // Make sure stencilTestEnable is set so that Stencil fail test will work
531 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600532 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800533 stencil.failOp = VK_STENCIL_OP_KEEP;
534 stencil.passOp = VK_STENCIL_OP_KEEP;
535 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
536 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600537
538 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
539 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600540 ds_ci.pNext = NULL;
541 ds_ci.depthTestEnable = VK_FALSE;
542 ds_ci.depthWriteEnable = VK_TRUE;
543 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
544 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600545 if (failMask & BsoFailDepthBounds) {
546 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600547 ds_ci.maxDepthBounds = 0.0f;
548 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600549 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600550 ds_ci.stencilTestEnable = VK_TRUE;
551 ds_ci.front = stencil;
552 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600553
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600554 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600555 pipelineobj.SetViewport(m_viewports);
556 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800557 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600558 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600559 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800560 commandBuffer->BindPipeline(pipelineobj);
561 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500562}
563
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600564class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700565 public:
566 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600567};
568
Ian Elliott2c1daf52016-05-12 09:41:46 -0600569class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700570 public:
571 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600572 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600573};
574
Mark Muellerdfe37552016-07-07 14:47:42 -0600575class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700576 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600577 enum eTestEnFlags {
578 eDoubleDelete,
579 eInvalidDeviceOffset,
580 eInvalidMemoryOffset,
581 eBindNullBuffer,
582 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600583 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600584 };
585
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600586 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600587
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600588 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
589 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600590 return true;
591 }
592 VkDeviceSize offset_limit = 0;
593 if (eInvalidMemoryOffset == aTestFlag) {
594 VkBuffer vulkanBuffer;
595 VkBufferCreateInfo buffer_create_info = {};
596 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
597 buffer_create_info.size = 32;
598 buffer_create_info.usage = aBufferUsage;
599
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600600 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600601 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600602
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600603 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600604 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
605 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600606 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
607 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600608 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600609 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600610 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600611 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600612 }
613 if (eOffsetAlignment < offset_limit) {
614 return true;
615 }
616 return false;
617 }
618
619 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600620 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
621 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600622 if (eBindNullBuffer == aTestFlag) {
623 VulkanMemory = 0;
624 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
625 } else {
626 VkBufferCreateInfo buffer_create_info = {};
627 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
628 buffer_create_info.size = 32;
629 buffer_create_info.usage = aBufferUsage;
630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600632
633 CreateCurrent = true;
634
635 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600636 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600637
638 VkMemoryAllocateInfo memory_allocate_info = {};
639 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
640 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600641 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
642 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600643 if (!pass) {
644 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
645 return;
646 }
647
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600648 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600649 AllocateCurrent = true;
650 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
652 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 BoundCurrent = true;
654
655 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
656 }
657 }
658
659 ~VkBufferTest() {
660 if (CreateCurrent) {
661 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
662 }
663 if (AllocateCurrent) {
664 if (InvalidDeleteEn) {
665 union {
666 VkDeviceMemory device_memory;
667 unsigned long long index_access;
668 } bad_index;
669
670 bad_index.device_memory = VulkanMemory;
671 bad_index.index_access++;
672
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600673 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 }
675 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
676 }
677 }
678
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600679 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600680
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600681 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600682
683 void TestDoubleDestroy() {
684 // Destroy the buffer but leave the flag set, which will cause
685 // the buffer to be destroyed again in the destructor.
686 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
687 }
688
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700689 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600690 bool AllocateCurrent;
691 bool BoundCurrent;
692 bool CreateCurrent;
693 bool InvalidDeleteEn;
694
695 VkBuffer VulkanBuffer;
696 VkDevice VulkanDevice;
697 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600698};
699
700class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700701 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600702 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600703 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700704 : BoundCurrent(false),
705 AttributeCount(aAttributeCount),
706 BindingCount(aBindingCount),
707 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600708 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600709 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
710 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700711 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600712
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600713 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
714 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600715
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600716 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
717 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
718 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
719 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
720 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600721
722 unsigned i = 0;
723 do {
724 VertexInputAttributeDescription[i].binding = BindId;
725 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600726 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
727 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600728 i++;
729 } while (AttributeCount < i);
730
731 i = 0;
732 do {
733 VertexInputBindingDescription[i].binding = BindId;
734 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600735 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600736 i++;
737 } while (BindingCount < i);
738 }
739
740 ~VkVerticesObj() {
741 if (VertexInputAttributeDescription) {
742 delete[] VertexInputAttributeDescription;
743 }
744 if (VertexInputBindingDescription) {
745 delete[] VertexInputBindingDescription;
746 }
747 }
748
749 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600750 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
751 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600752 return true;
753 }
754
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600755 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600756 VkDeviceSize *offsetList;
757 unsigned offsetCount;
758
759 if (aOffsetCount) {
760 offsetList = aOffsetList;
761 offsetCount = aOffsetCount;
762 } else {
763 offsetList = new VkDeviceSize[1]();
764 offsetCount = 1;
765 }
766
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600767 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600768 BoundCurrent = true;
769
770 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600772 }
773 }
774
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700775 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600776 static uint32_t BindIdGenerator;
777
778 bool BoundCurrent;
779 unsigned AttributeCount;
780 unsigned BindingCount;
781 uint32_t BindId;
782
783 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
784 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
785 VkVertexInputBindingDescription *VertexInputBindingDescription;
786 VkConstantBufferObj VulkanMemoryBuffer;
787};
788
789uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500790// ********************************************************************************************************************
791// ********************************************************************************************************************
792// ********************************************************************************************************************
793// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600794#if PARAMETER_VALIDATION_TESTS
795TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700796 TEST_DESCRIPTION(
797 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
798 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600799
800 ASSERT_NO_FATAL_FAILURE(InitState());
801
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600803 // Specify NULL for a pointer to a handle
804 // Expected to trigger an error with
805 // parameter_validation::validate_required_pointer
806 vkGetPhysicalDeviceFeatures(gpu(), NULL);
807 m_errorMonitor->VerifyFound();
808
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
810 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600811 // Specify NULL for pointer to array count
812 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600813 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600814 m_errorMonitor->VerifyFound();
815
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600817 // Specify 0 for a required array count
818 // Expected to trigger an error with parameter_validation::validate_array
819 VkViewport view_port = {};
820 m_commandBuffer->SetViewport(0, 0, &view_port);
821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600824 // Specify NULL for a required array
825 // Expected to trigger an error with parameter_validation::validate_array
826 m_commandBuffer->SetViewport(0, 1, NULL);
827 m_errorMonitor->VerifyFound();
828
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600830 // Specify VK_NULL_HANDLE for a required handle
831 // Expected to trigger an error with
832 // parameter_validation::validate_required_handle
833 vkUnmapMemory(device(), VK_NULL_HANDLE);
834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
837 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600838 // Specify VK_NULL_HANDLE for a required handle array entry
839 // Expected to trigger an error with
840 // parameter_validation::validate_required_handle_array
841 VkFence fence = VK_NULL_HANDLE;
842 vkResetFences(device(), 1, &fence);
843 m_errorMonitor->VerifyFound();
844
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600846 // Specify NULL for a required struct pointer
847 // Expected to trigger an error with
848 // parameter_validation::validate_struct_type
849 VkDeviceMemory memory = VK_NULL_HANDLE;
850 vkAllocateMemory(device(), NULL, NULL, &memory);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600854 // Specify 0 for a required VkFlags parameter
855 // Expected to trigger an error with parameter_validation::validate_flags
856 m_commandBuffer->SetStencilReference(0, 0);
857 m_errorMonitor->VerifyFound();
858
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600859 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 -0600860 // Specify 0 for a required VkFlags array entry
861 // Expected to trigger an error with
862 // parameter_validation::validate_flags_array
863 VkSemaphore semaphore = VK_NULL_HANDLE;
864 VkPipelineStageFlags stageFlags = 0;
865 VkSubmitInfo submitInfo = {};
866 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
867 submitInfo.waitSemaphoreCount = 1;
868 submitInfo.pWaitSemaphores = &semaphore;
869 submitInfo.pWaitDstStageMask = &stageFlags;
870 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
871 m_errorMonitor->VerifyFound();
872}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600873
Dustin Gravesfce74c02016-05-10 11:42:58 -0600874TEST_F(VkLayerTest, ReservedParameter) {
875 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
876
877 ASSERT_NO_FATAL_FAILURE(InitState());
878
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600880 // Specify 0 for a reserved VkFlags parameter
881 // Expected to trigger an error with
882 // parameter_validation::validate_reserved_flags
883 VkEvent event_handle = VK_NULL_HANDLE;
884 VkEventCreateInfo event_info = {};
885 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
886 event_info.flags = 1;
887 vkCreateEvent(device(), &event_info, NULL, &event_handle);
888 m_errorMonitor->VerifyFound();
889}
890
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600891TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700892 TEST_DESCRIPTION(
893 "Specify an invalid VkStructureType for a Vulkan "
894 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600895
896 ASSERT_NO_FATAL_FAILURE(InitState());
897
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600899 // Zero struct memory, effectively setting sType to
900 // VK_STRUCTURE_TYPE_APPLICATION_INFO
901 // Expected to trigger an error with
902 // parameter_validation::validate_struct_type
903 VkMemoryAllocateInfo alloc_info = {};
904 VkDeviceMemory memory = VK_NULL_HANDLE;
905 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
906 m_errorMonitor->VerifyFound();
907
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600909 // Zero struct memory, effectively setting sType to
910 // VK_STRUCTURE_TYPE_APPLICATION_INFO
911 // Expected to trigger an error with
912 // parameter_validation::validate_struct_type_array
913 VkSubmitInfo submit_info = {};
914 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
915 m_errorMonitor->VerifyFound();
916}
917
918TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600919 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600920
921 ASSERT_NO_FATAL_FAILURE(InitState());
922
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600924 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600925 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600926 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600927 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600928 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600929 // Zero-initialization will provide the correct sType
930 VkApplicationInfo app_info = {};
931 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
932 event_alloc_info.pNext = &app_info;
933 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
934 m_errorMonitor->VerifyFound();
935
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
937 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600938 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
939 // a function that has allowed pNext structure types and specify
940 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600941 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600942 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600943 VkMemoryAllocateInfo memory_alloc_info = {};
944 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
945 memory_alloc_info.pNext = &app_info;
946 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600947 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600948}
Dustin Graves5d33d532016-05-09 16:21:12 -0600949
950TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600951 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600952
953 ASSERT_NO_FATAL_FAILURE(InitState());
954
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
956 "does not fall within the begin..end "
957 "range of the core VkFormat "
958 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600959 // Specify an invalid VkFormat value
960 // Expected to trigger an error with
961 // parameter_validation::validate_ranged_enum
962 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600963 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600964 m_errorMonitor->VerifyFound();
965
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600966 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 -0600967 // Specify an invalid VkFlags bitmask value
968 // Expected to trigger an error with parameter_validation::validate_flags
969 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600970 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
971 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 m_errorMonitor->VerifyFound();
973
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600974 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 -0600975 // Specify an invalid VkFlags array entry
976 // Expected to trigger an error with
977 // parameter_validation::validate_flags_array
978 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600979 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600980 VkSubmitInfo submit_info = {};
981 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
982 submit_info.waitSemaphoreCount = 1;
983 submit_info.pWaitSemaphores = &semaphore;
984 submit_info.pWaitDstStageMask = &stage_flags;
985 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
986 m_errorMonitor->VerifyFound();
987
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600989 // Specify an invalid VkBool32 value
990 // Expected to trigger a warning with
991 // parameter_validation::validate_bool32
992 VkSampler sampler = VK_NULL_HANDLE;
993 VkSamplerCreateInfo sampler_info = {};
994 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
995 sampler_info.pNext = NULL;
996 sampler_info.magFilter = VK_FILTER_NEAREST;
997 sampler_info.minFilter = VK_FILTER_NEAREST;
998 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
999 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1000 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1001 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1002 sampler_info.mipLodBias = 1.0;
1003 sampler_info.maxAnisotropy = 1;
1004 sampler_info.compareEnable = VK_FALSE;
1005 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1006 sampler_info.minLod = 1.0;
1007 sampler_info.maxLod = 1.0;
1008 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1009 sampler_info.unnormalizedCoordinates = VK_FALSE;
1010 // Not VK_TRUE or VK_FALSE
1011 sampler_info.anisotropyEnable = 3;
1012 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1013 m_errorMonitor->VerifyFound();
1014}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001015
1016TEST_F(VkLayerTest, FailedReturnValue) {
1017 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1018
1019 ASSERT_NO_FATAL_FAILURE(InitState());
1020
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001021 // Find an unsupported image format
1022 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1023 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1024 VkFormat format = static_cast<VkFormat>(f);
1025 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001026 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001027 unsupported = format;
1028 break;
1029 }
1030 }
1031
1032 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1034 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001035 // Specify an unsupported VkFormat value to generate a
1036 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1037 // Expected to trigger a warning from
1038 // parameter_validation::validate_result
1039 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001040 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1041 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001042 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1043 m_errorMonitor->VerifyFound();
1044 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001045}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001046
1047TEST_F(VkLayerTest, UpdateBufferAlignment) {
1048 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001049 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001050
1051 ASSERT_NO_FATAL_FAILURE(InitState());
1052
1053 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1054 vk_testing::Buffer buffer;
1055 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1056
Tony Barbour552f6c02016-12-21 14:34:07 -07001057 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001058 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001060 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1061 m_errorMonitor->VerifyFound();
1062
1063 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001065 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1066 m_errorMonitor->VerifyFound();
1067
1068 // Introduce failure by using dataSize that is < 0
1069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001070 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001071 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1072 m_errorMonitor->VerifyFound();
1073
1074 // Introduce failure by using dataSize that is > 65536
1075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001076 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001077 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1078 m_errorMonitor->VerifyFound();
1079
Tony Barbour552f6c02016-12-21 14:34:07 -07001080 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001081}
1082
1083TEST_F(VkLayerTest, FillBufferAlignment) {
1084 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1085
1086 ASSERT_NO_FATAL_FAILURE(InitState());
1087
1088 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1089 vk_testing::Buffer buffer;
1090 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1091
Tony Barbour552f6c02016-12-21 14:34:07 -07001092 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001093
1094 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001096 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1097 m_errorMonitor->VerifyFound();
1098
1099 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001106 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1107 m_errorMonitor->VerifyFound();
1108
Tony Barbour552f6c02016-12-21 14:34:07 -07001109 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001110}
Dustin Graves40f35822016-06-23 11:12:53 -06001111
Cortd889ff92016-07-27 09:51:27 -07001112TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1113 VkResult err;
1114
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001115 TEST_DESCRIPTION(
1116 "Attempt to use a non-solid polygon fill mode in a "
1117 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001118
1119 ASSERT_NO_FATAL_FAILURE(InitState());
1120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1121
1122 std::vector<const char *> device_extension_names;
1123 auto features = m_device->phy().features();
1124 // Artificially disable support for non-solid fill modes
1125 features.fillModeNonSolid = false;
1126 // The sacrificial device object
1127 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1128
1129 VkRenderpassObj render_pass(&test_device);
1130
1131 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1132 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1133 pipeline_layout_ci.setLayoutCount = 0;
1134 pipeline_layout_ci.pSetLayouts = NULL;
1135
1136 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001137 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001138 ASSERT_VK_SUCCESS(err);
1139
1140 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1141 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1142 rs_ci.pNext = nullptr;
1143 rs_ci.lineWidth = 1.0f;
1144 rs_ci.rasterizerDiscardEnable = true;
1145
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001146 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1147 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001148
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001149 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1151 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001152 {
1153 VkPipelineObj pipe(&test_device);
1154 pipe.AddShader(&vs);
1155 pipe.AddShader(&fs);
1156 pipe.AddColorAttachment();
1157 // Introduce failure by setting unsupported polygon mode
1158 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1159 pipe.SetRasterization(&rs_ci);
1160 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1161 }
1162 m_errorMonitor->VerifyFound();
1163
1164 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1166 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001167 {
1168 VkPipelineObj pipe(&test_device);
1169 pipe.AddShader(&vs);
1170 pipe.AddShader(&fs);
1171 pipe.AddColorAttachment();
1172 // Introduce failure by setting unsupported polygon mode
1173 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1174 pipe.SetRasterization(&rs_ci);
1175 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1176 }
1177 m_errorMonitor->VerifyFound();
1178
Cortd889ff92016-07-27 09:51:27 -07001179 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1180}
1181
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001182#endif // PARAMETER_VALIDATION_TESTS
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001183
Tobin Ehlis0788f522015-05-26 16:11:58 -06001184#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001185#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001186TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001187{
1188 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001189 VkFenceCreateInfo fenceInfo = {};
1190 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1191 fenceInfo.pNext = NULL;
1192 fenceInfo.flags = 0;
1193
Mike Weiblencce7ec72016-10-17 19:33:05 -06001194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001195
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001196 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001197
1198 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1199 vk_testing::Buffer buffer;
1200 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001201
Tony Barbourfe3351b2015-07-28 10:17:20 -06001202 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001203 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001204 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001205
1206 testFence.init(*m_device, fenceInfo);
1207
1208 // Bypass framework since it does the waits automatically
1209 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001210 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001211 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1212 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001213 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001214 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001215 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001216 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001217 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001218 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001219 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001220
1221 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001222 ASSERT_VK_SUCCESS( err );
1223
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001224 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001225 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001226
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001227 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228}
1229
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001230TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001231{
1232 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001233 VkFenceCreateInfo fenceInfo = {};
1234 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1235 fenceInfo.pNext = NULL;
1236 fenceInfo.flags = 0;
1237
Mike Weiblencce7ec72016-10-17 19:33:05 -06001238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001239
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001240 ASSERT_NO_FATAL_FAILURE(InitState());
1241 ASSERT_NO_FATAL_FAILURE(InitViewport());
1242 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1243
Tony Barbourfe3351b2015-07-28 10:17:20 -06001244 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001245 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001246 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001247
1248 testFence.init(*m_device, fenceInfo);
1249
1250 // Bypass framework since it does the waits automatically
1251 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001252 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001253 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1254 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001255 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001256 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001257 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001258 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001259 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001260 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001261 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001262
1263 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001264 ASSERT_VK_SUCCESS( err );
1265
Jon Ashburnf19916e2016-01-11 13:12:43 -07001266 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001267 VkCommandBufferBeginInfo info = {};
1268 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1269 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001270 info.renderPass = VK_NULL_HANDLE;
1271 info.subpass = 0;
1272 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001273 info.occlusionQueryEnable = VK_FALSE;
1274 info.queryFlags = 0;
1275 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001276
1277 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001278 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001279
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001280 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001281}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001282#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001283
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001284TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1285 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1286
1287 ASSERT_NO_FATAL_FAILURE(InitState());
1288
1289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1290 VkBuffer buffer;
1291 VkBufferCreateInfo buf_info = {};
1292 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1293 buf_info.pNext = NULL;
1294 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1295 buf_info.size = 2048;
1296 buf_info.queueFamilyIndexCount = 0;
1297 buf_info.pQueueFamilyIndices = NULL;
1298 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1299 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1300 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1301 m_errorMonitor->VerifyFound();
1302
1303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1304 VkImage image;
1305 VkImageCreateInfo image_create_info = {};
1306 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1307 image_create_info.pNext = NULL;
1308 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1309 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1310 image_create_info.extent.width = 512;
1311 image_create_info.extent.height = 64;
1312 image_create_info.extent.depth = 1;
1313 image_create_info.mipLevels = 1;
1314 image_create_info.arrayLayers = 1;
1315 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1316 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1317 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1318 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1319 image_create_info.queueFamilyIndexCount = 0;
1320 image_create_info.pQueueFamilyIndices = NULL;
1321 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1322 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1323 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1324 m_errorMonitor->VerifyFound();
1325}
1326
Dave Houlton829c0d82017-01-24 15:09:17 -07001327TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1328 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1329
1330 // Determine which device feature are available
1331 VkPhysicalDeviceFeatures available_features;
1332 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1333
1334 // Mask out device features we don't want
1335 VkPhysicalDeviceFeatures desired_features = available_features;
1336 desired_features.sparseResidencyImage2D = VK_FALSE;
1337 desired_features.sparseResidencyImage3D = VK_FALSE;
1338 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1339
1340 VkImage image = VK_NULL_HANDLE;
1341 VkResult result = VK_RESULT_MAX_ENUM;
1342 VkImageCreateInfo image_create_info = {};
1343 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1344 image_create_info.pNext = NULL;
1345 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1346 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1347 image_create_info.extent.width = 512;
1348 image_create_info.extent.height = 1;
1349 image_create_info.extent.depth = 1;
1350 image_create_info.mipLevels = 1;
1351 image_create_info.arrayLayers = 1;
1352 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1353 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1354 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1355 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1356 image_create_info.queueFamilyIndexCount = 0;
1357 image_create_info.pQueueFamilyIndices = NULL;
1358 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1359 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1360
1361 // 1D image w/ sparse residency is an error
1362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1363 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1364 m_errorMonitor->VerifyFound();
1365 if (VK_SUCCESS == result) {
1366 vkDestroyImage(m_device->device(), image, NULL);
1367 image = VK_NULL_HANDLE;
1368 }
1369
1370 // 2D image w/ sparse residency when feature isn't available
1371 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1372 image_create_info.extent.height = 64;
1373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
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 // 3D image w/ sparse residency when feature isn't available
1382 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1383 image_create_info.extent.depth = 8;
1384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
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
1393TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1394 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1395
1396 // Determine which device feature are available
1397 VkPhysicalDeviceFeatures available_features;
1398 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1399
1400 // These tests all require that the device support sparse residency for 2D images
1401 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1402 return;
1403 }
1404
1405 // Mask out device features we don't want
1406 VkPhysicalDeviceFeatures desired_features = available_features;
1407 desired_features.sparseResidency2Samples = VK_FALSE;
1408 desired_features.sparseResidency4Samples = VK_FALSE;
1409 desired_features.sparseResidency8Samples = VK_FALSE;
1410 desired_features.sparseResidency16Samples = VK_FALSE;
1411 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1412
1413 VkImage image = VK_NULL_HANDLE;
1414 VkResult result = VK_RESULT_MAX_ENUM;
1415 VkImageCreateInfo image_create_info = {};
1416 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1417 image_create_info.pNext = NULL;
1418 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1419 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1420 image_create_info.extent.width = 64;
1421 image_create_info.extent.height = 64;
1422 image_create_info.extent.depth = 1;
1423 image_create_info.mipLevels = 1;
1424 image_create_info.arrayLayers = 1;
1425 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1426 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1427 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1428 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1429 image_create_info.queueFamilyIndexCount = 0;
1430 image_create_info.pQueueFamilyIndices = NULL;
1431 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1432 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1433
1434 // 2D image w/ sparse residency and linear tiling is an error
1435 m_errorMonitor->SetDesiredFailureMsg(
1436 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1437 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1438 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1439 m_errorMonitor->VerifyFound();
1440 if (VK_SUCCESS == result) {
1441 vkDestroyImage(m_device->device(), image, NULL);
1442 image = VK_NULL_HANDLE;
1443 }
1444 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1445
1446 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1447 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1449 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1450 m_errorMonitor->VerifyFound();
1451 if (VK_SUCCESS == result) {
1452 vkDestroyImage(m_device->device(), image, NULL);
1453 image = VK_NULL_HANDLE;
1454 }
1455
1456 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1458 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1459 m_errorMonitor->VerifyFound();
1460 if (VK_SUCCESS == result) {
1461 vkDestroyImage(m_device->device(), image, NULL);
1462 image = VK_NULL_HANDLE;
1463 }
1464
1465 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1467 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1468 m_errorMonitor->VerifyFound();
1469 if (VK_SUCCESS == result) {
1470 vkDestroyImage(m_device->device(), image, NULL);
1471 image = VK_NULL_HANDLE;
1472 }
1473
1474 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1476 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1477 m_errorMonitor->VerifyFound();
1478 if (VK_SUCCESS == result) {
1479 vkDestroyImage(m_device->device(), image, NULL);
1480 image = VK_NULL_HANDLE;
1481 }
1482}
1483
Tobin Ehlisf11be982016-05-11 13:52:53 -06001484TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001485 TEST_DESCRIPTION(
1486 "Create a buffer and image, allocate memory, and bind the "
1487 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001488 VkResult err;
1489 bool pass;
1490 ASSERT_NO_FATAL_FAILURE(InitState());
1491
Tobin Ehlis077ded32016-05-12 17:39:13 -06001492 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001493 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001494 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001495 VkDeviceMemory mem; // buffer will be bound first
1496 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001497 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001498 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001499
1500 VkBufferCreateInfo buf_info = {};
1501 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1502 buf_info.pNext = NULL;
1503 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1504 buf_info.size = 256;
1505 buf_info.queueFamilyIndexCount = 0;
1506 buf_info.pQueueFamilyIndices = NULL;
1507 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1508 buf_info.flags = 0;
1509 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1510 ASSERT_VK_SUCCESS(err);
1511
Tobin Ehlis077ded32016-05-12 17:39:13 -06001512 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001513
1514 VkImageCreateInfo image_create_info = {};
1515 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1516 image_create_info.pNext = NULL;
1517 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1518 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1519 image_create_info.extent.width = 64;
1520 image_create_info.extent.height = 64;
1521 image_create_info.extent.depth = 1;
1522 image_create_info.mipLevels = 1;
1523 image_create_info.arrayLayers = 1;
1524 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001525 // Image tiling must be optimal to trigger error when aliasing linear buffer
1526 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001527 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1528 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1529 image_create_info.queueFamilyIndexCount = 0;
1530 image_create_info.pQueueFamilyIndices = NULL;
1531 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1532 image_create_info.flags = 0;
1533
Tobin Ehlisf11be982016-05-11 13:52:53 -06001534 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1535 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001536 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1537 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001538
Tobin Ehlis077ded32016-05-12 17:39:13 -06001539 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1540
1541 VkMemoryAllocateInfo alloc_info = {};
1542 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1543 alloc_info.pNext = NULL;
1544 alloc_info.memoryTypeIndex = 0;
1545 // Ensure memory is big enough for both bindings
1546 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001547 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1548 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001549 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001550 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001551 vkDestroyImage(m_device->device(), image, NULL);
1552 return;
1553 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001554 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1555 ASSERT_VK_SUCCESS(err);
1556 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1557 ASSERT_VK_SUCCESS(err);
1558
Rene Lindsayd14f5572016-12-16 14:57:18 -07001559 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1560
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001562 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001563 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1564 m_errorMonitor->VerifyFound();
1565
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001566 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001567 // aliasing buffer2
1568 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1569 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001570 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1571 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001572 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001573 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001575 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001576 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001577 m_errorMonitor->VerifyFound();
1578
1579 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001580 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001581 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001582 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001583 vkFreeMemory(m_device->device(), mem, NULL);
1584 vkFreeMemory(m_device->device(), mem_img, NULL);
1585}
1586
Tobin Ehlis35372522016-05-12 08:32:31 -06001587TEST_F(VkLayerTest, InvalidMemoryMapping) {
1588 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1589 VkResult err;
1590 bool pass;
1591 ASSERT_NO_FATAL_FAILURE(InitState());
1592
1593 VkBuffer buffer;
1594 VkDeviceMemory mem;
1595 VkMemoryRequirements mem_reqs;
1596
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001597 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1598
Tobin Ehlis35372522016-05-12 08:32:31 -06001599 VkBufferCreateInfo buf_info = {};
1600 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1601 buf_info.pNext = NULL;
1602 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1603 buf_info.size = 256;
1604 buf_info.queueFamilyIndexCount = 0;
1605 buf_info.pQueueFamilyIndices = NULL;
1606 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1607 buf_info.flags = 0;
1608 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1609 ASSERT_VK_SUCCESS(err);
1610
1611 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1612 VkMemoryAllocateInfo alloc_info = {};
1613 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1614 alloc_info.pNext = NULL;
1615 alloc_info.memoryTypeIndex = 0;
1616
1617 // Ensure memory is big enough for both bindings
1618 static const VkDeviceSize allocation_size = 0x10000;
1619 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001620 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 -06001621 if (!pass) {
1622 vkDestroyBuffer(m_device->device(), buffer, NULL);
1623 return;
1624 }
1625 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1626 ASSERT_VK_SUCCESS(err);
1627
1628 uint8_t *pData;
1629 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001630 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 -06001631 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1632 m_errorMonitor->VerifyFound();
1633 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001634 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001635 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1637 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1638 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001639 m_errorMonitor->VerifyFound();
1640
1641 // Unmap the memory to avoid re-map error
1642 vkUnmapMemory(m_device->device(), mem);
1643 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1645 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1646 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001647 m_errorMonitor->VerifyFound();
1648 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1650 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001651 m_errorMonitor->VerifyFound();
1652 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001654 vkUnmapMemory(m_device->device(), mem);
1655 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001656
Tobin Ehlis35372522016-05-12 08:32:31 -06001657 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001658 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001659 ASSERT_VK_SUCCESS(err);
1660 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001661 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001662 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001663 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001665 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1666 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001667
Tobin Ehlis35372522016-05-12 08:32:31 -06001668 // Now flush range that oversteps mapped range
1669 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001670 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001671 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001672 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001673 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1675 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1676 m_errorMonitor->VerifyFound();
1677
1678 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1679 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001680 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001681 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001682 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001683 mmr.size = VK_WHOLE_SIZE;
1684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001685 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1686 m_errorMonitor->VerifyFound();
1687
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001688#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001689 // Some platforms have an atomsize of 1 which makes the test meaningless
1690 if (atom_size > 3) {
1691 // Now with an offset NOT a multiple of the device limit
1692 vkUnmapMemory(m_device->device(), mem);
1693 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1694 ASSERT_VK_SUCCESS(err);
1695 mmr.offset = 3; // Not a multiple of atom_size
1696 mmr.size = VK_WHOLE_SIZE;
1697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1698 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1699 m_errorMonitor->VerifyFound();
1700
1701 // Now with a size NOT a multiple of the device limit
1702 vkUnmapMemory(m_device->device(), mem);
1703 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1704 ASSERT_VK_SUCCESS(err);
1705 mmr.offset = atom_size;
1706 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1708 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1709 m_errorMonitor->VerifyFound();
1710 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001711#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001712 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1713 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001714 if (!pass) {
1715 vkFreeMemory(m_device->device(), mem, NULL);
1716 vkDestroyBuffer(m_device->device(), buffer, NULL);
1717 return;
1718 }
1719 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1720 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1721
1722 vkDestroyBuffer(m_device->device(), buffer, NULL);
1723 vkFreeMemory(m_device->device(), mem, NULL);
1724}
1725
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001726#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001727TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1728 VkResult err;
1729 bool pass;
1730
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001731 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1732 // following declaration (which is temporarily being moved below):
1733 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001734 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001735 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001736 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001737 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001738 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001739 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001740
1741 ASSERT_NO_FATAL_FAILURE(InitState());
1742
Ian Elliott3f06ce52016-04-29 14:46:21 -06001743#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1744#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1745 // Use the functions from the VK_KHR_android_surface extension without
1746 // enabling that extension:
1747
1748 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001749 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1751 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001752 pass = (err != VK_SUCCESS);
1753 ASSERT_TRUE(pass);
1754 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001755#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001756
Ian Elliott3f06ce52016-04-29 14:46:21 -06001757#if defined(VK_USE_PLATFORM_MIR_KHR)
1758 // Use the functions from the VK_KHR_mir_surface extension without enabling
1759 // that extension:
1760
1761 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001762 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001764 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1765 pass = (err != VK_SUCCESS);
1766 ASSERT_TRUE(pass);
1767 m_errorMonitor->VerifyFound();
1768
1769 // Tell whether an mir_connection supports presentation:
1770 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1772 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001773 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001774#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001775
Ian Elliott3f06ce52016-04-29 14:46:21 -06001776#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1777 // Use the functions from the VK_KHR_wayland_surface extension without
1778 // enabling that extension:
1779
1780 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001781 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1783 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001784 pass = (err != VK_SUCCESS);
1785 ASSERT_TRUE(pass);
1786 m_errorMonitor->VerifyFound();
1787
1788 // Tell whether an wayland_display supports presentation:
1789 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1791 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001792 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001793#endif // VK_USE_PLATFORM_WAYLAND_KHR
1794#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001795
Ian Elliott3f06ce52016-04-29 14:46:21 -06001796#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001797 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1798 // TO NON-LINUX PLATFORMS:
1799 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001800 // Use the functions from the VK_KHR_win32_surface extension without
1801 // enabling that extension:
1802
1803 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001804 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1806 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001807 pass = (err != VK_SUCCESS);
1808 ASSERT_TRUE(pass);
1809 m_errorMonitor->VerifyFound();
1810
1811 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001813 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001814 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001815// Set this (for now, until all platforms are supported and tested):
1816#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001817#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001818#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001819 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1820 // TO NON-LINUX PLATFORMS:
1821 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001822#endif
1823#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001824 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1825 // that extension:
1826
1827 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001828 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001830 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1831 pass = (err != VK_SUCCESS);
1832 ASSERT_TRUE(pass);
1833 m_errorMonitor->VerifyFound();
1834
1835 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001836 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001837 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1839 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001840 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001841// Set this (for now, until all platforms are supported and tested):
1842#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001843#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001844
Ian Elliott12630812016-04-29 14:35:43 -06001845#if defined(VK_USE_PLATFORM_XLIB_KHR)
1846 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1847 // that extension:
1848
1849 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001850 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001852 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1853 pass = (err != VK_SUCCESS);
1854 ASSERT_TRUE(pass);
1855 m_errorMonitor->VerifyFound();
1856
1857 // Tell whether an Xlib VisualID supports presentation:
1858 Display *dpy = NULL;
1859 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001861 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1862 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001863// Set this (for now, until all platforms are supported and tested):
1864#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001865#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001866
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001867// Use the functions from the VK_KHR_surface extension without enabling
1868// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001869
Ian Elliott489eec02016-05-05 14:12:44 -06001870#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001871 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001873 vkDestroySurfaceKHR(instance(), surface, NULL);
1874 m_errorMonitor->VerifyFound();
1875
1876 // Check if surface supports presentation:
1877 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001879 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1880 pass = (err != VK_SUCCESS);
1881 ASSERT_TRUE(pass);
1882 m_errorMonitor->VerifyFound();
1883
1884 // Check surface capabilities:
1885 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1887 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001888 pass = (err != VK_SUCCESS);
1889 ASSERT_TRUE(pass);
1890 m_errorMonitor->VerifyFound();
1891
1892 // Check surface formats:
1893 uint32_t format_count = 0;
1894 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1896 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001897 pass = (err != VK_SUCCESS);
1898 ASSERT_TRUE(pass);
1899 m_errorMonitor->VerifyFound();
1900
1901 // Check surface present modes:
1902 uint32_t present_mode_count = 0;
1903 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1905 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001906 pass = (err != VK_SUCCESS);
1907 ASSERT_TRUE(pass);
1908 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001909#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001910
Ian Elliott1c32c772016-04-28 14:47:13 -06001911 // Use the functions from the VK_KHR_swapchain extension without enabling
1912 // that extension:
1913
1914 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001916 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1917 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001918 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001919 pass = (err != VK_SUCCESS);
1920 ASSERT_TRUE(pass);
1921 m_errorMonitor->VerifyFound();
1922
1923 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1925 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001926 pass = (err != VK_SUCCESS);
1927 ASSERT_TRUE(pass);
1928 m_errorMonitor->VerifyFound();
1929
Chris Forbeseb7d5502016-09-13 18:19:21 +12001930 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1931 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1932 VkFence fence;
1933 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1934
Ian Elliott1c32c772016-04-28 14:47:13 -06001935 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001937 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001938 pass = (err != VK_SUCCESS);
1939 ASSERT_TRUE(pass);
1940 m_errorMonitor->VerifyFound();
1941
Chris Forbeseb7d5502016-09-13 18:19:21 +12001942 vkDestroyFence(m_device->device(), fence, nullptr);
1943
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001945 //
1946 // NOTE: Currently can't test this because a real swapchain is needed (as
1947 // opposed to the fake one we created) in order for the layer to lookup the
1948 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001949
1950 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001952 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1953 m_errorMonitor->VerifyFound();
1954}
Chris Forbes09368e42016-10-13 11:59:22 +13001955#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001956
Karl Schultz6addd812016-02-02 17:17:23 -07001957TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1958 VkResult err;
1959 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1962 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001963
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001964 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001965
1966 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001967 VkImage image;
1968 VkDeviceMemory mem;
1969 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001970
Karl Schultz6addd812016-02-02 17:17:23 -07001971 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1972 const int32_t tex_width = 32;
1973 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001974
Tony Barboureb254902015-07-15 12:50:33 -06001975 VkImageCreateInfo image_create_info = {};
1976 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001977 image_create_info.pNext = NULL;
1978 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1979 image_create_info.format = tex_format;
1980 image_create_info.extent.width = tex_width;
1981 image_create_info.extent.height = tex_height;
1982 image_create_info.extent.depth = 1;
1983 image_create_info.mipLevels = 1;
1984 image_create_info.arrayLayers = 1;
1985 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1986 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1987 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1988 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001989 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001990
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001991 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001992 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001993 mem_alloc.pNext = NULL;
1994 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001995
Chia-I Wuf7458c52015-10-26 21:10:41 +08001996 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001997 ASSERT_VK_SUCCESS(err);
1998
Karl Schultz6addd812016-02-02 17:17:23 -07001999 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002000
Mark Lobodzinski23065352015-05-29 09:32:35 -05002001 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002002
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002003 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 -07002004 if (!pass) { // If we can't find any unmappable memory this test doesn't
2005 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002006 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002007 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002008 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002009
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002010 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002011 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002012 ASSERT_VK_SUCCESS(err);
2013
2014 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002015 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002016 ASSERT_VK_SUCCESS(err);
2017
2018 // Map memory as if to initialize the image
2019 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002020 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002021
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002022 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002023
Chia-I Wuf7458c52015-10-26 21:10:41 +08002024 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002025 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002026}
2027
Karl Schultz6addd812016-02-02 17:17:23 -07002028TEST_F(VkLayerTest, RebindMemory) {
2029 VkResult err;
2030 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002033
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002034 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002035
2036 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002037 VkImage image;
2038 VkDeviceMemory mem1;
2039 VkDeviceMemory mem2;
2040 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002041
Karl Schultz6addd812016-02-02 17:17:23 -07002042 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2043 const int32_t tex_width = 32;
2044 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002045
Tony Barboureb254902015-07-15 12:50:33 -06002046 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002047 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2048 image_create_info.pNext = NULL;
2049 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2050 image_create_info.format = tex_format;
2051 image_create_info.extent.width = tex_width;
2052 image_create_info.extent.height = tex_height;
2053 image_create_info.extent.depth = 1;
2054 image_create_info.mipLevels = 1;
2055 image_create_info.arrayLayers = 1;
2056 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2057 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2058 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2059 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002060
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002061 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002062 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2063 mem_alloc.pNext = NULL;
2064 mem_alloc.allocationSize = 0;
2065 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002066
Karl Schultz6addd812016-02-02 17:17:23 -07002067 // Introduce failure, do NOT set memProps to
2068 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002069 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002070 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002071 ASSERT_VK_SUCCESS(err);
2072
Karl Schultz6addd812016-02-02 17:17:23 -07002073 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002074
2075 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002076 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002077 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002078
2079 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002080 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002081 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002082 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002083 ASSERT_VK_SUCCESS(err);
2084
2085 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002086 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002087 ASSERT_VK_SUCCESS(err);
2088
Karl Schultz6addd812016-02-02 17:17:23 -07002089 // Introduce validation failure, try to bind a different memory object to
2090 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002091 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002092
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002093 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002094
Chia-I Wuf7458c52015-10-26 21:10:41 +08002095 vkDestroyImage(m_device->device(), image, NULL);
2096 vkFreeMemory(m_device->device(), mem1, NULL);
2097 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002098}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002099
Karl Schultz6addd812016-02-02 17:17:23 -07002100TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002101 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002102
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2104 "submitted in SIGNALED state. Fences "
2105 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002106
2107 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002108 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2109 fenceInfo.pNext = NULL;
2110 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002111
Tony Barbour300a6082015-04-07 13:44:53 -06002112 ASSERT_NO_FATAL_FAILURE(InitState());
2113 ASSERT_NO_FATAL_FAILURE(InitViewport());
2114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2115
Tony Barbour552f6c02016-12-21 14:34:07 -07002116 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002117 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002118 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002119
2120 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002121
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002122 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002123 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2124 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002125 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002126 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002127 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002128 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002129 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002130 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002131 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002132
2133 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002134 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002135
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002136 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002137}
Chris Forbes4e44c912016-06-16 10:20:00 +12002138
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002139TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002140 TEST_DESCRIPTION(
2141 "Specify wrong usage for image then create conflicting view of image "
2142 "Initialize buffer with wrong usage then perform copy expecting errors "
2143 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002145
2146 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002147
2148 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
2149
Tony Barbourf92621a2016-05-02 14:28:12 -06002150 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002151 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002152 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002153 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002154
Tony Barbourf92621a2016-05-02 14:28:12 -06002155 VkImageView dsv;
2156 VkImageViewCreateInfo dsvci = {};
2157 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2158 dsvci.image = image.handle();
2159 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002160 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002161 dsvci.subresourceRange.layerCount = 1;
2162 dsvci.subresourceRange.baseMipLevel = 0;
2163 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002164 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002165
Tony Barbourf92621a2016-05-02 14:28:12 -06002166 // Create a view with depth / stencil aspect for image with different usage
2167 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002168
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002169 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002170
2171 // Initialize buffer with TRANSFER_DST usage
2172 vk_testing::Buffer buffer;
2173 VkMemoryPropertyFlags reqs = 0;
2174 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2175 VkBufferImageCopy region = {};
2176 region.bufferRowLength = 128;
2177 region.bufferImageHeight = 128;
2178 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2179 region.imageSubresource.layerCount = 1;
2180 region.imageExtent.height = 16;
2181 region.imageExtent.width = 16;
2182 region.imageExtent.depth = 1;
2183
Tony Barbourf92621a2016-05-02 14:28:12 -06002184 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2185 // TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002186 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002187
Chris Forbesda581202016-10-06 18:25:26 +13002188 // two separate errors from this call:
2189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2191
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002192 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2193 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002194 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002195}
Tony Barbour75d79f02016-08-30 09:39:07 -06002196
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002197#endif // MEM_TRACKER_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002198
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002199#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002200
2201TEST_F(VkLayerTest, LeakAnObject) {
2202 VkResult err;
2203
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002204 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002205
2206 // Note that we have to create a new device since destroying the
2207 // framework's device causes Teardown() to fail and just calling Teardown
2208 // will destroy the errorMonitor.
2209
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002211
2212 ASSERT_NO_FATAL_FAILURE(InitState());
2213
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002214 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002215 std::vector<VkDeviceQueueCreateInfo> queue_info;
2216 queue_info.reserve(queue_props.size());
2217 std::vector<std::vector<float>> queue_priorities;
2218 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2219 VkDeviceQueueCreateInfo qi = {};
2220 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2221 qi.pNext = NULL;
2222 qi.queueFamilyIndex = i;
2223 qi.queueCount = queue_props[i].queueCount;
2224 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2225 qi.pQueuePriorities = queue_priorities[i].data();
2226 queue_info.push_back(qi);
2227 }
2228
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002229 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002230
2231 // The sacrificial device object
2232 VkDevice testDevice;
2233 VkDeviceCreateInfo device_create_info = {};
2234 auto features = m_device->phy().features();
2235 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2236 device_create_info.pNext = NULL;
2237 device_create_info.queueCreateInfoCount = queue_info.size();
2238 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002239 device_create_info.enabledLayerCount = 0;
2240 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002241 device_create_info.pEnabledFeatures = &features;
2242 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2243 ASSERT_VK_SUCCESS(err);
2244
2245 VkFence fence;
2246 VkFenceCreateInfo fence_create_info = {};
2247 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2248 fence_create_info.pNext = NULL;
2249 fence_create_info.flags = 0;
2250 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2251 ASSERT_VK_SUCCESS(err);
2252
2253 // Induce failure by not calling vkDestroyFence
2254 vkDestroyDevice(testDevice, NULL);
2255 m_errorMonitor->VerifyFound();
2256}
2257
2258TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002259 TEST_DESCRIPTION(
2260 "Allocate command buffers from one command pool and "
2261 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002262
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002264
Cody Northropc31a84f2016-08-22 10:41:47 -06002265 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002266 VkCommandPool command_pool_one;
2267 VkCommandPool command_pool_two;
2268
2269 VkCommandPoolCreateInfo pool_create_info{};
2270 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2271 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2272 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2273
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002274 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002275
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002276 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002277
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002278 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002279 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002280 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002281 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002282 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002283 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002284 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002285
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002286 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002287
2288 m_errorMonitor->VerifyFound();
2289
2290 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2291 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2292}
2293
2294TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2295 VkResult err;
2296
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002297 TEST_DESCRIPTION(
2298 "Allocate descriptor sets from one DS pool and "
2299 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002300
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002302
2303 ASSERT_NO_FATAL_FAILURE(InitState());
2304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2305
2306 VkDescriptorPoolSize ds_type_count = {};
2307 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2308 ds_type_count.descriptorCount = 1;
2309
2310 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2311 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2312 ds_pool_ci.pNext = NULL;
2313 ds_pool_ci.flags = 0;
2314 ds_pool_ci.maxSets = 1;
2315 ds_pool_ci.poolSizeCount = 1;
2316 ds_pool_ci.pPoolSizes = &ds_type_count;
2317
2318 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002319 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002320 ASSERT_VK_SUCCESS(err);
2321
2322 // Create a second descriptor pool
2323 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002324 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002325 ASSERT_VK_SUCCESS(err);
2326
2327 VkDescriptorSetLayoutBinding dsl_binding = {};
2328 dsl_binding.binding = 0;
2329 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2330 dsl_binding.descriptorCount = 1;
2331 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2332 dsl_binding.pImmutableSamplers = NULL;
2333
2334 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2335 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2336 ds_layout_ci.pNext = NULL;
2337 ds_layout_ci.bindingCount = 1;
2338 ds_layout_ci.pBindings = &dsl_binding;
2339
2340 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002341 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002342 ASSERT_VK_SUCCESS(err);
2343
2344 VkDescriptorSet descriptorSet;
2345 VkDescriptorSetAllocateInfo alloc_info = {};
2346 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2347 alloc_info.descriptorSetCount = 1;
2348 alloc_info.descriptorPool = ds_pool_one;
2349 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002350 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002351 ASSERT_VK_SUCCESS(err);
2352
2353 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2354
2355 m_errorMonitor->VerifyFound();
2356
2357 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2358 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2359 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2360}
2361
2362TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002364
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002365 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002366
2367 ASSERT_NO_FATAL_FAILURE(InitState());
2368
2369 // Pass bogus handle into GetImageMemoryRequirements
2370 VkMemoryRequirements mem_reqs;
2371 uint64_t fakeImageHandle = 0xCADECADE;
2372 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2373
2374 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2375
2376 m_errorMonitor->VerifyFound();
2377}
2378
Karl Schultz6addd812016-02-02 17:17:23 -07002379TEST_F(VkLayerTest, PipelineNotBound) {
2380 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002381
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002382 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002383
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002385
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002386 ASSERT_NO_FATAL_FAILURE(InitState());
2387 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002388
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002389 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002390 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2391 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002392
2393 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002394 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2395 ds_pool_ci.pNext = NULL;
2396 ds_pool_ci.maxSets = 1;
2397 ds_pool_ci.poolSizeCount = 1;
2398 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002399
2400 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002401 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002402 ASSERT_VK_SUCCESS(err);
2403
2404 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002405 dsl_binding.binding = 0;
2406 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2407 dsl_binding.descriptorCount = 1;
2408 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2409 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002410
2411 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002412 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2413 ds_layout_ci.pNext = NULL;
2414 ds_layout_ci.bindingCount = 1;
2415 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002416
2417 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002418 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002419 ASSERT_VK_SUCCESS(err);
2420
2421 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002422 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002423 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002424 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002425 alloc_info.descriptorPool = ds_pool;
2426 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002427 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002428 ASSERT_VK_SUCCESS(err);
2429
2430 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002431 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2432 pipeline_layout_ci.pNext = NULL;
2433 pipeline_layout_ci.setLayoutCount = 1;
2434 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002435
2436 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002437 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002438 ASSERT_VK_SUCCESS(err);
2439
Mark Youngad779052016-01-06 14:26:04 -07002440 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002441
Tony Barbour552f6c02016-12-21 14:34:07 -07002442 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002443 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002444
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002445 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002446
Chia-I Wuf7458c52015-10-26 21:10:41 +08002447 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2448 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2449 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002450}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002451
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002452TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2453 VkResult err;
2454
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002455 TEST_DESCRIPTION(
2456 "Test validation check for an invalid memory type index "
2457 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002458
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002459 ASSERT_NO_FATAL_FAILURE(InitState());
2460
2461 // Create an image, allocate memory, set a bad typeIndex and then try to
2462 // bind it
2463 VkImage image;
2464 VkDeviceMemory mem;
2465 VkMemoryRequirements mem_reqs;
2466 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2467 const int32_t tex_width = 32;
2468 const int32_t tex_height = 32;
2469
2470 VkImageCreateInfo image_create_info = {};
2471 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2472 image_create_info.pNext = NULL;
2473 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2474 image_create_info.format = tex_format;
2475 image_create_info.extent.width = tex_width;
2476 image_create_info.extent.height = tex_height;
2477 image_create_info.extent.depth = 1;
2478 image_create_info.mipLevels = 1;
2479 image_create_info.arrayLayers = 1;
2480 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2481 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2482 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2483 image_create_info.flags = 0;
2484
2485 VkMemoryAllocateInfo mem_alloc = {};
2486 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2487 mem_alloc.pNext = NULL;
2488 mem_alloc.allocationSize = 0;
2489 mem_alloc.memoryTypeIndex = 0;
2490
2491 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2492 ASSERT_VK_SUCCESS(err);
2493
2494 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2495 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002496
2497 // Introduce Failure, select invalid TypeIndex
2498 VkPhysicalDeviceMemoryProperties memory_info;
2499
2500 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2501 unsigned int i;
2502 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2503 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2504 mem_alloc.memoryTypeIndex = i;
2505 break;
2506 }
2507 }
2508 if (i >= memory_info.memoryTypeCount) {
2509 printf("No invalid memory type index could be found; skipped.\n");
2510 vkDestroyImage(m_device->device(), image, NULL);
2511 return;
2512 }
2513
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002514 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 -06002515
2516 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2517 ASSERT_VK_SUCCESS(err);
2518
2519 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2520 (void)err;
2521
2522 m_errorMonitor->VerifyFound();
2523
2524 vkDestroyImage(m_device->device(), image, NULL);
2525 vkFreeMemory(m_device->device(), mem, NULL);
2526}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002527
Karl Schultz6addd812016-02-02 17:17:23 -07002528TEST_F(VkLayerTest, BindInvalidMemory) {
2529 VkResult err;
2530 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002531
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002533
Tobin Ehlisec598302015-09-15 15:02:17 -06002534 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002535
2536 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002537 VkImage image;
2538 VkDeviceMemory mem;
2539 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002540
Karl Schultz6addd812016-02-02 17:17:23 -07002541 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2542 const int32_t tex_width = 32;
2543 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002544
2545 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002546 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2547 image_create_info.pNext = NULL;
2548 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2549 image_create_info.format = tex_format;
2550 image_create_info.extent.width = tex_width;
2551 image_create_info.extent.height = tex_height;
2552 image_create_info.extent.depth = 1;
2553 image_create_info.mipLevels = 1;
2554 image_create_info.arrayLayers = 1;
2555 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2556 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2557 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2558 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002559
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002560 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002561 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2562 mem_alloc.pNext = NULL;
2563 mem_alloc.allocationSize = 0;
2564 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002565
Chia-I Wuf7458c52015-10-26 21:10:41 +08002566 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002567 ASSERT_VK_SUCCESS(err);
2568
Karl Schultz6addd812016-02-02 17:17:23 -07002569 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002570
2571 mem_alloc.allocationSize = mem_reqs.size;
2572
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002573 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002574 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002575
2576 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002577 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002578 ASSERT_VK_SUCCESS(err);
2579
2580 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002581 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002582
2583 // Try to bind free memory that has been freed
2584 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2585 // This may very well return an error.
2586 (void)err;
2587
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002588 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002589
Chia-I Wuf7458c52015-10-26 21:10:41 +08002590 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002591}
2592
Karl Schultz6addd812016-02-02 17:17:23 -07002593TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2594 VkResult err;
2595 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002596
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002598
Tobin Ehlisec598302015-09-15 15:02:17 -06002599 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002600
Karl Schultz6addd812016-02-02 17:17:23 -07002601 // Create an image object, allocate memory, destroy the object and then try
2602 // to bind it
2603 VkImage image;
2604 VkDeviceMemory mem;
2605 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002606
Karl Schultz6addd812016-02-02 17:17:23 -07002607 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2608 const int32_t tex_width = 32;
2609 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002610
2611 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002612 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2613 image_create_info.pNext = NULL;
2614 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2615 image_create_info.format = tex_format;
2616 image_create_info.extent.width = tex_width;
2617 image_create_info.extent.height = tex_height;
2618 image_create_info.extent.depth = 1;
2619 image_create_info.mipLevels = 1;
2620 image_create_info.arrayLayers = 1;
2621 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2622 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2623 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2624 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002625
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002626 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002627 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2628 mem_alloc.pNext = NULL;
2629 mem_alloc.allocationSize = 0;
2630 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002631
Chia-I Wuf7458c52015-10-26 21:10:41 +08002632 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002633 ASSERT_VK_SUCCESS(err);
2634
Karl Schultz6addd812016-02-02 17:17:23 -07002635 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002636
2637 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002638 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002639 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002640
2641 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002642 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002643 ASSERT_VK_SUCCESS(err);
2644
2645 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002646 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002647 ASSERT_VK_SUCCESS(err);
2648
2649 // Now Try to bind memory to this destroyed object
2650 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2651 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002652 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002653
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002654 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002655
Chia-I Wuf7458c52015-10-26 21:10:41 +08002656 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002657}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002658
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002659#endif // OBJ_TRACKER_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002660
Tobin Ehlis0788f522015-05-26 16:11:58 -06002661#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002662
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002663TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2664 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2665
2666 ASSERT_NO_FATAL_FAILURE(InitState());
2667 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2668
2669 VkVertexInputBindingDescription input_binding;
2670 memset(&input_binding, 0, sizeof(input_binding));
2671
2672 VkVertexInputAttributeDescription input_attribs;
2673 memset(&input_attribs, 0, sizeof(input_attribs));
2674
2675 // Pick a really bad format for this purpose and make sure it should fail
2676 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2677 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2678 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2679 printf("Format unsuitable for test; skipped.\n");
2680 return;
2681 }
2682
2683 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002684 char const *vsSource =
2685 "#version 450\n"
2686 "\n"
2687 "out gl_PerVertex {\n"
2688 " vec4 gl_Position;\n"
2689 "};\n"
2690 "void main(){\n"
2691 " gl_Position = vec4(1);\n"
2692 "}\n";
2693 char const *fsSource =
2694 "#version 450\n"
2695 "\n"
2696 "layout(location=0) out vec4 color;\n"
2697 "void main(){\n"
2698 " color = vec4(1);\n"
2699 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002700
2701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2702 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2703 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2704
2705 VkPipelineObj pipe(m_device);
2706 pipe.AddColorAttachment();
2707 pipe.AddShader(&vs);
2708 pipe.AddShader(&fs);
2709
2710 pipe.AddVertexInputBindings(&input_binding, 1);
2711 pipe.AddVertexInputAttribs(&input_attribs, 1);
2712
2713 VkDescriptorSetObj descriptorSet(m_device);
2714 descriptorSet.AppendDummy();
2715 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2716
2717 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2718
2719 m_errorMonitor->VerifyFound();
2720}
2721
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002722TEST_F(VkLayerTest, ImageSampleCounts) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002723 TEST_DESCRIPTION(
2724 "Use bad sample counts in image transfer calls to trigger "
2725 "validation errors.");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002726 ASSERT_NO_FATAL_FAILURE(InitState());
2727
2728 VkMemoryPropertyFlags reqs = 0;
2729 VkImageCreateInfo image_create_info = {};
2730 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2731 image_create_info.pNext = NULL;
2732 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2733 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2734 image_create_info.extent.width = 256;
2735 image_create_info.extent.height = 256;
2736 image_create_info.extent.depth = 1;
2737 image_create_info.mipLevels = 1;
2738 image_create_info.arrayLayers = 1;
2739 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2740 image_create_info.flags = 0;
2741
2742 VkImageBlit blit_region = {};
2743 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2744 blit_region.srcSubresource.baseArrayLayer = 0;
2745 blit_region.srcSubresource.layerCount = 1;
2746 blit_region.srcSubresource.mipLevel = 0;
2747 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2748 blit_region.dstSubresource.baseArrayLayer = 0;
2749 blit_region.dstSubresource.layerCount = 1;
2750 blit_region.dstSubresource.mipLevel = 0;
2751
2752 // Create two images, the source with sampleCount = 2, and attempt to blit
2753 // between them
2754 {
2755 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002756 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002757 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002758 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002759 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002760 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002761 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002762 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002763 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2765 "was created with a sample count "
2766 "of VK_SAMPLE_COUNT_2_BIT but "
2767 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002768 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2769 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002770 m_errorMonitor->VerifyFound();
2771 m_commandBuffer->EndCommandBuffer();
2772 }
2773
2774 // Create two images, the dest with sampleCount = 4, and attempt to blit
2775 // between them
2776 {
2777 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002778 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002779 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002780 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002781 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002782 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002783 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002784 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002785 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2787 "was created with a sample count "
2788 "of VK_SAMPLE_COUNT_4_BIT but "
2789 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002790 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2791 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002792 m_errorMonitor->VerifyFound();
2793 m_commandBuffer->EndCommandBuffer();
2794 }
2795
2796 VkBufferImageCopy copy_region = {};
2797 copy_region.bufferRowLength = 128;
2798 copy_region.bufferImageHeight = 128;
2799 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2800 copy_region.imageSubresource.layerCount = 1;
2801 copy_region.imageExtent.height = 64;
2802 copy_region.imageExtent.width = 64;
2803 copy_region.imageExtent.depth = 1;
2804
2805 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2806 // buffer to image
2807 {
2808 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002809 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2810 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002811 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002812 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002813 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002814 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2816 "was created with a sample count "
2817 "of VK_SAMPLE_COUNT_8_BIT but "
2818 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002819 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2820 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002821 m_errorMonitor->VerifyFound();
2822 m_commandBuffer->EndCommandBuffer();
2823 }
2824
2825 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2826 // image to buffer
2827 {
2828 vk_testing::Buffer dst_buffer;
2829 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2830 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002831 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002832 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002833 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002834 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2836 "was created with a sample count "
2837 "of VK_SAMPLE_COUNT_2_BIT but "
2838 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002839 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002840 dst_buffer.handle(), 1, &copy_region);
2841 m_errorMonitor->VerifyFound();
2842 m_commandBuffer->EndCommandBuffer();
2843 }
2844}
2845
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002846TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002847 ASSERT_NO_FATAL_FAILURE(InitState());
2848
2849 VkImageObj src_image(m_device);
2850 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2851 VkImageObj dst_image(m_device);
2852 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2853 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002854 dst_image2.init(64, 64, VK_FORMAT_R8G8B8A8_SINT, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002855
2856 VkImageBlit blitRegion = {};
2857 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2858 blitRegion.srcSubresource.baseArrayLayer = 0;
2859 blitRegion.srcSubresource.layerCount = 1;
2860 blitRegion.srcSubresource.mipLevel = 0;
2861 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2862 blitRegion.dstSubresource.baseArrayLayer = 0;
2863 blitRegion.dstSubresource.layerCount = 1;
2864 blitRegion.dstSubresource.mipLevel = 0;
2865
Dave Houlton34df4cb2016-12-01 16:43:06 -07002866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
2867
2868 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
2869 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002870
2871 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07002872 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002873 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
2874 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002875
2876 m_errorMonitor->VerifyFound();
2877
Dave Houlton34df4cb2016-12-01 16:43:06 -07002878 // Test should generate 2 VU failures
2879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
2880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002881
2882 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002883 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
2884 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002885
Dave Houlton34df4cb2016-12-01 16:43:06 -07002886 // TODO: Note that this only verifies that at least one of the VU enums was found
2887 // 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 -06002888 m_errorMonitor->VerifyFound();
2889
Tony Barbour552f6c02016-12-21 14:34:07 -07002890 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002891}
2892
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002893TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2894 VkResult err;
2895 bool pass;
2896
2897 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2898 ASSERT_NO_FATAL_FAILURE(InitState());
2899
2900 // If w/d/h granularity is 1, test is not meaningful
2901 // TODO: When virtual device limits are available, create a set of limits for this test that
2902 // will always have a granularity of > 1 for w, h, and d
2903 auto index = m_device->graphics_queue_node_index_;
2904 auto queue_family_properties = m_device->phy().queue_properties();
2905
2906 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2907 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2908 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2909 return;
2910 }
2911
2912 // Create two images of different types and try to copy between them
2913 VkImage srcImage;
2914 VkImage dstImage;
2915 VkDeviceMemory srcMem;
2916 VkDeviceMemory destMem;
2917 VkMemoryRequirements memReqs;
2918
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002919 VkImageCreateInfo image_create_info = {};
2920 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2921 image_create_info.pNext = NULL;
2922 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2923 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2924 image_create_info.extent.width = 32;
2925 image_create_info.extent.height = 32;
2926 image_create_info.extent.depth = 1;
2927 image_create_info.mipLevels = 1;
2928 image_create_info.arrayLayers = 4;
2929 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2930 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2931 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2932 image_create_info.flags = 0;
2933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002934 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002935 ASSERT_VK_SUCCESS(err);
2936
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002937 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002938 ASSERT_VK_SUCCESS(err);
2939
2940 // Allocate memory
2941 VkMemoryAllocateInfo memAlloc = {};
2942 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2943 memAlloc.pNext = NULL;
2944 memAlloc.allocationSize = 0;
2945 memAlloc.memoryTypeIndex = 0;
2946
2947 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2948 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002949 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002950 ASSERT_TRUE(pass);
2951 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2952 ASSERT_VK_SUCCESS(err);
2953
2954 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2955 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002956 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002957 ASSERT_VK_SUCCESS(err);
2958 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2959 ASSERT_VK_SUCCESS(err);
2960
2961 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2962 ASSERT_VK_SUCCESS(err);
2963 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2964 ASSERT_VK_SUCCESS(err);
2965
Tony Barbour552f6c02016-12-21 14:34:07 -07002966 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002967 VkImageCopy copyRegion;
2968 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2969 copyRegion.srcSubresource.mipLevel = 0;
2970 copyRegion.srcSubresource.baseArrayLayer = 0;
2971 copyRegion.srcSubresource.layerCount = 1;
2972 copyRegion.srcOffset.x = 0;
2973 copyRegion.srcOffset.y = 0;
2974 copyRegion.srcOffset.z = 0;
2975 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2976 copyRegion.dstSubresource.mipLevel = 0;
2977 copyRegion.dstSubresource.baseArrayLayer = 0;
2978 copyRegion.dstSubresource.layerCount = 1;
2979 copyRegion.dstOffset.x = 0;
2980 copyRegion.dstOffset.y = 0;
2981 copyRegion.dstOffset.z = 0;
2982 copyRegion.extent.width = 1;
2983 copyRegion.extent.height = 1;
2984 copyRegion.extent.depth = 1;
2985
2986 // Introduce failure by setting srcOffset to a bad granularity value
2987 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2989 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002990 m_errorMonitor->VerifyFound();
2991
2992 // Introduce failure by setting extent to a bad granularity value
2993 copyRegion.srcOffset.y = 0;
2994 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2996 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002997 m_errorMonitor->VerifyFound();
2998
2999 // Now do some buffer/image copies
3000 vk_testing::Buffer buffer;
3001 VkMemoryPropertyFlags reqs = 0;
3002 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3003 VkBufferImageCopy region = {};
3004 region.bufferOffset = 0;
3005 region.bufferRowLength = 3;
3006 region.bufferImageHeight = 128;
3007 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3008 region.imageSubresource.layerCount = 1;
3009 region.imageExtent.height = 16;
3010 region.imageExtent.width = 16;
3011 region.imageExtent.depth = 1;
3012 region.imageOffset.x = 0;
3013 region.imageOffset.y = 0;
3014 region.imageOffset.z = 0;
3015
3016 // Introduce failure by setting bufferRowLength to a bad granularity value
3017 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3019 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3020 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003021 m_errorMonitor->VerifyFound();
3022 region.bufferRowLength = 128;
3023
3024 // Introduce failure by setting bufferOffset to a bad granularity value
3025 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3027 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3028 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003029 m_errorMonitor->VerifyFound();
3030 region.bufferOffset = 0;
3031
3032 // Introduce failure by setting bufferImageHeight to a bad granularity value
3033 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3035 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3036 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003037 m_errorMonitor->VerifyFound();
3038 region.bufferImageHeight = 128;
3039
3040 // Introduce failure by setting imageExtent to a bad granularity value
3041 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3043 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3044 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003045 m_errorMonitor->VerifyFound();
3046 region.imageExtent.width = 16;
3047
3048 // Introduce failure by setting imageOffset to a bad granularity value
3049 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3051 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3052 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003053 m_errorMonitor->VerifyFound();
3054
Tony Barbour552f6c02016-12-21 14:34:07 -07003055 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003056
3057 vkDestroyImage(m_device->device(), srcImage, NULL);
3058 vkDestroyImage(m_device->device(), dstImage, NULL);
3059 vkFreeMemory(m_device->device(), srcMem, NULL);
3060 vkFreeMemory(m_device->device(), destMem, NULL);
3061}
3062
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003063TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003064 TEST_DESCRIPTION(
3065 "Submit command buffer created using one queue family and "
3066 "attempt to submit them on a queue created in a different "
3067 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003068
Cody Northropc31a84f2016-08-22 10:41:47 -06003069 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003070 // This test is meaningless unless we have multiple queue families
3071 auto queue_family_properties = m_device->phy().queue_properties();
3072 if (queue_family_properties.size() < 2) {
3073 return;
3074 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003076 // Get safe index of another queue family
3077 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3078 ASSERT_NO_FATAL_FAILURE(InitState());
3079 // Create a second queue using a different queue family
3080 VkQueue other_queue;
3081 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3082
3083 // Record an empty cmd buffer
3084 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3085 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3086 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3087 vkEndCommandBuffer(m_commandBuffer->handle());
3088
3089 // And submit on the wrong queue
3090 VkSubmitInfo submit_info = {};
3091 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3092 submit_info.commandBufferCount = 1;
3093 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003094 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003095
3096 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003097}
3098
Chris Forbes4c24a922016-11-16 08:59:10 +13003099TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3100 ASSERT_NO_FATAL_FAILURE(InitState());
3101
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003102 // There are no attachments, but refer to attachment 0.
3103 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003104 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003105 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003106 };
3107
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003108 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003109 VkRenderPass rp;
3110
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003111 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003113 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3114 m_errorMonitor->VerifyFound();
3115}
3116
Chris Forbesa58c4522016-09-28 15:19:39 +13003117TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3118 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3119 ASSERT_NO_FATAL_FAILURE(InitState());
3120
3121 // A renderpass with two subpasses, both writing the same attachment.
3122 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003123 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3124 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3125 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003126 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003127 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003128 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003129 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3130 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003131 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003132 VkSubpassDependency dep = {0,
3133 1,
3134 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3135 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3136 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3137 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3138 VK_DEPENDENCY_BY_REGION_BIT};
3139 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003140 VkRenderPass rp;
3141 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3142 ASSERT_VK_SUCCESS(err);
3143
3144 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003145 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbesa58c4522016-09-28 15:19:39 +13003146 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3147
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003148 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003149 VkFramebuffer fb;
3150 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3151 ASSERT_VK_SUCCESS(err);
3152
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003153 char const *vsSource =
3154 "#version 450\n"
3155 "void main() { gl_Position = vec4(1); }\n";
3156 char const *fsSource =
3157 "#version 450\n"
3158 "layout(location=0) out vec4 color;\n"
3159 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003160
3161 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3162 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3163 VkPipelineObj pipe(m_device);
3164 pipe.AddColorAttachment();
3165 pipe.AddShader(&vs);
3166 pipe.AddShader(&fs);
3167 VkViewport view_port = {};
3168 m_viewports.push_back(view_port);
3169 pipe.SetViewport(m_viewports);
3170 VkRect2D rect = {};
3171 m_scissors.push_back(rect);
3172 pipe.SetScissor(m_scissors);
3173
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003174 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003175 VkPipelineLayout pl;
3176 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3177 ASSERT_VK_SUCCESS(err);
3178 pipe.CreateVKPipeline(pl, rp);
3179
Tony Barbour552f6c02016-12-21 14:34:07 -07003180 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003181
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003182 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3183 nullptr,
3184 rp,
3185 fb,
3186 {{
3187 0, 0,
3188 },
3189 {32, 32}},
3190 0,
3191 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003192
3193 // subtest 1: bind in the wrong subpass
3194 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3195 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003196 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 +13003197 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3198 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3199 m_errorMonitor->VerifyFound();
3200
3201 vkCmdEndRenderPass(m_commandBuffer->handle());
3202
3203 // subtest 2: bind in correct subpass, then transition to next subpass
3204 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3205 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3206 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003207 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 +13003208 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3209 m_errorMonitor->VerifyFound();
3210
3211 vkCmdEndRenderPass(m_commandBuffer->handle());
3212
Tony Barbour552f6c02016-12-21 14:34:07 -07003213 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003214
3215 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3216 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3217 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3218}
3219
Tony Barbour4e919972016-08-09 13:27:40 -06003220TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003221 TEST_DESCRIPTION(
3222 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3223 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003224 ASSERT_NO_FATAL_FAILURE(InitState());
3225 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3226
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3228 "Cannot execute a render pass with renderArea "
3229 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003230
3231 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3232 m_renderPassBeginInfo.renderArea.extent.width = 257;
3233 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003234 m_commandBuffer->BeginCommandBuffer();
3235 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003236 m_errorMonitor->VerifyFound();
3237}
3238
3239TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003240 TEST_DESCRIPTION(
3241 "Generate INDEPENDENT_BLEND by disabling independent "
3242 "blend and then specifying different blend states for two "
3243 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003244 VkPhysicalDeviceFeatures features = {};
3245 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003246 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003247
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3249 "Invalid Pipeline CreateInfo: If independent blend feature not "
3250 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003251
Cody Northropc31a84f2016-08-22 10:41:47 -06003252 VkDescriptorSetObj descriptorSet(m_device);
3253 descriptorSet.AppendDummy();
3254 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003255
Cody Northropc31a84f2016-08-22 10:41:47 -06003256 VkPipelineObj pipeline(m_device);
3257 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003258 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003259 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003260
Cody Northropc31a84f2016-08-22 10:41:47 -06003261 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3262 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3263 att_state1.blendEnable = VK_TRUE;
3264 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3265 att_state2.blendEnable = VK_FALSE;
3266 pipeline.AddColorAttachment(0, &att_state1);
3267 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003268 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003269 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003270}
3271
Chris Forbes26ec2122016-11-29 08:58:33 +13003272#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003273TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3274 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3275 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003276 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3279 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003280
3281 // Create a renderPass with a single color attachment
3282 VkAttachmentReference attach = {};
3283 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3284 VkSubpassDescription subpass = {};
3285 VkRenderPassCreateInfo rpci = {};
3286 rpci.subpassCount = 1;
3287 rpci.pSubpasses = &subpass;
3288 rpci.attachmentCount = 1;
3289 VkAttachmentDescription attach_desc = {};
3290 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3291 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3292 rpci.pAttachments = &attach_desc;
3293 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3294 VkRenderPass rp;
3295 subpass.pDepthStencilAttachment = &attach;
3296 subpass.pColorAttachments = NULL;
3297 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3298 m_errorMonitor->VerifyFound();
3299}
Chris Forbes26ec2122016-11-29 08:58:33 +13003300#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003301
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003302TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003303 TEST_DESCRIPTION(
3304 "Create a framebuffer where a subpass has a preserve "
3305 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003306
3307 ASSERT_NO_FATAL_FAILURE(InitState());
3308 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3309
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003311
3312 VkAttachmentReference color_attach = {};
3313 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3314 color_attach.attachment = 0;
3315 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3316 VkSubpassDescription subpass = {};
3317 subpass.colorAttachmentCount = 1;
3318 subpass.pColorAttachments = &color_attach;
3319 subpass.preserveAttachmentCount = 1;
3320 subpass.pPreserveAttachments = &preserve_attachment;
3321
3322 VkRenderPassCreateInfo rpci = {};
3323 rpci.subpassCount = 1;
3324 rpci.pSubpasses = &subpass;
3325 rpci.attachmentCount = 1;
3326 VkAttachmentDescription attach_desc = {};
3327 attach_desc.format = VK_FORMAT_UNDEFINED;
3328 rpci.pAttachments = &attach_desc;
3329 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3330 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003331 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003332
3333 m_errorMonitor->VerifyFound();
3334
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003335 if (result == VK_SUCCESS) {
3336 vkDestroyRenderPass(m_device->device(), rp, NULL);
3337 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003338}
3339
Chris Forbesc5389742016-06-29 11:49:23 +12003340TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003341 TEST_DESCRIPTION(
3342 "Ensure that CreateRenderPass produces a validation error "
3343 "when the source of a subpass multisample resolve "
3344 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003345
Chris Forbesc5389742016-06-29 11:49:23 +12003346 ASSERT_NO_FATAL_FAILURE(InitState());
3347
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3349 "Subpass 0 requests multisample resolve from attachment 0 which has "
3350 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003351
3352 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003353 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3354 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3355 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3356 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3357 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3358 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003359 };
3360
3361 VkAttachmentReference color = {
3362 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3363 };
3364
3365 VkAttachmentReference resolve = {
3366 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3367 };
3368
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003369 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003370
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003371 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003372
3373 VkRenderPass rp;
3374 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3375
3376 m_errorMonitor->VerifyFound();
3377
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003378 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003379}
3380
3381TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003382 TEST_DESCRIPTION(
3383 "Ensure CreateRenderPass produces a validation error "
3384 "when a subpass multisample resolve operation is "
3385 "requested, and the destination of that resolve has "
3386 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003387
Chris Forbesc5389742016-06-29 11:49:23 +12003388 ASSERT_NO_FATAL_FAILURE(InitState());
3389
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3391 "Subpass 0 requests multisample resolve into attachment 1, which "
3392 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003393
3394 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003395 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3396 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3397 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3398 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3399 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3400 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003401 };
3402
3403 VkAttachmentReference color = {
3404 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3405 };
3406
3407 VkAttachmentReference resolve = {
3408 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3409 };
3410
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003411 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003412
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003413 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003414
3415 VkRenderPass rp;
3416 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3417
3418 m_errorMonitor->VerifyFound();
3419
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003420 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003421}
3422
Chris Forbes3f128ef2016-06-29 14:58:53 +12003423TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003424 TEST_DESCRIPTION(
3425 "Ensure CreateRenderPass produces a validation error "
3426 "when the color and depth attachments used by a subpass "
3427 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003428
Chris Forbes3f128ef2016-06-29 14:58:53 +12003429 ASSERT_NO_FATAL_FAILURE(InitState());
3430
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3432 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003433
3434 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003435 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3436 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3437 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3438 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3439 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3440 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003441 };
3442
3443 VkAttachmentReference color[] = {
3444 {
3445 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3446 },
3447 {
3448 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3449 },
3450 };
3451
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003452 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003453
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003454 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003455
3456 VkRenderPass rp;
3457 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3458
3459 m_errorMonitor->VerifyFound();
3460
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003461 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003462}
3463
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003464TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003465 TEST_DESCRIPTION(
3466 "Hit errors when attempting to create a framebuffer :\n"
3467 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3468 " 2. Use a color image as depthStencil attachment\n"
3469 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3470 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3471 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3472 " 6. Framebuffer attachment where dimensions don't match\n"
3473 " 7. Framebuffer attachment w/o identity swizzle\n"
3474 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003475
3476 ASSERT_NO_FATAL_FAILURE(InitState());
3477 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3478
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3480 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3481 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003482
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003483 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003484 VkAttachmentReference attach = {};
3485 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3486 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003487 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003488 VkRenderPassCreateInfo rpci = {};
3489 rpci.subpassCount = 1;
3490 rpci.pSubpasses = &subpass;
3491 rpci.attachmentCount = 1;
3492 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003493 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003494 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003495 rpci.pAttachments = &attach_desc;
3496 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3497 VkRenderPass rp;
3498 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3499 ASSERT_VK_SUCCESS(err);
3500
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003501 VkImageView ivs[2];
3502 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3503 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003504 VkFramebufferCreateInfo fb_info = {};
3505 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3506 fb_info.pNext = NULL;
3507 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003508 // Set mis-matching attachmentCount
3509 fb_info.attachmentCount = 2;
3510 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003511 fb_info.width = 100;
3512 fb_info.height = 100;
3513 fb_info.layers = 1;
3514
3515 VkFramebuffer fb;
3516 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3517
3518 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003519 if (err == VK_SUCCESS) {
3520 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3521 }
3522 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003523
3524 // Create a renderPass with a depth-stencil attachment created with
3525 // IMAGE_USAGE_COLOR_ATTACHMENT
3526 // Add our color attachment to pDepthStencilAttachment
3527 subpass.pDepthStencilAttachment = &attach;
3528 subpass.pColorAttachments = NULL;
3529 VkRenderPass rp_ds;
3530 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3531 ASSERT_VK_SUCCESS(err);
3532 // Set correct attachment count, but attachment has COLOR usage bit set
3533 fb_info.attachmentCount = 1;
3534 fb_info.renderPass = rp_ds;
3535
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003537 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3538
3539 m_errorMonitor->VerifyFound();
3540 if (err == VK_SUCCESS) {
3541 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3542 }
3543 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003544
3545 // Create new renderpass with alternate attachment format from fb
3546 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3547 subpass.pDepthStencilAttachment = NULL;
3548 subpass.pColorAttachments = &attach;
3549 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3550 ASSERT_VK_SUCCESS(err);
3551
3552 // Cause error due to mis-matched formats between rp & fb
3553 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3554 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3556 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003557 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3558
3559 m_errorMonitor->VerifyFound();
3560 if (err == VK_SUCCESS) {
3561 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3562 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003563 vkDestroyRenderPass(m_device->device(), rp, NULL);
3564
3565 // Create new renderpass with alternate sample count from fb
3566 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3567 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3568 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3569 ASSERT_VK_SUCCESS(err);
3570
3571 // Cause error due to mis-matched sample count between rp & fb
3572 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3574 " has VK_SAMPLE_COUNT_1_BIT samples "
3575 "that do not match the "
3576 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003577 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3578
3579 m_errorMonitor->VerifyFound();
3580 if (err == VK_SUCCESS) {
3581 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3582 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003583
3584 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003585
3586 // Create a custom imageView with non-1 mip levels
3587 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003588 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003589 ASSERT_TRUE(image.initialized());
3590
3591 VkImageView view;
3592 VkImageViewCreateInfo ivci = {};
3593 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3594 ivci.image = image.handle();
3595 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3596 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3597 ivci.subresourceRange.layerCount = 1;
3598 ivci.subresourceRange.baseMipLevel = 0;
3599 // Set level count 2 (only 1 is allowed for FB attachment)
3600 ivci.subresourceRange.levelCount = 2;
3601 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3602 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3603 ASSERT_VK_SUCCESS(err);
3604 // Re-create renderpass to have matching sample count
3605 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3606 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3607 ASSERT_VK_SUCCESS(err);
3608
3609 fb_info.renderPass = rp;
3610 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003612 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3613
3614 m_errorMonitor->VerifyFound();
3615 if (err == VK_SUCCESS) {
3616 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3617 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003618 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003619 // Update view to original color buffer and grow FB dimensions too big
3620 fb_info.pAttachments = ivs;
3621 fb_info.height = 1024;
3622 fb_info.width = 1024;
3623 fb_info.layers = 2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3625 " Attachment dimensions must be at "
3626 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003627 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3628
3629 m_errorMonitor->VerifyFound();
3630 if (err == VK_SUCCESS) {
3631 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3632 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003633 // Create view attachment with non-identity swizzle
3634 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3635 ivci.image = image.handle();
3636 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3637 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3638 ivci.subresourceRange.layerCount = 1;
3639 ivci.subresourceRange.baseMipLevel = 0;
3640 ivci.subresourceRange.levelCount = 1;
3641 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3642 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3643 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3644 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3645 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3646 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3647 ASSERT_VK_SUCCESS(err);
3648
3649 fb_info.pAttachments = &view;
3650 fb_info.height = 100;
3651 fb_info.width = 100;
3652 fb_info.layers = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3654 " has non-identy swizzle. All "
3655 "framebuffer attachments must have "
3656 "been created with the identity "
3657 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003658 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3659
3660 m_errorMonitor->VerifyFound();
3661 if (err == VK_SUCCESS) {
3662 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3663 }
3664 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003665 // reset attachment to color attachment
3666 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003667
3668 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003669 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003670 fb_info.height = 100;
3671 fb_info.layers = 1;
3672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
3673 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3674
3675 m_errorMonitor->VerifyFound();
3676 if (err == VK_SUCCESS) {
3677 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3678 }
3679
3680 // Request fb that exceeds max height
3681 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003682 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003683 fb_info.layers = 1;
3684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
3685 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3686
3687 m_errorMonitor->VerifyFound();
3688 if (err == VK_SUCCESS) {
3689 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3690 }
3691
3692 // Request fb that exceeds max layers
3693 fb_info.width = 100;
3694 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003695 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003697 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3698
3699 m_errorMonitor->VerifyFound();
3700 if (err == VK_SUCCESS) {
3701 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3702 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003703
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003704 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003705}
3706
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003707TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003708 TEST_DESCRIPTION(
3709 "Run a simple draw calls to validate failure when Depth Bias dynamic "
3710 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003711
Cody Northropc31a84f2016-08-22 10:41:47 -06003712 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003713 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3715 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003716 m_errorMonitor->VerifyFound();
3717}
3718
3719TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003720 TEST_DESCRIPTION(
3721 "Run a simple draw calls to validate failure when Line Width dynamic "
3722 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003723
Cody Northropc31a84f2016-08-22 10:41:47 -06003724 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003725 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3727 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003728 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003729}
3730
3731TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003732 TEST_DESCRIPTION(
3733 "Run a simple draw calls to validate failure when Viewport dynamic "
3734 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003735
Cody Northropc31a84f2016-08-22 10:41:47 -06003736 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003737 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3739 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003740 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003741 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003742}
3743
3744TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003745 TEST_DESCRIPTION(
3746 "Run a simple draw calls to validate failure when Scissor dynamic "
3747 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003748
Cody Northropc31a84f2016-08-22 10:41:47 -06003749 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003750 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3752 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003753 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003754 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003755}
3756
Cortd713fe82016-07-27 09:51:27 -07003757TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003758 TEST_DESCRIPTION(
3759 "Run a simple draw calls to validate failure when Blend Constants "
3760 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003761
3762 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003763 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3765 "Dynamic blend constants state not set for this command buffer");
3766 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003767 m_errorMonitor->VerifyFound();
3768}
3769
3770TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003771 TEST_DESCRIPTION(
3772 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
3773 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003774
3775 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003776 if (!m_device->phy().features().depthBounds) {
3777 printf("Device does not support depthBounds test; skipped.\n");
3778 return;
3779 }
3780 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3782 "Dynamic depth bounds state not set for this command buffer");
3783 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003784 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003785}
3786
3787TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003788 TEST_DESCRIPTION(
3789 "Run a simple draw calls to validate failure when Stencil Read dynamic "
3790 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003791
3792 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003793 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3795 "Dynamic stencil read mask state not set for this command buffer");
3796 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003797 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003798}
3799
3800TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003801 TEST_DESCRIPTION(
3802 "Run a simple draw calls to validate failure when Stencil Write dynamic"
3803 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003804
3805 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003806 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3808 "Dynamic stencil write mask state not set for this command buffer");
3809 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003810 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003811}
3812
3813TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003814 TEST_DESCRIPTION(
3815 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
3816 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003817
3818 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003819 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3821 "Dynamic stencil reference state not set for this command buffer");
3822 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003823 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003824}
3825
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003826TEST_F(VkLayerTest, IndexBufferNotBound) {
3827 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003828
3829 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3831 "Index buffer object not bound to this command buffer when Indexed ");
3832 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003833 m_errorMonitor->VerifyFound();
3834}
3835
Karl Schultz6addd812016-02-02 17:17:23 -07003836TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3838 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3839 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003840
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003841 ASSERT_NO_FATAL_FAILURE(InitState());
3842 ASSERT_NO_FATAL_FAILURE(InitViewport());
3843 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3844
Karl Schultz6addd812016-02-02 17:17:23 -07003845 // We luck out b/c by default the framework creates CB w/ the
3846 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07003847 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003848 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07003849 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003850
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003851 // Bypass framework since it does the waits automatically
3852 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003853 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003854 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3855 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003856 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003857 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003858 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003859 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003860 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003861 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003862 submit_info.pSignalSemaphores = NULL;
3863
Chris Forbes40028e22016-06-13 09:59:34 +12003864 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003865 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003866 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003867
Karl Schultz6addd812016-02-02 17:17:23 -07003868 // Cause validation error by re-submitting cmd buffer that should only be
3869 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003870 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003871 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003872
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003873 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003874}
3875
Karl Schultz6addd812016-02-02 17:17:23 -07003876TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003877 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003878 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003879
3880 ASSERT_NO_FATAL_FAILURE(InitState());
3881 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003882
Karl Schultz6addd812016-02-02 17:17:23 -07003883 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3884 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003885 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003886 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003887 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003888
3889 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003890 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3891 ds_pool_ci.pNext = NULL;
3892 ds_pool_ci.flags = 0;
3893 ds_pool_ci.maxSets = 1;
3894 ds_pool_ci.poolSizeCount = 1;
3895 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003896
3897 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003898 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003899 ASSERT_VK_SUCCESS(err);
3900
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003901 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3902 dsl_binding_samp.binding = 0;
3903 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3904 dsl_binding_samp.descriptorCount = 1;
3905 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3906 dsl_binding_samp.pImmutableSamplers = NULL;
3907
3908 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3909 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3910 ds_layout_ci.pNext = NULL;
3911 ds_layout_ci.bindingCount = 1;
3912 ds_layout_ci.pBindings = &dsl_binding_samp;
3913
3914 VkDescriptorSetLayout ds_layout_samp;
3915 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3916 ASSERT_VK_SUCCESS(err);
3917
3918 // Try to allocate 2 sets when pool only has 1 set
3919 VkDescriptorSet descriptor_sets[2];
3920 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3921 VkDescriptorSetAllocateInfo alloc_info = {};
3922 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3923 alloc_info.descriptorSetCount = 2;
3924 alloc_info.descriptorPool = ds_pool;
3925 alloc_info.pSetLayouts = set_layouts;
3926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3927 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3928 m_errorMonitor->VerifyFound();
3929
3930 alloc_info.descriptorSetCount = 1;
3931 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003932 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003933 dsl_binding.binding = 0;
3934 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3935 dsl_binding.descriptorCount = 1;
3936 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3937 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003938
Karl Schultz6addd812016-02-02 17:17:23 -07003939 ds_layout_ci.bindingCount = 1;
3940 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003941
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003942 VkDescriptorSetLayout ds_layout_ub;
3943 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003944 ASSERT_VK_SUCCESS(err);
3945
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003946 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003947 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003948 alloc_info.pSetLayouts = &ds_layout_ub;
3949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3950 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003951
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003952 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003953
Karl Schultz2825ab92016-12-02 08:23:14 -07003954 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003955 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003956 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003957}
3958
Karl Schultz6addd812016-02-02 17:17:23 -07003959TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3960 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003961
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07003962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003963
Tobin Ehlise735c692015-10-08 13:13:50 -06003964 ASSERT_NO_FATAL_FAILURE(InitState());
3965 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003966
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003967 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003968 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3969 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003970
3971 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003972 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3973 ds_pool_ci.pNext = NULL;
3974 ds_pool_ci.maxSets = 1;
3975 ds_pool_ci.poolSizeCount = 1;
3976 ds_pool_ci.flags = 0;
3977 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3978 // app can only call vkResetDescriptorPool on this pool.;
3979 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003980
3981 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003982 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003983 ASSERT_VK_SUCCESS(err);
3984
3985 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003986 dsl_binding.binding = 0;
3987 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3988 dsl_binding.descriptorCount = 1;
3989 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3990 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003991
3992 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003993 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3994 ds_layout_ci.pNext = NULL;
3995 ds_layout_ci.bindingCount = 1;
3996 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003997
3998 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003999 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004000 ASSERT_VK_SUCCESS(err);
4001
4002 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004003 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004004 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004005 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004006 alloc_info.descriptorPool = ds_pool;
4007 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004008 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004009 ASSERT_VK_SUCCESS(err);
4010
4011 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004012 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004013
Chia-I Wuf7458c52015-10-26 21:10:41 +08004014 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4015 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004016}
4017
Karl Schultz6addd812016-02-02 17:17:23 -07004018TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004019 // Attempt to clear Descriptor Pool with bad object.
4020 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004021
4022 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004024 uint64_t fake_pool_handle = 0xbaad6001;
4025 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4026 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004027 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004028}
4029
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004030TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004031 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4032 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004033 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004034 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004035
4036 uint64_t fake_set_handle = 0xbaad6001;
4037 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004038 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004040
4041 ASSERT_NO_FATAL_FAILURE(InitState());
4042
4043 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4044 layout_bindings[0].binding = 0;
4045 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4046 layout_bindings[0].descriptorCount = 1;
4047 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4048 layout_bindings[0].pImmutableSamplers = NULL;
4049
4050 VkDescriptorSetLayout descriptor_set_layout;
4051 VkDescriptorSetLayoutCreateInfo dslci = {};
4052 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4053 dslci.pNext = NULL;
4054 dslci.bindingCount = 1;
4055 dslci.pBindings = layout_bindings;
4056 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004057 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004058
4059 VkPipelineLayout pipeline_layout;
4060 VkPipelineLayoutCreateInfo plci = {};
4061 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4062 plci.pNext = NULL;
4063 plci.setLayoutCount = 1;
4064 plci.pSetLayouts = &descriptor_set_layout;
4065 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004066 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004067
Tony Barbour552f6c02016-12-21 14:34:07 -07004068 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004069 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4070 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004071 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004072 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004073 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4074 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004075}
4076
Karl Schultz6addd812016-02-02 17:17:23 -07004077TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004078 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4079 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004080 uint64_t fake_layout_handle = 0xbaad6001;
4081 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004083 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004084 VkPipelineLayout pipeline_layout;
4085 VkPipelineLayoutCreateInfo plci = {};
4086 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4087 plci.pNext = NULL;
4088 plci.setLayoutCount = 1;
4089 plci.pSetLayouts = &bad_layout;
4090 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4091
4092 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004093}
4094
Mark Muellerd4914412016-06-13 17:52:06 -06004095TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004096 TEST_DESCRIPTION(
4097 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4098 "1) A uniform buffer update must have a valid buffer index."
4099 "2) When using an array of descriptors in a single WriteDescriptor,"
4100 " the descriptor types and stageflags must all be the same."
4101 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004102
Mike Weiblena6666382017-01-05 15:16:11 -07004103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004104
4105 ASSERT_NO_FATAL_FAILURE(InitState());
4106 VkDescriptorPoolSize ds_type_count[4] = {};
4107 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4108 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004109 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004110 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004111 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004112 ds_type_count[2].descriptorCount = 1;
4113 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4114 ds_type_count[3].descriptorCount = 1;
4115
4116 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4117 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4118 ds_pool_ci.maxSets = 1;
4119 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4120 ds_pool_ci.pPoolSizes = ds_type_count;
4121
4122 VkDescriptorPool ds_pool;
4123 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4124 ASSERT_VK_SUCCESS(err);
4125
Mark Muellerb9896722016-06-16 09:54:29 -06004126 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004127 layout_binding[0].binding = 0;
4128 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4129 layout_binding[0].descriptorCount = 1;
4130 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4131 layout_binding[0].pImmutableSamplers = NULL;
4132
4133 layout_binding[1].binding = 1;
4134 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4135 layout_binding[1].descriptorCount = 1;
4136 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4137 layout_binding[1].pImmutableSamplers = NULL;
4138
4139 VkSamplerCreateInfo sampler_ci = {};
4140 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4141 sampler_ci.pNext = NULL;
4142 sampler_ci.magFilter = VK_FILTER_NEAREST;
4143 sampler_ci.minFilter = VK_FILTER_NEAREST;
4144 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4145 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4146 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4147 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4148 sampler_ci.mipLodBias = 1.0;
4149 sampler_ci.anisotropyEnable = VK_FALSE;
4150 sampler_ci.maxAnisotropy = 1;
4151 sampler_ci.compareEnable = VK_FALSE;
4152 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4153 sampler_ci.minLod = 1.0;
4154 sampler_ci.maxLod = 1.0;
4155 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4156 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4157 VkSampler sampler;
4158
4159 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4160 ASSERT_VK_SUCCESS(err);
4161
4162 layout_binding[2].binding = 2;
4163 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4164 layout_binding[2].descriptorCount = 1;
4165 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4166 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4167
Mark Muellerd4914412016-06-13 17:52:06 -06004168 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4169 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4170 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4171 ds_layout_ci.pBindings = layout_binding;
4172 VkDescriptorSetLayout ds_layout;
4173 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4174 ASSERT_VK_SUCCESS(err);
4175
4176 VkDescriptorSetAllocateInfo alloc_info = {};
4177 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4178 alloc_info.descriptorSetCount = 1;
4179 alloc_info.descriptorPool = ds_pool;
4180 alloc_info.pSetLayouts = &ds_layout;
4181 VkDescriptorSet descriptorSet;
4182 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4183 ASSERT_VK_SUCCESS(err);
4184
4185 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4186 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4187 pipeline_layout_ci.pNext = NULL;
4188 pipeline_layout_ci.setLayoutCount = 1;
4189 pipeline_layout_ci.pSetLayouts = &ds_layout;
4190
4191 VkPipelineLayout pipeline_layout;
4192 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4193 ASSERT_VK_SUCCESS(err);
4194
Mark Mueller5c838ce2016-06-16 09:54:29 -06004195 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004196 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4197 descriptor_write.dstSet = descriptorSet;
4198 descriptor_write.dstBinding = 0;
4199 descriptor_write.descriptorCount = 1;
4200 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4201
Mark Mueller5c838ce2016-06-16 09:54:29 -06004202 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004203 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4204 m_errorMonitor->VerifyFound();
4205
4206 // Create a buffer to update the descriptor with
4207 uint32_t qfi = 0;
4208 VkBufferCreateInfo buffCI = {};
4209 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4210 buffCI.size = 1024;
4211 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4212 buffCI.queueFamilyIndexCount = 1;
4213 buffCI.pQueueFamilyIndices = &qfi;
4214
4215 VkBuffer dyub;
4216 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4217 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004218
Tony Barboure132c5f2016-12-12 11:50:20 -07004219 VkDeviceMemory mem;
4220 VkMemoryRequirements mem_reqs;
4221 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4222
4223 VkMemoryAllocateInfo mem_alloc_info = {};
4224 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4225 mem_alloc_info.allocationSize = mem_reqs.size;
4226 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4227 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4228 ASSERT_VK_SUCCESS(err);
4229
4230 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4231 ASSERT_VK_SUCCESS(err);
4232
4233 VkDescriptorBufferInfo buffInfo[2] = {};
4234 buffInfo[0].buffer = dyub;
4235 buffInfo[0].offset = 0;
4236 buffInfo[0].range = 1024;
4237 buffInfo[1].buffer = dyub;
4238 buffInfo[1].offset = 0;
4239 buffInfo[1].range = 1024;
4240 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004241 descriptor_write.descriptorCount = 2;
4242
Mark Mueller5c838ce2016-06-16 09:54:29 -06004243 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004245 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4246 m_errorMonitor->VerifyFound();
4247
Mark Mueller5c838ce2016-06-16 09:54:29 -06004248 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4249 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004250 descriptor_write.dstBinding = 1;
4251 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004252
Mark Mueller5c838ce2016-06-16 09:54:29 -06004253 // Make pImageInfo index non-null to avoid complaints of it missing
4254 VkDescriptorImageInfo imageInfo = {};
4255 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4256 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004258 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4259 m_errorMonitor->VerifyFound();
4260
Mark Muellerd4914412016-06-13 17:52:06 -06004261 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004262 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004263 vkDestroySampler(m_device->device(), sampler, NULL);
4264 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4265 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4266 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4267}
4268
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004269TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004270 TEST_DESCRIPTION(
4271 "Attempt to draw with a command buffer that is invalid "
4272 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004273 ASSERT_NO_FATAL_FAILURE(InitState());
4274
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004275 VkBuffer buffer;
4276 VkDeviceMemory mem;
4277 VkMemoryRequirements mem_reqs;
4278
4279 VkBufferCreateInfo buf_info = {};
4280 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004281 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004282 buf_info.size = 256;
4283 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4284 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4285 ASSERT_VK_SUCCESS(err);
4286
4287 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4288
4289 VkMemoryAllocateInfo alloc_info = {};
4290 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4291 alloc_info.allocationSize = 256;
4292 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004293 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 -06004294 if (!pass) {
4295 vkDestroyBuffer(m_device->device(), buffer, NULL);
4296 return;
4297 }
4298 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4299 ASSERT_VK_SUCCESS(err);
4300
4301 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4302 ASSERT_VK_SUCCESS(err);
4303
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004304 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004305 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004306 m_commandBuffer->EndCommandBuffer();
4307
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004309 // Destroy buffer dependency prior to submit to cause ERROR
4310 vkDestroyBuffer(m_device->device(), buffer, NULL);
4311
4312 VkSubmitInfo submit_info = {};
4313 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4314 submit_info.commandBufferCount = 1;
4315 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4316 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4317
4318 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004319 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004320 vkFreeMemory(m_device->handle(), mem, NULL);
4321}
4322
Tobin Ehlisea413442016-09-28 10:23:59 -06004323TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4324 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4325
4326 ASSERT_NO_FATAL_FAILURE(InitState());
4327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4328
4329 VkDescriptorPoolSize ds_type_count;
4330 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4331 ds_type_count.descriptorCount = 1;
4332
4333 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4334 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4335 ds_pool_ci.maxSets = 1;
4336 ds_pool_ci.poolSizeCount = 1;
4337 ds_pool_ci.pPoolSizes = &ds_type_count;
4338
4339 VkDescriptorPool ds_pool;
4340 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4341 ASSERT_VK_SUCCESS(err);
4342
4343 VkDescriptorSetLayoutBinding layout_binding;
4344 layout_binding.binding = 0;
4345 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4346 layout_binding.descriptorCount = 1;
4347 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4348 layout_binding.pImmutableSamplers = NULL;
4349
4350 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4351 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4352 ds_layout_ci.bindingCount = 1;
4353 ds_layout_ci.pBindings = &layout_binding;
4354 VkDescriptorSetLayout ds_layout;
4355 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4356 ASSERT_VK_SUCCESS(err);
4357
4358 VkDescriptorSetAllocateInfo alloc_info = {};
4359 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4360 alloc_info.descriptorSetCount = 1;
4361 alloc_info.descriptorPool = ds_pool;
4362 alloc_info.pSetLayouts = &ds_layout;
4363 VkDescriptorSet descriptor_set;
4364 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4365 ASSERT_VK_SUCCESS(err);
4366
4367 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4368 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4369 pipeline_layout_ci.pNext = NULL;
4370 pipeline_layout_ci.setLayoutCount = 1;
4371 pipeline_layout_ci.pSetLayouts = &ds_layout;
4372
4373 VkPipelineLayout pipeline_layout;
4374 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4375 ASSERT_VK_SUCCESS(err);
4376
4377 VkBuffer buffer;
4378 uint32_t queue_family_index = 0;
4379 VkBufferCreateInfo buffer_create_info = {};
4380 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4381 buffer_create_info.size = 1024;
4382 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4383 buffer_create_info.queueFamilyIndexCount = 1;
4384 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4385
4386 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4387 ASSERT_VK_SUCCESS(err);
4388
4389 VkMemoryRequirements memory_reqs;
4390 VkDeviceMemory buffer_memory;
4391
4392 VkMemoryAllocateInfo memory_info = {};
4393 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4394 memory_info.allocationSize = 0;
4395 memory_info.memoryTypeIndex = 0;
4396
4397 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4398 memory_info.allocationSize = memory_reqs.size;
4399 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4400 ASSERT_TRUE(pass);
4401
4402 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4403 ASSERT_VK_SUCCESS(err);
4404 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4405 ASSERT_VK_SUCCESS(err);
4406
4407 VkBufferView view;
4408 VkBufferViewCreateInfo bvci = {};
4409 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4410 bvci.buffer = buffer;
4411 bvci.format = VK_FORMAT_R8_UNORM;
4412 bvci.range = VK_WHOLE_SIZE;
4413
4414 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4415 ASSERT_VK_SUCCESS(err);
4416
4417 VkWriteDescriptorSet descriptor_write = {};
4418 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4419 descriptor_write.dstSet = descriptor_set;
4420 descriptor_write.dstBinding = 0;
4421 descriptor_write.descriptorCount = 1;
4422 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4423 descriptor_write.pTexelBufferView = &view;
4424
4425 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4426
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004427 char const *vsSource =
4428 "#version 450\n"
4429 "\n"
4430 "out gl_PerVertex { \n"
4431 " vec4 gl_Position;\n"
4432 "};\n"
4433 "void main(){\n"
4434 " gl_Position = vec4(1);\n"
4435 "}\n";
4436 char const *fsSource =
4437 "#version 450\n"
4438 "\n"
4439 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4440 "layout(location=0) out vec4 x;\n"
4441 "void main(){\n"
4442 " x = imageLoad(s, 0);\n"
4443 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004444 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4445 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4446 VkPipelineObj pipe(m_device);
4447 pipe.AddShader(&vs);
4448 pipe.AddShader(&fs);
4449 pipe.AddColorAttachment();
4450 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4451
4452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4454
Tony Barbour552f6c02016-12-21 14:34:07 -07004455 m_commandBuffer->BeginCommandBuffer();
4456 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4457
Tobin Ehlisea413442016-09-28 10:23:59 -06004458 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4459 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4460 VkRect2D scissor = {{0, 0}, {16, 16}};
4461 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4462 // Bind pipeline to cmd buffer
4463 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4464 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4465 &descriptor_set, 0, nullptr);
4466 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004467 m_commandBuffer->EndRenderPass();
4468 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004469
4470 // Delete BufferView in order to invalidate cmd buffer
4471 vkDestroyBufferView(m_device->device(), view, NULL);
4472 // Now attempt submit of cmd buffer
4473 VkSubmitInfo submit_info = {};
4474 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4475 submit_info.commandBufferCount = 1;
4476 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4477 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4478 m_errorMonitor->VerifyFound();
4479
4480 // Clean-up
4481 vkDestroyBuffer(m_device->device(), buffer, NULL);
4482 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4483 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4484 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4485 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4486}
4487
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004488TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004489 TEST_DESCRIPTION(
4490 "Attempt to draw with a command buffer that is invalid "
4491 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004492 ASSERT_NO_FATAL_FAILURE(InitState());
4493
4494 VkImage image;
4495 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4496 VkImageCreateInfo image_create_info = {};
4497 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4498 image_create_info.pNext = NULL;
4499 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4500 image_create_info.format = tex_format;
4501 image_create_info.extent.width = 32;
4502 image_create_info.extent.height = 32;
4503 image_create_info.extent.depth = 1;
4504 image_create_info.mipLevels = 1;
4505 image_create_info.arrayLayers = 1;
4506 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4507 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004508 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004509 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004510 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004511 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004512 // Have to bind memory to image before recording cmd in cmd buffer using it
4513 VkMemoryRequirements mem_reqs;
4514 VkDeviceMemory image_mem;
4515 bool pass;
4516 VkMemoryAllocateInfo mem_alloc = {};
4517 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4518 mem_alloc.pNext = NULL;
4519 mem_alloc.memoryTypeIndex = 0;
4520 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4521 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004522 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004523 ASSERT_TRUE(pass);
4524 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4525 ASSERT_VK_SUCCESS(err);
4526 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4527 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004528
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004529 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004530 VkClearColorValue ccv;
4531 ccv.float32[0] = 1.0f;
4532 ccv.float32[1] = 1.0f;
4533 ccv.float32[2] = 1.0f;
4534 ccv.float32[3] = 1.0f;
4535 VkImageSubresourceRange isr = {};
4536 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004537 isr.baseArrayLayer = 0;
4538 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004539 isr.layerCount = 1;
4540 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004541 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004542 m_commandBuffer->EndCommandBuffer();
4543
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004545 // Destroy image dependency prior to submit to cause ERROR
4546 vkDestroyImage(m_device->device(), image, NULL);
4547
4548 VkSubmitInfo submit_info = {};
4549 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4550 submit_info.commandBufferCount = 1;
4551 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4552 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4553
4554 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004555 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004556}
4557
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004558TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004559 TEST_DESCRIPTION(
4560 "Attempt to draw with a command buffer that is invalid "
4561 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004562 VkFormatProperties format_properties;
4563 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004564 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4565 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004566 return;
4567 }
4568
4569 ASSERT_NO_FATAL_FAILURE(InitState());
4570 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4571
4572 VkImageCreateInfo image_ci = {};
4573 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4574 image_ci.pNext = NULL;
4575 image_ci.imageType = VK_IMAGE_TYPE_2D;
4576 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4577 image_ci.extent.width = 32;
4578 image_ci.extent.height = 32;
4579 image_ci.extent.depth = 1;
4580 image_ci.mipLevels = 1;
4581 image_ci.arrayLayers = 1;
4582 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4583 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004584 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004585 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4586 image_ci.flags = 0;
4587 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004588 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004589
4590 VkMemoryRequirements memory_reqs;
4591 VkDeviceMemory image_memory;
4592 bool pass;
4593 VkMemoryAllocateInfo memory_info = {};
4594 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4595 memory_info.pNext = NULL;
4596 memory_info.allocationSize = 0;
4597 memory_info.memoryTypeIndex = 0;
4598 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4599 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004600 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004601 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004602 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004603 ASSERT_VK_SUCCESS(err);
4604 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4605 ASSERT_VK_SUCCESS(err);
4606
4607 VkImageViewCreateInfo ivci = {
4608 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4609 nullptr,
4610 0,
4611 image,
4612 VK_IMAGE_VIEW_TYPE_2D,
4613 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004614 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004615 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4616 };
4617 VkImageView view;
4618 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4619 ASSERT_VK_SUCCESS(err);
4620
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004621 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004622 VkFramebuffer fb;
4623 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4624 ASSERT_VK_SUCCESS(err);
4625
4626 // Just use default renderpass with our framebuffer
4627 m_renderPassBeginInfo.framebuffer = fb;
4628 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004629 m_commandBuffer->BeginCommandBuffer();
4630 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4631 m_commandBuffer->EndRenderPass();
4632 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004633 // Destroy image attached to framebuffer to invalidate cmd buffer
4634 vkDestroyImage(m_device->device(), image, NULL);
4635 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004637 QueueCommandBuffer(false);
4638 m_errorMonitor->VerifyFound();
4639
4640 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4641 vkDestroyImageView(m_device->device(), view, nullptr);
4642 vkFreeMemory(m_device->device(), image_memory, nullptr);
4643}
4644
Tobin Ehlisb329f992016-10-12 13:20:29 -06004645TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4646 TEST_DESCRIPTION("Delete in-use framebuffer.");
4647 VkFormatProperties format_properties;
4648 VkResult err = VK_SUCCESS;
4649 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4650
4651 ASSERT_NO_FATAL_FAILURE(InitState());
4652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4653
4654 VkImageObj image(m_device);
4655 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4656 ASSERT_TRUE(image.initialized());
4657 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4658
4659 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4660 VkFramebuffer fb;
4661 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4662 ASSERT_VK_SUCCESS(err);
4663
4664 // Just use default renderpass with our framebuffer
4665 m_renderPassBeginInfo.framebuffer = fb;
4666 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004667 m_commandBuffer->BeginCommandBuffer();
4668 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4669 m_commandBuffer->EndRenderPass();
4670 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06004671 // Submit cmd buffer to put it in-flight
4672 VkSubmitInfo submit_info = {};
4673 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4674 submit_info.commandBufferCount = 1;
4675 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4676 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4677 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06004679 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4680 m_errorMonitor->VerifyFound();
4681 // Wait for queue to complete so we can safely destroy everything
4682 vkQueueWaitIdle(m_device->m_queue);
4683 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4684}
4685
Tobin Ehlis88becd72016-09-21 14:33:41 -06004686TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4687 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4688 VkFormatProperties format_properties;
4689 VkResult err = VK_SUCCESS;
4690 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004691
4692 ASSERT_NO_FATAL_FAILURE(InitState());
4693 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4694
4695 VkImageCreateInfo image_ci = {};
4696 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4697 image_ci.pNext = NULL;
4698 image_ci.imageType = VK_IMAGE_TYPE_2D;
4699 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4700 image_ci.extent.width = 256;
4701 image_ci.extent.height = 256;
4702 image_ci.extent.depth = 1;
4703 image_ci.mipLevels = 1;
4704 image_ci.arrayLayers = 1;
4705 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4706 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004707 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004708 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4709 image_ci.flags = 0;
4710 VkImage image;
4711 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4712
4713 VkMemoryRequirements memory_reqs;
4714 VkDeviceMemory image_memory;
4715 bool pass;
4716 VkMemoryAllocateInfo memory_info = {};
4717 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4718 memory_info.pNext = NULL;
4719 memory_info.allocationSize = 0;
4720 memory_info.memoryTypeIndex = 0;
4721 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4722 memory_info.allocationSize = memory_reqs.size;
4723 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4724 ASSERT_TRUE(pass);
4725 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4726 ASSERT_VK_SUCCESS(err);
4727 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4728 ASSERT_VK_SUCCESS(err);
4729
4730 VkImageViewCreateInfo ivci = {
4731 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4732 nullptr,
4733 0,
4734 image,
4735 VK_IMAGE_VIEW_TYPE_2D,
4736 VK_FORMAT_B8G8R8A8_UNORM,
4737 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4738 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4739 };
4740 VkImageView view;
4741 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4742 ASSERT_VK_SUCCESS(err);
4743
4744 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4745 VkFramebuffer fb;
4746 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4747 ASSERT_VK_SUCCESS(err);
4748
4749 // Just use default renderpass with our framebuffer
4750 m_renderPassBeginInfo.framebuffer = fb;
4751 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004752 m_commandBuffer->BeginCommandBuffer();
4753 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4754 m_commandBuffer->EndRenderPass();
4755 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06004756 // Submit cmd buffer to put it (and attached imageView) in-flight
4757 VkSubmitInfo submit_info = {};
4758 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4759 submit_info.commandBufferCount = 1;
4760 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4761 // Submit cmd buffer to put framebuffer and children in-flight
4762 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4763 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004765 vkDestroyImage(m_device->device(), image, NULL);
4766 m_errorMonitor->VerifyFound();
4767 // Wait for queue to complete so we can safely destroy image and other objects
4768 vkQueueWaitIdle(m_device->m_queue);
4769 vkDestroyImage(m_device->device(), image, NULL);
4770 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4771 vkDestroyImageView(m_device->device(), view, nullptr);
4772 vkFreeMemory(m_device->device(), image_memory, nullptr);
4773}
4774
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004775TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4776 TEST_DESCRIPTION("Delete in-use renderPass.");
4777
4778 ASSERT_NO_FATAL_FAILURE(InitState());
4779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4780
4781 // Create simple renderpass
4782 VkAttachmentReference attach = {};
4783 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4784 VkSubpassDescription subpass = {};
4785 subpass.pColorAttachments = &attach;
4786 VkRenderPassCreateInfo rpci = {};
4787 rpci.subpassCount = 1;
4788 rpci.pSubpasses = &subpass;
4789 rpci.attachmentCount = 1;
4790 VkAttachmentDescription attach_desc = {};
4791 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4792 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4793 rpci.pAttachments = &attach_desc;
4794 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4795 VkRenderPass rp;
4796 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4797 ASSERT_VK_SUCCESS(err);
4798
4799 // Create a pipeline that uses the given renderpass
4800 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4801 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4802
4803 VkPipelineLayout pipeline_layout;
4804 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4805 ASSERT_VK_SUCCESS(err);
4806
4807 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4808 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4809 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004810 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004811 vp_state_ci.pViewports = &vp;
4812 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004813 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004814 vp_state_ci.pScissors = &scissors;
4815
4816 VkPipelineShaderStageCreateInfo shaderStages[2];
4817 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4818
4819 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004820 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 -06004821 // but add it to be able to run on more devices
4822 shaderStages[0] = vs.GetStageCreateInfo();
4823 shaderStages[1] = fs.GetStageCreateInfo();
4824
4825 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4826 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4827
4828 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4829 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4830 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4831
4832 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4833 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4834 rs_ci.rasterizerDiscardEnable = true;
4835 rs_ci.lineWidth = 1.0f;
4836
4837 VkPipelineColorBlendAttachmentState att = {};
4838 att.blendEnable = VK_FALSE;
4839 att.colorWriteMask = 0xf;
4840
4841 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4842 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4843 cb_ci.attachmentCount = 1;
4844 cb_ci.pAttachments = &att;
4845
4846 VkGraphicsPipelineCreateInfo gp_ci = {};
4847 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4848 gp_ci.stageCount = 2;
4849 gp_ci.pStages = shaderStages;
4850 gp_ci.pVertexInputState = &vi_ci;
4851 gp_ci.pInputAssemblyState = &ia_ci;
4852 gp_ci.pViewportState = &vp_state_ci;
4853 gp_ci.pRasterizationState = &rs_ci;
4854 gp_ci.pColorBlendState = &cb_ci;
4855 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4856 gp_ci.layout = pipeline_layout;
4857 gp_ci.renderPass = rp;
4858
4859 VkPipelineCacheCreateInfo pc_ci = {};
4860 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4861
4862 VkPipeline pipeline;
4863 VkPipelineCache pipe_cache;
4864 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4865 ASSERT_VK_SUCCESS(err);
4866
4867 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4868 ASSERT_VK_SUCCESS(err);
4869 // Bind pipeline to cmd buffer, will also bind renderpass
4870 m_commandBuffer->BeginCommandBuffer();
4871 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4872 m_commandBuffer->EndCommandBuffer();
4873
4874 VkSubmitInfo submit_info = {};
4875 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4876 submit_info.commandBufferCount = 1;
4877 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4878 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4879
4880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4881 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4882 m_errorMonitor->VerifyFound();
4883
4884 // Wait for queue to complete so we can safely destroy everything
4885 vkQueueWaitIdle(m_device->m_queue);
4886 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4887 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4888 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4889 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4890}
4891
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004892TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004893 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004894 ASSERT_NO_FATAL_FAILURE(InitState());
4895
4896 VkImage image;
4897 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4898 VkImageCreateInfo image_create_info = {};
4899 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4900 image_create_info.pNext = NULL;
4901 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4902 image_create_info.format = tex_format;
4903 image_create_info.extent.width = 32;
4904 image_create_info.extent.height = 32;
4905 image_create_info.extent.depth = 1;
4906 image_create_info.mipLevels = 1;
4907 image_create_info.arrayLayers = 1;
4908 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4909 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004910 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004911 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004912 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004913 ASSERT_VK_SUCCESS(err);
4914 // Have to bind memory to image before recording cmd in cmd buffer using it
4915 VkMemoryRequirements mem_reqs;
4916 VkDeviceMemory image_mem;
4917 bool pass;
4918 VkMemoryAllocateInfo mem_alloc = {};
4919 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4920 mem_alloc.pNext = NULL;
4921 mem_alloc.memoryTypeIndex = 0;
4922 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4923 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004924 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004925 ASSERT_TRUE(pass);
4926 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4927 ASSERT_VK_SUCCESS(err);
4928
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004929 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004931 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004932
4933 m_commandBuffer->BeginCommandBuffer();
4934 VkClearColorValue ccv;
4935 ccv.float32[0] = 1.0f;
4936 ccv.float32[1] = 1.0f;
4937 ccv.float32[2] = 1.0f;
4938 ccv.float32[3] = 1.0f;
4939 VkImageSubresourceRange isr = {};
4940 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4941 isr.baseArrayLayer = 0;
4942 isr.baseMipLevel = 0;
4943 isr.layerCount = 1;
4944 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004945 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004946 m_commandBuffer->EndCommandBuffer();
4947
4948 m_errorMonitor->VerifyFound();
4949 vkDestroyImage(m_device->device(), image, NULL);
4950 vkFreeMemory(m_device->device(), image_mem, nullptr);
4951}
4952
4953TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004954 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004955 ASSERT_NO_FATAL_FAILURE(InitState());
4956
4957 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004958 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004959 VK_IMAGE_TILING_OPTIMAL, 0);
4960 ASSERT_TRUE(image.initialized());
4961
4962 VkBuffer buffer;
4963 VkDeviceMemory mem;
4964 VkMemoryRequirements mem_reqs;
4965
4966 VkBufferCreateInfo buf_info = {};
4967 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004968 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004969 buf_info.size = 256;
4970 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4971 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4972 ASSERT_VK_SUCCESS(err);
4973
4974 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4975
4976 VkMemoryAllocateInfo alloc_info = {};
4977 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4978 alloc_info.allocationSize = 256;
4979 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004980 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 -06004981 if (!pass) {
4982 vkDestroyBuffer(m_device->device(), buffer, NULL);
4983 return;
4984 }
4985 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4986 ASSERT_VK_SUCCESS(err);
4987
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004988 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004990 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004991 VkBufferImageCopy region = {};
4992 region.bufferRowLength = 128;
4993 region.bufferImageHeight = 128;
4994 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4995
4996 region.imageSubresource.layerCount = 1;
4997 region.imageExtent.height = 4;
4998 region.imageExtent.width = 4;
4999 region.imageExtent.depth = 1;
5000 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005001 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5002 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005003 m_commandBuffer->EndCommandBuffer();
5004
5005 m_errorMonitor->VerifyFound();
5006
5007 vkDestroyBuffer(m_device->device(), buffer, NULL);
5008 vkFreeMemory(m_device->handle(), mem, NULL);
5009}
5010
Tobin Ehlis85940f52016-07-07 16:57:21 -06005011TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005012 TEST_DESCRIPTION(
5013 "Attempt to draw with a command buffer that is invalid "
5014 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005015 ASSERT_NO_FATAL_FAILURE(InitState());
5016
5017 VkEvent event;
5018 VkEventCreateInfo evci = {};
5019 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5020 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5021 ASSERT_VK_SUCCESS(result);
5022
5023 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005024 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005025 m_commandBuffer->EndCommandBuffer();
5026
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005028 // Destroy event dependency prior to submit to cause ERROR
5029 vkDestroyEvent(m_device->device(), event, NULL);
5030
5031 VkSubmitInfo submit_info = {};
5032 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5033 submit_info.commandBufferCount = 1;
5034 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5035 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5036
5037 m_errorMonitor->VerifyFound();
5038}
5039
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005040TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005041 TEST_DESCRIPTION(
5042 "Attempt to draw with a command buffer that is invalid "
5043 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005044 ASSERT_NO_FATAL_FAILURE(InitState());
5045
5046 VkQueryPool query_pool;
5047 VkQueryPoolCreateInfo qpci{};
5048 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5049 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5050 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005051 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005052 ASSERT_VK_SUCCESS(result);
5053
5054 m_commandBuffer->BeginCommandBuffer();
5055 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5056 m_commandBuffer->EndCommandBuffer();
5057
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005059 // Destroy query pool dependency prior to submit to cause ERROR
5060 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5061
5062 VkSubmitInfo submit_info = {};
5063 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5064 submit_info.commandBufferCount = 1;
5065 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5066 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5067
5068 m_errorMonitor->VerifyFound();
5069}
5070
Tobin Ehlis24130d92016-07-08 15:50:53 -06005071TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005072 TEST_DESCRIPTION(
5073 "Attempt to draw with a command buffer that is invalid "
5074 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005075 ASSERT_NO_FATAL_FAILURE(InitState());
5076 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5077
5078 VkResult err;
5079
5080 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5081 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5082
5083 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005084 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005085 ASSERT_VK_SUCCESS(err);
5086
5087 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5088 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5089 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005090 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005091 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005092 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005093 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005094 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005095
5096 VkPipelineShaderStageCreateInfo shaderStages[2];
5097 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5098
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005099 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005100 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 -06005101 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005102 shaderStages[0] = vs.GetStageCreateInfo();
5103 shaderStages[1] = fs.GetStageCreateInfo();
5104
5105 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5106 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5107
5108 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5109 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5110 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5111
5112 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5113 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005114 rs_ci.rasterizerDiscardEnable = true;
5115 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005116
5117 VkPipelineColorBlendAttachmentState att = {};
5118 att.blendEnable = VK_FALSE;
5119 att.colorWriteMask = 0xf;
5120
5121 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5122 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5123 cb_ci.attachmentCount = 1;
5124 cb_ci.pAttachments = &att;
5125
5126 VkGraphicsPipelineCreateInfo gp_ci = {};
5127 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5128 gp_ci.stageCount = 2;
5129 gp_ci.pStages = shaderStages;
5130 gp_ci.pVertexInputState = &vi_ci;
5131 gp_ci.pInputAssemblyState = &ia_ci;
5132 gp_ci.pViewportState = &vp_state_ci;
5133 gp_ci.pRasterizationState = &rs_ci;
5134 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005135 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5136 gp_ci.layout = pipeline_layout;
5137 gp_ci.renderPass = renderPass();
5138
5139 VkPipelineCacheCreateInfo pc_ci = {};
5140 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5141
5142 VkPipeline pipeline;
5143 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005144 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005145 ASSERT_VK_SUCCESS(err);
5146
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005147 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005148 ASSERT_VK_SUCCESS(err);
5149
5150 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005151 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005152 m_commandBuffer->EndCommandBuffer();
5153 // Now destroy pipeline in order to cause error when submitting
5154 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5155
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005157
5158 VkSubmitInfo submit_info = {};
5159 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5160 submit_info.commandBufferCount = 1;
5161 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5162 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5163
5164 m_errorMonitor->VerifyFound();
5165 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5166 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5167}
5168
Tobin Ehlis31289162016-08-17 14:57:58 -06005169TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005170 TEST_DESCRIPTION(
5171 "Attempt to draw with a command buffer that is invalid "
5172 "due to a bound descriptor set with a buffer dependency "
5173 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005174 ASSERT_NO_FATAL_FAILURE(InitState());
5175 ASSERT_NO_FATAL_FAILURE(InitViewport());
5176 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5177
5178 VkDescriptorPoolSize ds_type_count = {};
5179 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5180 ds_type_count.descriptorCount = 1;
5181
5182 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5183 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5184 ds_pool_ci.pNext = NULL;
5185 ds_pool_ci.maxSets = 1;
5186 ds_pool_ci.poolSizeCount = 1;
5187 ds_pool_ci.pPoolSizes = &ds_type_count;
5188
5189 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005190 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005191 ASSERT_VK_SUCCESS(err);
5192
5193 VkDescriptorSetLayoutBinding dsl_binding = {};
5194 dsl_binding.binding = 0;
5195 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5196 dsl_binding.descriptorCount = 1;
5197 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5198 dsl_binding.pImmutableSamplers = NULL;
5199
5200 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5201 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5202 ds_layout_ci.pNext = NULL;
5203 ds_layout_ci.bindingCount = 1;
5204 ds_layout_ci.pBindings = &dsl_binding;
5205 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005206 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005207 ASSERT_VK_SUCCESS(err);
5208
5209 VkDescriptorSet descriptorSet;
5210 VkDescriptorSetAllocateInfo alloc_info = {};
5211 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5212 alloc_info.descriptorSetCount = 1;
5213 alloc_info.descriptorPool = ds_pool;
5214 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005215 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005216 ASSERT_VK_SUCCESS(err);
5217
5218 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5219 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5220 pipeline_layout_ci.pNext = NULL;
5221 pipeline_layout_ci.setLayoutCount = 1;
5222 pipeline_layout_ci.pSetLayouts = &ds_layout;
5223
5224 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005225 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005226 ASSERT_VK_SUCCESS(err);
5227
5228 // Create a buffer to update the descriptor with
5229 uint32_t qfi = 0;
5230 VkBufferCreateInfo buffCI = {};
5231 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5232 buffCI.size = 1024;
5233 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5234 buffCI.queueFamilyIndexCount = 1;
5235 buffCI.pQueueFamilyIndices = &qfi;
5236
5237 VkBuffer buffer;
5238 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5239 ASSERT_VK_SUCCESS(err);
5240 // Allocate memory and bind to buffer so we can make it to the appropriate
5241 // error
5242 VkMemoryAllocateInfo mem_alloc = {};
5243 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5244 mem_alloc.pNext = NULL;
5245 mem_alloc.allocationSize = 1024;
5246 mem_alloc.memoryTypeIndex = 0;
5247
5248 VkMemoryRequirements memReqs;
5249 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005250 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005251 if (!pass) {
5252 vkDestroyBuffer(m_device->device(), buffer, NULL);
5253 return;
5254 }
5255
5256 VkDeviceMemory mem;
5257 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5258 ASSERT_VK_SUCCESS(err);
5259 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5260 ASSERT_VK_SUCCESS(err);
5261 // Correctly update descriptor to avoid "NOT_UPDATED" error
5262 VkDescriptorBufferInfo buffInfo = {};
5263 buffInfo.buffer = buffer;
5264 buffInfo.offset = 0;
5265 buffInfo.range = 1024;
5266
5267 VkWriteDescriptorSet descriptor_write;
5268 memset(&descriptor_write, 0, sizeof(descriptor_write));
5269 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5270 descriptor_write.dstSet = descriptorSet;
5271 descriptor_write.dstBinding = 0;
5272 descriptor_write.descriptorCount = 1;
5273 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5274 descriptor_write.pBufferInfo = &buffInfo;
5275
5276 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5277
5278 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005279 char const *vsSource =
5280 "#version 450\n"
5281 "\n"
5282 "out gl_PerVertex { \n"
5283 " vec4 gl_Position;\n"
5284 "};\n"
5285 "void main(){\n"
5286 " gl_Position = vec4(1);\n"
5287 "}\n";
5288 char const *fsSource =
5289 "#version 450\n"
5290 "\n"
5291 "layout(location=0) out vec4 x;\n"
5292 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5293 "void main(){\n"
5294 " x = vec4(bar.y);\n"
5295 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005296 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5297 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5298 VkPipelineObj pipe(m_device);
5299 pipe.AddShader(&vs);
5300 pipe.AddShader(&fs);
5301 pipe.AddColorAttachment();
5302 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5303
Tony Barbour552f6c02016-12-21 14:34:07 -07005304 m_commandBuffer->BeginCommandBuffer();
5305 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005306 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5307 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5308 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005309
5310 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5311 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5312
Tobin Ehlis31289162016-08-17 14:57:58 -06005313 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005314 m_commandBuffer->EndRenderPass();
5315 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005317 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5318 vkDestroyBuffer(m_device->device(), buffer, NULL);
5319 // Attempt to submit cmd buffer
5320 VkSubmitInfo submit_info = {};
5321 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5322 submit_info.commandBufferCount = 1;
5323 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5324 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5325 m_errorMonitor->VerifyFound();
5326 // Cleanup
5327 vkFreeMemory(m_device->device(), mem, NULL);
5328
5329 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5330 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5331 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5332}
5333
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005334TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005335 TEST_DESCRIPTION(
5336 "Attempt to draw with a command buffer that is invalid "
5337 "due to a bound descriptor sets with a combined image "
5338 "sampler having their image, sampler, and descriptor set "
5339 "each respectively destroyed and then attempting to "
5340 "submit associated cmd buffers. Attempt to destroy a "
5341 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005342 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005343 ASSERT_NO_FATAL_FAILURE(InitViewport());
5344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5345
5346 VkDescriptorPoolSize ds_type_count = {};
5347 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5348 ds_type_count.descriptorCount = 1;
5349
5350 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5351 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5352 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005353 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005354 ds_pool_ci.maxSets = 1;
5355 ds_pool_ci.poolSizeCount = 1;
5356 ds_pool_ci.pPoolSizes = &ds_type_count;
5357
5358 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005359 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005360 ASSERT_VK_SUCCESS(err);
5361
5362 VkDescriptorSetLayoutBinding dsl_binding = {};
5363 dsl_binding.binding = 0;
5364 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5365 dsl_binding.descriptorCount = 1;
5366 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5367 dsl_binding.pImmutableSamplers = NULL;
5368
5369 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5370 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5371 ds_layout_ci.pNext = NULL;
5372 ds_layout_ci.bindingCount = 1;
5373 ds_layout_ci.pBindings = &dsl_binding;
5374 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005375 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005376 ASSERT_VK_SUCCESS(err);
5377
5378 VkDescriptorSet descriptorSet;
5379 VkDescriptorSetAllocateInfo alloc_info = {};
5380 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5381 alloc_info.descriptorSetCount = 1;
5382 alloc_info.descriptorPool = ds_pool;
5383 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005384 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005385 ASSERT_VK_SUCCESS(err);
5386
5387 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5388 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5389 pipeline_layout_ci.pNext = NULL;
5390 pipeline_layout_ci.setLayoutCount = 1;
5391 pipeline_layout_ci.pSetLayouts = &ds_layout;
5392
5393 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005394 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005395 ASSERT_VK_SUCCESS(err);
5396
5397 // Create images to update the descriptor with
5398 VkImage image;
5399 VkImage image2;
5400 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5401 const int32_t tex_width = 32;
5402 const int32_t tex_height = 32;
5403 VkImageCreateInfo image_create_info = {};
5404 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5405 image_create_info.pNext = NULL;
5406 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5407 image_create_info.format = tex_format;
5408 image_create_info.extent.width = tex_width;
5409 image_create_info.extent.height = tex_height;
5410 image_create_info.extent.depth = 1;
5411 image_create_info.mipLevels = 1;
5412 image_create_info.arrayLayers = 1;
5413 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5414 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5415 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5416 image_create_info.flags = 0;
5417 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5418 ASSERT_VK_SUCCESS(err);
5419 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5420 ASSERT_VK_SUCCESS(err);
5421
5422 VkMemoryRequirements memory_reqs;
5423 VkDeviceMemory image_memory;
5424 bool pass;
5425 VkMemoryAllocateInfo memory_info = {};
5426 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5427 memory_info.pNext = NULL;
5428 memory_info.allocationSize = 0;
5429 memory_info.memoryTypeIndex = 0;
5430 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5431 // Allocate enough memory for both images
5432 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005433 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005434 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005435 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005436 ASSERT_VK_SUCCESS(err);
5437 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5438 ASSERT_VK_SUCCESS(err);
5439 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005440 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005441 ASSERT_VK_SUCCESS(err);
5442
5443 VkImageViewCreateInfo image_view_create_info = {};
5444 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5445 image_view_create_info.image = image;
5446 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5447 image_view_create_info.format = tex_format;
5448 image_view_create_info.subresourceRange.layerCount = 1;
5449 image_view_create_info.subresourceRange.baseMipLevel = 0;
5450 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005451 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005452
5453 VkImageView view;
5454 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005455 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005456 ASSERT_VK_SUCCESS(err);
5457 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005458 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005459 ASSERT_VK_SUCCESS(err);
5460 // Create Samplers
5461 VkSamplerCreateInfo sampler_ci = {};
5462 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5463 sampler_ci.pNext = NULL;
5464 sampler_ci.magFilter = VK_FILTER_NEAREST;
5465 sampler_ci.minFilter = VK_FILTER_NEAREST;
5466 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5467 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5468 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5469 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5470 sampler_ci.mipLodBias = 1.0;
5471 sampler_ci.anisotropyEnable = VK_FALSE;
5472 sampler_ci.maxAnisotropy = 1;
5473 sampler_ci.compareEnable = VK_FALSE;
5474 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5475 sampler_ci.minLod = 1.0;
5476 sampler_ci.maxLod = 1.0;
5477 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5478 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5479 VkSampler sampler;
5480 VkSampler sampler2;
5481 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5482 ASSERT_VK_SUCCESS(err);
5483 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5484 ASSERT_VK_SUCCESS(err);
5485 // Update descriptor with image and sampler
5486 VkDescriptorImageInfo img_info = {};
5487 img_info.sampler = sampler;
5488 img_info.imageView = view;
5489 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5490
5491 VkWriteDescriptorSet descriptor_write;
5492 memset(&descriptor_write, 0, sizeof(descriptor_write));
5493 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5494 descriptor_write.dstSet = descriptorSet;
5495 descriptor_write.dstBinding = 0;
5496 descriptor_write.descriptorCount = 1;
5497 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5498 descriptor_write.pImageInfo = &img_info;
5499
5500 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5501
5502 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005503 char const *vsSource =
5504 "#version 450\n"
5505 "\n"
5506 "out gl_PerVertex { \n"
5507 " vec4 gl_Position;\n"
5508 "};\n"
5509 "void main(){\n"
5510 " gl_Position = vec4(1);\n"
5511 "}\n";
5512 char const *fsSource =
5513 "#version 450\n"
5514 "\n"
5515 "layout(set=0, binding=0) uniform sampler2D s;\n"
5516 "layout(location=0) out vec4 x;\n"
5517 "void main(){\n"
5518 " x = texture(s, vec2(1));\n"
5519 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005520 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5521 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5522 VkPipelineObj pipe(m_device);
5523 pipe.AddShader(&vs);
5524 pipe.AddShader(&fs);
5525 pipe.AddColorAttachment();
5526 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5527
5528 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005530 m_commandBuffer->BeginCommandBuffer();
5531 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005532 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5533 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5534 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005535 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5536 VkRect2D scissor = {{0, 0}, {16, 16}};
5537 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5538 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005539 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005540 m_commandBuffer->EndRenderPass();
5541 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005542 // Destroy sampler invalidates the cmd buffer, causing error on submit
5543 vkDestroySampler(m_device->device(), sampler, NULL);
5544 // Attempt to submit cmd buffer
5545 VkSubmitInfo submit_info = {};
5546 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5547 submit_info.commandBufferCount = 1;
5548 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5549 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5550 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005551
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005552 // Now re-update descriptor with valid sampler and delete image
5553 img_info.sampler = sampler2;
5554 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005555
5556 VkCommandBufferBeginInfo info = {};
5557 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5558 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5559
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005561 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005562 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005563 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5564 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5565 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005566 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5567 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005568 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005569 m_commandBuffer->EndRenderPass();
5570 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005571 // Destroy image invalidates the cmd buffer, causing error on submit
5572 vkDestroyImage(m_device->device(), image, NULL);
5573 // Attempt to submit cmd buffer
5574 submit_info = {};
5575 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5576 submit_info.commandBufferCount = 1;
5577 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5578 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5579 m_errorMonitor->VerifyFound();
5580 // Now update descriptor to be valid, but then free descriptor
5581 img_info.imageView = view2;
5582 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005583 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005584 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005585 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5586 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5587 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005588 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5589 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005590 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005591 m_commandBuffer->EndRenderPass();
5592 m_commandBuffer->EndCommandBuffer();
Dave Houltonfbf52152017-01-06 12:55:29 -07005593
5594 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005596 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005597 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005598
5599 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07005600 // 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 -07005601 vkQueueWaitIdle(m_device->m_queue);
5602 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5603
5604 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005605 submit_info = {};
5606 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5607 submit_info.commandBufferCount = 1;
5608 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005610 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5611 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005612
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005613 // Cleanup
5614 vkFreeMemory(m_device->device(), image_memory, NULL);
5615 vkDestroySampler(m_device->device(), sampler2, NULL);
5616 vkDestroyImage(m_device->device(), image2, NULL);
5617 vkDestroyImageView(m_device->device(), view, NULL);
5618 vkDestroyImageView(m_device->device(), view2, NULL);
5619 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5620 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5621 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5622}
5623
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005624TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5625 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5626 ASSERT_NO_FATAL_FAILURE(InitState());
5627 ASSERT_NO_FATAL_FAILURE(InitViewport());
5628 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5629
5630 VkDescriptorPoolSize ds_type_count = {};
5631 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5632 ds_type_count.descriptorCount = 1;
5633
5634 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5635 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5636 ds_pool_ci.pNext = NULL;
5637 ds_pool_ci.maxSets = 1;
5638 ds_pool_ci.poolSizeCount = 1;
5639 ds_pool_ci.pPoolSizes = &ds_type_count;
5640
5641 VkDescriptorPool ds_pool;
5642 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5643 ASSERT_VK_SUCCESS(err);
5644
5645 VkDescriptorSetLayoutBinding dsl_binding = {};
5646 dsl_binding.binding = 0;
5647 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5648 dsl_binding.descriptorCount = 1;
5649 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5650 dsl_binding.pImmutableSamplers = NULL;
5651
5652 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5653 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5654 ds_layout_ci.pNext = NULL;
5655 ds_layout_ci.bindingCount = 1;
5656 ds_layout_ci.pBindings = &dsl_binding;
5657 VkDescriptorSetLayout ds_layout;
5658 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5659 ASSERT_VK_SUCCESS(err);
5660
5661 VkDescriptorSet descriptor_set;
5662 VkDescriptorSetAllocateInfo alloc_info = {};
5663 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5664 alloc_info.descriptorSetCount = 1;
5665 alloc_info.descriptorPool = ds_pool;
5666 alloc_info.pSetLayouts = &ds_layout;
5667 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5668 ASSERT_VK_SUCCESS(err);
5669
5670 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5671 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5672 pipeline_layout_ci.pNext = NULL;
5673 pipeline_layout_ci.setLayoutCount = 1;
5674 pipeline_layout_ci.pSetLayouts = &ds_layout;
5675
5676 VkPipelineLayout pipeline_layout;
5677 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5678 ASSERT_VK_SUCCESS(err);
5679
5680 // Create image to update the descriptor with
5681 VkImageObj image(m_device);
5682 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5683 ASSERT_TRUE(image.initialized());
5684
5685 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5686 // Create Sampler
5687 VkSamplerCreateInfo sampler_ci = {};
5688 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5689 sampler_ci.pNext = NULL;
5690 sampler_ci.magFilter = VK_FILTER_NEAREST;
5691 sampler_ci.minFilter = VK_FILTER_NEAREST;
5692 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5693 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5694 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5695 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5696 sampler_ci.mipLodBias = 1.0;
5697 sampler_ci.anisotropyEnable = VK_FALSE;
5698 sampler_ci.maxAnisotropy = 1;
5699 sampler_ci.compareEnable = VK_FALSE;
5700 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5701 sampler_ci.minLod = 1.0;
5702 sampler_ci.maxLod = 1.0;
5703 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5704 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5705 VkSampler sampler;
5706 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5707 ASSERT_VK_SUCCESS(err);
5708 // Update descriptor with image and sampler
5709 VkDescriptorImageInfo img_info = {};
5710 img_info.sampler = sampler;
5711 img_info.imageView = view;
5712 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5713
5714 VkWriteDescriptorSet descriptor_write;
5715 memset(&descriptor_write, 0, sizeof(descriptor_write));
5716 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5717 descriptor_write.dstSet = descriptor_set;
5718 descriptor_write.dstBinding = 0;
5719 descriptor_write.descriptorCount = 1;
5720 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5721 descriptor_write.pImageInfo = &img_info;
5722
5723 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5724
5725 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005726 char const *vsSource =
5727 "#version 450\n"
5728 "\n"
5729 "out gl_PerVertex { \n"
5730 " vec4 gl_Position;\n"
5731 "};\n"
5732 "void main(){\n"
5733 " gl_Position = vec4(1);\n"
5734 "}\n";
5735 char const *fsSource =
5736 "#version 450\n"
5737 "\n"
5738 "layout(set=0, binding=0) uniform sampler2D s;\n"
5739 "layout(location=0) out vec4 x;\n"
5740 "void main(){\n"
5741 " x = texture(s, vec2(1));\n"
5742 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005743 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5744 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5745 VkPipelineObj pipe(m_device);
5746 pipe.AddShader(&vs);
5747 pipe.AddShader(&fs);
5748 pipe.AddColorAttachment();
5749 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5750
Tony Barbour552f6c02016-12-21 14:34:07 -07005751 m_commandBuffer->BeginCommandBuffer();
5752 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005753 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5754 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5755 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005756
5757 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5758 VkRect2D scissor = {{0, 0}, {16, 16}};
5759 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5760 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
5761
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005762 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005763 m_commandBuffer->EndRenderPass();
5764 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005765 // Submit cmd buffer to put pool in-flight
5766 VkSubmitInfo submit_info = {};
5767 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5768 submit_info.commandBufferCount = 1;
5769 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5770 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5771 // Destroy pool while in-flight, causing error
5772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5773 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5774 m_errorMonitor->VerifyFound();
5775 vkQueueWaitIdle(m_device->m_queue);
5776 // Cleanup
5777 vkDestroySampler(m_device->device(), sampler, NULL);
5778 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5779 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5780 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005781 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005782}
5783
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005784TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5785 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5786 ASSERT_NO_FATAL_FAILURE(InitState());
5787 ASSERT_NO_FATAL_FAILURE(InitViewport());
5788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5789
5790 VkDescriptorPoolSize ds_type_count = {};
5791 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5792 ds_type_count.descriptorCount = 1;
5793
5794 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5795 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5796 ds_pool_ci.pNext = NULL;
5797 ds_pool_ci.maxSets = 1;
5798 ds_pool_ci.poolSizeCount = 1;
5799 ds_pool_ci.pPoolSizes = &ds_type_count;
5800
5801 VkDescriptorPool ds_pool;
5802 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5803 ASSERT_VK_SUCCESS(err);
5804
5805 VkDescriptorSetLayoutBinding dsl_binding = {};
5806 dsl_binding.binding = 0;
5807 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5808 dsl_binding.descriptorCount = 1;
5809 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5810 dsl_binding.pImmutableSamplers = NULL;
5811
5812 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5813 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5814 ds_layout_ci.pNext = NULL;
5815 ds_layout_ci.bindingCount = 1;
5816 ds_layout_ci.pBindings = &dsl_binding;
5817 VkDescriptorSetLayout ds_layout;
5818 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5819 ASSERT_VK_SUCCESS(err);
5820
5821 VkDescriptorSet descriptorSet;
5822 VkDescriptorSetAllocateInfo alloc_info = {};
5823 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5824 alloc_info.descriptorSetCount = 1;
5825 alloc_info.descriptorPool = ds_pool;
5826 alloc_info.pSetLayouts = &ds_layout;
5827 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5828 ASSERT_VK_SUCCESS(err);
5829
5830 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5831 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5832 pipeline_layout_ci.pNext = NULL;
5833 pipeline_layout_ci.setLayoutCount = 1;
5834 pipeline_layout_ci.pSetLayouts = &ds_layout;
5835
5836 VkPipelineLayout pipeline_layout;
5837 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5838 ASSERT_VK_SUCCESS(err);
5839
5840 // Create images to update the descriptor with
5841 VkImage image;
5842 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5843 const int32_t tex_width = 32;
5844 const int32_t tex_height = 32;
5845 VkImageCreateInfo image_create_info = {};
5846 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5847 image_create_info.pNext = NULL;
5848 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5849 image_create_info.format = tex_format;
5850 image_create_info.extent.width = tex_width;
5851 image_create_info.extent.height = tex_height;
5852 image_create_info.extent.depth = 1;
5853 image_create_info.mipLevels = 1;
5854 image_create_info.arrayLayers = 1;
5855 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5856 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5857 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5858 image_create_info.flags = 0;
5859 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5860 ASSERT_VK_SUCCESS(err);
5861 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5862 VkMemoryRequirements memory_reqs;
5863 VkDeviceMemory image_memory;
5864 bool pass;
5865 VkMemoryAllocateInfo memory_info = {};
5866 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5867 memory_info.pNext = NULL;
5868 memory_info.allocationSize = 0;
5869 memory_info.memoryTypeIndex = 0;
5870 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5871 // Allocate enough memory for image
5872 memory_info.allocationSize = memory_reqs.size;
5873 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5874 ASSERT_TRUE(pass);
5875 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5876 ASSERT_VK_SUCCESS(err);
5877 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5878 ASSERT_VK_SUCCESS(err);
5879
5880 VkImageViewCreateInfo image_view_create_info = {};
5881 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5882 image_view_create_info.image = image;
5883 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5884 image_view_create_info.format = tex_format;
5885 image_view_create_info.subresourceRange.layerCount = 1;
5886 image_view_create_info.subresourceRange.baseMipLevel = 0;
5887 image_view_create_info.subresourceRange.levelCount = 1;
5888 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5889
5890 VkImageView view;
5891 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5892 ASSERT_VK_SUCCESS(err);
5893 // Create Samplers
5894 VkSamplerCreateInfo sampler_ci = {};
5895 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5896 sampler_ci.pNext = NULL;
5897 sampler_ci.magFilter = VK_FILTER_NEAREST;
5898 sampler_ci.minFilter = VK_FILTER_NEAREST;
5899 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5900 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5901 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5902 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5903 sampler_ci.mipLodBias = 1.0;
5904 sampler_ci.anisotropyEnable = VK_FALSE;
5905 sampler_ci.maxAnisotropy = 1;
5906 sampler_ci.compareEnable = VK_FALSE;
5907 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5908 sampler_ci.minLod = 1.0;
5909 sampler_ci.maxLod = 1.0;
5910 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5911 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5912 VkSampler sampler;
5913 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5914 ASSERT_VK_SUCCESS(err);
5915 // Update descriptor with image and sampler
5916 VkDescriptorImageInfo img_info = {};
5917 img_info.sampler = sampler;
5918 img_info.imageView = view;
5919 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5920
5921 VkWriteDescriptorSet descriptor_write;
5922 memset(&descriptor_write, 0, sizeof(descriptor_write));
5923 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5924 descriptor_write.dstSet = descriptorSet;
5925 descriptor_write.dstBinding = 0;
5926 descriptor_write.descriptorCount = 1;
5927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5928 descriptor_write.pImageInfo = &img_info;
5929 // Break memory binding and attempt update
5930 vkFreeMemory(m_device->device(), image_memory, nullptr);
5931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005932 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5934 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5935 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5936 m_errorMonitor->VerifyFound();
5937 // Cleanup
5938 vkDestroyImage(m_device->device(), image, NULL);
5939 vkDestroySampler(m_device->device(), sampler, NULL);
5940 vkDestroyImageView(m_device->device(), view, NULL);
5941 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5942 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5943 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5944}
5945
Karl Schultz6addd812016-02-02 17:17:23 -07005946TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005947 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5948 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005949 // Create a valid cmd buffer
5950 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005951 uint64_t fake_pipeline_handle = 0xbaad6001;
5952 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005953 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005954 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5955
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07005957 m_commandBuffer->BeginCommandBuffer();
5958 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005959 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005960 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005961
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005962 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005963 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 -06005964 Draw(1, 0, 0, 0);
5965 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005966
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005967 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005968 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 -07005969 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005970 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5971 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005972}
5973
Karl Schultz6addd812016-02-02 17:17:23 -07005974TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005975 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005976 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005977
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005979
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005980 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005981 ASSERT_NO_FATAL_FAILURE(InitViewport());
5982 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005983 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005984 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5985 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005986
5987 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005988 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5989 ds_pool_ci.pNext = NULL;
5990 ds_pool_ci.maxSets = 1;
5991 ds_pool_ci.poolSizeCount = 1;
5992 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005993
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005994 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005995 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005996 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005997
Tony Barboureb254902015-07-15 12:50:33 -06005998 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005999 dsl_binding.binding = 0;
6000 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6001 dsl_binding.descriptorCount = 1;
6002 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6003 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006004
Tony Barboureb254902015-07-15 12:50:33 -06006005 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006006 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6007 ds_layout_ci.pNext = NULL;
6008 ds_layout_ci.bindingCount = 1;
6009 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006010 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006011 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006012 ASSERT_VK_SUCCESS(err);
6013
6014 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006015 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006016 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006017 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006018 alloc_info.descriptorPool = ds_pool;
6019 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006020 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006021 ASSERT_VK_SUCCESS(err);
6022
Tony Barboureb254902015-07-15 12:50:33 -06006023 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006024 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6025 pipeline_layout_ci.pNext = NULL;
6026 pipeline_layout_ci.setLayoutCount = 1;
6027 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006028
6029 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006030 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006031 ASSERT_VK_SUCCESS(err);
6032
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006033 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006034 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006035 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006036 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006037
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006038 VkPipelineObj pipe(m_device);
6039 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006040 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006041 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006042 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006043
Tony Barbour552f6c02016-12-21 14:34:07 -07006044 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006045 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6046 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6047 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006048
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006049 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006050
Chia-I Wuf7458c52015-10-26 21:10:41 +08006051 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6052 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6053 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006054}
6055
Karl Schultz6addd812016-02-02 17:17:23 -07006056TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006057 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006058 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006059
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006061
6062 ASSERT_NO_FATAL_FAILURE(InitState());
6063 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006064 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6065 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006066
6067 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006068 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6069 ds_pool_ci.pNext = NULL;
6070 ds_pool_ci.maxSets = 1;
6071 ds_pool_ci.poolSizeCount = 1;
6072 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006073
6074 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006075 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006076 ASSERT_VK_SUCCESS(err);
6077
6078 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006079 dsl_binding.binding = 0;
6080 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6081 dsl_binding.descriptorCount = 1;
6082 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6083 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006084
6085 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006086 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6087 ds_layout_ci.pNext = NULL;
6088 ds_layout_ci.bindingCount = 1;
6089 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006090 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006091 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006092 ASSERT_VK_SUCCESS(err);
6093
6094 VkDescriptorSet descriptorSet;
6095 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006096 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006097 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006098 alloc_info.descriptorPool = ds_pool;
6099 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006100 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006101 ASSERT_VK_SUCCESS(err);
6102
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006103 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006104 VkWriteDescriptorSet descriptor_write;
6105 memset(&descriptor_write, 0, sizeof(descriptor_write));
6106 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6107 descriptor_write.dstSet = descriptorSet;
6108 descriptor_write.dstBinding = 0;
6109 descriptor_write.descriptorCount = 1;
6110 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6111 descriptor_write.pTexelBufferView = &view;
6112
6113 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6114
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006115 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006116
6117 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6118 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6119}
6120
Mark Youngd339ba32016-05-30 13:28:35 -06006121TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006122 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 -06006123
6124 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006126 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006127
6128 ASSERT_NO_FATAL_FAILURE(InitState());
6129
6130 // Create a buffer with no bound memory and then attempt to create
6131 // a buffer view.
6132 VkBufferCreateInfo buff_ci = {};
6133 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006134 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006135 buff_ci.size = 256;
6136 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6137 VkBuffer buffer;
6138 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6139 ASSERT_VK_SUCCESS(err);
6140
6141 VkBufferViewCreateInfo buff_view_ci = {};
6142 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6143 buff_view_ci.buffer = buffer;
6144 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6145 buff_view_ci.range = VK_WHOLE_SIZE;
6146 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006147 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006148
6149 m_errorMonitor->VerifyFound();
6150 vkDestroyBuffer(m_device->device(), buffer, NULL);
6151 // If last error is success, it still created the view, so delete it.
6152 if (err == VK_SUCCESS) {
6153 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6154 }
6155}
6156
Karl Schultz6addd812016-02-02 17:17:23 -07006157TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6158 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6159 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006160 // 1. No dynamicOffset supplied
6161 // 2. Too many dynamicOffsets supplied
6162 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006163 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6165 " requires 1 dynamicOffsets, but only "
6166 "0 dynamicOffsets are left in "
6167 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006168
6169 ASSERT_NO_FATAL_FAILURE(InitState());
6170 ASSERT_NO_FATAL_FAILURE(InitViewport());
6171 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6172
6173 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006174 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6175 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006176
6177 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006178 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6179 ds_pool_ci.pNext = NULL;
6180 ds_pool_ci.maxSets = 1;
6181 ds_pool_ci.poolSizeCount = 1;
6182 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006183
6184 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006185 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006186 ASSERT_VK_SUCCESS(err);
6187
6188 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006189 dsl_binding.binding = 0;
6190 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6191 dsl_binding.descriptorCount = 1;
6192 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6193 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006194
6195 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006196 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6197 ds_layout_ci.pNext = NULL;
6198 ds_layout_ci.bindingCount = 1;
6199 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006200 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006201 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006202 ASSERT_VK_SUCCESS(err);
6203
6204 VkDescriptorSet descriptorSet;
6205 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006206 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006207 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006208 alloc_info.descriptorPool = ds_pool;
6209 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006210 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006211 ASSERT_VK_SUCCESS(err);
6212
6213 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006214 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6215 pipeline_layout_ci.pNext = NULL;
6216 pipeline_layout_ci.setLayoutCount = 1;
6217 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006218
6219 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006220 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006221 ASSERT_VK_SUCCESS(err);
6222
6223 // Create a buffer to update the descriptor with
6224 uint32_t qfi = 0;
6225 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006226 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6227 buffCI.size = 1024;
6228 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6229 buffCI.queueFamilyIndexCount = 1;
6230 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006231
6232 VkBuffer dyub;
6233 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6234 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006235 // Allocate memory and bind to buffer so we can make it to the appropriate
6236 // error
6237 VkMemoryAllocateInfo mem_alloc = {};
6238 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6239 mem_alloc.pNext = NULL;
6240 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006241 mem_alloc.memoryTypeIndex = 0;
6242
6243 VkMemoryRequirements memReqs;
6244 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006245 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006246 if (!pass) {
6247 vkDestroyBuffer(m_device->device(), dyub, NULL);
6248 return;
6249 }
6250
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006251 VkDeviceMemory mem;
6252 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6253 ASSERT_VK_SUCCESS(err);
6254 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6255 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006256 // Correctly update descriptor to avoid "NOT_UPDATED" error
6257 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006258 buffInfo.buffer = dyub;
6259 buffInfo.offset = 0;
6260 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006261
6262 VkWriteDescriptorSet descriptor_write;
6263 memset(&descriptor_write, 0, sizeof(descriptor_write));
6264 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6265 descriptor_write.dstSet = descriptorSet;
6266 descriptor_write.dstBinding = 0;
6267 descriptor_write.descriptorCount = 1;
6268 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6269 descriptor_write.pBufferInfo = &buffInfo;
6270
6271 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6272
Tony Barbour552f6c02016-12-21 14:34:07 -07006273 m_commandBuffer->BeginCommandBuffer();
6274 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006275 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6276 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006277 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006278 uint32_t pDynOff[2] = {512, 756};
6279 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6281 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6282 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6283 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006284 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006285 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6287 " dynamic offset 512 combined with "
6288 "offset 0 and range 1024 that "
6289 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006290 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006291 char const *vsSource =
6292 "#version 450\n"
6293 "\n"
6294 "out gl_PerVertex { \n"
6295 " vec4 gl_Position;\n"
6296 "};\n"
6297 "void main(){\n"
6298 " gl_Position = vec4(1);\n"
6299 "}\n";
6300 char const *fsSource =
6301 "#version 450\n"
6302 "\n"
6303 "layout(location=0) out vec4 x;\n"
6304 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6305 "void main(){\n"
6306 " x = vec4(bar.y);\n"
6307 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006308 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6309 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6310 VkPipelineObj pipe(m_device);
6311 pipe.AddShader(&vs);
6312 pipe.AddShader(&fs);
6313 pipe.AddColorAttachment();
6314 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6315
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006316 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6317 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6318 VkRect2D scissor = {{0, 0}, {16, 16}};
6319 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6320
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006321 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006322 // This update should succeed, but offset size of 512 will overstep buffer
6323 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006324 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6325 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006326 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006327 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006328
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006329 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006330 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006331
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006332 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006333 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006334 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6335}
6336
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006337TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006338 TEST_DESCRIPTION(
6339 "Attempt to update a descriptor with a non-sparse buffer "
6340 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006341 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006343 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6345 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006346
6347 ASSERT_NO_FATAL_FAILURE(InitState());
6348 ASSERT_NO_FATAL_FAILURE(InitViewport());
6349 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6350
6351 VkDescriptorPoolSize ds_type_count = {};
6352 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6353 ds_type_count.descriptorCount = 1;
6354
6355 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6356 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6357 ds_pool_ci.pNext = NULL;
6358 ds_pool_ci.maxSets = 1;
6359 ds_pool_ci.poolSizeCount = 1;
6360 ds_pool_ci.pPoolSizes = &ds_type_count;
6361
6362 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006363 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006364 ASSERT_VK_SUCCESS(err);
6365
6366 VkDescriptorSetLayoutBinding dsl_binding = {};
6367 dsl_binding.binding = 0;
6368 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6369 dsl_binding.descriptorCount = 1;
6370 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6371 dsl_binding.pImmutableSamplers = NULL;
6372
6373 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6374 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6375 ds_layout_ci.pNext = NULL;
6376 ds_layout_ci.bindingCount = 1;
6377 ds_layout_ci.pBindings = &dsl_binding;
6378 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006379 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006380 ASSERT_VK_SUCCESS(err);
6381
6382 VkDescriptorSet descriptorSet;
6383 VkDescriptorSetAllocateInfo alloc_info = {};
6384 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6385 alloc_info.descriptorSetCount = 1;
6386 alloc_info.descriptorPool = ds_pool;
6387 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006388 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006389 ASSERT_VK_SUCCESS(err);
6390
6391 // Create a buffer to update the descriptor with
6392 uint32_t qfi = 0;
6393 VkBufferCreateInfo buffCI = {};
6394 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6395 buffCI.size = 1024;
6396 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6397 buffCI.queueFamilyIndexCount = 1;
6398 buffCI.pQueueFamilyIndices = &qfi;
6399
6400 VkBuffer dyub;
6401 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6402 ASSERT_VK_SUCCESS(err);
6403
6404 // Attempt to update descriptor without binding memory to it
6405 VkDescriptorBufferInfo buffInfo = {};
6406 buffInfo.buffer = dyub;
6407 buffInfo.offset = 0;
6408 buffInfo.range = 1024;
6409
6410 VkWriteDescriptorSet descriptor_write;
6411 memset(&descriptor_write, 0, sizeof(descriptor_write));
6412 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6413 descriptor_write.dstSet = descriptorSet;
6414 descriptor_write.dstBinding = 0;
6415 descriptor_write.descriptorCount = 1;
6416 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6417 descriptor_write.pBufferInfo = &buffInfo;
6418
6419 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6420 m_errorMonitor->VerifyFound();
6421
6422 vkDestroyBuffer(m_device->device(), dyub, NULL);
6423 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6424 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6425}
6426
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006427TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006428 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006429 ASSERT_NO_FATAL_FAILURE(InitState());
6430 ASSERT_NO_FATAL_FAILURE(InitViewport());
6431 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6432
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006433 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006434 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006435 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6436 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6437 pipeline_layout_ci.pushConstantRangeCount = 1;
6438 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6439
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006440 //
6441 // Check for invalid push constant ranges in pipeline layouts.
6442 //
6443 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006444 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006445 char const *msg;
6446 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006447
Karl Schultzc81037d2016-05-12 08:11:23 -06006448 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6449 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6450 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6451 "vkCreatePipelineLayout() call has push constants index 0 with "
6452 "size 0."},
6453 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6454 "vkCreatePipelineLayout() call has push constants index 0 with "
6455 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006456 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006457 "vkCreatePipelineLayout() call has push constants index 0 with "
6458 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006459 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006460 "vkCreatePipelineLayout() call has push constants index 0 with "
6461 "size 0."},
6462 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6463 "vkCreatePipelineLayout() call has push constants index 0 with "
6464 "offset 1. Offset must"},
6465 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6466 "vkCreatePipelineLayout() call has push constants index 0 "
6467 "with offset "},
6468 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6469 "vkCreatePipelineLayout() call has push constants "
6470 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006471 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006472 "vkCreatePipelineLayout() call has push constants index 0 "
6473 "with offset "},
6474 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6475 "vkCreatePipelineLayout() call has push "
6476 "constants index 0 with offset "},
6477 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6478 "vkCreatePipelineLayout() call has push "
6479 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006480 }};
6481
6482 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006483 for (const auto &iter : range_tests) {
6484 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6486 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006487 m_errorMonitor->VerifyFound();
6488 if (VK_SUCCESS == err) {
6489 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6490 }
6491 }
6492
6493 // Check for invalid stage flag
6494 pc_range.offset = 0;
6495 pc_range.size = 16;
6496 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006497 m_errorMonitor->SetDesiredFailureMsg(
6498 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6499 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006500 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006501 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006502 if (VK_SUCCESS == err) {
6503 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6504 }
6505
6506 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006507 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006508 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006509 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006510 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006511 };
6512
Karl Schultzc81037d2016-05-12 08:11:23 -06006513 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006514 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6515 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6516 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6517 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6518 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006519 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 1:[0, 4)",
6520 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 2:[0, 4)",
6521 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 3:[0, 4)",
6522 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 4:[0, 4)",
6523 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 2:[0, 4)",
6524 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 3:[0, 4)",
6525 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 4:[0, 4)",
6526 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 3:[0, 4)",
6527 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 4:[0, 4)",
6528 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[0, 4), 4:[0, 4)"}},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006529 {
6530 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6531 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6532 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6533 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6534 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006535 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006536 },
6537 {
6538 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6539 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6540 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6541 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6542 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006543 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006544 },
6545 {
6546 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6547 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6548 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6549 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6550 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006551 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006552 },
6553 {
6554 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6555 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6556 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6557 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6558 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006559 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 2:[4, 100)",
6560 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[32, 36), 2:[4, 100)",
6561 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 3:[40, 48)",
6562 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 4:[52, 56)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006563 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006564
Karl Schultzc81037d2016-05-12 08:11:23 -06006565 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006566 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006567 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006569 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006570 m_errorMonitor->VerifyFound();
6571 if (VK_SUCCESS == err) {
6572 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6573 }
6574 }
6575
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006576 //
6577 // CmdPushConstants tests
6578 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006579 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006580
6581 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006582 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6583 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006584 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006585 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6586 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006587 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006588 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6589 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006590 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006591 "vkCmdPushConstants() call has push constants with offset 1. "
6592 "Offset must be a multiple of 4."},
6593 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6594 "vkCmdPushConstants() call has push constants with offset 1. "
6595 "Offset must be a multiple of 4."},
6596 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6597 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6598 "0x1 not within flag-matching ranges in pipeline layout"},
6599 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6600 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6601 "0x1 not within flag-matching ranges in pipeline layout"},
6602 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6603 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6604 "0x1 not within flag-matching ranges in pipeline layout"},
6605 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6606 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6607 "0x1 not within flag-matching ranges in pipeline layout"},
6608 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6609 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6610 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006611 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006612 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6613 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006614 }};
6615
Tony Barbour552f6c02016-12-21 14:34:07 -07006616 m_commandBuffer->BeginCommandBuffer();
6617 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006618
6619 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006620 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006621 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006622 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006623 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006624 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006625 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006626 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006627 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6629 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006630 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006631 m_errorMonitor->VerifyFound();
6632 }
6633
6634 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006636 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006637 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006638 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006639
Karl Schultzc81037d2016-05-12 08:11:23 -06006640 // overlapping range tests with cmd
6641 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6642 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6643 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6644 "0x1 not within flag-matching ranges in pipeline layout"},
6645 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6646 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6647 "0x1 not within flag-matching ranges in pipeline layout"},
6648 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6649 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6650 "0x1 not within flag-matching ranges in pipeline layout"},
6651 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006652 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006653 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006654 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6655 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006656 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006657 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006658 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006659 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006660 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006661 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6663 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006664 iter.range.size, dummy_values);
6665 m_errorMonitor->VerifyFound();
6666 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006667 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6668
Tony Barbour552f6c02016-12-21 14:34:07 -07006669 m_commandBuffer->EndRenderPass();
6670 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006671}
6672
Karl Schultz6addd812016-02-02 17:17:23 -07006673TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006674 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006675 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006676
6677 ASSERT_NO_FATAL_FAILURE(InitState());
6678 ASSERT_NO_FATAL_FAILURE(InitViewport());
6679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6680
6681 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6682 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006683 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6684 ds_type_count[0].descriptorCount = 10;
6685 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6686 ds_type_count[1].descriptorCount = 2;
6687 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6688 ds_type_count[2].descriptorCount = 2;
6689 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6690 ds_type_count[3].descriptorCount = 5;
6691 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6692 // type
6693 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6694 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6695 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006696
6697 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006698 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6699 ds_pool_ci.pNext = NULL;
6700 ds_pool_ci.maxSets = 5;
6701 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6702 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006703
6704 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006705 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006706 ASSERT_VK_SUCCESS(err);
6707
6708 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6709 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006710 dsl_binding[0].binding = 0;
6711 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6712 dsl_binding[0].descriptorCount = 5;
6713 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6714 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006715
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006716 // Create layout identical to set0 layout but w/ different stageFlags
6717 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006718 dsl_fs_stage_only.binding = 0;
6719 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6720 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006721 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6722 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006723 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006724 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006725 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6726 ds_layout_ci.pNext = NULL;
6727 ds_layout_ci.bindingCount = 1;
6728 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006729 static const uint32_t NUM_LAYOUTS = 4;
6730 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006731 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006732 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6733 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006734 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006735 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006736 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006737 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006738 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006739 dsl_binding[0].binding = 0;
6740 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006741 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006742 dsl_binding[1].binding = 1;
6743 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6744 dsl_binding[1].descriptorCount = 2;
6745 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6746 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006747 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006748 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006749 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006750 ASSERT_VK_SUCCESS(err);
6751 dsl_binding[0].binding = 0;
6752 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006753 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006754 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006755 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006756 ASSERT_VK_SUCCESS(err);
6757 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006758 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006759 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006760 ASSERT_VK_SUCCESS(err);
6761
6762 static const uint32_t NUM_SETS = 4;
6763 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6764 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006765 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006766 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006767 alloc_info.descriptorPool = ds_pool;
6768 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006769 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006770 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006771 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006772 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006773 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006774 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006775 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006776
6777 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006778 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6779 pipeline_layout_ci.pNext = NULL;
6780 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6781 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006782
6783 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006784 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006785 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006786 // Create pipelineLayout with only one setLayout
6787 pipeline_layout_ci.setLayoutCount = 1;
6788 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006789 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006790 ASSERT_VK_SUCCESS(err);
6791 // Create pipelineLayout with 2 descriptor setLayout at index 0
6792 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6793 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006794 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006795 ASSERT_VK_SUCCESS(err);
6796 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6797 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6798 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006799 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006800 ASSERT_VK_SUCCESS(err);
6801 // Create pipelineLayout with UB type, but stageFlags for FS only
6802 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6803 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006804 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006805 ASSERT_VK_SUCCESS(err);
6806 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6807 VkDescriptorSetLayout pl_bad_s0[2] = {};
6808 pl_bad_s0[0] = ds_layout_fs_only;
6809 pl_bad_s0[1] = ds_layout[1];
6810 pipeline_layout_ci.setLayoutCount = 2;
6811 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6812 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006813 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006814 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006815
Tobin Ehlis88452832015-12-03 09:40:56 -07006816 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006817 char const *vsSource =
6818 "#version 450\n"
6819 "\n"
6820 "out gl_PerVertex {\n"
6821 " vec4 gl_Position;\n"
6822 "};\n"
6823 "void main(){\n"
6824 " gl_Position = vec4(1);\n"
6825 "}\n";
6826 char const *fsSource =
6827 "#version 450\n"
6828 "\n"
6829 "layout(location=0) out vec4 x;\n"
6830 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6831 "void main(){\n"
6832 " x = vec4(bar.y);\n"
6833 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006834 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6835 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006836 VkPipelineObj pipe(m_device);
6837 pipe.AddShader(&vs);
6838 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006839 pipe.AddColorAttachment();
6840 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006841
Tony Barbour552f6c02016-12-21 14:34:07 -07006842 m_commandBuffer->BeginCommandBuffer();
6843 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07006844
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006845 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006846 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6847 // of PSO
6848 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6849 // cmd_pipeline.c
6850 // due to the fact that cmd_alloc_dset_data() has not been called in
6851 // cmd_bind_graphics_pipeline()
6852 // TODO : Want to cause various binding incompatibility issues here to test
6853 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006854 // First cause various verify_layout_compatibility() fails
6855 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006856 // verify_set_layout_compatibility fail cases:
6857 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006859 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6860 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006861 m_errorMonitor->VerifyFound();
6862
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006863 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6865 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6866 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006867 m_errorMonitor->VerifyFound();
6868
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006869 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006870 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6871 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6873 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6874 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006875 m_errorMonitor->VerifyFound();
6876
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006877 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6878 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6880 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6881 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006882 m_errorMonitor->VerifyFound();
6883
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006884 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6885 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6887 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6888 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6889 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006890 m_errorMonitor->VerifyFound();
6891
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006892 // Cause INFO messages due to disturbing previously bound Sets
6893 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006894 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6895 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006896 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6898 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6899 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006900 m_errorMonitor->VerifyFound();
6901
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006902 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6903 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006904 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6906 " newly bound as set #0 so set #1 and "
6907 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006908 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6909 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006910 m_errorMonitor->VerifyFound();
6911
Tobin Ehlis10fad692016-07-07 12:00:36 -06006912 // Now that we're done actively using the pipelineLayout that gfx pipeline
6913 // was created with, we should be able to delete it. Do that now to verify
6914 // that validation obeys pipelineLayout lifetime
6915 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6916
Tobin Ehlis88452832015-12-03 09:40:56 -07006917 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006918 // 1. Error due to not binding required set (we actually use same code as
6919 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006920 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6921 &descriptorSet[0], 0, NULL);
6922 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6923 &descriptorSet[1], 0, NULL);
6924 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 -07006925
6926 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6927 VkRect2D scissor = {{0, 0}, {16, 16}};
6928 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6929 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6930
Tobin Ehlis88452832015-12-03 09:40:56 -07006931 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006932 m_errorMonitor->VerifyFound();
6933
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006934 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006935 // 2. Error due to bound set not being compatible with PSO's
6936 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006937 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6938 &descriptorSet[0], 0, NULL);
6939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006940 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006941 m_errorMonitor->VerifyFound();
6942
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006943 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006944 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006945 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6946 }
6947 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006948 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6949 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6950}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006951
Karl Schultz6addd812016-02-02 17:17:23 -07006952TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6954 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006955
6956 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006957 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006958 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006959 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006960
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006961 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006962}
6963
Karl Schultz6addd812016-02-02 17:17:23 -07006964TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6965 VkResult err;
6966 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006967
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006969
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006970 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006971
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006972 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006973 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006974 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006975 cmd.commandPool = m_commandPool;
6976 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006977 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006978
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006979 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006980 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006981
6982 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07006983 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07006984 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
6985
6986 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006987 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006988 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006989 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 -07006990 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006991
6992 // The error should be caught by validation of the BeginCommandBuffer call
6993 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6994
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006995 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006996 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006997}
6998
Karl Schultz6addd812016-02-02 17:17:23 -07006999TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007000 // Cause error due to Begin while recording CB
7001 // Then cause 2 errors for attempting to reset CB w/o having
7002 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7003 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007005
7006 ASSERT_NO_FATAL_FAILURE(InitState());
7007
7008 // Calls AllocateCommandBuffers
7009 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7010
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007011 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007012 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007013 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7014 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007015 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7016 cmd_buf_info.pNext = NULL;
7017 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007018 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007019
7020 // Begin CB to transition to recording state
7021 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7022 // Can't re-begin. This should trigger error
7023 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007024 m_errorMonitor->VerifyFound();
7025
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007027 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007028 // Reset attempt will trigger error due to incorrect CommandPool state
7029 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007030 m_errorMonitor->VerifyFound();
7031
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007033 // Transition CB to RECORDED state
7034 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7035 // Now attempting to Begin will implicitly reset, which triggers error
7036 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007037 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007038}
7039
Karl Schultz6addd812016-02-02 17:17:23 -07007040TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007041 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007042 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007043
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7045 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007046
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007047 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007048 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007049
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007050 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007051 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7052 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007053
7054 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007055 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7056 ds_pool_ci.pNext = NULL;
7057 ds_pool_ci.maxSets = 1;
7058 ds_pool_ci.poolSizeCount = 1;
7059 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007060
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007061 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007062 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007063 ASSERT_VK_SUCCESS(err);
7064
Tony Barboureb254902015-07-15 12:50:33 -06007065 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007066 dsl_binding.binding = 0;
7067 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7068 dsl_binding.descriptorCount = 1;
7069 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7070 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007071
Tony Barboureb254902015-07-15 12:50:33 -06007072 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007073 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7074 ds_layout_ci.pNext = NULL;
7075 ds_layout_ci.bindingCount = 1;
7076 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007077
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007078 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007079 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007080 ASSERT_VK_SUCCESS(err);
7081
7082 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007083 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007084 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007085 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007086 alloc_info.descriptorPool = ds_pool;
7087 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007088 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007089 ASSERT_VK_SUCCESS(err);
7090
Tony Barboureb254902015-07-15 12:50:33 -06007091 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007092 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7093 pipeline_layout_ci.setLayoutCount = 1;
7094 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007095
7096 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007097 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007098 ASSERT_VK_SUCCESS(err);
7099
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007100 VkViewport vp = {}; // Just need dummy vp to point to
7101 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007102
7103 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007104 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7105 vp_state_ci.scissorCount = 1;
7106 vp_state_ci.pScissors = &sc;
7107 vp_state_ci.viewportCount = 1;
7108 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007109
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007110 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7111 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7112 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7113 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7114 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7115 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007116 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007117 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007118 rs_state_ci.lineWidth = 1.0f;
7119
7120 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7121 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7122 vi_ci.pNext = nullptr;
7123 vi_ci.vertexBindingDescriptionCount = 0;
7124 vi_ci.pVertexBindingDescriptions = nullptr;
7125 vi_ci.vertexAttributeDescriptionCount = 0;
7126 vi_ci.pVertexAttributeDescriptions = nullptr;
7127
7128 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7129 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7130 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7131
7132 VkPipelineShaderStageCreateInfo shaderStages[2];
7133 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7134
7135 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7136 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7137 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
7138 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007139
Tony Barboureb254902015-07-15 12:50:33 -06007140 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007141 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7142 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007143 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007144 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7145 gp_ci.layout = pipeline_layout;
7146 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007147 gp_ci.pVertexInputState = &vi_ci;
7148 gp_ci.pInputAssemblyState = &ia_ci;
7149
7150 gp_ci.stageCount = 1;
7151 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007152
7153 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007154 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7155 pc_ci.initialDataSize = 0;
7156 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007157
7158 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007159 VkPipelineCache pipelineCache;
7160
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007161 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007162 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007163 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007164 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007165
Chia-I Wuf7458c52015-10-26 21:10:41 +08007166 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7167 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7168 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7169 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007170}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007171
Tobin Ehlis912df022015-09-17 08:46:18 -06007172/*// TODO : This test should be good, but needs Tess support in compiler to run
7173TEST_F(VkLayerTest, InvalidPatchControlPoints)
7174{
7175 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007176 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007177
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007179 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7180primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007181
Tobin Ehlis912df022015-09-17 08:46:18 -06007182 ASSERT_NO_FATAL_FAILURE(InitState());
7183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007184
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007185 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007186 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007187 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007188
7189 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7190 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7191 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007192 ds_pool_ci.poolSizeCount = 1;
7193 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007194
7195 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007196 err = vkCreateDescriptorPool(m_device->device(),
7197VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007198 ASSERT_VK_SUCCESS(err);
7199
7200 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007201 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007202 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007203 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007204 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7205 dsl_binding.pImmutableSamplers = NULL;
7206
7207 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007208 ds_layout_ci.sType =
7209VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007210 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007211 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007212 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007213
7214 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007215 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7216&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007217 ASSERT_VK_SUCCESS(err);
7218
7219 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007220 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7221VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007222 ASSERT_VK_SUCCESS(err);
7223
7224 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007225 pipeline_layout_ci.sType =
7226VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007227 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007228 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007229 pipeline_layout_ci.pSetLayouts = &ds_layout;
7230
7231 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007232 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7233&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007234 ASSERT_VK_SUCCESS(err);
7235
7236 VkPipelineShaderStageCreateInfo shaderStages[3];
7237 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7238
Karl Schultz6addd812016-02-02 17:17:23 -07007239 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7240this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007241 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007242 VkShaderObj
7243tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7244this);
7245 VkShaderObj
7246te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7247this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007248
Karl Schultz6addd812016-02-02 17:17:23 -07007249 shaderStages[0].sType =
7250VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007251 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007252 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007253 shaderStages[1].sType =
7254VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007255 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007256 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007257 shaderStages[2].sType =
7258VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007259 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007260 shaderStages[2].shader = te.handle();
7261
7262 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007263 iaCI.sType =
7264VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007265 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007266
7267 VkPipelineTessellationStateCreateInfo tsCI = {};
7268 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7269 tsCI.patchControlPoints = 0; // This will cause an error
7270
7271 VkGraphicsPipelineCreateInfo gp_ci = {};
7272 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7273 gp_ci.pNext = NULL;
7274 gp_ci.stageCount = 3;
7275 gp_ci.pStages = shaderStages;
7276 gp_ci.pVertexInputState = NULL;
7277 gp_ci.pInputAssemblyState = &iaCI;
7278 gp_ci.pTessellationState = &tsCI;
7279 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007280 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007281 gp_ci.pMultisampleState = NULL;
7282 gp_ci.pDepthStencilState = NULL;
7283 gp_ci.pColorBlendState = NULL;
7284 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7285 gp_ci.layout = pipeline_layout;
7286 gp_ci.renderPass = renderPass();
7287
7288 VkPipelineCacheCreateInfo pc_ci = {};
7289 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7290 pc_ci.pNext = NULL;
7291 pc_ci.initialSize = 0;
7292 pc_ci.initialData = 0;
7293 pc_ci.maxSize = 0;
7294
7295 VkPipeline pipeline;
7296 VkPipelineCache pipelineCache;
7297
Karl Schultz6addd812016-02-02 17:17:23 -07007298 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7299&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007300 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007301 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7302&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007304 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007305
Chia-I Wuf7458c52015-10-26 21:10:41 +08007306 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7307 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7308 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7309 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007310}
7311*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007312
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007313TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007314 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007315
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007316 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007317
Tobin Ehlise68360f2015-10-01 11:15:13 -06007318 ASSERT_NO_FATAL_FAILURE(InitState());
7319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007320
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007321 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007322 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7323 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007324
7325 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007326 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7327 ds_pool_ci.maxSets = 1;
7328 ds_pool_ci.poolSizeCount = 1;
7329 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007330
7331 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007332 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007333 ASSERT_VK_SUCCESS(err);
7334
7335 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007336 dsl_binding.binding = 0;
7337 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7338 dsl_binding.descriptorCount = 1;
7339 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007340
7341 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007342 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7343 ds_layout_ci.bindingCount = 1;
7344 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007345
7346 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007347 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007348 ASSERT_VK_SUCCESS(err);
7349
7350 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007351 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007352 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007353 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007354 alloc_info.descriptorPool = ds_pool;
7355 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007356 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007357 ASSERT_VK_SUCCESS(err);
7358
7359 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007360 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7361 pipeline_layout_ci.setLayoutCount = 1;
7362 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007363
7364 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007365 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007366 ASSERT_VK_SUCCESS(err);
7367
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007368 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007369 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007370 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007371 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007372 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007373 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007374
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007375 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7376 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7377 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7378 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7379 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7380 rs_state_ci.depthClampEnable = VK_FALSE;
7381 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7382 rs_state_ci.depthBiasEnable = VK_FALSE;
7383
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007384 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7385 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7386 vi_ci.pNext = nullptr;
7387 vi_ci.vertexBindingDescriptionCount = 0;
7388 vi_ci.pVertexBindingDescriptions = nullptr;
7389 vi_ci.vertexAttributeDescriptionCount = 0;
7390 vi_ci.pVertexAttributeDescriptions = nullptr;
7391
7392 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7393 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7394 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7395
7396 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7397 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7398 pipe_ms_state_ci.pNext = NULL;
7399 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7400 pipe_ms_state_ci.sampleShadingEnable = 0;
7401 pipe_ms_state_ci.minSampleShading = 1.0;
7402 pipe_ms_state_ci.pSampleMask = NULL;
7403
Cody Northropeb3a6c12015-10-05 14:44:45 -06007404 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007405 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007406
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007407 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007408 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007409 shaderStages[0] = vs.GetStageCreateInfo();
7410 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007411
7412 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007413 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7414 gp_ci.stageCount = 2;
7415 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007416 gp_ci.pVertexInputState = &vi_ci;
7417 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007418 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007419 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007420 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007421 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7422 gp_ci.layout = pipeline_layout;
7423 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007424
7425 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007426 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007427
7428 VkPipeline pipeline;
7429 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007430 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007431 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007432
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007433 if (!m_device->phy().features().multiViewport) {
7434 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7435
7436 // Check case where multiViewport is disabled and viewport count is not 1
7437 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7440 vp_state_ci.scissorCount = 0;
7441 vp_state_ci.viewportCount = 0;
7442 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7443 m_errorMonitor->VerifyFound();
7444 } else {
7445 if (m_device->props.limits.maxViewports == 1) {
7446 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7447 } else {
7448 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7449
7450 // Check is that viewportcount and scissorcount match
7451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7452 vp_state_ci.scissorCount = 1;
7453 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7454 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7455 m_errorMonitor->VerifyFound();
7456
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007457 // Check case where multiViewport is enabled and viewport count is greater than max
7458 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7461 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7462 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7463 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7464 m_errorMonitor->VerifyFound();
7465 }
7466 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007467
Chia-I Wuf7458c52015-10-26 21:10:41 +08007468 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7469 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7470 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7471 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007472}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007473
7474// 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
7475// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007476TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007477 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007478
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007479 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7480
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007482
Tobin Ehlise68360f2015-10-01 11:15:13 -06007483 ASSERT_NO_FATAL_FAILURE(InitState());
7484 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007485
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007486 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007487 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7488 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007489
7490 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007491 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7492 ds_pool_ci.maxSets = 1;
7493 ds_pool_ci.poolSizeCount = 1;
7494 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007495
7496 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007497 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007498 ASSERT_VK_SUCCESS(err);
7499
7500 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007501 dsl_binding.binding = 0;
7502 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7503 dsl_binding.descriptorCount = 1;
7504 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007505
7506 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007507 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7508 ds_layout_ci.bindingCount = 1;
7509 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007510
7511 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007512 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007513 ASSERT_VK_SUCCESS(err);
7514
7515 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007516 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007517 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007518 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007519 alloc_info.descriptorPool = ds_pool;
7520 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007521 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007522 ASSERT_VK_SUCCESS(err);
7523
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007524 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7525 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7526 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7527
7528 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7529 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7530 vi_ci.pNext = nullptr;
7531 vi_ci.vertexBindingDescriptionCount = 0;
7532 vi_ci.pVertexBindingDescriptions = nullptr;
7533 vi_ci.vertexAttributeDescriptionCount = 0;
7534 vi_ci.pVertexAttributeDescriptions = nullptr;
7535
7536 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7537 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7538 pipe_ms_state_ci.pNext = NULL;
7539 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7540 pipe_ms_state_ci.sampleShadingEnable = 0;
7541 pipe_ms_state_ci.minSampleShading = 1.0;
7542 pipe_ms_state_ci.pSampleMask = NULL;
7543
Tobin Ehlise68360f2015-10-01 11:15:13 -06007544 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007545 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7546 pipeline_layout_ci.setLayoutCount = 1;
7547 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007548
7549 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007550 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007551 ASSERT_VK_SUCCESS(err);
7552
7553 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7554 // Set scissor as dynamic to avoid second error
7555 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007556 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7557 dyn_state_ci.dynamicStateCount = 1;
7558 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007559
Cody Northropeb3a6c12015-10-05 14:44:45 -06007560 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007561 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007562
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007563 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007564 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7565 // 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 +08007566 shaderStages[0] = vs.GetStageCreateInfo();
7567 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007568
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007569 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7570 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7571 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7572 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7573 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7574 rs_state_ci.depthClampEnable = VK_FALSE;
7575 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7576 rs_state_ci.depthBiasEnable = VK_FALSE;
7577
Tobin Ehlise68360f2015-10-01 11:15:13 -06007578 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007579 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7580 gp_ci.stageCount = 2;
7581 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007582 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007583 // Not setting VP state w/o dynamic vp state should cause validation error
7584 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007585 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007586 gp_ci.pVertexInputState = &vi_ci;
7587 gp_ci.pInputAssemblyState = &ia_ci;
7588 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007589 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7590 gp_ci.layout = pipeline_layout;
7591 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007592
7593 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007594 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007595
7596 VkPipeline pipeline;
7597 VkPipelineCache pipelineCache;
7598
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007599 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007600 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007601 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007602
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007603 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007604
Chia-I Wuf7458c52015-10-26 21:10:41 +08007605 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7606 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7607 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7608 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007609}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007610
7611// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7612// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007613TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7614 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007615
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007617
Tobin Ehlise68360f2015-10-01 11:15:13 -06007618 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007619
7620 if (!m_device->phy().features().multiViewport) {
7621 printf("Device does not support multiple viewports/scissors; skipped.\n");
7622 return;
7623 }
7624
Tobin Ehlise68360f2015-10-01 11:15:13 -06007625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007626
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007627 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007628 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7629 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007630
7631 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007632 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7633 ds_pool_ci.maxSets = 1;
7634 ds_pool_ci.poolSizeCount = 1;
7635 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007636
7637 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007638 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007639 ASSERT_VK_SUCCESS(err);
7640
7641 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007642 dsl_binding.binding = 0;
7643 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7644 dsl_binding.descriptorCount = 1;
7645 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007646
7647 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007648 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7649 ds_layout_ci.bindingCount = 1;
7650 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007651
7652 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007653 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007654 ASSERT_VK_SUCCESS(err);
7655
7656 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007657 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007658 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007659 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007660 alloc_info.descriptorPool = ds_pool;
7661 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007662 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007663 ASSERT_VK_SUCCESS(err);
7664
7665 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007666 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7667 pipeline_layout_ci.setLayoutCount = 1;
7668 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007669
7670 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007671 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007672 ASSERT_VK_SUCCESS(err);
7673
7674 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007675 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7676 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007677 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007678 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007679 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007680
7681 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7682 // Set scissor as dynamic to avoid that error
7683 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007684 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7685 dyn_state_ci.dynamicStateCount = 1;
7686 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007687
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007688 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7689 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7690 pipe_ms_state_ci.pNext = NULL;
7691 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7692 pipe_ms_state_ci.sampleShadingEnable = 0;
7693 pipe_ms_state_ci.minSampleShading = 1.0;
7694 pipe_ms_state_ci.pSampleMask = NULL;
7695
Cody Northropeb3a6c12015-10-05 14:44:45 -06007696 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007697 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007698
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007699 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007700 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7701 // 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 +08007702 shaderStages[0] = vs.GetStageCreateInfo();
7703 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007704
Cody Northropf6622dc2015-10-06 10:33:21 -06007705 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7706 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7707 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007708 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007709 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007710 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007711 vi_ci.pVertexAttributeDescriptions = nullptr;
7712
7713 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7714 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7715 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7716
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007717 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007718 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007719 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007720 rs_ci.pNext = nullptr;
7721
Mark Youngc89c6312016-03-31 16:03:20 -06007722 VkPipelineColorBlendAttachmentState att = {};
7723 att.blendEnable = VK_FALSE;
7724 att.colorWriteMask = 0xf;
7725
Cody Northropf6622dc2015-10-06 10:33:21 -06007726 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7727 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7728 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007729 cb_ci.attachmentCount = 1;
7730 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007731
Tobin Ehlise68360f2015-10-01 11:15:13 -06007732 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007733 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7734 gp_ci.stageCount = 2;
7735 gp_ci.pStages = shaderStages;
7736 gp_ci.pVertexInputState = &vi_ci;
7737 gp_ci.pInputAssemblyState = &ia_ci;
7738 gp_ci.pViewportState = &vp_state_ci;
7739 gp_ci.pRasterizationState = &rs_ci;
7740 gp_ci.pColorBlendState = &cb_ci;
7741 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007742 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007743 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7744 gp_ci.layout = pipeline_layout;
7745 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007746
7747 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007748 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007749
7750 VkPipeline pipeline;
7751 VkPipelineCache pipelineCache;
7752
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007753 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007754 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007755 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007756
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007757 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007758
Tobin Ehlisd332f282015-10-02 11:00:56 -06007759 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007760 // First need to successfully create the PSO from above by setting
7761 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007762 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 -07007763
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007764 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07007765 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007766 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007767 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007768 m_commandBuffer->BeginCommandBuffer();
7769 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007770 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007771 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007772 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007773 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007774 Draw(1, 0, 0, 0);
7775
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007776 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007777
7778 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7779 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7780 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7781 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007782 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007783}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007784
7785// 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 -07007786// viewportCount
7787TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7788 VkResult err;
7789
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007791
7792 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007793
7794 if (!m_device->phy().features().multiViewport) {
7795 printf("Device does not support multiple viewports/scissors; skipped.\n");
7796 return;
7797 }
7798
Karl Schultz6addd812016-02-02 17:17:23 -07007799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7800
7801 VkDescriptorPoolSize ds_type_count = {};
7802 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7803 ds_type_count.descriptorCount = 1;
7804
7805 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7806 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7807 ds_pool_ci.maxSets = 1;
7808 ds_pool_ci.poolSizeCount = 1;
7809 ds_pool_ci.pPoolSizes = &ds_type_count;
7810
7811 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007812 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007813 ASSERT_VK_SUCCESS(err);
7814
7815 VkDescriptorSetLayoutBinding dsl_binding = {};
7816 dsl_binding.binding = 0;
7817 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7818 dsl_binding.descriptorCount = 1;
7819 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7820
7821 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7822 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7823 ds_layout_ci.bindingCount = 1;
7824 ds_layout_ci.pBindings = &dsl_binding;
7825
7826 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007827 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007828 ASSERT_VK_SUCCESS(err);
7829
7830 VkDescriptorSet descriptorSet;
7831 VkDescriptorSetAllocateInfo alloc_info = {};
7832 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7833 alloc_info.descriptorSetCount = 1;
7834 alloc_info.descriptorPool = ds_pool;
7835 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007836 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007837 ASSERT_VK_SUCCESS(err);
7838
7839 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7840 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7841 pipeline_layout_ci.setLayoutCount = 1;
7842 pipeline_layout_ci.pSetLayouts = &ds_layout;
7843
7844 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007845 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007846 ASSERT_VK_SUCCESS(err);
7847
7848 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7849 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7850 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007851 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007852 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007853 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007854
7855 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7856 // Set scissor as dynamic to avoid that error
7857 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7858 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7859 dyn_state_ci.dynamicStateCount = 1;
7860 dyn_state_ci.pDynamicStates = &vp_state;
7861
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007862 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7863 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7864 pipe_ms_state_ci.pNext = NULL;
7865 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7866 pipe_ms_state_ci.sampleShadingEnable = 0;
7867 pipe_ms_state_ci.minSampleShading = 1.0;
7868 pipe_ms_state_ci.pSampleMask = NULL;
7869
Karl Schultz6addd812016-02-02 17:17:23 -07007870 VkPipelineShaderStageCreateInfo shaderStages[2];
7871 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7872
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007873 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007874 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7875 // 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 -07007876 shaderStages[0] = vs.GetStageCreateInfo();
7877 shaderStages[1] = fs.GetStageCreateInfo();
7878
7879 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7880 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7881 vi_ci.pNext = nullptr;
7882 vi_ci.vertexBindingDescriptionCount = 0;
7883 vi_ci.pVertexBindingDescriptions = nullptr;
7884 vi_ci.vertexAttributeDescriptionCount = 0;
7885 vi_ci.pVertexAttributeDescriptions = nullptr;
7886
7887 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7888 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7889 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7890
7891 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7892 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007893 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007894 rs_ci.pNext = nullptr;
7895
Mark Youngc89c6312016-03-31 16:03:20 -06007896 VkPipelineColorBlendAttachmentState att = {};
7897 att.blendEnable = VK_FALSE;
7898 att.colorWriteMask = 0xf;
7899
Karl Schultz6addd812016-02-02 17:17:23 -07007900 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7901 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7902 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007903 cb_ci.attachmentCount = 1;
7904 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007905
7906 VkGraphicsPipelineCreateInfo gp_ci = {};
7907 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7908 gp_ci.stageCount = 2;
7909 gp_ci.pStages = shaderStages;
7910 gp_ci.pVertexInputState = &vi_ci;
7911 gp_ci.pInputAssemblyState = &ia_ci;
7912 gp_ci.pViewportState = &vp_state_ci;
7913 gp_ci.pRasterizationState = &rs_ci;
7914 gp_ci.pColorBlendState = &cb_ci;
7915 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007916 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007917 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7918 gp_ci.layout = pipeline_layout;
7919 gp_ci.renderPass = renderPass();
7920
7921 VkPipelineCacheCreateInfo pc_ci = {};
7922 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7923
7924 VkPipeline pipeline;
7925 VkPipelineCache pipelineCache;
7926
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007927 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007928 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007929 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007930
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007931 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007932
7933 // Now hit second fail case where we set scissor w/ different count than PSO
7934 // First need to successfully create the PSO from above by setting
7935 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7937 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007938
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007939 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06007940 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007941 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007942 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007943 m_commandBuffer->BeginCommandBuffer();
7944 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007945 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007946 VkViewport viewports[1] = {};
7947 viewports[0].width = 8;
7948 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007949 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007950 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007951 Draw(1, 0, 0, 0);
7952
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007953 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007954
Chia-I Wuf7458c52015-10-26 21:10:41 +08007955 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7956 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7957 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7958 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007959 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007960}
7961
Mark Young7394fdd2016-03-31 14:56:43 -06007962TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7963 VkResult err;
7964
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007966
7967 ASSERT_NO_FATAL_FAILURE(InitState());
7968 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7969
7970 VkDescriptorPoolSize ds_type_count = {};
7971 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7972 ds_type_count.descriptorCount = 1;
7973
7974 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7975 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7976 ds_pool_ci.maxSets = 1;
7977 ds_pool_ci.poolSizeCount = 1;
7978 ds_pool_ci.pPoolSizes = &ds_type_count;
7979
7980 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007981 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007982 ASSERT_VK_SUCCESS(err);
7983
7984 VkDescriptorSetLayoutBinding dsl_binding = {};
7985 dsl_binding.binding = 0;
7986 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7987 dsl_binding.descriptorCount = 1;
7988 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7989
7990 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7991 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7992 ds_layout_ci.bindingCount = 1;
7993 ds_layout_ci.pBindings = &dsl_binding;
7994
7995 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007996 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007997 ASSERT_VK_SUCCESS(err);
7998
7999 VkDescriptorSet descriptorSet;
8000 VkDescriptorSetAllocateInfo alloc_info = {};
8001 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8002 alloc_info.descriptorSetCount = 1;
8003 alloc_info.descriptorPool = ds_pool;
8004 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008005 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008006 ASSERT_VK_SUCCESS(err);
8007
8008 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8009 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8010 pipeline_layout_ci.setLayoutCount = 1;
8011 pipeline_layout_ci.pSetLayouts = &ds_layout;
8012
8013 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008014 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008015 ASSERT_VK_SUCCESS(err);
8016
8017 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8018 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8019 vp_state_ci.scissorCount = 1;
8020 vp_state_ci.pScissors = NULL;
8021 vp_state_ci.viewportCount = 1;
8022 vp_state_ci.pViewports = NULL;
8023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008024 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008025 // Set scissor as dynamic to avoid that error
8026 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8027 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8028 dyn_state_ci.dynamicStateCount = 2;
8029 dyn_state_ci.pDynamicStates = dynamic_states;
8030
8031 VkPipelineShaderStageCreateInfo shaderStages[2];
8032 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8033
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008034 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8035 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008036 this); // TODO - We shouldn't need a fragment shader
8037 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008038 shaderStages[0] = vs.GetStageCreateInfo();
8039 shaderStages[1] = fs.GetStageCreateInfo();
8040
8041 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8042 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8043 vi_ci.pNext = nullptr;
8044 vi_ci.vertexBindingDescriptionCount = 0;
8045 vi_ci.pVertexBindingDescriptions = nullptr;
8046 vi_ci.vertexAttributeDescriptionCount = 0;
8047 vi_ci.pVertexAttributeDescriptions = nullptr;
8048
8049 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8050 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8051 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8052
8053 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8054 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8055 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008056 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008057
Mark Young47107952016-05-02 15:59:55 -06008058 // Check too low (line width of -1.0f).
8059 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008060
8061 VkPipelineColorBlendAttachmentState att = {};
8062 att.blendEnable = VK_FALSE;
8063 att.colorWriteMask = 0xf;
8064
8065 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8066 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8067 cb_ci.pNext = nullptr;
8068 cb_ci.attachmentCount = 1;
8069 cb_ci.pAttachments = &att;
8070
8071 VkGraphicsPipelineCreateInfo gp_ci = {};
8072 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8073 gp_ci.stageCount = 2;
8074 gp_ci.pStages = shaderStages;
8075 gp_ci.pVertexInputState = &vi_ci;
8076 gp_ci.pInputAssemblyState = &ia_ci;
8077 gp_ci.pViewportState = &vp_state_ci;
8078 gp_ci.pRasterizationState = &rs_ci;
8079 gp_ci.pColorBlendState = &cb_ci;
8080 gp_ci.pDynamicState = &dyn_state_ci;
8081 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8082 gp_ci.layout = pipeline_layout;
8083 gp_ci.renderPass = renderPass();
8084
8085 VkPipelineCacheCreateInfo pc_ci = {};
8086 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8087
8088 VkPipeline pipeline;
8089 VkPipelineCache pipelineCache;
8090
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008091 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008092 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008093 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008094
8095 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008096 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008097
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008099
8100 // Check too high (line width of 65536.0f).
8101 rs_ci.lineWidth = 65536.0f;
8102
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008103 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008104 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008105 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008106
8107 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008108 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008109
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008111
8112 dyn_state_ci.dynamicStateCount = 3;
8113
8114 rs_ci.lineWidth = 1.0f;
8115
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008116 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008117 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008118 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008119 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008120 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008121
8122 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008123 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008124 m_errorMonitor->VerifyFound();
8125
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008127
8128 // Check too high with dynamic setting.
8129 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8130 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008131 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008132
8133 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8134 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8135 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8136 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008137 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008138}
8139
Karl Schultz6addd812016-02-02 17:17:23 -07008140TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008141 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008143 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008144
8145 ASSERT_NO_FATAL_FAILURE(InitState());
8146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008147
Tony Barbour552f6c02016-12-21 14:34:07 -07008148 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008149 // Don't care about RenderPass handle b/c error should be flagged before
8150 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008151 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008152
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008153 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008154}
8155
Karl Schultz6addd812016-02-02 17:17:23 -07008156TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008157 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8159 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008160
8161 ASSERT_NO_FATAL_FAILURE(InitState());
8162 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008163
Tony Barbour552f6c02016-12-21 14:34:07 -07008164 m_commandBuffer->BeginCommandBuffer();
8165 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008166 // Just create a dummy Renderpass that's non-NULL so we can get to the
8167 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008168 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008169
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008170 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008171}
8172
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008173TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008174 TEST_DESCRIPTION(
8175 "Begin a renderPass where clearValueCount is less than"
8176 "the number of renderPass attachments that use loadOp"
8177 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008178
8179 ASSERT_NO_FATAL_FAILURE(InitState());
8180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8181
8182 // Create a renderPass with a single attachment that uses loadOp CLEAR
8183 VkAttachmentReference attach = {};
8184 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8185 VkSubpassDescription subpass = {};
8186 subpass.inputAttachmentCount = 1;
8187 subpass.pInputAttachments = &attach;
8188 VkRenderPassCreateInfo rpci = {};
8189 rpci.subpassCount = 1;
8190 rpci.pSubpasses = &subpass;
8191 rpci.attachmentCount = 1;
8192 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008193 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008194 // Set loadOp to CLEAR
8195 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8196 rpci.pAttachments = &attach_desc;
8197 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8198 VkRenderPass rp;
8199 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8200
8201 VkCommandBufferInheritanceInfo hinfo = {};
8202 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8203 hinfo.renderPass = VK_NULL_HANDLE;
8204 hinfo.subpass = 0;
8205 hinfo.framebuffer = VK_NULL_HANDLE;
8206 hinfo.occlusionQueryEnable = VK_FALSE;
8207 hinfo.queryFlags = 0;
8208 hinfo.pipelineStatistics = 0;
8209 VkCommandBufferBeginInfo info = {};
8210 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8211 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8212 info.pInheritanceInfo = &hinfo;
8213
8214 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8215 VkRenderPassBeginInfo rp_begin = {};
8216 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8217 rp_begin.pNext = NULL;
8218 rp_begin.renderPass = renderPass();
8219 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008220 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008221
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008223
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008224 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008225
8226 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008227
8228 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008229}
8230
Slawomir Cygan0808f392016-11-28 17:53:23 +01008231TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008232 TEST_DESCRIPTION(
8233 "Begin a renderPass where clearValueCount is greater than"
8234 "the number of renderPass attachments that use loadOp"
8235 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008236
8237 ASSERT_NO_FATAL_FAILURE(InitState());
8238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8239
8240 // Create a renderPass with a single attachment that uses loadOp CLEAR
8241 VkAttachmentReference attach = {};
8242 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8243 VkSubpassDescription subpass = {};
8244 subpass.inputAttachmentCount = 1;
8245 subpass.pInputAttachments = &attach;
8246 VkRenderPassCreateInfo rpci = {};
8247 rpci.subpassCount = 1;
8248 rpci.pSubpasses = &subpass;
8249 rpci.attachmentCount = 1;
8250 VkAttachmentDescription attach_desc = {};
8251 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8252 // Set loadOp to CLEAR
8253 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8254 rpci.pAttachments = &attach_desc;
8255 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8256 VkRenderPass rp;
8257 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8258
8259 VkCommandBufferBeginInfo info = {};
8260 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8261 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8262
8263 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8264 VkRenderPassBeginInfo rp_begin = {};
8265 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8266 rp_begin.pNext = NULL;
8267 rp_begin.renderPass = renderPass();
8268 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008269 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008270
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8272 " has a clearValueCount of"
8273 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008274
8275 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8276
8277 m_errorMonitor->VerifyFound();
8278
8279 vkDestroyRenderPass(m_device->device(), rp, NULL);
8280}
8281
Cody Northrop3bb4d962016-05-09 16:15:57 -06008282TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008283 TEST_DESCRIPTION("End a command buffer with an active render pass");
8284
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8286 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008287
8288 ASSERT_NO_FATAL_FAILURE(InitState());
8289 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8290
Tony Barbour552f6c02016-12-21 14:34:07 -07008291 m_commandBuffer->BeginCommandBuffer();
8292 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8293 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008294
8295 m_errorMonitor->VerifyFound();
8296
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008297 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8298 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008299}
8300
Karl Schultz6addd812016-02-02 17:17:23 -07008301TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008302 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8304 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008305
8306 ASSERT_NO_FATAL_FAILURE(InitState());
8307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008308
Tony Barbour552f6c02016-12-21 14:34:07 -07008309 m_commandBuffer->BeginCommandBuffer();
8310 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008311
8312 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008313 vk_testing::Buffer dstBuffer;
8314 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008315
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008316 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008317
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008318 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008319}
8320
Karl Schultz6addd812016-02-02 17:17:23 -07008321TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008322 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8324 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008325
8326 ASSERT_NO_FATAL_FAILURE(InitState());
8327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008328
Tony Barbour552f6c02016-12-21 14:34:07 -07008329 m_commandBuffer->BeginCommandBuffer();
8330 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008331
8332 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008333 vk_testing::Buffer dstBuffer;
8334 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008335
Karl Schultz6addd812016-02-02 17:17:23 -07008336 VkDeviceSize dstOffset = 0;
8337 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008338 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008339
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008340 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008341
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008342 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008343}
8344
Karl Schultz6addd812016-02-02 17:17:23 -07008345TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008346 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8348 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008349
8350 ASSERT_NO_FATAL_FAILURE(InitState());
8351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008352
Tony Barbour552f6c02016-12-21 14:34:07 -07008353 m_commandBuffer->BeginCommandBuffer();
8354 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008355
Michael Lentine0a369f62016-02-03 16:51:46 -06008356 VkClearColorValue clear_color;
8357 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008358 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8359 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8360 const int32_t tex_width = 32;
8361 const int32_t tex_height = 32;
8362 VkImageCreateInfo image_create_info = {};
8363 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8364 image_create_info.pNext = NULL;
8365 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8366 image_create_info.format = tex_format;
8367 image_create_info.extent.width = tex_width;
8368 image_create_info.extent.height = tex_height;
8369 image_create_info.extent.depth = 1;
8370 image_create_info.mipLevels = 1;
8371 image_create_info.arrayLayers = 1;
8372 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8373 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8374 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008375
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008376 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008377 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008378
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008379 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008380
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008381 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008382
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008383 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008384}
8385
Karl Schultz6addd812016-02-02 17:17:23 -07008386TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008387 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8389 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008390
8391 ASSERT_NO_FATAL_FAILURE(InitState());
8392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008393
Tony Barbour552f6c02016-12-21 14:34:07 -07008394 m_commandBuffer->BeginCommandBuffer();
8395 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008396
8397 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008398 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008399 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8400 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8401 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8402 image_create_info.extent.width = 64;
8403 image_create_info.extent.height = 64;
8404 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8405 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008406
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008407 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008408 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008409
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008410 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008411
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008412 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8413 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008414
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008415 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008416}
8417
Karl Schultz6addd812016-02-02 17:17:23 -07008418TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008419 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008420 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008421
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8423 "vkCmdClearAttachments(): This call "
8424 "must be issued inside an active "
8425 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008426
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008427 ASSERT_NO_FATAL_FAILURE(InitState());
8428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008429
8430 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008431 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008432 ASSERT_VK_SUCCESS(err);
8433
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008434 VkClearAttachment color_attachment;
8435 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8436 color_attachment.clearValue.color.float32[0] = 0;
8437 color_attachment.clearValue.color.float32[1] = 0;
8438 color_attachment.clearValue.color.float32[2] = 0;
8439 color_attachment.clearValue.color.float32[3] = 0;
8440 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008441 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008442 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008443
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008444 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008445}
8446
Chris Forbes3b97e932016-09-07 11:29:24 +12008447TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008448 TEST_DESCRIPTION(
8449 "Test that an error is produced when CmdNextSubpass is "
8450 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008451
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8453 "vkCmdNextSubpass(): Attempted to advance "
8454 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008455
8456 ASSERT_NO_FATAL_FAILURE(InitState());
8457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8458
Tony Barbour552f6c02016-12-21 14:34:07 -07008459 m_commandBuffer->BeginCommandBuffer();
8460 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008461
8462 // error here.
8463 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8464 m_errorMonitor->VerifyFound();
8465
Tony Barbour552f6c02016-12-21 14:34:07 -07008466 m_commandBuffer->EndRenderPass();
8467 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008468}
8469
Chris Forbes6d624702016-09-07 13:57:05 +12008470TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008471 TEST_DESCRIPTION(
8472 "Test that an error is produced when CmdEndRenderPass is "
8473 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008474
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8476 "vkCmdEndRenderPass(): Called before reaching "
8477 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008478
8479 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008480 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8481 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008482
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008483 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008484
8485 VkRenderPass rp;
8486 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8487 ASSERT_VK_SUCCESS(err);
8488
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008489 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008490
8491 VkFramebuffer fb;
8492 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8493 ASSERT_VK_SUCCESS(err);
8494
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008495 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008496
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008497 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 +12008498
8499 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8500
8501 // Error here.
8502 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8503 m_errorMonitor->VerifyFound();
8504
8505 // Clean up.
8506 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8507 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8508}
8509
Karl Schultz9e66a292016-04-21 15:57:51 -06008510TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8511 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8513 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008514
8515 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008516 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008517
8518 VkBufferMemoryBarrier buf_barrier = {};
8519 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8520 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8521 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8522 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8523 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8524 buf_barrier.buffer = VK_NULL_HANDLE;
8525 buf_barrier.offset = 0;
8526 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008527 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8528 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008529
8530 m_errorMonitor->VerifyFound();
8531}
8532
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008533TEST_F(VkLayerTest, InvalidBarriers) {
8534 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8535
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008537
8538 ASSERT_NO_FATAL_FAILURE(InitState());
8539 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8540
8541 VkMemoryBarrier mem_barrier = {};
8542 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8543 mem_barrier.pNext = NULL;
8544 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8545 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008546 m_commandBuffer->BeginCommandBuffer();
8547 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008548 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008549 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008550 &mem_barrier, 0, nullptr, 0, nullptr);
8551 m_errorMonitor->VerifyFound();
8552
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008554 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008555 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008556 ASSERT_TRUE(image.initialized());
8557 VkImageMemoryBarrier img_barrier = {};
8558 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8559 img_barrier.pNext = NULL;
8560 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8561 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8562 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8563 // New layout can't be UNDEFINED
8564 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8565 img_barrier.image = image.handle();
8566 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8567 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8568 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8569 img_barrier.subresourceRange.baseArrayLayer = 0;
8570 img_barrier.subresourceRange.baseMipLevel = 0;
8571 img_barrier.subresourceRange.layerCount = 1;
8572 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008573 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8574 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008575 m_errorMonitor->VerifyFound();
8576 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8577
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8579 "Subresource must have the sum of the "
8580 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008581 // baseArrayLayer + layerCount must be <= image's arrayLayers
8582 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008583 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8584 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008585 m_errorMonitor->VerifyFound();
8586 img_barrier.subresourceRange.baseArrayLayer = 0;
8587
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008589 // baseMipLevel + levelCount must be <= image's mipLevels
8590 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008591 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8592 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008593 m_errorMonitor->VerifyFound();
8594 img_barrier.subresourceRange.baseMipLevel = 0;
8595
Mike Weiblen7053aa32017-01-25 15:21:10 -07008596 // levelCount must be non-zero.
8597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8598 img_barrier.subresourceRange.levelCount = 0;
8599 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8600 nullptr, 0, nullptr, 1, &img_barrier);
8601 m_errorMonitor->VerifyFound();
8602 img_barrier.subresourceRange.levelCount = 1;
8603
8604 // layerCount must be non-zero.
8605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8606 img_barrier.subresourceRange.layerCount = 0;
8607 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8608 nullptr, 0, nullptr, 1, &img_barrier);
8609 m_errorMonitor->VerifyFound();
8610 img_barrier.subresourceRange.layerCount = 1;
8611
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008612 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 -06008613 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008614 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8615 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008616 VkBufferMemoryBarrier buf_barrier = {};
8617 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8618 buf_barrier.pNext = NULL;
8619 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8620 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8621 buf_barrier.buffer = buffer.handle();
8622 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8623 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8624 buf_barrier.offset = 0;
8625 buf_barrier.size = VK_WHOLE_SIZE;
8626 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008627 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8628 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008629 m_errorMonitor->VerifyFound();
8630 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8631
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008633 buf_barrier.offset = 257;
8634 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008635 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8636 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008637 m_errorMonitor->VerifyFound();
8638 buf_barrier.offset = 0;
8639
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008641 buf_barrier.size = 257;
8642 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008643 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8644 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008645 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008646
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008647 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008648 m_errorMonitor->SetDesiredFailureMsg(
8649 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008650 "Depth/stencil image formats must have at least one of VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008651 VkDepthStencilObj ds_image(m_device);
8652 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8653 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008654 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8655 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008656 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008657
8658 // Not having DEPTH or STENCIL set is an error
8659 img_barrier.subresourceRange.aspectMask = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008660 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8661 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008662 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07008663
8664 // Having anything other than DEPTH or STENCIL is an error
8665 m_errorMonitor->SetDesiredFailureMsg(
8666 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8667 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8668 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
8669 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8670 nullptr, 0, nullptr, 1, &img_barrier);
8671 m_errorMonitor->VerifyFound();
8672
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008673 // Now test depth-only
8674 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008675 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8676 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008677 VkDepthStencilObj d_image(m_device);
8678 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8679 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008680 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008681 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008682 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008683
8684 // DEPTH bit must be set
8685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8686 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8687 img_barrier.subresourceRange.aspectMask = 0;
8688 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8689 0, nullptr, 0, nullptr, 1, &img_barrier);
8690 m_errorMonitor->VerifyFound();
8691
8692 // No bits other than DEPTH may be set
8693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8694 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8695 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8697 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008698 m_errorMonitor->VerifyFound();
8699 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008700
8701 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008702 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8703 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8705 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008706 VkDepthStencilObj s_image(m_device);
8707 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8708 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008709 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008710 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008711 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008712 // Use of COLOR aspect on depth image is error
8713 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008714 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8715 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008716 m_errorMonitor->VerifyFound();
8717 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008718
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008719 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008720 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008721 c_image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008722 ASSERT_TRUE(c_image.initialized());
8723 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8724 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8725 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008726
8727 // COLOR bit must be set
8728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8729 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8730 img_barrier.subresourceRange.aspectMask = 0;
8731 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8732 nullptr, 0, nullptr, 1, &img_barrier);
8733 m_errorMonitor->VerifyFound();
8734
8735 // No bits other than COLOR may be set
8736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8737 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
8738 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008739 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8740 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008741 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008742
8743 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8744
8745 // Create command pool with incompatible queueflags
8746 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8747 uint32_t queue_family_index = UINT32_MAX;
8748 for (uint32_t i = 0; i < queue_props.size(); i++) {
8749 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8750 queue_family_index = i;
8751 break;
8752 }
8753 }
8754 if (queue_family_index == UINT32_MAX) {
8755 printf("No non-compute queue found; skipped.\n");
8756 return;
8757 }
8758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8759
8760 VkCommandPool command_pool;
8761 VkCommandPoolCreateInfo pool_create_info{};
8762 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8763 pool_create_info.queueFamilyIndex = queue_family_index;
8764 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8765 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8766
8767 // Allocate a command buffer
8768 VkCommandBuffer bad_command_buffer;
8769 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8770 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8771 command_buffer_allocate_info.commandPool = command_pool;
8772 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8773 command_buffer_allocate_info.commandBufferCount = 1;
8774 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8775
8776 VkCommandBufferBeginInfo cbbi = {};
8777 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8778 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8779 buf_barrier.offset = 0;
8780 buf_barrier.size = VK_WHOLE_SIZE;
8781 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8782 &buf_barrier, 0, nullptr);
8783 m_errorMonitor->VerifyFound();
8784
8785 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8786 vkEndCommandBuffer(bad_command_buffer);
8787 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8788 printf("The non-compute queue does not support graphics; skipped.\n");
8789 return;
8790 }
8791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8792 VkEvent event;
8793 VkEventCreateInfo event_create_info{};
8794 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8795 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8796 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8797 nullptr, 0, nullptr);
8798 m_errorMonitor->VerifyFound();
8799
8800 vkEndCommandBuffer(bad_command_buffer);
8801 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008802}
8803
Tony Barbour18ba25c2016-09-29 13:42:40 -06008804TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8805 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8806
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06008808 ASSERT_NO_FATAL_FAILURE(InitState());
8809 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008810 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06008811 ASSERT_TRUE(image.initialized());
8812
8813 VkImageMemoryBarrier barrier = {};
8814 VkImageSubresourceRange range;
8815 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8816 barrier.srcAccessMask = 0;
8817 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8818 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8819 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8820 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8821 barrier.image = image.handle();
8822 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8823 range.baseMipLevel = 0;
8824 range.levelCount = 1;
8825 range.baseArrayLayer = 0;
8826 range.layerCount = 1;
8827 barrier.subresourceRange = range;
8828 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8829 cmdbuf.BeginCommandBuffer();
8830 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8831 &barrier);
8832 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8833 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8834 barrier.srcAccessMask = 0;
8835 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8836 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8837 &barrier);
8838
8839 m_errorMonitor->VerifyFound();
8840}
8841
Karl Schultz6addd812016-02-02 17:17:23 -07008842TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008843 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008844 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008845
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008847
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008848 ASSERT_NO_FATAL_FAILURE(InitState());
8849 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008850 uint32_t qfi = 0;
8851 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008852 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8853 buffCI.size = 1024;
8854 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8855 buffCI.queueFamilyIndexCount = 1;
8856 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008857
8858 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008859 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008860 ASSERT_VK_SUCCESS(err);
8861
Tony Barbour552f6c02016-12-21 14:34:07 -07008862 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008863 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008864 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8865 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008866 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008867 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008868
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008869 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008870
Chia-I Wuf7458c52015-10-26 21:10:41 +08008871 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008872}
8873
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008874TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8875 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8877 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8878 "of the indices specified when the device was created, via the "
8879 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008880
8881 ASSERT_NO_FATAL_FAILURE(InitState());
8882 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8883 VkBufferCreateInfo buffCI = {};
8884 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8885 buffCI.size = 1024;
8886 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8887 buffCI.queueFamilyIndexCount = 1;
8888 // Introduce failure by specifying invalid queue_family_index
8889 uint32_t qfi = 777;
8890 buffCI.pQueueFamilyIndices = &qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008891 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008892
8893 VkBuffer ib;
8894 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8895
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008896 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008897 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008898}
8899
Karl Schultz6addd812016-02-02 17:17:23 -07008900TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008901 TEST_DESCRIPTION(
8902 "Attempt vkCmdExecuteCommands with a primary command buffer"
8903 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008904
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008905 ASSERT_NO_FATAL_FAILURE(InitState());
8906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008907
Chris Forbesf29a84f2016-10-06 18:39:28 +13008908 // An empty primary command buffer
8909 VkCommandBufferObj cb(m_device, m_commandPool);
8910 cb.BeginCommandBuffer();
8911 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008912
Chris Forbesf29a84f2016-10-06 18:39:28 +13008913 m_commandBuffer->BeginCommandBuffer();
8914 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8915 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008916
Chris Forbesf29a84f2016-10-06 18:39:28 +13008917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8918 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008919 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008920}
8921
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008922TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008923 TEST_DESCRIPTION(
8924 "Attempt to update descriptor sets for images and buffers "
8925 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008926 VkResult err;
8927
8928 ASSERT_NO_FATAL_FAILURE(InitState());
8929 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8930 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8931 ds_type_count[i].type = VkDescriptorType(i);
8932 ds_type_count[i].descriptorCount = 1;
8933 }
8934 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8935 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8936 ds_pool_ci.pNext = NULL;
8937 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8938 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8939 ds_pool_ci.pPoolSizes = ds_type_count;
8940
8941 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008942 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008943 ASSERT_VK_SUCCESS(err);
8944
8945 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008946 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008947 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8948 dsl_binding[i].binding = 0;
8949 dsl_binding[i].descriptorType = VkDescriptorType(i);
8950 dsl_binding[i].descriptorCount = 1;
8951 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8952 dsl_binding[i].pImmutableSamplers = NULL;
8953 }
8954
8955 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8956 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8957 ds_layout_ci.pNext = NULL;
8958 ds_layout_ci.bindingCount = 1;
8959 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8960 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8961 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008962 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008963 ASSERT_VK_SUCCESS(err);
8964 }
8965 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8966 VkDescriptorSetAllocateInfo alloc_info = {};
8967 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8968 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8969 alloc_info.descriptorPool = ds_pool;
8970 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008971 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008972 ASSERT_VK_SUCCESS(err);
8973
8974 // Create a buffer & bufferView to be used for invalid updates
8975 VkBufferCreateInfo buff_ci = {};
8976 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07008977 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008978 buff_ci.size = 256;
8979 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07008980 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008981 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8982 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07008983
8984 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
8985 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
8986 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
8987 ASSERT_VK_SUCCESS(err);
8988
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008989 VkMemoryRequirements mem_reqs;
8990 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
8991 VkMemoryAllocateInfo mem_alloc_info = {};
8992 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8993 mem_alloc_info.pNext = NULL;
8994 mem_alloc_info.memoryTypeIndex = 0;
8995 mem_alloc_info.allocationSize = mem_reqs.size;
8996 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8997 if (!pass) {
8998 vkDestroyBuffer(m_device->device(), buffer, NULL);
8999 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9000 return;
9001 }
9002 VkDeviceMemory mem;
9003 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9004 ASSERT_VK_SUCCESS(err);
9005 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9006 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009007
9008 VkBufferViewCreateInfo buff_view_ci = {};
9009 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9010 buff_view_ci.buffer = buffer;
9011 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9012 buff_view_ci.range = VK_WHOLE_SIZE;
9013 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009014 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009015 ASSERT_VK_SUCCESS(err);
9016
Tony Barbour415497c2017-01-24 10:06:09 -07009017 // Now get resources / view for storage_texel_buffer
9018 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9019 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9020 if (!pass) {
9021 vkDestroyBuffer(m_device->device(), buffer, NULL);
9022 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9023 vkFreeMemory(m_device->device(), mem, NULL);
9024 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9025 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9026 return;
9027 }
9028 VkDeviceMemory storage_texel_buffer_mem;
9029 VkBufferView storage_texel_buffer_view;
9030 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9031 ASSERT_VK_SUCCESS(err);
9032 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9033 ASSERT_VK_SUCCESS(err);
9034 buff_view_ci.buffer = storage_texel_buffer;
9035 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9036 ASSERT_VK_SUCCESS(err);
9037
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009038 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009039 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009040 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009041 image_ci.format = VK_FORMAT_UNDEFINED;
9042 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9043 VkFormat format = static_cast<VkFormat>(f);
9044 VkFormatProperties fProps = m_device->format_properties(format);
9045 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9046 image_ci.format = format;
9047 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9048 break;
9049 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9050 image_ci.format = format;
9051 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9052 break;
9053 }
9054 }
9055 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9056 return;
9057 }
9058
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009059 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9060 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009061 image_ci.extent.width = 64;
9062 image_ci.extent.height = 64;
9063 image_ci.extent.depth = 1;
9064 image_ci.mipLevels = 1;
9065 image_ci.arrayLayers = 1;
9066 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009067 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009068 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009069 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9070 VkImage image;
9071 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9072 ASSERT_VK_SUCCESS(err);
9073 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009074 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009075
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009076 VkMemoryAllocateInfo mem_alloc = {};
9077 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9078 mem_alloc.pNext = NULL;
9079 mem_alloc.allocationSize = 0;
9080 mem_alloc.memoryTypeIndex = 0;
9081 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9082 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009083 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009084 ASSERT_TRUE(pass);
9085 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9086 ASSERT_VK_SUCCESS(err);
9087 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9088 ASSERT_VK_SUCCESS(err);
9089 // Now create view for image
9090 VkImageViewCreateInfo image_view_ci = {};
9091 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9092 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009093 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009094 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9095 image_view_ci.subresourceRange.layerCount = 1;
9096 image_view_ci.subresourceRange.baseArrayLayer = 0;
9097 image_view_ci.subresourceRange.levelCount = 1;
9098 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9099 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009100 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009101 ASSERT_VK_SUCCESS(err);
9102
9103 VkDescriptorBufferInfo buff_info = {};
9104 buff_info.buffer = buffer;
9105 VkDescriptorImageInfo img_info = {};
9106 img_info.imageView = image_view;
9107 VkWriteDescriptorSet descriptor_write = {};
9108 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9109 descriptor_write.dstBinding = 0;
9110 descriptor_write.descriptorCount = 1;
9111 descriptor_write.pTexelBufferView = &buff_view;
9112 descriptor_write.pBufferInfo = &buff_info;
9113 descriptor_write.pImageInfo = &img_info;
9114
9115 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009116 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009117 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9118 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9119 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9120 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9121 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9122 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9123 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9124 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9125 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9126 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9127 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009128 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009129 // Start loop at 1 as SAMPLER desc type has no usage bit error
9130 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009131 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9132 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9133 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9134 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009135 descriptor_write.descriptorType = VkDescriptorType(i);
9136 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009138
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009139 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009140
9141 m_errorMonitor->VerifyFound();
9142 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009143 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9144 descriptor_write.pTexelBufferView = &buff_view;
9145 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009146 }
Tony Barbour415497c2017-01-24 10:06:09 -07009147
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009148 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9149 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009150 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009151 vkDestroyImageView(m_device->device(), image_view, NULL);
9152 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009153 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009154 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009155 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009156 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009157 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009158 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9159}
9160
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009161TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009162 TEST_DESCRIPTION(
9163 "Attempt to update buffer descriptor set that has incorrect "
9164 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9165 "1. offset value greater than buffer size\n"
9166 "2. range value of 0\n"
9167 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009168 VkResult err;
9169
9170 ASSERT_NO_FATAL_FAILURE(InitState());
9171 VkDescriptorPoolSize ds_type_count = {};
9172 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9173 ds_type_count.descriptorCount = 1;
9174
9175 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9176 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9177 ds_pool_ci.pNext = NULL;
9178 ds_pool_ci.maxSets = 1;
9179 ds_pool_ci.poolSizeCount = 1;
9180 ds_pool_ci.pPoolSizes = &ds_type_count;
9181
9182 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009183 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009184 ASSERT_VK_SUCCESS(err);
9185
9186 // Create layout with single uniform buffer descriptor
9187 VkDescriptorSetLayoutBinding dsl_binding = {};
9188 dsl_binding.binding = 0;
9189 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9190 dsl_binding.descriptorCount = 1;
9191 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9192 dsl_binding.pImmutableSamplers = NULL;
9193
9194 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9195 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9196 ds_layout_ci.pNext = NULL;
9197 ds_layout_ci.bindingCount = 1;
9198 ds_layout_ci.pBindings = &dsl_binding;
9199 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009200 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009201 ASSERT_VK_SUCCESS(err);
9202
9203 VkDescriptorSet descriptor_set = {};
9204 VkDescriptorSetAllocateInfo alloc_info = {};
9205 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9206 alloc_info.descriptorSetCount = 1;
9207 alloc_info.descriptorPool = ds_pool;
9208 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009209 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009210 ASSERT_VK_SUCCESS(err);
9211
9212 // Create a buffer to be used for invalid updates
9213 VkBufferCreateInfo buff_ci = {};
9214 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9215 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9216 buff_ci.size = 256;
9217 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9218 VkBuffer buffer;
9219 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9220 ASSERT_VK_SUCCESS(err);
9221 // Have to bind memory to buffer before descriptor update
9222 VkMemoryAllocateInfo mem_alloc = {};
9223 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9224 mem_alloc.pNext = NULL;
9225 mem_alloc.allocationSize = 256;
9226 mem_alloc.memoryTypeIndex = 0;
9227
9228 VkMemoryRequirements mem_reqs;
9229 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009230 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009231 if (!pass) {
9232 vkDestroyBuffer(m_device->device(), buffer, NULL);
9233 return;
9234 }
9235
9236 VkDeviceMemory mem;
9237 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9238 ASSERT_VK_SUCCESS(err);
9239 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9240 ASSERT_VK_SUCCESS(err);
9241
9242 VkDescriptorBufferInfo buff_info = {};
9243 buff_info.buffer = buffer;
9244 // First make offset 1 larger than buffer size
9245 buff_info.offset = 257;
9246 buff_info.range = VK_WHOLE_SIZE;
9247 VkWriteDescriptorSet descriptor_write = {};
9248 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9249 descriptor_write.dstBinding = 0;
9250 descriptor_write.descriptorCount = 1;
9251 descriptor_write.pTexelBufferView = nullptr;
9252 descriptor_write.pBufferInfo = &buff_info;
9253 descriptor_write.pImageInfo = nullptr;
9254
9255 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9256 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009258
9259 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9260
9261 m_errorMonitor->VerifyFound();
9262 // Now cause error due to range of 0
9263 buff_info.offset = 0;
9264 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009266
9267 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9268
9269 m_errorMonitor->VerifyFound();
9270 // Now cause error due to range exceeding buffer size - offset
9271 buff_info.offset = 128;
9272 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009274
9275 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9276
9277 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009278 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009279 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9280 vkDestroyBuffer(m_device->device(), buffer, NULL);
9281 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9282 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9283}
9284
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009285TEST_F(VkLayerTest, DSAspectBitsErrors) {
9286 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9287 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009288 TEST_DESCRIPTION(
9289 "Attempt to update descriptor sets for images "
9290 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009291 VkResult err;
9292
9293 ASSERT_NO_FATAL_FAILURE(InitState());
9294 VkDescriptorPoolSize ds_type_count = {};
9295 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9296 ds_type_count.descriptorCount = 1;
9297
9298 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9299 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9300 ds_pool_ci.pNext = NULL;
9301 ds_pool_ci.maxSets = 5;
9302 ds_pool_ci.poolSizeCount = 1;
9303 ds_pool_ci.pPoolSizes = &ds_type_count;
9304
9305 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009306 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009307 ASSERT_VK_SUCCESS(err);
9308
9309 VkDescriptorSetLayoutBinding dsl_binding = {};
9310 dsl_binding.binding = 0;
9311 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9312 dsl_binding.descriptorCount = 1;
9313 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9314 dsl_binding.pImmutableSamplers = NULL;
9315
9316 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9317 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9318 ds_layout_ci.pNext = NULL;
9319 ds_layout_ci.bindingCount = 1;
9320 ds_layout_ci.pBindings = &dsl_binding;
9321 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009322 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009323 ASSERT_VK_SUCCESS(err);
9324
9325 VkDescriptorSet descriptor_set = {};
9326 VkDescriptorSetAllocateInfo alloc_info = {};
9327 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9328 alloc_info.descriptorSetCount = 1;
9329 alloc_info.descriptorPool = ds_pool;
9330 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009331 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009332 ASSERT_VK_SUCCESS(err);
9333
9334 // Create an image to be used for invalid updates
9335 VkImageCreateInfo image_ci = {};
9336 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9337 image_ci.imageType = VK_IMAGE_TYPE_2D;
9338 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9339 image_ci.extent.width = 64;
9340 image_ci.extent.height = 64;
9341 image_ci.extent.depth = 1;
9342 image_ci.mipLevels = 1;
9343 image_ci.arrayLayers = 1;
9344 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9345 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9346 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9347 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9348 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9349 VkImage image;
9350 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9351 ASSERT_VK_SUCCESS(err);
9352 // Bind memory to image
9353 VkMemoryRequirements mem_reqs;
9354 VkDeviceMemory image_mem;
9355 bool pass;
9356 VkMemoryAllocateInfo mem_alloc = {};
9357 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9358 mem_alloc.pNext = NULL;
9359 mem_alloc.allocationSize = 0;
9360 mem_alloc.memoryTypeIndex = 0;
9361 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9362 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009363 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009364 ASSERT_TRUE(pass);
9365 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9366 ASSERT_VK_SUCCESS(err);
9367 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9368 ASSERT_VK_SUCCESS(err);
9369 // Now create view for image
9370 VkImageViewCreateInfo image_view_ci = {};
9371 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9372 image_view_ci.image = image;
9373 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9374 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9375 image_view_ci.subresourceRange.layerCount = 1;
9376 image_view_ci.subresourceRange.baseArrayLayer = 0;
9377 image_view_ci.subresourceRange.levelCount = 1;
9378 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009379 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009380
9381 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009382 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009383 ASSERT_VK_SUCCESS(err);
9384
9385 VkDescriptorImageInfo img_info = {};
9386 img_info.imageView = image_view;
9387 VkWriteDescriptorSet descriptor_write = {};
9388 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9389 descriptor_write.dstBinding = 0;
9390 descriptor_write.descriptorCount = 1;
9391 descriptor_write.pTexelBufferView = NULL;
9392 descriptor_write.pBufferInfo = NULL;
9393 descriptor_write.pImageInfo = &img_info;
9394 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9395 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009396 const char *error_msg =
9397 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9398 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009400
9401 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9402
9403 m_errorMonitor->VerifyFound();
9404 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9405 vkDestroyImage(m_device->device(), image, NULL);
9406 vkFreeMemory(m_device->device(), image_mem, NULL);
9407 vkDestroyImageView(m_device->device(), image_view, NULL);
9408 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9409 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9410}
9411
Karl Schultz6addd812016-02-02 17:17:23 -07009412TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009413 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009414 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009415
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9417 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9418 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009419
Tobin Ehlis3b780662015-05-28 12:11:26 -06009420 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009421 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009422 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009423 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9424 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009425
9426 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009427 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9428 ds_pool_ci.pNext = NULL;
9429 ds_pool_ci.maxSets = 1;
9430 ds_pool_ci.poolSizeCount = 1;
9431 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009432
Tobin Ehlis3b780662015-05-28 12:11:26 -06009433 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009434 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009435 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009436 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009437 dsl_binding.binding = 0;
9438 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9439 dsl_binding.descriptorCount = 1;
9440 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9441 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009442
Tony Barboureb254902015-07-15 12:50:33 -06009443 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009444 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9445 ds_layout_ci.pNext = NULL;
9446 ds_layout_ci.bindingCount = 1;
9447 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009448
Tobin Ehlis3b780662015-05-28 12:11:26 -06009449 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009450 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009451 ASSERT_VK_SUCCESS(err);
9452
9453 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009454 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009455 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009456 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009457 alloc_info.descriptorPool = ds_pool;
9458 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009459 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009460 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009461
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009462 VkSamplerCreateInfo sampler_ci = {};
9463 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9464 sampler_ci.pNext = NULL;
9465 sampler_ci.magFilter = VK_FILTER_NEAREST;
9466 sampler_ci.minFilter = VK_FILTER_NEAREST;
9467 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9468 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9469 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9470 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9471 sampler_ci.mipLodBias = 1.0;
9472 sampler_ci.anisotropyEnable = VK_FALSE;
9473 sampler_ci.maxAnisotropy = 1;
9474 sampler_ci.compareEnable = VK_FALSE;
9475 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9476 sampler_ci.minLod = 1.0;
9477 sampler_ci.maxLod = 1.0;
9478 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9479 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9480 VkSampler sampler;
9481 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9482 ASSERT_VK_SUCCESS(err);
9483
9484 VkDescriptorImageInfo info = {};
9485 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009486
9487 VkWriteDescriptorSet descriptor_write;
9488 memset(&descriptor_write, 0, sizeof(descriptor_write));
9489 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009490 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009491 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009492 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009493 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009494 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009495
9496 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9497
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009498 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009499
Chia-I Wuf7458c52015-10-26 21:10:41 +08009500 vkDestroySampler(m_device->device(), sampler, NULL);
9501 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9502 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009503}
9504
Karl Schultz6addd812016-02-02 17:17:23 -07009505TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009506 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009507 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009508
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009510
Tobin Ehlis3b780662015-05-28 12:11:26 -06009511 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009512 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009513 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009514 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9515 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009516
9517 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009518 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9519 ds_pool_ci.pNext = NULL;
9520 ds_pool_ci.maxSets = 1;
9521 ds_pool_ci.poolSizeCount = 1;
9522 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009523
Tobin Ehlis3b780662015-05-28 12:11:26 -06009524 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009525 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009526 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009527
Tony Barboureb254902015-07-15 12:50:33 -06009528 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009529 dsl_binding.binding = 0;
9530 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9531 dsl_binding.descriptorCount = 1;
9532 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9533 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009534
9535 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009536 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9537 ds_layout_ci.pNext = NULL;
9538 ds_layout_ci.bindingCount = 1;
9539 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009540
Tobin Ehlis3b780662015-05-28 12:11:26 -06009541 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009542 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009543 ASSERT_VK_SUCCESS(err);
9544
9545 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009546 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009547 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009548 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009549 alloc_info.descriptorPool = ds_pool;
9550 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009551 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009552 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009553
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009554 // Correctly update descriptor to avoid "NOT_UPDATED" error
9555 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009556 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009557 buff_info.offset = 0;
9558 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009559
9560 VkWriteDescriptorSet descriptor_write;
9561 memset(&descriptor_write, 0, sizeof(descriptor_write));
9562 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009563 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009564 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009565 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009566 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9567 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009568
9569 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9570
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009571 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009572
Chia-I Wuf7458c52015-10-26 21:10:41 +08009573 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9574 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009575}
9576
Karl Schultz6addd812016-02-02 17:17:23 -07009577TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009578 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009579 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009580
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009582
Tobin Ehlis3b780662015-05-28 12:11:26 -06009583 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009584 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009585 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009586 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9587 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009588
9589 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009590 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9591 ds_pool_ci.pNext = NULL;
9592 ds_pool_ci.maxSets = 1;
9593 ds_pool_ci.poolSizeCount = 1;
9594 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009595
Tobin Ehlis3b780662015-05-28 12:11:26 -06009596 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009597 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009598 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009599
Tony Barboureb254902015-07-15 12:50:33 -06009600 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009601 dsl_binding.binding = 0;
9602 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9603 dsl_binding.descriptorCount = 1;
9604 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9605 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009606
9607 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009608 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9609 ds_layout_ci.pNext = NULL;
9610 ds_layout_ci.bindingCount = 1;
9611 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009612 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009613 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009614 ASSERT_VK_SUCCESS(err);
9615
9616 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009617 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009618 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009619 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009620 alloc_info.descriptorPool = ds_pool;
9621 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009622 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009623 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009624
Tony Barboureb254902015-07-15 12:50:33 -06009625 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009626 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9627 sampler_ci.pNext = NULL;
9628 sampler_ci.magFilter = VK_FILTER_NEAREST;
9629 sampler_ci.minFilter = VK_FILTER_NEAREST;
9630 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9631 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9632 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9633 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9634 sampler_ci.mipLodBias = 1.0;
9635 sampler_ci.anisotropyEnable = VK_FALSE;
9636 sampler_ci.maxAnisotropy = 1;
9637 sampler_ci.compareEnable = VK_FALSE;
9638 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9639 sampler_ci.minLod = 1.0;
9640 sampler_ci.maxLod = 1.0;
9641 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9642 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009643
Tobin Ehlis3b780662015-05-28 12:11:26 -06009644 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009645 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009646 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009647
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009648 VkDescriptorImageInfo info = {};
9649 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009650
9651 VkWriteDescriptorSet descriptor_write;
9652 memset(&descriptor_write, 0, sizeof(descriptor_write));
9653 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009654 descriptor_write.dstSet = descriptorSet;
9655 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009656 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009657 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009658 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009659 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009660
9661 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9662
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009663 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009664
Chia-I Wuf7458c52015-10-26 21:10:41 +08009665 vkDestroySampler(m_device->device(), sampler, NULL);
9666 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9667 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009668}
9669
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009670TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9671 // Create layout w/ empty binding and attempt to update it
9672 VkResult err;
9673
9674 ASSERT_NO_FATAL_FAILURE(InitState());
9675
9676 VkDescriptorPoolSize ds_type_count = {};
9677 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9678 ds_type_count.descriptorCount = 1;
9679
9680 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9681 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9682 ds_pool_ci.pNext = NULL;
9683 ds_pool_ci.maxSets = 1;
9684 ds_pool_ci.poolSizeCount = 1;
9685 ds_pool_ci.pPoolSizes = &ds_type_count;
9686
9687 VkDescriptorPool ds_pool;
9688 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9689 ASSERT_VK_SUCCESS(err);
9690
9691 VkDescriptorSetLayoutBinding dsl_binding = {};
9692 dsl_binding.binding = 0;
9693 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9694 dsl_binding.descriptorCount = 0;
9695 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9696 dsl_binding.pImmutableSamplers = NULL;
9697
9698 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9699 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9700 ds_layout_ci.pNext = NULL;
9701 ds_layout_ci.bindingCount = 1;
9702 ds_layout_ci.pBindings = &dsl_binding;
9703 VkDescriptorSetLayout ds_layout;
9704 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9705 ASSERT_VK_SUCCESS(err);
9706
9707 VkDescriptorSet descriptor_set;
9708 VkDescriptorSetAllocateInfo alloc_info = {};
9709 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9710 alloc_info.descriptorSetCount = 1;
9711 alloc_info.descriptorPool = ds_pool;
9712 alloc_info.pSetLayouts = &ds_layout;
9713 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9714 ASSERT_VK_SUCCESS(err);
9715
9716 VkSamplerCreateInfo sampler_ci = {};
9717 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9718 sampler_ci.magFilter = VK_FILTER_NEAREST;
9719 sampler_ci.minFilter = VK_FILTER_NEAREST;
9720 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9721 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9722 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9723 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9724 sampler_ci.mipLodBias = 1.0;
9725 sampler_ci.maxAnisotropy = 1;
9726 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9727 sampler_ci.minLod = 1.0;
9728 sampler_ci.maxLod = 1.0;
9729 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9730
9731 VkSampler sampler;
9732 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9733 ASSERT_VK_SUCCESS(err);
9734
9735 VkDescriptorImageInfo info = {};
9736 info.sampler = sampler;
9737
9738 VkWriteDescriptorSet descriptor_write;
9739 memset(&descriptor_write, 0, sizeof(descriptor_write));
9740 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9741 descriptor_write.dstSet = descriptor_set;
9742 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009743 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009744 // This is the wrong type, but empty binding error will be flagged first
9745 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9746 descriptor_write.pImageInfo = &info;
9747
9748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9749 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9750 m_errorMonitor->VerifyFound();
9751
9752 vkDestroySampler(m_device->device(), sampler, NULL);
9753 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9754 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9755}
9756
Karl Schultz6addd812016-02-02 17:17:23 -07009757TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9758 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9759 // types
9760 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009761
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009762 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 -06009763
Tobin Ehlis3b780662015-05-28 12:11:26 -06009764 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009765
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009766 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009767 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9768 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009769
9770 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009771 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9772 ds_pool_ci.pNext = NULL;
9773 ds_pool_ci.maxSets = 1;
9774 ds_pool_ci.poolSizeCount = 1;
9775 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009776
Tobin Ehlis3b780662015-05-28 12:11:26 -06009777 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009778 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009779 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009780 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009781 dsl_binding.binding = 0;
9782 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9783 dsl_binding.descriptorCount = 1;
9784 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9785 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009786
Tony Barboureb254902015-07-15 12:50:33 -06009787 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009788 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9789 ds_layout_ci.pNext = NULL;
9790 ds_layout_ci.bindingCount = 1;
9791 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009792
Tobin Ehlis3b780662015-05-28 12:11:26 -06009793 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009794 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009795 ASSERT_VK_SUCCESS(err);
9796
9797 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009798 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009799 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009800 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009801 alloc_info.descriptorPool = ds_pool;
9802 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009803 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009804 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009805
Tony Barboureb254902015-07-15 12:50:33 -06009806 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009807 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9808 sampler_ci.pNext = NULL;
9809 sampler_ci.magFilter = VK_FILTER_NEAREST;
9810 sampler_ci.minFilter = VK_FILTER_NEAREST;
9811 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9812 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9813 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9814 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9815 sampler_ci.mipLodBias = 1.0;
9816 sampler_ci.anisotropyEnable = VK_FALSE;
9817 sampler_ci.maxAnisotropy = 1;
9818 sampler_ci.compareEnable = VK_FALSE;
9819 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9820 sampler_ci.minLod = 1.0;
9821 sampler_ci.maxLod = 1.0;
9822 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9823 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009824 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009825 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009826 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009827
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009828 VkDescriptorImageInfo info = {};
9829 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009830
9831 VkWriteDescriptorSet descriptor_write;
9832 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009833 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009834 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009835 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009836 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009837 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009838 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009839
9840 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9841
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009842 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009843
Chia-I Wuf7458c52015-10-26 21:10:41 +08009844 vkDestroySampler(m_device->device(), sampler, NULL);
9845 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9846 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009847}
9848
Karl Schultz6addd812016-02-02 17:17:23 -07009849TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009850 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009851 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009852
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009854
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009855 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009856 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9857 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009858 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009859 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9860 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009861
9862 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009863 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9864 ds_pool_ci.pNext = NULL;
9865 ds_pool_ci.maxSets = 1;
9866 ds_pool_ci.poolSizeCount = 1;
9867 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009868
9869 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009870 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009871 ASSERT_VK_SUCCESS(err);
9872
9873 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009874 dsl_binding.binding = 0;
9875 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9876 dsl_binding.descriptorCount = 1;
9877 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9878 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009879
9880 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009881 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9882 ds_layout_ci.pNext = NULL;
9883 ds_layout_ci.bindingCount = 1;
9884 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009885 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009886 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009887 ASSERT_VK_SUCCESS(err);
9888
9889 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009890 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009891 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009892 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009893 alloc_info.descriptorPool = ds_pool;
9894 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009896 ASSERT_VK_SUCCESS(err);
9897
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009898 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009899
9900 VkDescriptorImageInfo descriptor_info;
9901 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9902 descriptor_info.sampler = sampler;
9903
9904 VkWriteDescriptorSet descriptor_write;
9905 memset(&descriptor_write, 0, sizeof(descriptor_write));
9906 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009907 descriptor_write.dstSet = descriptorSet;
9908 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009909 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009910 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9911 descriptor_write.pImageInfo = &descriptor_info;
9912
9913 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9914
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009915 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009916
Chia-I Wuf7458c52015-10-26 21:10:41 +08009917 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9918 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009919}
9920
Karl Schultz6addd812016-02-02 17:17:23 -07009921TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9922 // Create a single combined Image/Sampler descriptor and send it an invalid
9923 // imageView
9924 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009925
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009927
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009928 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009929 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009930 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9931 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009932
9933 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009934 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9935 ds_pool_ci.pNext = NULL;
9936 ds_pool_ci.maxSets = 1;
9937 ds_pool_ci.poolSizeCount = 1;
9938 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009939
9940 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009941 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009942 ASSERT_VK_SUCCESS(err);
9943
9944 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009945 dsl_binding.binding = 0;
9946 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9947 dsl_binding.descriptorCount = 1;
9948 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9949 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009950
9951 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009952 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9953 ds_layout_ci.pNext = NULL;
9954 ds_layout_ci.bindingCount = 1;
9955 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009956 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009957 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009958 ASSERT_VK_SUCCESS(err);
9959
9960 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009961 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009962 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009963 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009964 alloc_info.descriptorPool = ds_pool;
9965 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009966 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009967 ASSERT_VK_SUCCESS(err);
9968
9969 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009970 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9971 sampler_ci.pNext = NULL;
9972 sampler_ci.magFilter = VK_FILTER_NEAREST;
9973 sampler_ci.minFilter = VK_FILTER_NEAREST;
9974 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9975 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9976 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9977 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9978 sampler_ci.mipLodBias = 1.0;
9979 sampler_ci.anisotropyEnable = VK_FALSE;
9980 sampler_ci.maxAnisotropy = 1;
9981 sampler_ci.compareEnable = VK_FALSE;
9982 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9983 sampler_ci.minLod = 1.0;
9984 sampler_ci.maxLod = 1.0;
9985 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9986 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009987
9988 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009989 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009990 ASSERT_VK_SUCCESS(err);
9991
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009992 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009993
9994 VkDescriptorImageInfo descriptor_info;
9995 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9996 descriptor_info.sampler = sampler;
9997 descriptor_info.imageView = view;
9998
9999 VkWriteDescriptorSet descriptor_write;
10000 memset(&descriptor_write, 0, sizeof(descriptor_write));
10001 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010002 descriptor_write.dstSet = descriptorSet;
10003 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010004 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010005 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10006 descriptor_write.pImageInfo = &descriptor_info;
10007
10008 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10009
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010010 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010011
Chia-I Wuf7458c52015-10-26 21:10:41 +080010012 vkDestroySampler(m_device->device(), sampler, NULL);
10013 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10014 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010015}
10016
Karl Schultz6addd812016-02-02 17:17:23 -070010017TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10018 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10019 // into the other
10020 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010021
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10023 " binding #1 with type "
10024 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10025 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010026
Tobin Ehlis04356f92015-10-27 16:35:27 -060010027 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010028 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010029 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010030 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10031 ds_type_count[0].descriptorCount = 1;
10032 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10033 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010034
10035 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010036 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10037 ds_pool_ci.pNext = NULL;
10038 ds_pool_ci.maxSets = 1;
10039 ds_pool_ci.poolSizeCount = 2;
10040 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010041
10042 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010043 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010044 ASSERT_VK_SUCCESS(err);
10045 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010046 dsl_binding[0].binding = 0;
10047 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10048 dsl_binding[0].descriptorCount = 1;
10049 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10050 dsl_binding[0].pImmutableSamplers = NULL;
10051 dsl_binding[1].binding = 1;
10052 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10053 dsl_binding[1].descriptorCount = 1;
10054 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10055 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010056
10057 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010058 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10059 ds_layout_ci.pNext = NULL;
10060 ds_layout_ci.bindingCount = 2;
10061 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010062
10063 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010064 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010065 ASSERT_VK_SUCCESS(err);
10066
10067 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010068 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010069 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010070 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010071 alloc_info.descriptorPool = ds_pool;
10072 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010073 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010074 ASSERT_VK_SUCCESS(err);
10075
10076 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010077 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10078 sampler_ci.pNext = NULL;
10079 sampler_ci.magFilter = VK_FILTER_NEAREST;
10080 sampler_ci.minFilter = VK_FILTER_NEAREST;
10081 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10082 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10083 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10084 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10085 sampler_ci.mipLodBias = 1.0;
10086 sampler_ci.anisotropyEnable = VK_FALSE;
10087 sampler_ci.maxAnisotropy = 1;
10088 sampler_ci.compareEnable = VK_FALSE;
10089 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10090 sampler_ci.minLod = 1.0;
10091 sampler_ci.maxLod = 1.0;
10092 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10093 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010094
10095 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010096 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010097 ASSERT_VK_SUCCESS(err);
10098
10099 VkDescriptorImageInfo info = {};
10100 info.sampler = sampler;
10101
10102 VkWriteDescriptorSet descriptor_write;
10103 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10104 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010105 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010106 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010107 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010108 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10109 descriptor_write.pImageInfo = &info;
10110 // This write update should succeed
10111 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10112 // Now perform a copy update that fails due to type mismatch
10113 VkCopyDescriptorSet copy_ds_update;
10114 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10115 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10116 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010117 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010118 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010119 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10120 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010121 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10122
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010123 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010124 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010125 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 -060010126 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10127 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10128 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010129 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010130 copy_ds_update.dstSet = descriptorSet;
10131 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010132 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010133 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10134
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010135 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010136
Tobin Ehlis04356f92015-10-27 16:35:27 -060010137 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10139 " binding#1 with offset index of 1 plus "
10140 "update array offset of 0 and update of "
10141 "5 descriptors oversteps total number "
10142 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010143
Tobin Ehlis04356f92015-10-27 16:35:27 -060010144 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10145 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10146 copy_ds_update.srcSet = descriptorSet;
10147 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010148 copy_ds_update.dstSet = descriptorSet;
10149 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010150 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010151 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10152
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010153 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010154
Chia-I Wuf7458c52015-10-26 21:10:41 +080010155 vkDestroySampler(m_device->device(), sampler, NULL);
10156 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10157 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010158}
10159
Karl Schultz6addd812016-02-02 17:17:23 -070010160TEST_F(VkLayerTest, NumSamplesMismatch) {
10161 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10162 // sampleCount
10163 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010164
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010166
Tobin Ehlis3b780662015-05-28 12:11:26 -060010167 ASSERT_NO_FATAL_FAILURE(InitState());
10168 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010169 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010170 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010171 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010172
10173 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010174 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10175 ds_pool_ci.pNext = NULL;
10176 ds_pool_ci.maxSets = 1;
10177 ds_pool_ci.poolSizeCount = 1;
10178 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010179
Tobin Ehlis3b780662015-05-28 12:11:26 -060010180 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010181 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010182 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010183
Tony Barboureb254902015-07-15 12:50:33 -060010184 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010185 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010186 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010187 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010188 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10189 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010190
Tony Barboureb254902015-07-15 12:50:33 -060010191 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10192 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10193 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010194 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010195 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010196
Tobin Ehlis3b780662015-05-28 12:11:26 -060010197 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010199 ASSERT_VK_SUCCESS(err);
10200
10201 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010202 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010203 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010204 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010205 alloc_info.descriptorPool = ds_pool;
10206 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010207 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010208 ASSERT_VK_SUCCESS(err);
10209
Tony Barboureb254902015-07-15 12:50:33 -060010210 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010211 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010212 pipe_ms_state_ci.pNext = NULL;
10213 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10214 pipe_ms_state_ci.sampleShadingEnable = 0;
10215 pipe_ms_state_ci.minSampleShading = 1.0;
10216 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010217
Tony Barboureb254902015-07-15 12:50:33 -060010218 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010219 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10220 pipeline_layout_ci.pNext = NULL;
10221 pipeline_layout_ci.setLayoutCount = 1;
10222 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010223
10224 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010225 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010226 ASSERT_VK_SUCCESS(err);
10227
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010228 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010229 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 -060010230 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010231 VkPipelineObj pipe(m_device);
10232 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010233 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010234 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010235 pipe.SetMSAA(&pipe_ms_state_ci);
10236 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010237
Tony Barbour552f6c02016-12-21 14:34:07 -070010238 m_commandBuffer->BeginCommandBuffer();
10239 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010240 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010241
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010242 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10243 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10244 VkRect2D scissor = {{0, 0}, {16, 16}};
10245 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10246
Mark Young29927482016-05-04 14:38:51 -060010247 // Render triangle (the error should trigger on the attempt to draw).
10248 Draw(3, 1, 0, 0);
10249
10250 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010251 m_commandBuffer->EndRenderPass();
10252 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010253
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010254 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010255
Chia-I Wuf7458c52015-10-26 21:10:41 +080010256 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10257 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10258 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010259}
Mark Young29927482016-05-04 14:38:51 -060010260
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010261TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010262 TEST_DESCRIPTION(
10263 "Hit RenderPass incompatible cases. "
10264 "Initial case is drawing with an active renderpass that's "
10265 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010266 VkResult err;
10267
10268 ASSERT_NO_FATAL_FAILURE(InitState());
10269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10270
10271 VkDescriptorSetLayoutBinding dsl_binding = {};
10272 dsl_binding.binding = 0;
10273 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10274 dsl_binding.descriptorCount = 1;
10275 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10276 dsl_binding.pImmutableSamplers = NULL;
10277
10278 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10279 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10280 ds_layout_ci.pNext = NULL;
10281 ds_layout_ci.bindingCount = 1;
10282 ds_layout_ci.pBindings = &dsl_binding;
10283
10284 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010285 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010286 ASSERT_VK_SUCCESS(err);
10287
10288 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10289 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10290 pipeline_layout_ci.pNext = NULL;
10291 pipeline_layout_ci.setLayoutCount = 1;
10292 pipeline_layout_ci.pSetLayouts = &ds_layout;
10293
10294 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010295 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010296 ASSERT_VK_SUCCESS(err);
10297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010298 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010299 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 -060010300 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010301 // Create a renderpass that will be incompatible with default renderpass
10302 VkAttachmentReference attach = {};
10303 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10304 VkAttachmentReference color_att = {};
10305 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10306 VkSubpassDescription subpass = {};
10307 subpass.inputAttachmentCount = 1;
10308 subpass.pInputAttachments = &attach;
10309 subpass.colorAttachmentCount = 1;
10310 subpass.pColorAttachments = &color_att;
10311 VkRenderPassCreateInfo rpci = {};
10312 rpci.subpassCount = 1;
10313 rpci.pSubpasses = &subpass;
10314 rpci.attachmentCount = 1;
10315 VkAttachmentDescription attach_desc = {};
10316 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010317 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10318 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010319 rpci.pAttachments = &attach_desc;
10320 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10321 VkRenderPass rp;
10322 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10323 VkPipelineObj pipe(m_device);
10324 pipe.AddShader(&vs);
10325 pipe.AddShader(&fs);
10326 pipe.AddColorAttachment();
10327 VkViewport view_port = {};
10328 m_viewports.push_back(view_port);
10329 pipe.SetViewport(m_viewports);
10330 VkRect2D rect = {};
10331 m_scissors.push_back(rect);
10332 pipe.SetScissor(m_scissors);
10333 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10334
10335 VkCommandBufferInheritanceInfo cbii = {};
10336 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10337 cbii.renderPass = rp;
10338 cbii.subpass = 0;
10339 VkCommandBufferBeginInfo cbbi = {};
10340 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10341 cbbi.pInheritanceInfo = &cbii;
10342 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10343 VkRenderPassBeginInfo rpbi = {};
10344 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10345 rpbi.framebuffer = m_framebuffer;
10346 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010347 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10348 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010351 // Render triangle (the error should trigger on the attempt to draw).
10352 Draw(3, 1, 0, 0);
10353
10354 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010355 m_commandBuffer->EndRenderPass();
10356 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010357
10358 m_errorMonitor->VerifyFound();
10359
10360 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10361 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10362 vkDestroyRenderPass(m_device->device(), rp, NULL);
10363}
10364
Mark Youngc89c6312016-03-31 16:03:20 -060010365TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10366 // Create Pipeline where the number of blend attachments doesn't match the
10367 // number of color attachments. In this case, we don't add any color
10368 // blend attachments even though we have a color attachment.
10369 VkResult err;
10370
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010372
10373 ASSERT_NO_FATAL_FAILURE(InitState());
10374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10375 VkDescriptorPoolSize ds_type_count = {};
10376 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10377 ds_type_count.descriptorCount = 1;
10378
10379 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10380 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10381 ds_pool_ci.pNext = NULL;
10382 ds_pool_ci.maxSets = 1;
10383 ds_pool_ci.poolSizeCount = 1;
10384 ds_pool_ci.pPoolSizes = &ds_type_count;
10385
10386 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010387 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010388 ASSERT_VK_SUCCESS(err);
10389
10390 VkDescriptorSetLayoutBinding dsl_binding = {};
10391 dsl_binding.binding = 0;
10392 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10393 dsl_binding.descriptorCount = 1;
10394 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10395 dsl_binding.pImmutableSamplers = NULL;
10396
10397 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10398 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10399 ds_layout_ci.pNext = NULL;
10400 ds_layout_ci.bindingCount = 1;
10401 ds_layout_ci.pBindings = &dsl_binding;
10402
10403 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010404 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010405 ASSERT_VK_SUCCESS(err);
10406
10407 VkDescriptorSet descriptorSet;
10408 VkDescriptorSetAllocateInfo alloc_info = {};
10409 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10410 alloc_info.descriptorSetCount = 1;
10411 alloc_info.descriptorPool = ds_pool;
10412 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010413 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010414 ASSERT_VK_SUCCESS(err);
10415
10416 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010417 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010418 pipe_ms_state_ci.pNext = NULL;
10419 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10420 pipe_ms_state_ci.sampleShadingEnable = 0;
10421 pipe_ms_state_ci.minSampleShading = 1.0;
10422 pipe_ms_state_ci.pSampleMask = NULL;
10423
10424 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10425 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10426 pipeline_layout_ci.pNext = NULL;
10427 pipeline_layout_ci.setLayoutCount = 1;
10428 pipeline_layout_ci.pSetLayouts = &ds_layout;
10429
10430 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010431 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010432 ASSERT_VK_SUCCESS(err);
10433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010434 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010435 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 -060010436 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010437 VkPipelineObj pipe(m_device);
10438 pipe.AddShader(&vs);
10439 pipe.AddShader(&fs);
10440 pipe.SetMSAA(&pipe_ms_state_ci);
10441 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010442 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010443
10444 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10445 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10446 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10447}
Mark Young29927482016-05-04 14:38:51 -060010448
Mark Muellerd4914412016-06-13 17:52:06 -060010449TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010450 TEST_DESCRIPTION(
10451 "Points to a wrong colorAttachment index in a VkClearAttachment "
10452 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010453 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010455
10456 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10457 m_errorMonitor->VerifyFound();
10458}
10459
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010460TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010461 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10462 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010463
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010464 ASSERT_NO_FATAL_FAILURE(InitState());
10465 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010466
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010467 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010468 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10469 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010470
10471 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010472 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10473 ds_pool_ci.pNext = NULL;
10474 ds_pool_ci.maxSets = 1;
10475 ds_pool_ci.poolSizeCount = 1;
10476 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010477
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010478 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010479 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010480 ASSERT_VK_SUCCESS(err);
10481
Tony Barboureb254902015-07-15 12:50:33 -060010482 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010483 dsl_binding.binding = 0;
10484 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10485 dsl_binding.descriptorCount = 1;
10486 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10487 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010488
Tony Barboureb254902015-07-15 12:50:33 -060010489 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010490 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10491 ds_layout_ci.pNext = NULL;
10492 ds_layout_ci.bindingCount = 1;
10493 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010494
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010495 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010496 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010497 ASSERT_VK_SUCCESS(err);
10498
10499 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010500 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010501 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010502 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010503 alloc_info.descriptorPool = ds_pool;
10504 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010505 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010506 ASSERT_VK_SUCCESS(err);
10507
Tony Barboureb254902015-07-15 12:50:33 -060010508 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010509 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010510 pipe_ms_state_ci.pNext = NULL;
10511 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10512 pipe_ms_state_ci.sampleShadingEnable = 0;
10513 pipe_ms_state_ci.minSampleShading = 1.0;
10514 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010515
Tony Barboureb254902015-07-15 12:50:33 -060010516 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010517 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10518 pipeline_layout_ci.pNext = NULL;
10519 pipeline_layout_ci.setLayoutCount = 1;
10520 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010521
10522 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010523 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010524 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010525
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010526 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010527 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010528 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010529 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010530
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010531 VkPipelineObj pipe(m_device);
10532 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010533 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010534 pipe.SetMSAA(&pipe_ms_state_ci);
10535 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010536
Tony Barbour552f6c02016-12-21 14:34:07 -070010537 m_commandBuffer->BeginCommandBuffer();
10538 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010539
Karl Schultz6addd812016-02-02 17:17:23 -070010540 // Main thing we care about for this test is that the VkImage obj we're
10541 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010542 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010543 VkClearAttachment color_attachment;
10544 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10545 color_attachment.clearValue.color.float32[0] = 1.0;
10546 color_attachment.clearValue.color.float32[1] = 1.0;
10547 color_attachment.clearValue.color.float32[2] = 1.0;
10548 color_attachment.clearValue.color.float32[3] = 1.0;
10549 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010550 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010551
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010552 // Call for full-sized FB Color attachment prior to issuing a Draw
10553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070010554 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010555 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010556 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010557
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010558 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
10559 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
10560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
10561 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
10562 m_errorMonitor->VerifyFound();
10563
10564 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
10565 clear_rect.layerCount = 2;
10566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
10567 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010568 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010569
Chia-I Wuf7458c52015-10-26 21:10:41 +080010570 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10571 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10572 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010573}
10574
Karl Schultz6addd812016-02-02 17:17:23 -070010575TEST_F(VkLayerTest, VtxBufferBadIndex) {
10576 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010577
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10579 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010580
Tobin Ehlis502480b2015-06-24 15:53:07 -060010581 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010582 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010583 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010584
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010585 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010586 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10587 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010588
10589 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010590 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10591 ds_pool_ci.pNext = NULL;
10592 ds_pool_ci.maxSets = 1;
10593 ds_pool_ci.poolSizeCount = 1;
10594 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010595
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010596 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010597 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010598 ASSERT_VK_SUCCESS(err);
10599
Tony Barboureb254902015-07-15 12:50:33 -060010600 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010601 dsl_binding.binding = 0;
10602 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10603 dsl_binding.descriptorCount = 1;
10604 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10605 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010606
Tony Barboureb254902015-07-15 12:50:33 -060010607 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010608 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10609 ds_layout_ci.pNext = NULL;
10610 ds_layout_ci.bindingCount = 1;
10611 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010612
Tobin Ehlis502480b2015-06-24 15:53:07 -060010613 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010614 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010615 ASSERT_VK_SUCCESS(err);
10616
10617 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010618 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010619 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010620 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010621 alloc_info.descriptorPool = ds_pool;
10622 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010623 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010624 ASSERT_VK_SUCCESS(err);
10625
Tony Barboureb254902015-07-15 12:50:33 -060010626 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010627 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010628 pipe_ms_state_ci.pNext = NULL;
10629 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10630 pipe_ms_state_ci.sampleShadingEnable = 0;
10631 pipe_ms_state_ci.minSampleShading = 1.0;
10632 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010633
Tony Barboureb254902015-07-15 12:50:33 -060010634 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010635 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10636 pipeline_layout_ci.pNext = NULL;
10637 pipeline_layout_ci.setLayoutCount = 1;
10638 pipeline_layout_ci.pSetLayouts = &ds_layout;
10639 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010640
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010641 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010642 ASSERT_VK_SUCCESS(err);
10643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010644 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010645 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 -060010646 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010647 VkPipelineObj pipe(m_device);
10648 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010649 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010650 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010651 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010652 pipe.SetViewport(m_viewports);
10653 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010654 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010655
Tony Barbour552f6c02016-12-21 14:34:07 -070010656 m_commandBuffer->BeginCommandBuffer();
10657 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010658 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010659 // Don't care about actual data, just need to get to draw to flag error
10660 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010661 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010662 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010663 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010664
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010665 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010666
Chia-I Wuf7458c52015-10-26 21:10:41 +080010667 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10668 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10669 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010670}
Mark Muellerdfe37552016-07-07 14:47:42 -060010671
Mark Mueller2ee294f2016-08-04 12:59:48 -060010672TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010673 TEST_DESCRIPTION(
10674 "Use an invalid count in a vkEnumeratePhysicalDevices call."
10675 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010676 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010677
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010678 const char *invalid_queueFamilyIndex_message =
10679 "Invalid queue create request in vkCreateDevice(). Invalid "
10680 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010681
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010682 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010683
Mark Mueller880fce52016-08-17 15:23:23 -060010684 // The following test fails with recent NVidia drivers.
10685 // By the time core_validation is reached, the NVidia
10686 // driver has sanitized the invalid condition and core_validation
10687 // is not introduced to the failure condition. This is not the case
10688 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010689 // uint32_t count = static_cast<uint32_t>(~0);
10690 // VkPhysicalDevice physical_device;
10691 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10692 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010693
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010695 float queue_priority = 0.0;
10696
10697 VkDeviceQueueCreateInfo queue_create_info = {};
10698 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10699 queue_create_info.queueCount = 1;
10700 queue_create_info.pQueuePriorities = &queue_priority;
10701 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10702
10703 VkPhysicalDeviceFeatures features = m_device->phy().features();
10704 VkDevice testDevice;
10705 VkDeviceCreateInfo device_create_info = {};
10706 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10707 device_create_info.queueCreateInfoCount = 1;
10708 device_create_info.pQueueCreateInfos = &queue_create_info;
10709 device_create_info.pEnabledFeatures = &features;
10710 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10711 m_errorMonitor->VerifyFound();
10712
10713 queue_create_info.queueFamilyIndex = 1;
10714
10715 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10716 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10717 for (unsigned i = 0; i < feature_count; i++) {
10718 if (VK_FALSE == feature_array[i]) {
10719 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010721 device_create_info.pEnabledFeatures = &features;
10722 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10723 m_errorMonitor->VerifyFound();
10724 break;
10725 }
10726 }
10727}
10728
Tobin Ehlis16edf082016-11-21 12:33:49 -070010729TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10730 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10731
10732 ASSERT_NO_FATAL_FAILURE(InitState());
10733
10734 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10735 std::vector<VkDeviceQueueCreateInfo> queue_info;
10736 queue_info.reserve(queue_props.size());
10737 std::vector<std::vector<float>> queue_priorities;
10738 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10739 VkDeviceQueueCreateInfo qi{};
10740 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10741 qi.queueFamilyIndex = i;
10742 qi.queueCount = queue_props[i].queueCount;
10743 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10744 qi.pQueuePriorities = queue_priorities[i].data();
10745 queue_info.push_back(qi);
10746 }
10747
10748 std::vector<const char *> device_extension_names;
10749
10750 VkDevice local_device;
10751 VkDeviceCreateInfo device_create_info = {};
10752 auto features = m_device->phy().features();
10753 // Intentionally disable pipeline stats
10754 features.pipelineStatisticsQuery = VK_FALSE;
10755 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10756 device_create_info.pNext = NULL;
10757 device_create_info.queueCreateInfoCount = queue_info.size();
10758 device_create_info.pQueueCreateInfos = queue_info.data();
10759 device_create_info.enabledLayerCount = 0;
10760 device_create_info.ppEnabledLayerNames = NULL;
10761 device_create_info.pEnabledFeatures = &features;
10762 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10763 ASSERT_VK_SUCCESS(err);
10764
10765 VkQueryPoolCreateInfo qpci{};
10766 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10767 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10768 qpci.queryCount = 1;
10769 VkQueryPool query_pool;
10770
10771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10772 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10773 m_errorMonitor->VerifyFound();
10774
10775 vkDestroyDevice(local_device, nullptr);
10776}
10777
Mark Mueller2ee294f2016-08-04 12:59:48 -060010778TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010779 TEST_DESCRIPTION(
10780 "Use an invalid queue index in a vkCmdWaitEvents call."
10781 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060010782
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010783 const char *invalid_queue_index =
10784 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10785 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10786 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010788 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010789
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010791
10792 ASSERT_NO_FATAL_FAILURE(InitState());
10793
10794 VkEvent event;
10795 VkEventCreateInfo event_create_info{};
10796 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10797 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10798
Mark Mueller2ee294f2016-08-04 12:59:48 -060010799 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010800 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010801
Tony Barbour552f6c02016-12-21 14:34:07 -070010802 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010803
10804 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010805 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010806 ASSERT_TRUE(image.initialized());
10807 VkImageMemoryBarrier img_barrier = {};
10808 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10809 img_barrier.pNext = NULL;
10810 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10811 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10812 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10813 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10814 img_barrier.image = image.handle();
10815 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010816
10817 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10818 // that layer validation catches the case when it is not.
10819 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010820 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10821 img_barrier.subresourceRange.baseArrayLayer = 0;
10822 img_barrier.subresourceRange.baseMipLevel = 0;
10823 img_barrier.subresourceRange.layerCount = 1;
10824 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010825 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10826 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010827 m_errorMonitor->VerifyFound();
10828
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010830
10831 VkQueryPool query_pool;
10832 VkQueryPoolCreateInfo query_pool_create_info = {};
10833 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10834 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10835 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010836 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010838 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010839 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10840
10841 vkEndCommandBuffer(m_commandBuffer->handle());
10842 m_errorMonitor->VerifyFound();
10843
10844 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10845 vkDestroyEvent(m_device->device(), event, nullptr);
10846}
10847
Mark Muellerdfe37552016-07-07 14:47:42 -060010848TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010849 TEST_DESCRIPTION(
10850 "Submit a command buffer using deleted vertex buffer, "
10851 "delete a buffer twice, use an invalid offset for each "
10852 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060010853
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010854 const char *deleted_buffer_in_command_buffer =
10855 "Cannot submit cmd buffer "
10856 "using deleted buffer ";
10857 const char *invalid_offset_message =
10858 "vkBindBufferMemory(): "
10859 "memoryOffset is 0x";
10860 const char *invalid_storage_buffer_offset_message =
10861 "vkBindBufferMemory(): "
10862 "storage memoryOffset "
10863 "is 0x";
10864 const char *invalid_texel_buffer_offset_message =
10865 "vkBindBufferMemory(): "
10866 "texel memoryOffset "
10867 "is 0x";
10868 const char *invalid_uniform_buffer_offset_message =
10869 "vkBindBufferMemory(): "
10870 "uniform memoryOffset "
10871 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010872
10873 ASSERT_NO_FATAL_FAILURE(InitState());
10874 ASSERT_NO_FATAL_FAILURE(InitViewport());
10875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10876
10877 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010878 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010879 pipe_ms_state_ci.pNext = NULL;
10880 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10881 pipe_ms_state_ci.sampleShadingEnable = 0;
10882 pipe_ms_state_ci.minSampleShading = 1.0;
10883 pipe_ms_state_ci.pSampleMask = nullptr;
10884
10885 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10886 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10887 VkPipelineLayout pipeline_layout;
10888
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010889 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010890 ASSERT_VK_SUCCESS(err);
10891
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010892 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10893 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010894 VkPipelineObj pipe(m_device);
10895 pipe.AddShader(&vs);
10896 pipe.AddShader(&fs);
10897 pipe.AddColorAttachment();
10898 pipe.SetMSAA(&pipe_ms_state_ci);
10899 pipe.SetViewport(m_viewports);
10900 pipe.SetScissor(m_scissors);
10901 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10902
Tony Barbour552f6c02016-12-21 14:34:07 -070010903 m_commandBuffer->BeginCommandBuffer();
10904 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010905 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010906
10907 {
10908 // Create and bind a vertex buffer in a reduced scope, which will cause
10909 // it to be deleted upon leaving this scope
10910 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010911 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010912 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10913 draw_verticies.AddVertexInputToPipe(pipe);
10914 }
10915
10916 Draw(1, 0, 0, 0);
10917
Tony Barbour552f6c02016-12-21 14:34:07 -070010918 m_commandBuffer->EndRenderPass();
10919 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060010920
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010922 QueueCommandBuffer(false);
10923 m_errorMonitor->VerifyFound();
10924
10925 {
10926 // Create and bind a vertex buffer in a reduced scope, and delete it
10927 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010928 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010930 buffer_test.TestDoubleDestroy();
10931 }
10932 m_errorMonitor->VerifyFound();
10933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010934 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010935 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10937 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10938 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010939 m_errorMonitor->VerifyFound();
10940 }
10941
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010942 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10943 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010944 // Create and bind a memory buffer with an invalid offset again,
10945 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10947 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10948 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010949 m_errorMonitor->VerifyFound();
10950 }
10951
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010952 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010953 // Create and bind a memory buffer with an invalid offset again, but
10954 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10956 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10957 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010958 m_errorMonitor->VerifyFound();
10959 }
10960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010961 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010962 // Create and bind a memory buffer with an invalid offset again, but
10963 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10965 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10966 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010967 m_errorMonitor->VerifyFound();
10968 }
10969
10970 {
10971 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010973 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10974 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010975 m_errorMonitor->VerifyFound();
10976 }
10977
10978 {
10979 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010981 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10982 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010983 }
10984 m_errorMonitor->VerifyFound();
10985
10986 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10987}
10988
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010989// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10990TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010991 TEST_DESCRIPTION(
10992 "Hit all possible validation checks associated with the "
10993 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10994 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010995 // 3 in ValidateCmdBufImageLayouts
10996 // * -1 Attempt to submit cmd buf w/ deleted image
10997 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10998 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010999
11000 ASSERT_NO_FATAL_FAILURE(InitState());
11001 // Create src & dst images to use for copy operations
11002 VkImage src_image;
11003 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011004 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011005
11006 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11007 const int32_t tex_width = 32;
11008 const int32_t tex_height = 32;
11009
11010 VkImageCreateInfo image_create_info = {};
11011 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11012 image_create_info.pNext = NULL;
11013 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11014 image_create_info.format = tex_format;
11015 image_create_info.extent.width = tex_width;
11016 image_create_info.extent.height = tex_height;
11017 image_create_info.extent.depth = 1;
11018 image_create_info.mipLevels = 1;
11019 image_create_info.arrayLayers = 4;
11020 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11021 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11022 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011023 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011024 image_create_info.flags = 0;
11025
11026 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11027 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011028 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011029 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11030 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011031 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11032 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11033 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11034 ASSERT_VK_SUCCESS(err);
11035
11036 // Allocate memory
11037 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011038 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011039 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011040 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11041 mem_alloc.pNext = NULL;
11042 mem_alloc.allocationSize = 0;
11043 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011044
11045 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011046 mem_alloc.allocationSize = img_mem_reqs.size;
11047 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011048 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011049 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011050 ASSERT_VK_SUCCESS(err);
11051
11052 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011053 mem_alloc.allocationSize = img_mem_reqs.size;
11054 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011055 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011056 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011057 ASSERT_VK_SUCCESS(err);
11058
11059 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011060 mem_alloc.allocationSize = img_mem_reqs.size;
11061 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011062 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011063 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011064 ASSERT_VK_SUCCESS(err);
11065
11066 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11067 ASSERT_VK_SUCCESS(err);
11068 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11069 ASSERT_VK_SUCCESS(err);
11070 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11071 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011072
Tony Barbour552f6c02016-12-21 14:34:07 -070011073 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011074 VkImageCopy copy_region;
11075 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11076 copy_region.srcSubresource.mipLevel = 0;
11077 copy_region.srcSubresource.baseArrayLayer = 0;
11078 copy_region.srcSubresource.layerCount = 1;
11079 copy_region.srcOffset.x = 0;
11080 copy_region.srcOffset.y = 0;
11081 copy_region.srcOffset.z = 0;
11082 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11083 copy_region.dstSubresource.mipLevel = 0;
11084 copy_region.dstSubresource.baseArrayLayer = 0;
11085 copy_region.dstSubresource.layerCount = 1;
11086 copy_region.dstOffset.x = 0;
11087 copy_region.dstOffset.y = 0;
11088 copy_region.dstOffset.z = 0;
11089 copy_region.extent.width = 1;
11090 copy_region.extent.height = 1;
11091 copy_region.extent.depth = 1;
11092
11093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11094 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
11095 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 -060011096 m_errorMonitor->VerifyFound();
11097 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11099 "Cannot copy from an image whose source layout is "
11100 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11101 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011102 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 -060011103 m_errorMonitor->VerifyFound();
11104 // Final src error is due to bad layout type
11105 m_errorMonitor->SetDesiredFailureMsg(
11106 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11107 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011108 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 -060011109 m_errorMonitor->VerifyFound();
11110 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11112 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011113 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 -060011114 m_errorMonitor->VerifyFound();
11115 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11117 "Cannot copy from an image whose dest layout is "
11118 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11119 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011120 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 -060011121 m_errorMonitor->VerifyFound();
11122 m_errorMonitor->SetDesiredFailureMsg(
11123 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11124 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011125 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 -060011126 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011127
Cort3b021012016-12-07 12:00:57 -080011128 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11129 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11130 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11131 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11132 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11133 transfer_dst_image_barrier[0].srcAccessMask = 0;
11134 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11135 transfer_dst_image_barrier[0].image = dst_image;
11136 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11137 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11138 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11139 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11140 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11141 transfer_dst_image_barrier[0].image = depth_image;
11142 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11143 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11144 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11145
11146 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011147 VkClearColorValue color_clear_value = {};
11148 VkImageSubresourceRange clear_range;
11149 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11150 clear_range.baseMipLevel = 0;
11151 clear_range.baseArrayLayer = 0;
11152 clear_range.layerCount = 1;
11153 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011154
Cort3b021012016-12-07 12:00:57 -080011155 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11156 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011159 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011160 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011161 // Fail due to provided layout not matching actual current layout for color clear.
11162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011163 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011164 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011165
Cort530cf382016-12-08 09:59:47 -080011166 VkClearDepthStencilValue depth_clear_value = {};
11167 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011168
11169 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11170 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011173 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011174 m_errorMonitor->VerifyFound();
11175 // Fail due to provided layout not matching actual current layout for depth clear.
11176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011177 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011178 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011179
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011180 // Now cause error due to bad image layout transition in PipelineBarrier
11181 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011182 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011183 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011184 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011185 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011186 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11187 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011188 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11190 "You cannot transition the layout of aspect 1 from "
11191 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11192 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011193 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11194 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011195 m_errorMonitor->VerifyFound();
11196
11197 // Finally some layout errors at RenderPass create time
11198 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11199 VkAttachmentReference attach = {};
11200 // perf warning for GENERAL layout w/ non-DS input attachment
11201 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11202 VkSubpassDescription subpass = {};
11203 subpass.inputAttachmentCount = 1;
11204 subpass.pInputAttachments = &attach;
11205 VkRenderPassCreateInfo rpci = {};
11206 rpci.subpassCount = 1;
11207 rpci.pSubpasses = &subpass;
11208 rpci.attachmentCount = 1;
11209 VkAttachmentDescription attach_desc = {};
11210 attach_desc.format = VK_FORMAT_UNDEFINED;
11211 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011212 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011213 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11215 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011216 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11217 m_errorMonitor->VerifyFound();
11218 // error w/ non-general layout
11219 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11220
11221 m_errorMonitor->SetDesiredFailureMsg(
11222 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11223 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11224 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11225 m_errorMonitor->VerifyFound();
11226 subpass.inputAttachmentCount = 0;
11227 subpass.colorAttachmentCount = 1;
11228 subpass.pColorAttachments = &attach;
11229 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11230 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11232 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011233 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11234 m_errorMonitor->VerifyFound();
11235 // error w/ non-color opt or GENERAL layout for color attachment
11236 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11237 m_errorMonitor->SetDesiredFailureMsg(
11238 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11239 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11240 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11241 m_errorMonitor->VerifyFound();
11242 subpass.colorAttachmentCount = 0;
11243 subpass.pDepthStencilAttachment = &attach;
11244 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11245 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11247 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011248 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11249 m_errorMonitor->VerifyFound();
11250 // error w/ non-ds opt or GENERAL layout for color attachment
11251 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11253 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11254 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011255 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11256 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011257 // For this error we need a valid renderpass so create default one
11258 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11259 attach.attachment = 0;
11260 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11261 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11262 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11263 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11264 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11265 // Can't do a CLEAR load on READ_ONLY initialLayout
11266 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11267 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11268 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11270 " with invalid first layout "
11271 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11272 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011273 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11274 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011275
Cort3b021012016-12-07 12:00:57 -080011276 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11277 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11278 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011279 vkDestroyImage(m_device->device(), src_image, NULL);
11280 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011281 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011282}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011283
Tobin Ehlise0936662016-10-11 08:10:51 -060011284TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11285 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11286 VkResult err;
11287
11288 ASSERT_NO_FATAL_FAILURE(InitState());
11289
11290 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11291 VkImageTiling tiling;
11292 VkFormatProperties format_properties;
11293 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11294 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11295 tiling = VK_IMAGE_TILING_LINEAR;
11296 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11297 tiling = VK_IMAGE_TILING_OPTIMAL;
11298 } else {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011299 printf(
11300 "Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11301 "skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011302 return;
11303 }
11304
11305 VkDescriptorPoolSize ds_type = {};
11306 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11307 ds_type.descriptorCount = 1;
11308
11309 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11310 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11311 ds_pool_ci.maxSets = 1;
11312 ds_pool_ci.poolSizeCount = 1;
11313 ds_pool_ci.pPoolSizes = &ds_type;
11314 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11315
11316 VkDescriptorPool ds_pool;
11317 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11318 ASSERT_VK_SUCCESS(err);
11319
11320 VkDescriptorSetLayoutBinding dsl_binding = {};
11321 dsl_binding.binding = 0;
11322 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11323 dsl_binding.descriptorCount = 1;
11324 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11325 dsl_binding.pImmutableSamplers = NULL;
11326
11327 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11328 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11329 ds_layout_ci.pNext = NULL;
11330 ds_layout_ci.bindingCount = 1;
11331 ds_layout_ci.pBindings = &dsl_binding;
11332
11333 VkDescriptorSetLayout ds_layout;
11334 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11335 ASSERT_VK_SUCCESS(err);
11336
11337 VkDescriptorSetAllocateInfo alloc_info = {};
11338 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11339 alloc_info.descriptorSetCount = 1;
11340 alloc_info.descriptorPool = ds_pool;
11341 alloc_info.pSetLayouts = &ds_layout;
11342 VkDescriptorSet descriptor_set;
11343 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11344 ASSERT_VK_SUCCESS(err);
11345
11346 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11347 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11348 pipeline_layout_ci.pNext = NULL;
11349 pipeline_layout_ci.setLayoutCount = 1;
11350 pipeline_layout_ci.pSetLayouts = &ds_layout;
11351 VkPipelineLayout pipeline_layout;
11352 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11353 ASSERT_VK_SUCCESS(err);
11354
11355 VkImageObj image(m_device);
11356 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11357 ASSERT_TRUE(image.initialized());
11358 VkImageView view = image.targetView(tex_format);
11359
11360 VkDescriptorImageInfo image_info = {};
11361 image_info.imageView = view;
11362 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11363
11364 VkWriteDescriptorSet descriptor_write = {};
11365 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11366 descriptor_write.dstSet = descriptor_set;
11367 descriptor_write.dstBinding = 0;
11368 descriptor_write.descriptorCount = 1;
11369 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11370 descriptor_write.pImageInfo = &image_info;
11371
11372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11373 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11374 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11375 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11376 m_errorMonitor->VerifyFound();
11377
11378 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11379 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11380 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11381 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11382}
11383
Mark Mueller93b938f2016-08-18 10:27:40 -060011384TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011385 TEST_DESCRIPTION(
11386 "Use vkCmdExecuteCommands with invalid state "
11387 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011388
11389 ASSERT_NO_FATAL_FAILURE(InitState());
11390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11391
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011392 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011393 const char *simultaneous_use_message2 =
11394 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11395 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011396
11397 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011398 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011399 command_buffer_allocate_info.commandPool = m_commandPool;
11400 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11401 command_buffer_allocate_info.commandBufferCount = 1;
11402
11403 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011404 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011405 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11406 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011407 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011408 command_buffer_inheritance_info.renderPass = m_renderPass;
11409 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011410
Mark Mueller93b938f2016-08-18 10:27:40 -060011411 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011412 command_buffer_begin_info.flags =
11413 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011414 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11415
11416 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11417 vkEndCommandBuffer(secondary_command_buffer);
11418
Mark Mueller93b938f2016-08-18 10:27:40 -060011419 VkSubmitInfo submit_info = {};
11420 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11421 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011422 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011423
Mark Mueller4042b652016-09-05 22:52:21 -060011424 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011425 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11427 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011428 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011429 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011430 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11431 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011432
Dave Houltonfbf52152017-01-06 12:55:29 -070011433 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060011434 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070011435 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060011436
Mark Mueller4042b652016-09-05 22:52:21 -060011437 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011438 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011439 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011440
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11442 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011443 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011444 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11445 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011446
11447 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011448}
11449
Tobin Ehlisb093da82017-01-19 12:05:27 -070011450TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011451 TEST_DESCRIPTION(
11452 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
11453 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070011454
11455 ASSERT_NO_FATAL_FAILURE(InitState());
11456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11457
11458 std::vector<const char *> device_extension_names;
11459 auto features = m_device->phy().features();
11460 // Make sure gs & ts are disabled
11461 features.geometryShader = false;
11462 features.tessellationShader = false;
11463 // The sacrificial device object
11464 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11465
11466 VkCommandPoolCreateInfo pool_create_info{};
11467 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
11468 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
11469
11470 VkCommandPool command_pool;
11471 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
11472
11473 VkCommandBufferAllocateInfo cmd = {};
11474 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11475 cmd.pNext = NULL;
11476 cmd.commandPool = command_pool;
11477 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
11478 cmd.commandBufferCount = 1;
11479
11480 VkCommandBuffer cmd_buffer;
11481 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
11482 ASSERT_VK_SUCCESS(err);
11483
11484 VkEvent event;
11485 VkEventCreateInfo evci = {};
11486 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11487 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
11488 ASSERT_VK_SUCCESS(result);
11489
11490 VkCommandBufferBeginInfo cbbi = {};
11491 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11492 vkBeginCommandBuffer(cmd_buffer, &cbbi);
11493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
11494 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
11495 m_errorMonitor->VerifyFound();
11496
11497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
11498 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
11499 m_errorMonitor->VerifyFound();
11500
11501 vkDestroyEvent(test_device.handle(), event, NULL);
11502 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
11503}
11504
Mark Mueller917f6bc2016-08-30 10:57:19 -060011505TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011506 TEST_DESCRIPTION(
11507 "Use vkCmdExecuteCommands with invalid state "
11508 "in primary and secondary command buffers. "
11509 "Delete objects that are inuse. Call VkQueueSubmit "
11510 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011511
11512 ASSERT_NO_FATAL_FAILURE(InitState());
11513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11514
Tony Barbour552f6c02016-12-21 14:34:07 -070011515 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011516
11517 VkEvent event;
11518 VkEventCreateInfo event_create_info = {};
11519 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11520 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011521 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011522
Tony Barbour552f6c02016-12-21 14:34:07 -070011523 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011524 vkDestroyEvent(m_device->device(), event, nullptr);
11525
11526 VkSubmitInfo submit_info = {};
11527 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11528 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011529 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b082d72017-01-27 11:34:28 -070011530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted event 0x");
11531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You are submitting command buffer 0x");
Mark Muellerc8d441e2016-08-23 17:36:00 -060011532 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11533 m_errorMonitor->VerifyFound();
11534
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011535 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060011536 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11537
11538 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11539
Mark Mueller917f6bc2016-08-30 10:57:19 -060011540 VkSemaphoreCreateInfo semaphore_create_info = {};
11541 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11542 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011543 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011544 VkFenceCreateInfo fence_create_info = {};
11545 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11546 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011547 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011548
11549 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011550 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011551 descriptor_pool_type_count.descriptorCount = 1;
11552
11553 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11554 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11555 descriptor_pool_create_info.maxSets = 1;
11556 descriptor_pool_create_info.poolSizeCount = 1;
11557 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011558 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011559
11560 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011561 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011562
11563 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011564 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011565 descriptorset_layout_binding.descriptorCount = 1;
11566 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11567
11568 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011569 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011570 descriptorset_layout_create_info.bindingCount = 1;
11571 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11572
11573 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011574 ASSERT_VK_SUCCESS(
11575 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011576
11577 VkDescriptorSet descriptorset;
11578 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011579 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011580 descriptorset_allocate_info.descriptorSetCount = 1;
11581 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11582 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011583 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011584
Mark Mueller4042b652016-09-05 22:52:21 -060011585 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11586
11587 VkDescriptorBufferInfo buffer_info = {};
11588 buffer_info.buffer = buffer_test.GetBuffer();
11589 buffer_info.offset = 0;
11590 buffer_info.range = 1024;
11591
11592 VkWriteDescriptorSet write_descriptor_set = {};
11593 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11594 write_descriptor_set.dstSet = descriptorset;
11595 write_descriptor_set.descriptorCount = 1;
11596 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11597 write_descriptor_set.pBufferInfo = &buffer_info;
11598
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011599 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011600
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011601 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11602 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011603
11604 VkPipelineObj pipe(m_device);
11605 pipe.AddColorAttachment();
11606 pipe.AddShader(&vs);
11607 pipe.AddShader(&fs);
11608
11609 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011610 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011611 pipeline_layout_create_info.setLayoutCount = 1;
11612 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11613
11614 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011615 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011616
11617 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11618
Tony Barbour552f6c02016-12-21 14:34:07 -070011619 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011620 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011621
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011622 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11623 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11624 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011625
Tony Barbour552f6c02016-12-21 14:34:07 -070011626 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011627
Mark Mueller917f6bc2016-08-30 10:57:19 -060011628 submit_info.signalSemaphoreCount = 1;
11629 submit_info.pSignalSemaphores = &semaphore;
11630 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011631 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060011632
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011634 vkDestroyEvent(m_device->device(), event, nullptr);
11635 m_errorMonitor->VerifyFound();
11636
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011638 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11639 m_errorMonitor->VerifyFound();
11640
Jeremy Hayes08369882017-02-02 10:31:06 -070011641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011642 vkDestroyFence(m_device->device(), fence, nullptr);
11643 m_errorMonitor->VerifyFound();
11644
Tobin Ehlis122207b2016-09-01 08:50:06 -070011645 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011646 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11647 vkDestroyFence(m_device->device(), fence, nullptr);
11648 vkDestroyEvent(m_device->device(), event, nullptr);
11649 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011650 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011651 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11652}
11653
Tobin Ehlis2adda372016-09-01 08:51:06 -070011654TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11655 TEST_DESCRIPTION("Delete in-use query pool.");
11656
11657 ASSERT_NO_FATAL_FAILURE(InitState());
11658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11659
11660 VkQueryPool query_pool;
11661 VkQueryPoolCreateInfo query_pool_ci{};
11662 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11663 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11664 query_pool_ci.queryCount = 1;
11665 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011666 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011667 // Reset query pool to create binding with cmd buffer
11668 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11669
Tony Barbour552f6c02016-12-21 14:34:07 -070011670 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011671
11672 VkSubmitInfo submit_info = {};
11673 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11674 submit_info.commandBufferCount = 1;
11675 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11676 // Submit cmd buffer and then destroy query pool while in-flight
11677 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11678
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011680 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11681 m_errorMonitor->VerifyFound();
11682
11683 vkQueueWaitIdle(m_device->m_queue);
11684 // Now that cmd buffer done we can safely destroy query_pool
11685 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11686}
11687
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011688TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11689 TEST_DESCRIPTION("Delete in-use pipeline.");
11690
11691 ASSERT_NO_FATAL_FAILURE(InitState());
11692 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11693
11694 // Empty pipeline layout used for binding PSO
11695 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11696 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11697 pipeline_layout_ci.setLayoutCount = 0;
11698 pipeline_layout_ci.pSetLayouts = NULL;
11699
11700 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011701 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011702 ASSERT_VK_SUCCESS(err);
11703
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011705 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011706 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11707 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011708 // Store pipeline handle so we can actually delete it before test finishes
11709 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011710 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011711 VkPipelineObj pipe(m_device);
11712 pipe.AddShader(&vs);
11713 pipe.AddShader(&fs);
11714 pipe.AddColorAttachment();
11715 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11716 delete_this_pipeline = pipe.handle();
11717
Tony Barbour552f6c02016-12-21 14:34:07 -070011718 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011719 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011720 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011721
Tony Barbour552f6c02016-12-21 14:34:07 -070011722 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011723
11724 VkSubmitInfo submit_info = {};
11725 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11726 submit_info.commandBufferCount = 1;
11727 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11728 // Submit cmd buffer and then pipeline destroyed while in-flight
11729 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011730 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011731 m_errorMonitor->VerifyFound();
11732 // Make sure queue finished and then actually delete pipeline
11733 vkQueueWaitIdle(m_device->m_queue);
11734 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11735 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11736}
11737
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011738TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11739 TEST_DESCRIPTION("Delete in-use imageView.");
11740
11741 ASSERT_NO_FATAL_FAILURE(InitState());
11742 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11743
11744 VkDescriptorPoolSize ds_type_count;
11745 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11746 ds_type_count.descriptorCount = 1;
11747
11748 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11749 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11750 ds_pool_ci.maxSets = 1;
11751 ds_pool_ci.poolSizeCount = 1;
11752 ds_pool_ci.pPoolSizes = &ds_type_count;
11753
11754 VkDescriptorPool ds_pool;
11755 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11756 ASSERT_VK_SUCCESS(err);
11757
11758 VkSamplerCreateInfo sampler_ci = {};
11759 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11760 sampler_ci.pNext = NULL;
11761 sampler_ci.magFilter = VK_FILTER_NEAREST;
11762 sampler_ci.minFilter = VK_FILTER_NEAREST;
11763 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11764 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11765 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11766 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11767 sampler_ci.mipLodBias = 1.0;
11768 sampler_ci.anisotropyEnable = VK_FALSE;
11769 sampler_ci.maxAnisotropy = 1;
11770 sampler_ci.compareEnable = VK_FALSE;
11771 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11772 sampler_ci.minLod = 1.0;
11773 sampler_ci.maxLod = 1.0;
11774 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11775 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11776 VkSampler sampler;
11777
11778 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11779 ASSERT_VK_SUCCESS(err);
11780
11781 VkDescriptorSetLayoutBinding layout_binding;
11782 layout_binding.binding = 0;
11783 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11784 layout_binding.descriptorCount = 1;
11785 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11786 layout_binding.pImmutableSamplers = NULL;
11787
11788 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11789 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11790 ds_layout_ci.bindingCount = 1;
11791 ds_layout_ci.pBindings = &layout_binding;
11792 VkDescriptorSetLayout ds_layout;
11793 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11794 ASSERT_VK_SUCCESS(err);
11795
11796 VkDescriptorSetAllocateInfo alloc_info = {};
11797 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11798 alloc_info.descriptorSetCount = 1;
11799 alloc_info.descriptorPool = ds_pool;
11800 alloc_info.pSetLayouts = &ds_layout;
11801 VkDescriptorSet descriptor_set;
11802 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11803 ASSERT_VK_SUCCESS(err);
11804
11805 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11806 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11807 pipeline_layout_ci.pNext = NULL;
11808 pipeline_layout_ci.setLayoutCount = 1;
11809 pipeline_layout_ci.pSetLayouts = &ds_layout;
11810
11811 VkPipelineLayout pipeline_layout;
11812 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11813 ASSERT_VK_SUCCESS(err);
11814
11815 VkImageObj image(m_device);
11816 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11817 ASSERT_TRUE(image.initialized());
11818
11819 VkImageView view;
11820 VkImageViewCreateInfo ivci = {};
11821 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11822 ivci.image = image.handle();
11823 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11824 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11825 ivci.subresourceRange.layerCount = 1;
11826 ivci.subresourceRange.baseMipLevel = 0;
11827 ivci.subresourceRange.levelCount = 1;
11828 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11829
11830 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11831 ASSERT_VK_SUCCESS(err);
11832
11833 VkDescriptorImageInfo image_info{};
11834 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11835 image_info.imageView = view;
11836 image_info.sampler = sampler;
11837
11838 VkWriteDescriptorSet descriptor_write = {};
11839 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11840 descriptor_write.dstSet = descriptor_set;
11841 descriptor_write.dstBinding = 0;
11842 descriptor_write.descriptorCount = 1;
11843 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11844 descriptor_write.pImageInfo = &image_info;
11845
11846 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11847
11848 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011849 char const *vsSource =
11850 "#version 450\n"
11851 "\n"
11852 "out gl_PerVertex { \n"
11853 " vec4 gl_Position;\n"
11854 "};\n"
11855 "void main(){\n"
11856 " gl_Position = vec4(1);\n"
11857 "}\n";
11858 char const *fsSource =
11859 "#version 450\n"
11860 "\n"
11861 "layout(set=0, binding=0) uniform sampler2D s;\n"
11862 "layout(location=0) out vec4 x;\n"
11863 "void main(){\n"
11864 " x = texture(s, vec2(1));\n"
11865 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011866 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11867 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11868 VkPipelineObj pipe(m_device);
11869 pipe.AddShader(&vs);
11870 pipe.AddShader(&fs);
11871 pipe.AddColorAttachment();
11872 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11873
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011875
Tony Barbour552f6c02016-12-21 14:34:07 -070011876 m_commandBuffer->BeginCommandBuffer();
11877 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011878 // Bind pipeline to cmd buffer
11879 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11880 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11881 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070011882
11883 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11884 VkRect2D scissor = {{0, 0}, {16, 16}};
11885 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11886 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11887
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011888 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011889 m_commandBuffer->EndRenderPass();
11890 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011891 // Submit cmd buffer then destroy sampler
11892 VkSubmitInfo submit_info = {};
11893 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11894 submit_info.commandBufferCount = 1;
11895 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11896 // Submit cmd buffer and then destroy imageView while in-flight
11897 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11898
11899 vkDestroyImageView(m_device->device(), view, nullptr);
11900 m_errorMonitor->VerifyFound();
11901 vkQueueWaitIdle(m_device->m_queue);
11902 // Now we can actually destroy imageView
11903 vkDestroyImageView(m_device->device(), view, NULL);
11904 vkDestroySampler(m_device->device(), sampler, nullptr);
11905 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11906 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11907 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11908}
11909
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011910TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11911 TEST_DESCRIPTION("Delete in-use bufferView.");
11912
11913 ASSERT_NO_FATAL_FAILURE(InitState());
11914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11915
11916 VkDescriptorPoolSize ds_type_count;
11917 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11918 ds_type_count.descriptorCount = 1;
11919
11920 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11921 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11922 ds_pool_ci.maxSets = 1;
11923 ds_pool_ci.poolSizeCount = 1;
11924 ds_pool_ci.pPoolSizes = &ds_type_count;
11925
11926 VkDescriptorPool ds_pool;
11927 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11928 ASSERT_VK_SUCCESS(err);
11929
11930 VkDescriptorSetLayoutBinding layout_binding;
11931 layout_binding.binding = 0;
11932 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11933 layout_binding.descriptorCount = 1;
11934 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11935 layout_binding.pImmutableSamplers = NULL;
11936
11937 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11938 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11939 ds_layout_ci.bindingCount = 1;
11940 ds_layout_ci.pBindings = &layout_binding;
11941 VkDescriptorSetLayout ds_layout;
11942 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11943 ASSERT_VK_SUCCESS(err);
11944
11945 VkDescriptorSetAllocateInfo alloc_info = {};
11946 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11947 alloc_info.descriptorSetCount = 1;
11948 alloc_info.descriptorPool = ds_pool;
11949 alloc_info.pSetLayouts = &ds_layout;
11950 VkDescriptorSet descriptor_set;
11951 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11952 ASSERT_VK_SUCCESS(err);
11953
11954 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11955 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11956 pipeline_layout_ci.pNext = NULL;
11957 pipeline_layout_ci.setLayoutCount = 1;
11958 pipeline_layout_ci.pSetLayouts = &ds_layout;
11959
11960 VkPipelineLayout pipeline_layout;
11961 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11962 ASSERT_VK_SUCCESS(err);
11963
11964 VkBuffer buffer;
11965 uint32_t queue_family_index = 0;
11966 VkBufferCreateInfo buffer_create_info = {};
11967 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11968 buffer_create_info.size = 1024;
11969 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11970 buffer_create_info.queueFamilyIndexCount = 1;
11971 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11972
11973 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11974 ASSERT_VK_SUCCESS(err);
11975
11976 VkMemoryRequirements memory_reqs;
11977 VkDeviceMemory buffer_memory;
11978
11979 VkMemoryAllocateInfo memory_info = {};
11980 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11981 memory_info.allocationSize = 0;
11982 memory_info.memoryTypeIndex = 0;
11983
11984 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11985 memory_info.allocationSize = memory_reqs.size;
11986 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11987 ASSERT_TRUE(pass);
11988
11989 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11990 ASSERT_VK_SUCCESS(err);
11991 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11992 ASSERT_VK_SUCCESS(err);
11993
11994 VkBufferView view;
11995 VkBufferViewCreateInfo bvci = {};
11996 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11997 bvci.buffer = buffer;
11998 bvci.format = VK_FORMAT_R8_UNORM;
11999 bvci.range = VK_WHOLE_SIZE;
12000
12001 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12002 ASSERT_VK_SUCCESS(err);
12003
12004 VkWriteDescriptorSet descriptor_write = {};
12005 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12006 descriptor_write.dstSet = descriptor_set;
12007 descriptor_write.dstBinding = 0;
12008 descriptor_write.descriptorCount = 1;
12009 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12010 descriptor_write.pTexelBufferView = &view;
12011
12012 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12013
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012014 char const *vsSource =
12015 "#version 450\n"
12016 "\n"
12017 "out gl_PerVertex { \n"
12018 " vec4 gl_Position;\n"
12019 "};\n"
12020 "void main(){\n"
12021 " gl_Position = vec4(1);\n"
12022 "}\n";
12023 char const *fsSource =
12024 "#version 450\n"
12025 "\n"
12026 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12027 "layout(location=0) out vec4 x;\n"
12028 "void main(){\n"
12029 " x = imageLoad(s, 0);\n"
12030 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012031 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12032 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12033 VkPipelineObj pipe(m_device);
12034 pipe.AddShader(&vs);
12035 pipe.AddShader(&fs);
12036 pipe.AddColorAttachment();
12037 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12038
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012040
Tony Barbour552f6c02016-12-21 14:34:07 -070012041 m_commandBuffer->BeginCommandBuffer();
12042 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012043 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12044 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12045 VkRect2D scissor = {{0, 0}, {16, 16}};
12046 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12047 // Bind pipeline to cmd buffer
12048 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12049 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12050 &descriptor_set, 0, nullptr);
12051 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012052 m_commandBuffer->EndRenderPass();
12053 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012054
12055 VkSubmitInfo submit_info = {};
12056 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12057 submit_info.commandBufferCount = 1;
12058 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12059 // Submit cmd buffer and then destroy bufferView while in-flight
12060 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12061
12062 vkDestroyBufferView(m_device->device(), view, nullptr);
12063 m_errorMonitor->VerifyFound();
12064 vkQueueWaitIdle(m_device->m_queue);
12065 // Now we can actually destroy bufferView
12066 vkDestroyBufferView(m_device->device(), view, NULL);
12067 vkDestroyBuffer(m_device->device(), buffer, NULL);
12068 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12069 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12070 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12071 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12072}
12073
Tobin Ehlis209532e2016-09-07 13:52:18 -060012074TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12075 TEST_DESCRIPTION("Delete in-use sampler.");
12076
12077 ASSERT_NO_FATAL_FAILURE(InitState());
12078 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12079
12080 VkDescriptorPoolSize ds_type_count;
12081 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12082 ds_type_count.descriptorCount = 1;
12083
12084 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12085 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12086 ds_pool_ci.maxSets = 1;
12087 ds_pool_ci.poolSizeCount = 1;
12088 ds_pool_ci.pPoolSizes = &ds_type_count;
12089
12090 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012091 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012092 ASSERT_VK_SUCCESS(err);
12093
12094 VkSamplerCreateInfo sampler_ci = {};
12095 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12096 sampler_ci.pNext = NULL;
12097 sampler_ci.magFilter = VK_FILTER_NEAREST;
12098 sampler_ci.minFilter = VK_FILTER_NEAREST;
12099 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12100 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12101 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12102 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12103 sampler_ci.mipLodBias = 1.0;
12104 sampler_ci.anisotropyEnable = VK_FALSE;
12105 sampler_ci.maxAnisotropy = 1;
12106 sampler_ci.compareEnable = VK_FALSE;
12107 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12108 sampler_ci.minLod = 1.0;
12109 sampler_ci.maxLod = 1.0;
12110 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12111 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12112 VkSampler sampler;
12113
12114 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12115 ASSERT_VK_SUCCESS(err);
12116
12117 VkDescriptorSetLayoutBinding layout_binding;
12118 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012119 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012120 layout_binding.descriptorCount = 1;
12121 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12122 layout_binding.pImmutableSamplers = NULL;
12123
12124 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12125 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12126 ds_layout_ci.bindingCount = 1;
12127 ds_layout_ci.pBindings = &layout_binding;
12128 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012129 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012130 ASSERT_VK_SUCCESS(err);
12131
12132 VkDescriptorSetAllocateInfo alloc_info = {};
12133 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12134 alloc_info.descriptorSetCount = 1;
12135 alloc_info.descriptorPool = ds_pool;
12136 alloc_info.pSetLayouts = &ds_layout;
12137 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012138 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012139 ASSERT_VK_SUCCESS(err);
12140
12141 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12142 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12143 pipeline_layout_ci.pNext = NULL;
12144 pipeline_layout_ci.setLayoutCount = 1;
12145 pipeline_layout_ci.pSetLayouts = &ds_layout;
12146
12147 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012148 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012149 ASSERT_VK_SUCCESS(err);
12150
12151 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012152 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012153 ASSERT_TRUE(image.initialized());
12154
12155 VkImageView view;
12156 VkImageViewCreateInfo ivci = {};
12157 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12158 ivci.image = image.handle();
12159 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12160 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12161 ivci.subresourceRange.layerCount = 1;
12162 ivci.subresourceRange.baseMipLevel = 0;
12163 ivci.subresourceRange.levelCount = 1;
12164 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12165
12166 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12167 ASSERT_VK_SUCCESS(err);
12168
12169 VkDescriptorImageInfo image_info{};
12170 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12171 image_info.imageView = view;
12172 image_info.sampler = sampler;
12173
12174 VkWriteDescriptorSet descriptor_write = {};
12175 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12176 descriptor_write.dstSet = descriptor_set;
12177 descriptor_write.dstBinding = 0;
12178 descriptor_write.descriptorCount = 1;
12179 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12180 descriptor_write.pImageInfo = &image_info;
12181
12182 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12183
12184 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012185 char const *vsSource =
12186 "#version 450\n"
12187 "\n"
12188 "out gl_PerVertex { \n"
12189 " vec4 gl_Position;\n"
12190 "};\n"
12191 "void main(){\n"
12192 " gl_Position = vec4(1);\n"
12193 "}\n";
12194 char const *fsSource =
12195 "#version 450\n"
12196 "\n"
12197 "layout(set=0, binding=0) uniform sampler2D s;\n"
12198 "layout(location=0) out vec4 x;\n"
12199 "void main(){\n"
12200 " x = texture(s, vec2(1));\n"
12201 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012202 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12203 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12204 VkPipelineObj pipe(m_device);
12205 pipe.AddShader(&vs);
12206 pipe.AddShader(&fs);
12207 pipe.AddColorAttachment();
12208 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12209
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012211
Tony Barbour552f6c02016-12-21 14:34:07 -070012212 m_commandBuffer->BeginCommandBuffer();
12213 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012214 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012215 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12216 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12217 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012218
12219 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12220 VkRect2D scissor = {{0, 0}, {16, 16}};
12221 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12222 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12223
Tobin Ehlis209532e2016-09-07 13:52:18 -060012224 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012225 m_commandBuffer->EndRenderPass();
12226 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012227 // Submit cmd buffer then destroy sampler
12228 VkSubmitInfo submit_info = {};
12229 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12230 submit_info.commandBufferCount = 1;
12231 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12232 // Submit cmd buffer and then destroy sampler while in-flight
12233 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12234
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012235 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012236 m_errorMonitor->VerifyFound();
12237 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012238
Tobin Ehlis209532e2016-09-07 13:52:18 -060012239 // Now we can actually destroy sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012240 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012241 vkDestroyImageView(m_device->device(), view, NULL);
12242 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12243 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12244 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12245}
12246
Mark Mueller1cd9f412016-08-25 13:23:52 -060012247TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012248 TEST_DESCRIPTION(
12249 "Call VkQueueSubmit with a semaphore that is already "
12250 "signaled but not waited on by the queue. Wait on a "
12251 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012252
12253 ASSERT_NO_FATAL_FAILURE(InitState());
12254 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012256 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 -070012257 const char *invalid_fence_wait_message =
12258 " which has not been submitted on a Queue or during "
12259 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012260
Tony Barbour552f6c02016-12-21 14:34:07 -070012261 m_commandBuffer->BeginCommandBuffer();
12262 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012263
12264 VkSemaphoreCreateInfo semaphore_create_info = {};
12265 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12266 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012267 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012268 VkSubmitInfo submit_info = {};
12269 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12270 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012271 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012272 submit_info.signalSemaphoreCount = 1;
12273 submit_info.pSignalSemaphores = &semaphore;
12274 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012275 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012276 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012277 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012278 m_commandBuffer->BeginCommandBuffer();
12279 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012281 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12282 m_errorMonitor->VerifyFound();
12283
Mark Mueller1cd9f412016-08-25 13:23:52 -060012284 VkFenceCreateInfo fence_create_info = {};
12285 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12286 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012287 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012288
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012290 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12291 m_errorMonitor->VerifyFound();
12292
Mark Mueller4042b652016-09-05 22:52:21 -060012293 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012294 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012295 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12296}
12297
Tobin Ehlis4af23302016-07-19 10:50:30 -060012298TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012299 TEST_DESCRIPTION(
12300 "Bind a secondary command buffer with with a framebuffer "
12301 "that does not match the framebuffer for the active "
12302 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012303 ASSERT_NO_FATAL_FAILURE(InitState());
12304 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12305
12306 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012307 VkAttachmentDescription attachment = {0,
12308 VK_FORMAT_B8G8R8A8_UNORM,
12309 VK_SAMPLE_COUNT_1_BIT,
12310 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12311 VK_ATTACHMENT_STORE_OP_STORE,
12312 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12313 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12314 VK_IMAGE_LAYOUT_UNDEFINED,
12315 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012316
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012317 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012318
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012319 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012321 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012322
12323 VkRenderPass rp;
12324 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12325 ASSERT_VK_SUCCESS(err);
12326
12327 // A compatible framebuffer.
12328 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012329 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012330 ASSERT_TRUE(image.initialized());
12331
12332 VkImageViewCreateInfo ivci = {
12333 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12334 nullptr,
12335 0,
12336 image.handle(),
12337 VK_IMAGE_VIEW_TYPE_2D,
12338 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012339 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12340 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012341 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12342 };
12343 VkImageView view;
12344 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12345 ASSERT_VK_SUCCESS(err);
12346
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012347 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012348 VkFramebuffer fb;
12349 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12350 ASSERT_VK_SUCCESS(err);
12351
12352 VkCommandBufferAllocateInfo cbai = {};
12353 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12354 cbai.commandPool = m_commandPool;
12355 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12356 cbai.commandBufferCount = 1;
12357
12358 VkCommandBuffer sec_cb;
12359 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12360 ASSERT_VK_SUCCESS(err);
12361 VkCommandBufferBeginInfo cbbi = {};
12362 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130012363 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060012364 cbii.renderPass = renderPass();
12365 cbii.framebuffer = fb;
12366 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12367 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012368 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 -060012369 cbbi.pInheritanceInfo = &cbii;
12370 vkBeginCommandBuffer(sec_cb, &cbbi);
12371 vkEndCommandBuffer(sec_cb);
12372
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012373 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120012374 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12375 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012376
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012378 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012379 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12380 m_errorMonitor->VerifyFound();
12381 // Cleanup
12382 vkDestroyImageView(m_device->device(), view, NULL);
12383 vkDestroyRenderPass(m_device->device(), rp, NULL);
12384 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12385}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012386
12387TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012388 TEST_DESCRIPTION(
12389 "If logicOp is available on the device, set it to an "
12390 "invalid value. If logicOp is not available, attempt to "
12391 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012392 ASSERT_NO_FATAL_FAILURE(InitState());
12393 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12394
12395 auto features = m_device->phy().features();
12396 // Set the expected error depending on whether or not logicOp available
12397 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12399 "If logic operations feature not "
12400 "enabled, logicOpEnable must be "
12401 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012402 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012404 }
12405 // Create a pipeline using logicOp
12406 VkResult err;
12407
12408 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12409 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12410
12411 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012412 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012413 ASSERT_VK_SUCCESS(err);
12414
12415 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12416 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12417 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012418 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012419 vp_state_ci.pViewports = &vp;
12420 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012421 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012422 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012423
12424 VkPipelineShaderStageCreateInfo shaderStages[2];
12425 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12426
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012427 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12428 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012429 shaderStages[0] = vs.GetStageCreateInfo();
12430 shaderStages[1] = fs.GetStageCreateInfo();
12431
12432 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12433 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12434
12435 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12436 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12437 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12438
12439 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12440 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012441 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012442
12443 VkPipelineColorBlendAttachmentState att = {};
12444 att.blendEnable = VK_FALSE;
12445 att.colorWriteMask = 0xf;
12446
12447 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12448 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12449 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12450 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012451 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012452 cb_ci.attachmentCount = 1;
12453 cb_ci.pAttachments = &att;
12454
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012455 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12456 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12457 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12458
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012459 VkGraphicsPipelineCreateInfo gp_ci = {};
12460 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12461 gp_ci.stageCount = 2;
12462 gp_ci.pStages = shaderStages;
12463 gp_ci.pVertexInputState = &vi_ci;
12464 gp_ci.pInputAssemblyState = &ia_ci;
12465 gp_ci.pViewportState = &vp_state_ci;
12466 gp_ci.pRasterizationState = &rs_ci;
12467 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012468 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012469 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12470 gp_ci.layout = pipeline_layout;
12471 gp_ci.renderPass = renderPass();
12472
12473 VkPipelineCacheCreateInfo pc_ci = {};
12474 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12475
12476 VkPipeline pipeline;
12477 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012478 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012479 ASSERT_VK_SUCCESS(err);
12480
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012481 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012482 m_errorMonitor->VerifyFound();
12483 if (VK_SUCCESS == err) {
12484 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12485 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012486 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12487 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12488}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012489#endif // DRAW_STATE_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012490
Tobin Ehlis0788f522015-05-26 16:11:58 -060012491#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012492#if GTEST_IS_THREADSAFE
12493struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012494 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012495 VkEvent event;
12496 bool bailout;
12497};
12498
Karl Schultz6addd812016-02-02 17:17:23 -070012499extern "C" void *AddToCommandBuffer(void *arg) {
12500 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012501
Mike Stroyana6d14942016-07-13 15:10:05 -060012502 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012503 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012504 if (data->bailout) {
12505 break;
12506 }
12507 }
12508 return NULL;
12509}
12510
Karl Schultz6addd812016-02-02 17:17:23 -070012511TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012512 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012513
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012515
Mike Stroyanaccf7692015-05-12 16:00:45 -060012516 ASSERT_NO_FATAL_FAILURE(InitState());
12517 ASSERT_NO_FATAL_FAILURE(InitViewport());
12518 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12519
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012520 // Calls AllocateCommandBuffers
12521 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012522
12523 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012524 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012525
12526 VkEventCreateInfo event_info;
12527 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012528 VkResult err;
12529
12530 memset(&event_info, 0, sizeof(event_info));
12531 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12532
Chia-I Wuf7458c52015-10-26 21:10:41 +080012533 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012534 ASSERT_VK_SUCCESS(err);
12535
Mike Stroyanaccf7692015-05-12 16:00:45 -060012536 err = vkResetEvent(device(), event);
12537 ASSERT_VK_SUCCESS(err);
12538
12539 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012540 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012541 data.event = event;
12542 data.bailout = false;
12543 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012544
12545 // First do some correct operations using multiple threads.
12546 // Add many entries to command buffer from another thread.
12547 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12548 // Make non-conflicting calls from this thread at the same time.
12549 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012550 uint32_t count;
12551 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012552 }
12553 test_platform_thread_join(thread, NULL);
12554
12555 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012556 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012557 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012558 // Add many entries to command buffer from this thread at the same time.
12559 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012560
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012561 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012562 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012563
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012564 m_errorMonitor->SetBailout(NULL);
12565
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012566 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012567
Chia-I Wuf7458c52015-10-26 21:10:41 +080012568 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012569}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012570#endif // GTEST_IS_THREADSAFE
12571#endif // THREADING_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012572
Chris Forbes9f7ff632015-05-25 11:13:08 +120012573#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012574TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012575 TEST_DESCRIPTION(
12576 "Test that an error is produced for a spirv module "
12577 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120012578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012580
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012581 ASSERT_NO_FATAL_FAILURE(InitState());
12582 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12583
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012584 VkShaderModule module;
12585 VkShaderModuleCreateInfo moduleCreateInfo;
12586 struct icd_spv_header spv;
12587
12588 spv.magic = ICD_SPV_MAGIC;
12589 spv.version = ICD_SPV_VERSION;
12590 spv.gen_magic = 0;
12591
12592 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12593 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012594 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012595 moduleCreateInfo.codeSize = 4;
12596 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012597 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012598
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012599 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012600}
12601
Karl Schultz6addd812016-02-02 17:17:23 -070012602TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012603 TEST_DESCRIPTION(
12604 "Test that an error is produced for a spirv module "
12605 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120012606
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012608
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012609 ASSERT_NO_FATAL_FAILURE(InitState());
12610 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12611
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012612 VkShaderModule module;
12613 VkShaderModuleCreateInfo moduleCreateInfo;
12614 struct icd_spv_header spv;
12615
12616 spv.magic = ~ICD_SPV_MAGIC;
12617 spv.version = ICD_SPV_VERSION;
12618 spv.gen_magic = 0;
12619
12620 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12621 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012622 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012623 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12624 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012625 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012626
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012627 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012628}
12629
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012630#if 0
12631// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012632TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012634 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012635
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012636 ASSERT_NO_FATAL_FAILURE(InitState());
12637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12638
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012639 VkShaderModule module;
12640 VkShaderModuleCreateInfo moduleCreateInfo;
12641 struct icd_spv_header spv;
12642
12643 spv.magic = ICD_SPV_MAGIC;
12644 spv.version = ~ICD_SPV_VERSION;
12645 spv.gen_magic = 0;
12646
12647 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12648 moduleCreateInfo.pNext = NULL;
12649
Karl Schultz6addd812016-02-02 17:17:23 -070012650 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012651 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12652 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012653 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012654
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012655 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012656}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012657#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012658
Karl Schultz6addd812016-02-02 17:17:23 -070012659TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012660 TEST_DESCRIPTION(
12661 "Test that a warning is produced for a vertex output that "
12662 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012664
Chris Forbes9f7ff632015-05-25 11:13:08 +120012665 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012666 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012667
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012668 char const *vsSource =
12669 "#version 450\n"
12670 "\n"
12671 "layout(location=0) out float x;\n"
12672 "out gl_PerVertex {\n"
12673 " vec4 gl_Position;\n"
12674 "};\n"
12675 "void main(){\n"
12676 " gl_Position = vec4(1);\n"
12677 " x = 0;\n"
12678 "}\n";
12679 char const *fsSource =
12680 "#version 450\n"
12681 "\n"
12682 "layout(location=0) out vec4 color;\n"
12683 "void main(){\n"
12684 " color = vec4(1);\n"
12685 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012686
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012687 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12688 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012689
12690 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012691 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012692 pipe.AddShader(&vs);
12693 pipe.AddShader(&fs);
12694
Chris Forbes9f7ff632015-05-25 11:13:08 +120012695 VkDescriptorSetObj descriptorSet(m_device);
12696 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012697 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012698
Tony Barbour5781e8f2015-08-04 16:23:11 -060012699 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012700
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012701 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012702}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012703
Mark Mueller098c9cb2016-09-08 09:01:57 -060012704TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12705 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12706
12707 ASSERT_NO_FATAL_FAILURE(InitState());
12708 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12709
12710 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012711 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012712
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012713 char const *vsSource =
12714 "#version 450\n"
12715 "\n"
12716 "out gl_PerVertex {\n"
12717 " vec4 gl_Position;\n"
12718 "};\n"
12719 "void main(){\n"
12720 " gl_Position = vec4(1);\n"
12721 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012722
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012723 char const *fsSource =
12724 "#version 450\n"
12725 "\n"
12726 "layout (constant_id = 0) const float r = 0.0f;\n"
12727 "layout(location = 0) out vec4 uFragColor;\n"
12728 "void main(){\n"
12729 " uFragColor = vec4(r,1,0,1);\n"
12730 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012731
12732 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12733 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12734
12735 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12736 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12737
12738 VkPipelineLayout pipeline_layout;
12739 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12740
12741 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12742 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12743 vp_state_create_info.viewportCount = 1;
12744 VkViewport viewport = {};
12745 vp_state_create_info.pViewports = &viewport;
12746 vp_state_create_info.scissorCount = 1;
12747 VkRect2D scissors = {};
12748 vp_state_create_info.pScissors = &scissors;
12749
12750 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12751
12752 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12753 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12754 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12755 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12756
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012757 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060012758
12759 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12760 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12761
12762 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12763 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12764 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12765
12766 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12767 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12768 rasterization_state_create_info.pNext = nullptr;
12769 rasterization_state_create_info.lineWidth = 1.0f;
12770 rasterization_state_create_info.rasterizerDiscardEnable = true;
12771
12772 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12773 color_blend_attachment_state.blendEnable = VK_FALSE;
12774 color_blend_attachment_state.colorWriteMask = 0xf;
12775
12776 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12777 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12778 color_blend_state_create_info.attachmentCount = 1;
12779 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12780
12781 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12782 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12783 graphicspipe_create_info.stageCount = 2;
12784 graphicspipe_create_info.pStages = shader_stage_create_info;
12785 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12786 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12787 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12788 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12789 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12790 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12791 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12792 graphicspipe_create_info.layout = pipeline_layout;
12793 graphicspipe_create_info.renderPass = renderPass();
12794
12795 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12796 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12797
12798 VkPipelineCache pipelineCache;
12799 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12800
12801 // This structure maps constant ids to data locations.
12802 const VkSpecializationMapEntry entry =
12803 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012804 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060012805
12806 uint32_t data = 1;
12807
12808 // Set up the info describing spec map and data
12809 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012810 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060012811 };
12812 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12813
12814 VkPipeline pipeline;
12815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12816 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12817 m_errorMonitor->VerifyFound();
12818
12819 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12820 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12821}
12822
12823TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12824 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12825
12826 ASSERT_NO_FATAL_FAILURE(InitState());
12827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12828
12829 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12830
12831 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12832 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12833 descriptor_pool_type_count[0].descriptorCount = 1;
12834 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12835 descriptor_pool_type_count[1].descriptorCount = 1;
12836
12837 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12838 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12839 descriptor_pool_create_info.maxSets = 1;
12840 descriptor_pool_create_info.poolSizeCount = 2;
12841 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12842 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12843
12844 VkDescriptorPool descriptorset_pool;
12845 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12846
12847 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12848 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12849 descriptorset_layout_binding.descriptorCount = 1;
12850 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12851
12852 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12853 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12854 descriptorset_layout_create_info.bindingCount = 1;
12855 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12856
12857 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012858 ASSERT_VK_SUCCESS(
12859 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060012860
12861 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12862 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12863 descriptorset_allocate_info.descriptorSetCount = 1;
12864 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12865 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12866 VkDescriptorSet descriptorset;
12867 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12868
12869 // Challenge core_validation with a non uniform buffer type.
12870 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12871
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012872 char const *vsSource =
12873 "#version 450\n"
12874 "\n"
12875 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12876 " mat4 mvp;\n"
12877 "} ubuf;\n"
12878 "out gl_PerVertex {\n"
12879 " vec4 gl_Position;\n"
12880 "};\n"
12881 "void main(){\n"
12882 " gl_Position = ubuf.mvp * vec4(1);\n"
12883 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012884
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012885 char const *fsSource =
12886 "#version 450\n"
12887 "\n"
12888 "layout(location = 0) out vec4 uFragColor;\n"
12889 "void main(){\n"
12890 " uFragColor = vec4(0,1,0,1);\n"
12891 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012892
12893 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12894 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12895
12896 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12897 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12898 pipeline_layout_create_info.setLayoutCount = 1;
12899 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12900
12901 VkPipelineLayout pipeline_layout;
12902 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12903
12904 VkPipelineObj pipe(m_device);
12905 pipe.AddColorAttachment();
12906 pipe.AddShader(&vs);
12907 pipe.AddShader(&fs);
12908
12909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12910 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12911 m_errorMonitor->VerifyFound();
12912
12913 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12914 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12915 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12916}
12917
12918TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12919 TEST_DESCRIPTION(
12920 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12921
12922 ASSERT_NO_FATAL_FAILURE(InitState());
12923 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12924
12925 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12926
12927 VkDescriptorPoolSize descriptor_pool_type_count = {};
12928 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12929 descriptor_pool_type_count.descriptorCount = 1;
12930
12931 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12932 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12933 descriptor_pool_create_info.maxSets = 1;
12934 descriptor_pool_create_info.poolSizeCount = 1;
12935 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12936 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12937
12938 VkDescriptorPool descriptorset_pool;
12939 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12940
12941 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12942 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12943 descriptorset_layout_binding.descriptorCount = 1;
12944 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12945 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12946
12947 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12948 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12949 descriptorset_layout_create_info.bindingCount = 1;
12950 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12951
12952 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012953 ASSERT_VK_SUCCESS(
12954 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060012955
12956 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12957 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12958 descriptorset_allocate_info.descriptorSetCount = 1;
12959 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12960 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12961 VkDescriptorSet descriptorset;
12962 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12963
12964 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12965
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012966 char const *vsSource =
12967 "#version 450\n"
12968 "\n"
12969 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12970 " mat4 mvp;\n"
12971 "} ubuf;\n"
12972 "out gl_PerVertex {\n"
12973 " vec4 gl_Position;\n"
12974 "};\n"
12975 "void main(){\n"
12976 " gl_Position = ubuf.mvp * vec4(1);\n"
12977 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012978
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012979 char const *fsSource =
12980 "#version 450\n"
12981 "\n"
12982 "layout(location = 0) out vec4 uFragColor;\n"
12983 "void main(){\n"
12984 " uFragColor = vec4(0,1,0,1);\n"
12985 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012986
12987 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12988 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12989
12990 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12991 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12992 pipeline_layout_create_info.setLayoutCount = 1;
12993 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12994
12995 VkPipelineLayout pipeline_layout;
12996 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12997
12998 VkPipelineObj pipe(m_device);
12999 pipe.AddColorAttachment();
13000 pipe.AddShader(&vs);
13001 pipe.AddShader(&fs);
13002
13003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13004 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13005 m_errorMonitor->VerifyFound();
13006
13007 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13008 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13009 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13010}
13011
13012TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013013 TEST_DESCRIPTION(
13014 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13015 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013016
13017 ASSERT_NO_FATAL_FAILURE(InitState());
13018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13019
13020 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013021 "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 -060013022
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013023 char const *vsSource =
13024 "#version 450\n"
13025 "\n"
13026 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13027 "out gl_PerVertex {\n"
13028 " vec4 gl_Position;\n"
13029 "};\n"
13030 "void main(){\n"
13031 " gl_Position = vec4(consts.x);\n"
13032 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013033
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013034 char const *fsSource =
13035 "#version 450\n"
13036 "\n"
13037 "layout(location = 0) out vec4 uFragColor;\n"
13038 "void main(){\n"
13039 " uFragColor = vec4(0,1,0,1);\n"
13040 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013041
13042 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13043 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13044
13045 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13046 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13047
13048 // Set up a push constant range
13049 VkPushConstantRange push_constant_ranges = {};
13050 // Set to the wrong stage to challenge core_validation
13051 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13052 push_constant_ranges.size = 4;
13053
13054 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13055 pipeline_layout_create_info.pushConstantRangeCount = 1;
13056
13057 VkPipelineLayout pipeline_layout;
13058 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13059
13060 VkPipelineObj pipe(m_device);
13061 pipe.AddColorAttachment();
13062 pipe.AddShader(&vs);
13063 pipe.AddShader(&fs);
13064
13065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13066 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13067 m_errorMonitor->VerifyFound();
13068
13069 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13070}
13071
13072TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13073 TEST_DESCRIPTION(
13074 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13075
13076 ASSERT_NO_FATAL_FAILURE(InitState());
13077 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13078
13079 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013080 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013081
13082 // Some awkward steps are required to test with custom device features.
13083 std::vector<const char *> device_extension_names;
13084 auto features = m_device->phy().features();
13085 // Disable support for 64 bit floats
13086 features.shaderFloat64 = false;
13087 // The sacrificial device object
13088 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13089
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013090 char const *vsSource =
13091 "#version 450\n"
13092 "\n"
13093 "out gl_PerVertex {\n"
13094 " vec4 gl_Position;\n"
13095 "};\n"
13096 "void main(){\n"
13097 " gl_Position = vec4(1);\n"
13098 "}\n";
13099 char const *fsSource =
13100 "#version 450\n"
13101 "\n"
13102 "layout(location=0) out vec4 color;\n"
13103 "void main(){\n"
13104 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13105 " color = vec4(green);\n"
13106 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013107
13108 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13109 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13110
13111 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013112
13113 VkPipelineObj pipe(&test_device);
13114 pipe.AddColorAttachment();
13115 pipe.AddShader(&vs);
13116 pipe.AddShader(&fs);
13117
13118 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13119 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13120 VkPipelineLayout pipeline_layout;
13121 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13122
13123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13124 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13125 m_errorMonitor->VerifyFound();
13126
13127 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13128}
13129
13130TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13131 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13132
13133 ASSERT_NO_FATAL_FAILURE(InitState());
13134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13135
13136 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13137
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013138 char const *vsSource =
13139 "#version 450\n"
13140 "\n"
13141 "out gl_PerVertex {\n"
13142 " vec4 gl_Position;\n"
13143 "};\n"
13144 "layout(xfb_buffer = 1) out;"
13145 "void main(){\n"
13146 " gl_Position = vec4(1);\n"
13147 "}\n";
13148 char const *fsSource =
13149 "#version 450\n"
13150 "\n"
13151 "layout(location=0) out vec4 color;\n"
13152 "void main(){\n"
13153 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13154 " color = vec4(green);\n"
13155 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013156
13157 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13158 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13159
13160 VkPipelineObj pipe(m_device);
13161 pipe.AddColorAttachment();
13162 pipe.AddShader(&vs);
13163 pipe.AddShader(&fs);
13164
13165 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13166 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13167 VkPipelineLayout pipeline_layout;
13168 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13169
13170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13171 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13172 m_errorMonitor->VerifyFound();
13173
13174 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13175}
13176
Karl Schultz6addd812016-02-02 17:17:23 -070013177TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013178 TEST_DESCRIPTION(
13179 "Test that an error is produced for a fragment shader input "
13180 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013183
Chris Forbes59cb88d2015-05-25 11:13:13 +120013184 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013185 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013186
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013187 char const *vsSource =
13188 "#version 450\n"
13189 "\n"
13190 "out gl_PerVertex {\n"
13191 " vec4 gl_Position;\n"
13192 "};\n"
13193 "void main(){\n"
13194 " gl_Position = vec4(1);\n"
13195 "}\n";
13196 char const *fsSource =
13197 "#version 450\n"
13198 "\n"
13199 "layout(location=0) in float x;\n"
13200 "layout(location=0) out vec4 color;\n"
13201 "void main(){\n"
13202 " color = vec4(x);\n"
13203 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013204
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013205 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13206 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013207
13208 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013209 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013210 pipe.AddShader(&vs);
13211 pipe.AddShader(&fs);
13212
Chris Forbes59cb88d2015-05-25 11:13:13 +120013213 VkDescriptorSetObj descriptorSet(m_device);
13214 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013215 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013216
Tony Barbour5781e8f2015-08-04 16:23:11 -060013217 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013218
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013219 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013220}
13221
Karl Schultz6addd812016-02-02 17:17:23 -070013222TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013223 TEST_DESCRIPTION(
13224 "Test that an error is produced for a fragment shader input "
13225 "within an interace block, which is not present in the outputs "
13226 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013228
13229 ASSERT_NO_FATAL_FAILURE(InitState());
13230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13231
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013232 char const *vsSource =
13233 "#version 450\n"
13234 "\n"
13235 "out gl_PerVertex {\n"
13236 " vec4 gl_Position;\n"
13237 "};\n"
13238 "void main(){\n"
13239 " gl_Position = vec4(1);\n"
13240 "}\n";
13241 char const *fsSource =
13242 "#version 450\n"
13243 "\n"
13244 "in block { layout(location=0) float x; } ins;\n"
13245 "layout(location=0) out vec4 color;\n"
13246 "void main(){\n"
13247 " color = vec4(ins.x);\n"
13248 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013249
13250 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13251 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13252
13253 VkPipelineObj pipe(m_device);
13254 pipe.AddColorAttachment();
13255 pipe.AddShader(&vs);
13256 pipe.AddShader(&fs);
13257
13258 VkDescriptorSetObj descriptorSet(m_device);
13259 descriptorSet.AppendDummy();
13260 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13261
13262 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13263
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013264 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013265}
13266
Karl Schultz6addd812016-02-02 17:17:23 -070013267TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013268 TEST_DESCRIPTION(
13269 "Test that an error is produced for mismatched array sizes "
13270 "across the vertex->fragment shader interface");
13271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13272 "Type mismatch on location 0.0: 'ptr to "
13273 "output arr[2] of float32' vs 'ptr to "
13274 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013275
13276 ASSERT_NO_FATAL_FAILURE(InitState());
13277 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13278
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013279 char const *vsSource =
13280 "#version 450\n"
13281 "\n"
13282 "layout(location=0) out float x[2];\n"
13283 "out gl_PerVertex {\n"
13284 " vec4 gl_Position;\n"
13285 "};\n"
13286 "void main(){\n"
13287 " x[0] = 0; x[1] = 0;\n"
13288 " gl_Position = vec4(1);\n"
13289 "}\n";
13290 char const *fsSource =
13291 "#version 450\n"
13292 "\n"
13293 "layout(location=0) in float x[1];\n"
13294 "layout(location=0) out vec4 color;\n"
13295 "void main(){\n"
13296 " color = vec4(x[0]);\n"
13297 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013298
13299 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13300 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13301
13302 VkPipelineObj pipe(m_device);
13303 pipe.AddColorAttachment();
13304 pipe.AddShader(&vs);
13305 pipe.AddShader(&fs);
13306
13307 VkDescriptorSetObj descriptorSet(m_device);
13308 descriptorSet.AppendDummy();
13309 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13310
13311 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13312
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013313 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013314}
13315
Karl Schultz6addd812016-02-02 17:17:23 -070013316TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013317 TEST_DESCRIPTION(
13318 "Test that an error is produced for mismatched types across "
13319 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013321
Chris Forbesb56af562015-05-25 11:13:17 +120013322 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013324
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013325 char const *vsSource =
13326 "#version 450\n"
13327 "\n"
13328 "layout(location=0) out int x;\n"
13329 "out gl_PerVertex {\n"
13330 " vec4 gl_Position;\n"
13331 "};\n"
13332 "void main(){\n"
13333 " x = 0;\n"
13334 " gl_Position = vec4(1);\n"
13335 "}\n";
13336 char const *fsSource =
13337 "#version 450\n"
13338 "\n"
13339 "layout(location=0) in float x;\n" /* VS writes int */
13340 "layout(location=0) out vec4 color;\n"
13341 "void main(){\n"
13342 " color = vec4(x);\n"
13343 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013344
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013345 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13346 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013347
13348 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013349 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013350 pipe.AddShader(&vs);
13351 pipe.AddShader(&fs);
13352
Chris Forbesb56af562015-05-25 11:13:17 +120013353 VkDescriptorSetObj descriptorSet(m_device);
13354 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013355 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013356
Tony Barbour5781e8f2015-08-04 16:23:11 -060013357 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013358
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013359 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013360}
13361
Karl Schultz6addd812016-02-02 17:17:23 -070013362TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013363 TEST_DESCRIPTION(
13364 "Test that an error is produced for mismatched types across "
13365 "the vertex->fragment shader interface, when the variable is contained within "
13366 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013368
13369 ASSERT_NO_FATAL_FAILURE(InitState());
13370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13371
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013372 char const *vsSource =
13373 "#version 450\n"
13374 "\n"
13375 "out block { layout(location=0) int x; } outs;\n"
13376 "out gl_PerVertex {\n"
13377 " vec4 gl_Position;\n"
13378 "};\n"
13379 "void main(){\n"
13380 " outs.x = 0;\n"
13381 " gl_Position = vec4(1);\n"
13382 "}\n";
13383 char const *fsSource =
13384 "#version 450\n"
13385 "\n"
13386 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13387 "layout(location=0) out vec4 color;\n"
13388 "void main(){\n"
13389 " color = vec4(ins.x);\n"
13390 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013391
13392 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13393 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13394
13395 VkPipelineObj pipe(m_device);
13396 pipe.AddColorAttachment();
13397 pipe.AddShader(&vs);
13398 pipe.AddShader(&fs);
13399
13400 VkDescriptorSetObj descriptorSet(m_device);
13401 descriptorSet.AppendDummy();
13402 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13403
13404 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13405
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013406 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013407}
13408
13409TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013410 TEST_DESCRIPTION(
13411 "Test that an error is produced for location mismatches across "
13412 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
13413 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013414 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 +130013415
13416 ASSERT_NO_FATAL_FAILURE(InitState());
13417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13418
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013419 char const *vsSource =
13420 "#version 450\n"
13421 "\n"
13422 "out block { layout(location=1) float x; } outs;\n"
13423 "out gl_PerVertex {\n"
13424 " vec4 gl_Position;\n"
13425 "};\n"
13426 "void main(){\n"
13427 " outs.x = 0;\n"
13428 " gl_Position = vec4(1);\n"
13429 "}\n";
13430 char const *fsSource =
13431 "#version 450\n"
13432 "\n"
13433 "in block { layout(location=0) float x; } ins;\n"
13434 "layout(location=0) out vec4 color;\n"
13435 "void main(){\n"
13436 " color = vec4(ins.x);\n"
13437 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013438
13439 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13440 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13441
13442 VkPipelineObj pipe(m_device);
13443 pipe.AddColorAttachment();
13444 pipe.AddShader(&vs);
13445 pipe.AddShader(&fs);
13446
13447 VkDescriptorSetObj descriptorSet(m_device);
13448 descriptorSet.AppendDummy();
13449 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13450
13451 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13452
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013453 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013454}
13455
13456TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013457 TEST_DESCRIPTION(
13458 "Test that an error is produced for component mismatches across the "
13459 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
13460 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013461 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 +130013462
13463 ASSERT_NO_FATAL_FAILURE(InitState());
13464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13465
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013466 char const *vsSource =
13467 "#version 450\n"
13468 "\n"
13469 "out block { layout(location=0, component=0) float x; } outs;\n"
13470 "out gl_PerVertex {\n"
13471 " vec4 gl_Position;\n"
13472 "};\n"
13473 "void main(){\n"
13474 " outs.x = 0;\n"
13475 " gl_Position = vec4(1);\n"
13476 "}\n";
13477 char const *fsSource =
13478 "#version 450\n"
13479 "\n"
13480 "in block { layout(location=0, component=1) float x; } ins;\n"
13481 "layout(location=0) out vec4 color;\n"
13482 "void main(){\n"
13483 " color = vec4(ins.x);\n"
13484 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013485
13486 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13487 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13488
13489 VkPipelineObj pipe(m_device);
13490 pipe.AddColorAttachment();
13491 pipe.AddShader(&vs);
13492 pipe.AddShader(&fs);
13493
13494 VkDescriptorSetObj descriptorSet(m_device);
13495 descriptorSet.AppendDummy();
13496 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13497
13498 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13499
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013500 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013501}
13502
Chris Forbes1f3b0152016-11-30 12:48:40 +130013503TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13504 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13505
13506 ASSERT_NO_FATAL_FAILURE(InitState());
13507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13508
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013509 char const *vsSource =
13510 "#version 450\n"
13511 "layout(location=0) out mediump float x;\n"
13512 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13513 char const *fsSource =
13514 "#version 450\n"
13515 "layout(location=0) in highp float x;\n"
13516 "layout(location=0) out vec4 color;\n"
13517 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130013518
13519 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13520 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13521
13522 VkPipelineObj pipe(m_device);
13523 pipe.AddColorAttachment();
13524 pipe.AddShader(&vs);
13525 pipe.AddShader(&fs);
13526
13527 VkDescriptorSetObj descriptorSet(m_device);
13528 descriptorSet.AppendDummy();
13529 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13530
13531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13532
13533 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13534
13535 m_errorMonitor->VerifyFound();
13536}
13537
Chris Forbes870a39e2016-11-30 12:55:56 +130013538TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13539 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13540
13541 ASSERT_NO_FATAL_FAILURE(InitState());
13542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13543
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013544 char const *vsSource =
13545 "#version 450\n"
13546 "out block { layout(location=0) mediump float x; };\n"
13547 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13548 char const *fsSource =
13549 "#version 450\n"
13550 "in block { layout(location=0) highp float x; };\n"
13551 "layout(location=0) out vec4 color;\n"
13552 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130013553
13554 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13555 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13556
13557 VkPipelineObj pipe(m_device);
13558 pipe.AddColorAttachment();
13559 pipe.AddShader(&vs);
13560 pipe.AddShader(&fs);
13561
13562 VkDescriptorSetObj descriptorSet(m_device);
13563 descriptorSet.AppendDummy();
13564 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13565
13566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13567
13568 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13569
13570 m_errorMonitor->VerifyFound();
13571}
13572
Karl Schultz6addd812016-02-02 17:17:23 -070013573TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013574 TEST_DESCRIPTION(
13575 "Test that a warning is produced for a vertex attribute which is "
13576 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013578
Chris Forbesde136e02015-05-25 11:13:28 +120013579 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013580 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013581
13582 VkVertexInputBindingDescription input_binding;
13583 memset(&input_binding, 0, sizeof(input_binding));
13584
13585 VkVertexInputAttributeDescription input_attrib;
13586 memset(&input_attrib, 0, sizeof(input_attrib));
13587 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13588
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013589 char const *vsSource =
13590 "#version 450\n"
13591 "\n"
13592 "out gl_PerVertex {\n"
13593 " vec4 gl_Position;\n"
13594 "};\n"
13595 "void main(){\n"
13596 " gl_Position = vec4(1);\n"
13597 "}\n";
13598 char const *fsSource =
13599 "#version 450\n"
13600 "\n"
13601 "layout(location=0) out vec4 color;\n"
13602 "void main(){\n"
13603 " color = vec4(1);\n"
13604 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013605
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013606 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13607 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013608
13609 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013610 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013611 pipe.AddShader(&vs);
13612 pipe.AddShader(&fs);
13613
13614 pipe.AddVertexInputBindings(&input_binding, 1);
13615 pipe.AddVertexInputAttribs(&input_attrib, 1);
13616
Chris Forbesde136e02015-05-25 11:13:28 +120013617 VkDescriptorSetObj descriptorSet(m_device);
13618 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013619 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013620
Tony Barbour5781e8f2015-08-04 16:23:11 -060013621 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013622
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013623 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013624}
13625
Karl Schultz6addd812016-02-02 17:17:23 -070013626TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013627 TEST_DESCRIPTION(
13628 "Test that a warning is produced for a location mismatch on "
13629 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013631
13632 ASSERT_NO_FATAL_FAILURE(InitState());
13633 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13634
13635 VkVertexInputBindingDescription input_binding;
13636 memset(&input_binding, 0, sizeof(input_binding));
13637
13638 VkVertexInputAttributeDescription input_attrib;
13639 memset(&input_attrib, 0, sizeof(input_attrib));
13640 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13641
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013642 char const *vsSource =
13643 "#version 450\n"
13644 "\n"
13645 "layout(location=1) in float x;\n"
13646 "out gl_PerVertex {\n"
13647 " vec4 gl_Position;\n"
13648 "};\n"
13649 "void main(){\n"
13650 " gl_Position = vec4(x);\n"
13651 "}\n";
13652 char const *fsSource =
13653 "#version 450\n"
13654 "\n"
13655 "layout(location=0) out vec4 color;\n"
13656 "void main(){\n"
13657 " color = vec4(1);\n"
13658 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013659
13660 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13661 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13662
13663 VkPipelineObj pipe(m_device);
13664 pipe.AddColorAttachment();
13665 pipe.AddShader(&vs);
13666 pipe.AddShader(&fs);
13667
13668 pipe.AddVertexInputBindings(&input_binding, 1);
13669 pipe.AddVertexInputAttribs(&input_attrib, 1);
13670
13671 VkDescriptorSetObj descriptorSet(m_device);
13672 descriptorSet.AppendDummy();
13673 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13674
13675 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13676
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013677 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013678}
13679
Karl Schultz6addd812016-02-02 17:17:23 -070013680TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013681 TEST_DESCRIPTION(
13682 "Test that an error is produced for a vertex shader input which is not "
13683 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13685 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013686
Chris Forbes62e8e502015-05-25 11:13:29 +120013687 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013688 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013689
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013690 char const *vsSource =
13691 "#version 450\n"
13692 "\n"
13693 "layout(location=0) in vec4 x;\n" /* not provided */
13694 "out gl_PerVertex {\n"
13695 " vec4 gl_Position;\n"
13696 "};\n"
13697 "void main(){\n"
13698 " gl_Position = x;\n"
13699 "}\n";
13700 char const *fsSource =
13701 "#version 450\n"
13702 "\n"
13703 "layout(location=0) out vec4 color;\n"
13704 "void main(){\n"
13705 " color = vec4(1);\n"
13706 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013707
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013708 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13709 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013710
13711 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013712 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013713 pipe.AddShader(&vs);
13714 pipe.AddShader(&fs);
13715
Chris Forbes62e8e502015-05-25 11:13:29 +120013716 VkDescriptorSetObj descriptorSet(m_device);
13717 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013718 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013719
Tony Barbour5781e8f2015-08-04 16:23:11 -060013720 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013721
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013722 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013723}
13724
Karl Schultz6addd812016-02-02 17:17:23 -070013725TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013726 TEST_DESCRIPTION(
13727 "Test that an error is produced for a mismatch between the "
13728 "fundamental type (float/int/uint) of an attribute and the "
13729 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013730 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 -060013731
Chris Forbesc97d98e2015-05-25 11:13:31 +120013732 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013733 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013734
13735 VkVertexInputBindingDescription input_binding;
13736 memset(&input_binding, 0, sizeof(input_binding));
13737
13738 VkVertexInputAttributeDescription input_attrib;
13739 memset(&input_attrib, 0, sizeof(input_attrib));
13740 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13741
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013742 char const *vsSource =
13743 "#version 450\n"
13744 "\n"
13745 "layout(location=0) in int x;\n" /* attrib provided float */
13746 "out gl_PerVertex {\n"
13747 " vec4 gl_Position;\n"
13748 "};\n"
13749 "void main(){\n"
13750 " gl_Position = vec4(x);\n"
13751 "}\n";
13752 char const *fsSource =
13753 "#version 450\n"
13754 "\n"
13755 "layout(location=0) out vec4 color;\n"
13756 "void main(){\n"
13757 " color = vec4(1);\n"
13758 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013759
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013760 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13761 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013762
13763 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013764 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013765 pipe.AddShader(&vs);
13766 pipe.AddShader(&fs);
13767
13768 pipe.AddVertexInputBindings(&input_binding, 1);
13769 pipe.AddVertexInputAttribs(&input_attrib, 1);
13770
Chris Forbesc97d98e2015-05-25 11:13:31 +120013771 VkDescriptorSetObj descriptorSet(m_device);
13772 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013773 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013774
Tony Barbour5781e8f2015-08-04 16:23:11 -060013775 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013776
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013777 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013778}
13779
Chris Forbesc68b43c2016-04-06 11:18:47 +120013780TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013781 TEST_DESCRIPTION(
13782 "Test that an error is produced for a pipeline containing multiple "
13783 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13785 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013786
13787 ASSERT_NO_FATAL_FAILURE(InitState());
13788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13789
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013790 char const *vsSource =
13791 "#version 450\n"
13792 "\n"
13793 "out gl_PerVertex {\n"
13794 " vec4 gl_Position;\n"
13795 "};\n"
13796 "void main(){\n"
13797 " gl_Position = vec4(1);\n"
13798 "}\n";
13799 char const *fsSource =
13800 "#version 450\n"
13801 "\n"
13802 "layout(location=0) out vec4 color;\n"
13803 "void main(){\n"
13804 " color = vec4(1);\n"
13805 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013806
13807 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13808 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13809
13810 VkPipelineObj pipe(m_device);
13811 pipe.AddColorAttachment();
13812 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013813 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013814 pipe.AddShader(&fs);
13815
13816 VkDescriptorSetObj descriptorSet(m_device);
13817 descriptorSet.AppendDummy();
13818 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13819
13820 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13821
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013822 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013823}
13824
Chris Forbes82ff92a2016-09-09 10:50:24 +120013825TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120013827
13828 ASSERT_NO_FATAL_FAILURE(InitState());
13829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13830
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013831 char const *vsSource =
13832 "#version 450\n"
13833 "out gl_PerVertex {\n"
13834 " vec4 gl_Position;\n"
13835 "};\n"
13836 "void main(){\n"
13837 " gl_Position = vec4(0);\n"
13838 "}\n";
13839 char const *fsSource =
13840 "#version 450\n"
13841 "\n"
13842 "layout(location=0) out vec4 color;\n"
13843 "void main(){\n"
13844 " color = vec4(1);\n"
13845 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120013846
13847 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13848 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13849
13850 VkPipelineObj pipe(m_device);
13851 pipe.AddColorAttachment();
13852 pipe.AddShader(&vs);
13853 pipe.AddShader(&fs);
13854
13855 VkDescriptorSetObj descriptorSet(m_device);
13856 descriptorSet.AppendDummy();
13857 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13858
13859 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13860
13861 m_errorMonitor->VerifyFound();
13862}
13863
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013864TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13866 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13867 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013868
13869 ASSERT_NO_FATAL_FAILURE(InitState());
13870 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13871
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013872 char const *vsSource =
13873 "#version 450\n"
13874 "void main(){ gl_Position = vec4(0); }\n";
13875 char const *fsSource =
13876 "#version 450\n"
13877 "\n"
13878 "layout(location=0) out vec4 color;\n"
13879 "void main(){\n"
13880 " color = vec4(1);\n"
13881 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013882
13883 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13884 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13885
13886 VkPipelineObj pipe(m_device);
13887 pipe.AddColorAttachment();
13888 pipe.AddShader(&vs);
13889 pipe.AddShader(&fs);
13890
13891 VkDescriptorSetObj descriptorSet(m_device);
13892 descriptorSet.AppendDummy();
13893 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13894
13895 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013896 {
13897 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13898 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
13899 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013900 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013901 {
13902 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13903 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
13904 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013905 },
13906 };
13907 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013908 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013909 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013910 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
13911 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013912 VkRenderPass rp;
13913 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13914 ASSERT_VK_SUCCESS(err);
13915
13916 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13917
13918 m_errorMonitor->VerifyFound();
13919
13920 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13921}
13922
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013923TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013924 TEST_DESCRIPTION(
13925 "Test that an error is produced for a variable output from "
13926 "the TCS without the patch decoration, but consumed in the TES "
13927 "with the decoration.");
13928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13929 "is per-vertex in tessellation control shader stage "
13930 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013931
13932 ASSERT_NO_FATAL_FAILURE(InitState());
13933 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13934
Chris Forbesc1e852d2016-04-04 19:26:42 +120013935 if (!m_device->phy().features().tessellationShader) {
13936 printf("Device does not support tessellation shaders; skipped.\n");
13937 return;
13938 }
13939
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013940 char const *vsSource =
13941 "#version 450\n"
13942 "void main(){}\n";
13943 char const *tcsSource =
13944 "#version 450\n"
13945 "layout(location=0) out int x[];\n"
13946 "layout(vertices=3) out;\n"
13947 "void main(){\n"
13948 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13949 " gl_TessLevelInner[0] = 1;\n"
13950 " x[gl_InvocationID] = gl_InvocationID;\n"
13951 "}\n";
13952 char const *tesSource =
13953 "#version 450\n"
13954 "layout(triangles, equal_spacing, cw) in;\n"
13955 "layout(location=0) patch in int x;\n"
13956 "out gl_PerVertex { vec4 gl_Position; };\n"
13957 "void main(){\n"
13958 " gl_Position.xyz = gl_TessCoord;\n"
13959 " gl_Position.w = x;\n"
13960 "}\n";
13961 char const *fsSource =
13962 "#version 450\n"
13963 "layout(location=0) out vec4 color;\n"
13964 "void main(){\n"
13965 " color = vec4(1);\n"
13966 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013967
13968 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13969 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13970 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13971 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13972
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013973 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13974 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013975
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013976 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013977
13978 VkPipelineObj pipe(m_device);
13979 pipe.SetInputAssembly(&iasci);
13980 pipe.SetTessellation(&tsci);
13981 pipe.AddColorAttachment();
13982 pipe.AddShader(&vs);
13983 pipe.AddShader(&tcs);
13984 pipe.AddShader(&tes);
13985 pipe.AddShader(&fs);
13986
13987 VkDescriptorSetObj descriptorSet(m_device);
13988 descriptorSet.AppendDummy();
13989 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13990
13991 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13992
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013993 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013994}
13995
Karl Schultz6addd812016-02-02 17:17:23 -070013996TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013997 TEST_DESCRIPTION(
13998 "Test that an error is produced for a vertex attribute setup where multiple "
13999 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14001 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014002
Chris Forbes280ba2c2015-06-12 11:16:41 +120014003 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014005
14006 /* Two binding descriptions for binding 0 */
14007 VkVertexInputBindingDescription input_bindings[2];
14008 memset(input_bindings, 0, sizeof(input_bindings));
14009
14010 VkVertexInputAttributeDescription input_attrib;
14011 memset(&input_attrib, 0, sizeof(input_attrib));
14012 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14013
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014014 char const *vsSource =
14015 "#version 450\n"
14016 "\n"
14017 "layout(location=0) in float x;\n" /* attrib provided float */
14018 "out gl_PerVertex {\n"
14019 " vec4 gl_Position;\n"
14020 "};\n"
14021 "void main(){\n"
14022 " gl_Position = vec4(x);\n"
14023 "}\n";
14024 char const *fsSource =
14025 "#version 450\n"
14026 "\n"
14027 "layout(location=0) out vec4 color;\n"
14028 "void main(){\n"
14029 " color = vec4(1);\n"
14030 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014031
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014032 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14033 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014034
14035 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014036 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014037 pipe.AddShader(&vs);
14038 pipe.AddShader(&fs);
14039
14040 pipe.AddVertexInputBindings(input_bindings, 2);
14041 pipe.AddVertexInputAttribs(&input_attrib, 1);
14042
Chris Forbes280ba2c2015-06-12 11:16:41 +120014043 VkDescriptorSetObj descriptorSet(m_device);
14044 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014045 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014046
Tony Barbour5781e8f2015-08-04 16:23:11 -060014047 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014048
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014049 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014050}
Chris Forbes8f68b562015-05-25 11:13:32 +120014051
Karl Schultz6addd812016-02-02 17:17:23 -070014052TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014053 TEST_DESCRIPTION(
14054 "Test that an error is produced for a fragment shader which does not "
14055 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014057
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014058 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014059
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014060 char const *vsSource =
14061 "#version 450\n"
14062 "\n"
14063 "out gl_PerVertex {\n"
14064 " vec4 gl_Position;\n"
14065 "};\n"
14066 "void main(){\n"
14067 " gl_Position = vec4(1);\n"
14068 "}\n";
14069 char const *fsSource =
14070 "#version 450\n"
14071 "\n"
14072 "void main(){\n"
14073 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014074
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014075 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14076 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014077
14078 VkPipelineObj pipe(m_device);
14079 pipe.AddShader(&vs);
14080 pipe.AddShader(&fs);
14081
Chia-I Wu08accc62015-07-07 11:50:03 +080014082 /* set up CB 0, not written */
14083 pipe.AddColorAttachment();
14084 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014085
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014086 VkDescriptorSetObj descriptorSet(m_device);
14087 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014088 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014089
Tony Barbour5781e8f2015-08-04 16:23:11 -060014090 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014091
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014092 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014093}
14094
Karl Schultz6addd812016-02-02 17:17:23 -070014095TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014096 TEST_DESCRIPTION(
14097 "Test that a warning is produced for a fragment shader which provides a spurious "
14098 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014100 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014101
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014102 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014103
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014104 char const *vsSource =
14105 "#version 450\n"
14106 "\n"
14107 "out gl_PerVertex {\n"
14108 " vec4 gl_Position;\n"
14109 "};\n"
14110 "void main(){\n"
14111 " gl_Position = vec4(1);\n"
14112 "}\n";
14113 char const *fsSource =
14114 "#version 450\n"
14115 "\n"
14116 "layout(location=0) out vec4 x;\n"
14117 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14118 "void main(){\n"
14119 " x = vec4(1);\n"
14120 " y = vec4(1);\n"
14121 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014122
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014123 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14124 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014125
14126 VkPipelineObj pipe(m_device);
14127 pipe.AddShader(&vs);
14128 pipe.AddShader(&fs);
14129
Chia-I Wu08accc62015-07-07 11:50:03 +080014130 /* set up CB 0, not written */
14131 pipe.AddColorAttachment();
14132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014133 /* FS writes CB 1, but we don't configure it */
14134
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014135 VkDescriptorSetObj descriptorSet(m_device);
14136 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014137 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014138
Tony Barbour5781e8f2015-08-04 16:23:11 -060014139 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014140
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014141 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014142}
14143
Karl Schultz6addd812016-02-02 17:17:23 -070014144TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014145 TEST_DESCRIPTION(
14146 "Test that an error is produced for a mismatch between the fundamental "
14147 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014149
Chris Forbesa36d69e2015-05-25 11:13:44 +120014150 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014151
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014152 char const *vsSource =
14153 "#version 450\n"
14154 "\n"
14155 "out gl_PerVertex {\n"
14156 " vec4 gl_Position;\n"
14157 "};\n"
14158 "void main(){\n"
14159 " gl_Position = vec4(1);\n"
14160 "}\n";
14161 char const *fsSource =
14162 "#version 450\n"
14163 "\n"
14164 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14165 "void main(){\n"
14166 " x = ivec4(1);\n"
14167 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014168
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014169 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14170 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014171
14172 VkPipelineObj pipe(m_device);
14173 pipe.AddShader(&vs);
14174 pipe.AddShader(&fs);
14175
Chia-I Wu08accc62015-07-07 11:50:03 +080014176 /* set up CB 0; type is UNORM by default */
14177 pipe.AddColorAttachment();
14178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014179
Chris Forbesa36d69e2015-05-25 11:13:44 +120014180 VkDescriptorSetObj descriptorSet(m_device);
14181 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014182 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014183
Tony Barbour5781e8f2015-08-04 16:23:11 -060014184 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014185
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014186 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014187}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014188
Karl Schultz6addd812016-02-02 17:17:23 -070014189TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014190 TEST_DESCRIPTION(
14191 "Test that an error is produced for a shader consuming a uniform "
14192 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014194
Chris Forbes556c76c2015-08-14 12:04:59 +120014195 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014196
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014197 char const *vsSource =
14198 "#version 450\n"
14199 "\n"
14200 "out gl_PerVertex {\n"
14201 " vec4 gl_Position;\n"
14202 "};\n"
14203 "void main(){\n"
14204 " gl_Position = vec4(1);\n"
14205 "}\n";
14206 char const *fsSource =
14207 "#version 450\n"
14208 "\n"
14209 "layout(location=0) out vec4 x;\n"
14210 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14211 "void main(){\n"
14212 " x = vec4(bar.y);\n"
14213 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014214
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014215 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14216 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014217
Chris Forbes556c76c2015-08-14 12:04:59 +120014218 VkPipelineObj pipe(m_device);
14219 pipe.AddShader(&vs);
14220 pipe.AddShader(&fs);
14221
14222 /* set up CB 0; type is UNORM by default */
14223 pipe.AddColorAttachment();
14224 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14225
14226 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014227 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014228
14229 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14230
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014231 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014232}
14233
Chris Forbes5c59e902016-02-26 16:56:09 +130014234TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014235 TEST_DESCRIPTION(
14236 "Test that an error is produced for a shader consuming push constants "
14237 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014239
14240 ASSERT_NO_FATAL_FAILURE(InitState());
14241
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014242 char const *vsSource =
14243 "#version 450\n"
14244 "\n"
14245 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14246 "out gl_PerVertex {\n"
14247 " vec4 gl_Position;\n"
14248 "};\n"
14249 "void main(){\n"
14250 " gl_Position = vec4(consts.x);\n"
14251 "}\n";
14252 char const *fsSource =
14253 "#version 450\n"
14254 "\n"
14255 "layout(location=0) out vec4 x;\n"
14256 "void main(){\n"
14257 " x = vec4(1);\n"
14258 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014259
14260 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14261 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14262
14263 VkPipelineObj pipe(m_device);
14264 pipe.AddShader(&vs);
14265 pipe.AddShader(&fs);
14266
14267 /* set up CB 0; type is UNORM by default */
14268 pipe.AddColorAttachment();
14269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14270
14271 VkDescriptorSetObj descriptorSet(m_device);
14272 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14273
14274 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14275
14276 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014277 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014278}
14279
Chris Forbes3fb17902016-08-22 14:57:55 +120014280TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014281 TEST_DESCRIPTION(
14282 "Test that an error is produced for a shader consuming an input attachment "
14283 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14285 "consumes input attachment index 0 but not provided in subpass");
14286
14287 ASSERT_NO_FATAL_FAILURE(InitState());
14288
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014289 char const *vsSource =
14290 "#version 450\n"
14291 "\n"
14292 "out gl_PerVertex {\n"
14293 " vec4 gl_Position;\n"
14294 "};\n"
14295 "void main(){\n"
14296 " gl_Position = vec4(1);\n"
14297 "}\n";
14298 char const *fsSource =
14299 "#version 450\n"
14300 "\n"
14301 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14302 "layout(location=0) out vec4 color;\n"
14303 "void main() {\n"
14304 " color = subpassLoad(x);\n"
14305 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014306
14307 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14308 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14309
14310 VkPipelineObj pipe(m_device);
14311 pipe.AddShader(&vs);
14312 pipe.AddShader(&fs);
14313 pipe.AddColorAttachment();
14314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14315
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014316 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14317 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014318 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014319 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014320 ASSERT_VK_SUCCESS(err);
14321
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014322 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014323 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014324 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014325 ASSERT_VK_SUCCESS(err);
14326
14327 // error here.
14328 pipe.CreateVKPipeline(pl, renderPass());
14329
14330 m_errorMonitor->VerifyFound();
14331
14332 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14333 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14334}
14335
Chris Forbes5a9a0472016-08-22 16:02:09 +120014336TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014337 TEST_DESCRIPTION(
14338 "Test that an error is produced for a shader consuming an input attachment "
14339 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120014340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14341 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14342
14343 ASSERT_NO_FATAL_FAILURE(InitState());
14344
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014345 char const *vsSource =
14346 "#version 450\n"
14347 "\n"
14348 "out gl_PerVertex {\n"
14349 " vec4 gl_Position;\n"
14350 "};\n"
14351 "void main(){\n"
14352 " gl_Position = vec4(1);\n"
14353 "}\n";
14354 char const *fsSource =
14355 "#version 450\n"
14356 "\n"
14357 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14358 "layout(location=0) out vec4 color;\n"
14359 "void main() {\n"
14360 " color = subpassLoad(x);\n"
14361 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014362
14363 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14364 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14365
14366 VkPipelineObj pipe(m_device);
14367 pipe.AddShader(&vs);
14368 pipe.AddShader(&fs);
14369 pipe.AddColorAttachment();
14370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014372 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14373 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014374 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014375 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014376 ASSERT_VK_SUCCESS(err);
14377
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014378 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014379 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014380 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014381 ASSERT_VK_SUCCESS(err);
14382
14383 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014384 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14385 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14386 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14387 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14388 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 +120014389 };
14390 VkAttachmentReference color = {
14391 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14392 };
14393 VkAttachmentReference input = {
14394 1, VK_IMAGE_LAYOUT_GENERAL,
14395 };
14396
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014397 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014398
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014399 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014400 VkRenderPass rp;
14401 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14402 ASSERT_VK_SUCCESS(err);
14403
14404 // error here.
14405 pipe.CreateVKPipeline(pl, rp);
14406
14407 m_errorMonitor->VerifyFound();
14408
14409 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14410 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14411 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14412}
14413
Chris Forbes541f7b02016-08-22 15:30:27 +120014414TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014415 TEST_DESCRIPTION(
14416 "Test that an error is produced for a shader consuming an input attachment "
14417 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120014418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070014419 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120014420
14421 ASSERT_NO_FATAL_FAILURE(InitState());
14422
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014423 char const *vsSource =
14424 "#version 450\n"
14425 "\n"
14426 "out gl_PerVertex {\n"
14427 " vec4 gl_Position;\n"
14428 "};\n"
14429 "void main(){\n"
14430 " gl_Position = vec4(1);\n"
14431 "}\n";
14432 char const *fsSource =
14433 "#version 450\n"
14434 "\n"
14435 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
14436 "layout(location=0) out vec4 color;\n"
14437 "void main() {\n"
14438 " color = subpassLoad(xs[0]);\n"
14439 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014440
14441 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14442 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14443
14444 VkPipelineObj pipe(m_device);
14445 pipe.AddShader(&vs);
14446 pipe.AddShader(&fs);
14447 pipe.AddColorAttachment();
14448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014450 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14451 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014452 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014453 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014454 ASSERT_VK_SUCCESS(err);
14455
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014456 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014457 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014458 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014459 ASSERT_VK_SUCCESS(err);
14460
14461 // error here.
14462 pipe.CreateVKPipeline(pl, renderPass());
14463
14464 m_errorMonitor->VerifyFound();
14465
14466 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14467 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14468}
14469
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014470TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014471 TEST_DESCRIPTION(
14472 "Test that an error is produced for a compute pipeline consuming a "
14473 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014475
14476 ASSERT_NO_FATAL_FAILURE(InitState());
14477
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014478 char const *csSource =
14479 "#version 450\n"
14480 "\n"
14481 "layout(local_size_x=1) in;\n"
14482 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14483 "void main(){\n"
14484 " x = vec4(1);\n"
14485 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014486
14487 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14488
14489 VkDescriptorSetObj descriptorSet(m_device);
14490 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014492 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14493 nullptr,
14494 0,
14495 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14496 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14497 descriptorSet.GetPipelineLayout(),
14498 VK_NULL_HANDLE,
14499 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014500
14501 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014502 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014503
14504 m_errorMonitor->VerifyFound();
14505
14506 if (err == VK_SUCCESS) {
14507 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14508 }
14509}
14510
Chris Forbes22a9b092016-07-19 14:34:05 +120014511TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014512 TEST_DESCRIPTION(
14513 "Test that an error is produced for a pipeline consuming a "
14514 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14516 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014517
14518 ASSERT_NO_FATAL_FAILURE(InitState());
14519
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014520 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14521 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014522 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014523 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014524 ASSERT_VK_SUCCESS(err);
14525
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014526 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014527 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014528 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014529 ASSERT_VK_SUCCESS(err);
14530
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014531 char const *csSource =
14532 "#version 450\n"
14533 "\n"
14534 "layout(local_size_x=1) in;\n"
14535 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14536 "void main() {\n"
14537 " x.x = 1.0f;\n"
14538 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014539 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14540
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014541 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14542 nullptr,
14543 0,
14544 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14545 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14546 pl,
14547 VK_NULL_HANDLE,
14548 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014549
14550 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014551 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014552
14553 m_errorMonitor->VerifyFound();
14554
14555 if (err == VK_SUCCESS) {
14556 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14557 }
14558
14559 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14560 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14561}
14562
Chris Forbes50020592016-07-27 13:52:41 +120014563TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014564 TEST_DESCRIPTION(
14565 "Test that an error is produced when an image view type "
14566 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120014567
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014568 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 +120014569
14570 ASSERT_NO_FATAL_FAILURE(InitState());
14571 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14572
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014573 char const *vsSource =
14574 "#version 450\n"
14575 "\n"
14576 "out gl_PerVertex { vec4 gl_Position; };\n"
14577 "void main() { gl_Position = vec4(0); }\n";
14578 char const *fsSource =
14579 "#version 450\n"
14580 "\n"
14581 "layout(set=0, binding=0) uniform sampler3D s;\n"
14582 "layout(location=0) out vec4 color;\n"
14583 "void main() {\n"
14584 " color = texture(s, vec3(0));\n"
14585 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014586 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14587 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14588
14589 VkPipelineObj pipe(m_device);
14590 pipe.AddShader(&vs);
14591 pipe.AddShader(&fs);
14592 pipe.AddColorAttachment();
14593
14594 VkTextureObj texture(m_device, nullptr);
14595 VkSamplerObj sampler(m_device);
14596
14597 VkDescriptorSetObj descriptorSet(m_device);
14598 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14599 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14600
14601 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14602 ASSERT_VK_SUCCESS(err);
14603
Tony Barbour552f6c02016-12-21 14:34:07 -070014604 m_commandBuffer->BeginCommandBuffer();
14605 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014606
14607 m_commandBuffer->BindPipeline(pipe);
14608 m_commandBuffer->BindDescriptorSet(descriptorSet);
14609
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014610 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014611 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014612 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014613 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14614
14615 // error produced here.
14616 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14617
14618 m_errorMonitor->VerifyFound();
14619
Tony Barbour552f6c02016-12-21 14:34:07 -070014620 m_commandBuffer->EndRenderPass();
14621 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014622}
14623
Chris Forbes5533bfc2016-07-27 14:12:34 +120014624TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014625 TEST_DESCRIPTION(
14626 "Test that an error is produced when a multisampled images "
14627 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014628
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014630
14631 ASSERT_NO_FATAL_FAILURE(InitState());
14632 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14633
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014634 char const *vsSource =
14635 "#version 450\n"
14636 "\n"
14637 "out gl_PerVertex { vec4 gl_Position; };\n"
14638 "void main() { gl_Position = vec4(0); }\n";
14639 char const *fsSource =
14640 "#version 450\n"
14641 "\n"
14642 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14643 "layout(location=0) out vec4 color;\n"
14644 "void main() {\n"
14645 " color = texelFetch(s, ivec2(0), 0);\n"
14646 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014647 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14648 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14649
14650 VkPipelineObj pipe(m_device);
14651 pipe.AddShader(&vs);
14652 pipe.AddShader(&fs);
14653 pipe.AddColorAttachment();
14654
14655 VkTextureObj texture(m_device, nullptr);
14656 VkSamplerObj sampler(m_device);
14657
14658 VkDescriptorSetObj descriptorSet(m_device);
14659 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14660 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14661
14662 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14663 ASSERT_VK_SUCCESS(err);
14664
Tony Barbour552f6c02016-12-21 14:34:07 -070014665 m_commandBuffer->BeginCommandBuffer();
14666 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014667
14668 m_commandBuffer->BindPipeline(pipe);
14669 m_commandBuffer->BindDescriptorSet(descriptorSet);
14670
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014671 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014672 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014673 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014674 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14675
14676 // error produced here.
14677 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14678
14679 m_errorMonitor->VerifyFound();
14680
Tony Barbour552f6c02016-12-21 14:34:07 -070014681 m_commandBuffer->EndRenderPass();
14682 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014683}
14684
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014685#endif // SHADER_CHECKER_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014686
14687#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014688TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014690
14691 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014692
14693 // Create an image
14694 VkImage image;
14695
Karl Schultz6addd812016-02-02 17:17:23 -070014696 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14697 const int32_t tex_width = 32;
14698 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014699
14700 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014701 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14702 image_create_info.pNext = NULL;
14703 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14704 image_create_info.format = tex_format;
14705 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014706 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014707 image_create_info.extent.depth = 1;
14708 image_create_info.mipLevels = 1;
14709 image_create_info.arrayLayers = 1;
14710 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14711 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14712 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14713 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014714
14715 // Introduce error by sending down a bogus width extent
14716 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014717 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014718
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014719 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014720}
14721
Mark Youngc48c4c12016-04-11 14:26:49 -060014722TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070014723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060014724
14725 ASSERT_NO_FATAL_FAILURE(InitState());
14726
14727 // Create an image
14728 VkImage image;
14729
14730 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14731 const int32_t tex_width = 32;
14732 const int32_t tex_height = 32;
14733
14734 VkImageCreateInfo image_create_info = {};
14735 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14736 image_create_info.pNext = NULL;
14737 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14738 image_create_info.format = tex_format;
14739 image_create_info.extent.width = tex_width;
14740 image_create_info.extent.height = tex_height;
14741 image_create_info.extent.depth = 1;
14742 image_create_info.mipLevels = 1;
14743 image_create_info.arrayLayers = 1;
14744 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14745 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14746 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14747 image_create_info.flags = 0;
14748
14749 // Introduce error by sending down a bogus width extent
14750 image_create_info.extent.width = 0;
14751 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14752
14753 m_errorMonitor->VerifyFound();
14754}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014755#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014756
Tobin Ehliscde08892015-09-22 10:11:37 -060014757#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014758
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014759TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014760 TEST_DESCRIPTION(
14761 "Create a render pass with an attachment description "
14762 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014763
14764 ASSERT_NO_FATAL_FAILURE(InitState());
14765 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14766
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014768
14769 VkAttachmentReference color_attach = {};
14770 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14771 color_attach.attachment = 0;
14772 VkSubpassDescription subpass = {};
14773 subpass.colorAttachmentCount = 1;
14774 subpass.pColorAttachments = &color_attach;
14775
14776 VkRenderPassCreateInfo rpci = {};
14777 rpci.subpassCount = 1;
14778 rpci.pSubpasses = &subpass;
14779 rpci.attachmentCount = 1;
14780 VkAttachmentDescription attach_desc = {};
14781 attach_desc.format = VK_FORMAT_UNDEFINED;
14782 rpci.pAttachments = &attach_desc;
14783 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14784 VkRenderPass rp;
14785 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14786
14787 m_errorMonitor->VerifyFound();
14788
14789 if (result == VK_SUCCESS) {
14790 vkDestroyRenderPass(m_device->device(), rp, NULL);
14791 }
14792}
14793
Karl Schultz6addd812016-02-02 17:17:23 -070014794TEST_F(VkLayerTest, InvalidImageView) {
14795 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014796
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014798
Tobin Ehliscde08892015-09-22 10:11:37 -060014799 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014800
Mike Stroyana3082432015-09-25 13:39:21 -060014801 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014802 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014803
Karl Schultz6addd812016-02-02 17:17:23 -070014804 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14805 const int32_t tex_width = 32;
14806 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014807
14808 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014809 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14810 image_create_info.pNext = NULL;
14811 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14812 image_create_info.format = tex_format;
14813 image_create_info.extent.width = tex_width;
14814 image_create_info.extent.height = tex_height;
14815 image_create_info.extent.depth = 1;
14816 image_create_info.mipLevels = 1;
14817 image_create_info.arrayLayers = 1;
14818 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14819 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14820 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14821 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014822
Chia-I Wuf7458c52015-10-26 21:10:41 +080014823 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014824 ASSERT_VK_SUCCESS(err);
14825
14826 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014827 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014828 image_view_create_info.image = image;
14829 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14830 image_view_create_info.format = tex_format;
14831 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014832 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070014833 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014834 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014835
14836 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014837 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014838
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014839 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014840 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014841}
Mike Stroyana3082432015-09-25 13:39:21 -060014842
Mark Youngd339ba32016-05-30 13:28:35 -060014843TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14844 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014846 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014847
14848 ASSERT_NO_FATAL_FAILURE(InitState());
14849
14850 // Create an image and try to create a view with no memory backing the image
14851 VkImage image;
14852
14853 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14854 const int32_t tex_width = 32;
14855 const int32_t tex_height = 32;
14856
14857 VkImageCreateInfo image_create_info = {};
14858 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14859 image_create_info.pNext = NULL;
14860 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14861 image_create_info.format = tex_format;
14862 image_create_info.extent.width = tex_width;
14863 image_create_info.extent.height = tex_height;
14864 image_create_info.extent.depth = 1;
14865 image_create_info.mipLevels = 1;
14866 image_create_info.arrayLayers = 1;
14867 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14868 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14869 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14870 image_create_info.flags = 0;
14871
14872 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14873 ASSERT_VK_SUCCESS(err);
14874
14875 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014876 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014877 image_view_create_info.image = image;
14878 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14879 image_view_create_info.format = tex_format;
14880 image_view_create_info.subresourceRange.layerCount = 1;
14881 image_view_create_info.subresourceRange.baseMipLevel = 0;
14882 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014883 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014884
14885 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014886 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014887
14888 m_errorMonitor->VerifyFound();
14889 vkDestroyImage(m_device->device(), image, NULL);
14890 // If last error is success, it still created the view, so delete it.
14891 if (err == VK_SUCCESS) {
14892 vkDestroyImageView(m_device->device(), view, NULL);
14893 }
Mark Youngd339ba32016-05-30 13:28:35 -060014894}
14895
Karl Schultz6addd812016-02-02 17:17:23 -070014896TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014897 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014899
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014900 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014901
Karl Schultz6addd812016-02-02 17:17:23 -070014902 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014903 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014904 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014905 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014906
14907 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014908 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014909 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014910 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14911 image_view_create_info.format = tex_format;
14912 image_view_create_info.subresourceRange.baseMipLevel = 0;
14913 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014914 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014915 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014916 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014917
14918 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014919 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014920
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014921 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014922}
14923
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014924TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014925 VkResult err;
14926 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014927
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014929
Mike Stroyana3082432015-09-25 13:39:21 -060014930 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014931
14932 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014933 VkImage srcImage;
14934 VkImage dstImage;
14935 VkDeviceMemory srcMem;
14936 VkDeviceMemory destMem;
14937 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014938
14939 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014940 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14941 image_create_info.pNext = NULL;
14942 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14943 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14944 image_create_info.extent.width = 32;
14945 image_create_info.extent.height = 32;
14946 image_create_info.extent.depth = 1;
14947 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014948 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014949 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14950 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14951 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14952 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014953
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014954 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014955 ASSERT_VK_SUCCESS(err);
14956
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014957 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014958 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014959 ASSERT_VK_SUCCESS(err);
14960
14961 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014962 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014963 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14964 memAlloc.pNext = NULL;
14965 memAlloc.allocationSize = 0;
14966 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014967
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014968 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014969 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014970 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014971 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014972 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014973 ASSERT_VK_SUCCESS(err);
14974
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014975 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014976 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014977 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014978 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014979 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014980 ASSERT_VK_SUCCESS(err);
14981
14982 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14983 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014984 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014985 ASSERT_VK_SUCCESS(err);
14986
Tony Barbour552f6c02016-12-21 14:34:07 -070014987 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014988 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014989 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014990 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014991 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014992 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014993 copyRegion.srcOffset.x = 0;
14994 copyRegion.srcOffset.y = 0;
14995 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014996 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014997 copyRegion.dstSubresource.mipLevel = 0;
14998 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014999 // Introduce failure by forcing the dst layerCount to differ from src
15000 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015001 copyRegion.dstOffset.x = 0;
15002 copyRegion.dstOffset.y = 0;
15003 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015004 copyRegion.extent.width = 1;
15005 copyRegion.extent.height = 1;
15006 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015007 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015008 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015009
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015010 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015011
Chia-I Wuf7458c52015-10-26 21:10:41 +080015012 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015013 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015014 vkFreeMemory(m_device->device(), srcMem, NULL);
15015 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015016}
15017
Tony Barbourd6673642016-05-05 14:46:39 -060015018TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015019 TEST_DESCRIPTION("Creating images with unsuported formats ");
15020
15021 ASSERT_NO_FATAL_FAILURE(InitState());
15022 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15023 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015024 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060015025 VK_IMAGE_TILING_OPTIMAL, 0);
15026 ASSERT_TRUE(image.initialized());
15027
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015028 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015029 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015030 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015031 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15032 image_create_info.format = VK_FORMAT_UNDEFINED;
15033 image_create_info.extent.width = 32;
15034 image_create_info.extent.height = 32;
15035 image_create_info.extent.depth = 1;
15036 image_create_info.mipLevels = 1;
15037 image_create_info.arrayLayers = 1;
15038 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15039 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15040 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15043 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015044
15045 VkImage localImage;
15046 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15047 m_errorMonitor->VerifyFound();
15048
Tony Barbourd6673642016-05-05 14:46:39 -060015049 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015050 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015051 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15052 VkFormat format = static_cast<VkFormat>(f);
15053 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015054 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015055 unsupported = format;
15056 break;
15057 }
15058 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015059
Tony Barbourd6673642016-05-05 14:46:39 -060015060 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015061 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015063
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015064 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015065 m_errorMonitor->VerifyFound();
15066 }
15067}
15068
15069TEST_F(VkLayerTest, ImageLayerViewTests) {
15070 VkResult ret;
15071 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15072
15073 ASSERT_NO_FATAL_FAILURE(InitState());
15074
15075 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015076 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Tony Barbourd6673642016-05-05 14:46:39 -060015077 VK_IMAGE_TILING_OPTIMAL, 0);
15078 ASSERT_TRUE(image.initialized());
15079
15080 VkImageView imgView;
15081 VkImageViewCreateInfo imgViewInfo = {};
15082 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15083 imgViewInfo.image = image.handle();
15084 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15085 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15086 imgViewInfo.subresourceRange.layerCount = 1;
15087 imgViewInfo.subresourceRange.baseMipLevel = 0;
15088 imgViewInfo.subresourceRange.levelCount = 1;
15089 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15090
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015092 // View can't have baseMipLevel >= image's mipLevels - Expect
15093 // VIEW_CREATE_ERROR
15094 imgViewInfo.subresourceRange.baseMipLevel = 1;
15095 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15096 m_errorMonitor->VerifyFound();
15097 imgViewInfo.subresourceRange.baseMipLevel = 0;
15098
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015100 // View can't have baseArrayLayer >= image's arraySize - Expect
15101 // VIEW_CREATE_ERROR
15102 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15103 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15104 m_errorMonitor->VerifyFound();
15105 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15106
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015108 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15109 imgViewInfo.subresourceRange.levelCount = 0;
15110 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15111 m_errorMonitor->VerifyFound();
15112 imgViewInfo.subresourceRange.levelCount = 1;
15113
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015114 m_errorMonitor->SetDesiredFailureMsg(
15115 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15116 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015117 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15118 imgViewInfo.subresourceRange.layerCount = 0;
15119 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15120 m_errorMonitor->VerifyFound();
15121 imgViewInfo.subresourceRange.layerCount = 1;
15122
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15124 "Formats MUST be IDENTICAL unless "
15125 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15126 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015127 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15128 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15129 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15130 m_errorMonitor->VerifyFound();
15131 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15132
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015134 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15135 // VIEW_CREATE_ERROR
15136 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15137 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15138 m_errorMonitor->VerifyFound();
15139 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15140
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015142 // TODO: Update framework to easily passing mutable flag into ImageObj init
15143 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015144 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15145 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15146 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015147 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15148 // VIEW_CREATE_ERROR
15149 VkImageCreateInfo mutImgInfo = image.create_info();
15150 VkImage mutImage;
15151 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015152 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015153 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15154 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15155 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15156 ASSERT_VK_SUCCESS(ret);
15157 imgViewInfo.image = mutImage;
15158 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15159 m_errorMonitor->VerifyFound();
15160 imgViewInfo.image = image.handle();
15161 vkDestroyImage(m_device->handle(), mutImage, NULL);
15162}
15163
15164TEST_F(VkLayerTest, MiscImageLayerTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060015165 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15166
15167 ASSERT_NO_FATAL_FAILURE(InitState());
15168
Rene Lindsay135204f2016-12-22 17:11:09 -070015169 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060015170 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070015171 image.init(128, 128, VK_FORMAT_R16G16B16A16_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015172 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060015173 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060015174 vk_testing::Buffer buffer;
15175 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070015176 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060015177 VkBufferImageCopy region = {};
15178 region.bufferRowLength = 128;
15179 region.bufferImageHeight = 128;
15180 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15181 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070015182 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015183 region.imageExtent.height = 4;
15184 region.imageExtent.width = 4;
15185 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070015186
15187 VkImageObj image2(m_device);
15188 image2.init(128, 128, VK_FORMAT_R8G8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015189 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070015190 ASSERT_TRUE(image2.initialized());
15191 vk_testing::Buffer buffer2;
15192 VkMemoryPropertyFlags reqs2 = 0;
15193 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
15194 VkBufferImageCopy region2 = {};
15195 region2.bufferRowLength = 128;
15196 region2.bufferImageHeight = 128;
15197 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15198 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15199 region2.imageSubresource.layerCount = 1;
15200 region2.imageExtent.height = 4;
15201 region2.imageExtent.width = 4;
15202 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015203 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060015204
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015205 // Image must have offset.z of 0 and extent.depth of 1
15206 // Introduce failure by setting imageExtent.depth to 0
15207 region.imageExtent.depth = 0;
15208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15209 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015210 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015211 m_errorMonitor->VerifyFound();
15212
15213 region.imageExtent.depth = 1;
15214
15215 // Image must have offset.z of 0 and extent.depth of 1
15216 // Introduce failure by setting imageOffset.z to 4
15217 region.imageOffset.z = 4;
15218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15219 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015220 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015221 m_errorMonitor->VerifyFound();
15222
15223 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015224 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15225 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070015226 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015228 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15229 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015230 m_errorMonitor->VerifyFound();
15231
15232 // BufferOffset must be a multiple of 4
15233 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070015234 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070015236 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
15237 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015238 m_errorMonitor->VerifyFound();
15239
15240 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15241 region.bufferOffset = 0;
15242 region.imageExtent.height = 128;
15243 region.imageExtent.width = 128;
15244 // Introduce failure by setting bufferRowLength > 0 but less than width
15245 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015247 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15248 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015249 m_errorMonitor->VerifyFound();
15250
15251 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15252 region.bufferRowLength = 128;
15253 // Introduce failure by setting bufferRowHeight > 0 but less than height
15254 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015256 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15257 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015258 m_errorMonitor->VerifyFound();
15259
15260 region.bufferImageHeight = 128;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15262 "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015263 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060015264 // Expect INVALID_FILTER
15265 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015266 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
15267 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015268 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015269 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15270 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015271 VkImageBlit blitRegion = {};
15272 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15273 blitRegion.srcSubresource.baseArrayLayer = 0;
15274 blitRegion.srcSubresource.layerCount = 1;
15275 blitRegion.srcSubresource.mipLevel = 0;
15276 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15277 blitRegion.dstSubresource.baseArrayLayer = 0;
15278 blitRegion.dstSubresource.layerCount = 1;
15279 blitRegion.dstSubresource.mipLevel = 0;
15280
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015281 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015282 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060015283 m_errorMonitor->VerifyFound();
15284
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015285 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
15287 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15288 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015289 m_errorMonitor->VerifyFound();
15290
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060015292 VkImageMemoryBarrier img_barrier;
15293 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15294 img_barrier.pNext = NULL;
15295 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15296 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15297 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15298 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15299 img_barrier.image = image.handle();
15300 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15301 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15302 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15303 img_barrier.subresourceRange.baseArrayLayer = 0;
15304 img_barrier.subresourceRange.baseMipLevel = 0;
15305 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
15306 img_barrier.subresourceRange.layerCount = 0;
15307 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015308 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
15309 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060015310 m_errorMonitor->VerifyFound();
15311 img_barrier.subresourceRange.layerCount = 1;
15312}
15313
15314TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060015315 TEST_DESCRIPTION("Exceed the limits of image format ");
15316
Cody Northropc31a84f2016-08-22 10:41:47 -060015317 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060015319 VkImageCreateInfo image_create_info = {};
15320 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15321 image_create_info.pNext = NULL;
15322 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15323 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15324 image_create_info.extent.width = 32;
15325 image_create_info.extent.height = 32;
15326 image_create_info.extent.depth = 1;
15327 image_create_info.mipLevels = 1;
15328 image_create_info.arrayLayers = 1;
15329 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15330 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15331 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15332 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15333 image_create_info.flags = 0;
15334
15335 VkImage nullImg;
15336 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015337 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15338 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070015339 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015340 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15341 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15342 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070015343 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015344
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015346 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15347 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15348 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15349 m_errorMonitor->VerifyFound();
15350 image_create_info.mipLevels = 1;
15351
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015353 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15354 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15355 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15356 m_errorMonitor->VerifyFound();
15357 image_create_info.arrayLayers = 1;
15358
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060015360 int samples = imgFmtProps.sampleCounts >> 1;
15361 image_create_info.samples = (VkSampleCountFlagBits)samples;
15362 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15363 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15364 m_errorMonitor->VerifyFound();
15365 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15366
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15368 "pCreateInfo->initialLayout, must be "
15369 "VK_IMAGE_LAYOUT_UNDEFINED or "
15370 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060015371 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15372 // Expect INVALID_LAYOUT
15373 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15374 m_errorMonitor->VerifyFound();
15375 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15376}
15377
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015378TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015379 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015381
15382 ASSERT_NO_FATAL_FAILURE(InitState());
15383
15384 VkImageObj src_image(m_device);
15385 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15386 VkImageObj dst_image(m_device);
15387 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15388
Tony Barbour552f6c02016-12-21 14:34:07 -070015389 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015390 VkImageCopy copy_region;
15391 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15392 copy_region.srcSubresource.mipLevel = 0;
15393 copy_region.srcSubresource.baseArrayLayer = 0;
15394 copy_region.srcSubresource.layerCount = 0;
15395 copy_region.srcOffset.x = 0;
15396 copy_region.srcOffset.y = 0;
15397 copy_region.srcOffset.z = 0;
15398 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15399 copy_region.dstSubresource.mipLevel = 0;
15400 copy_region.dstSubresource.baseArrayLayer = 0;
15401 copy_region.dstSubresource.layerCount = 0;
15402 copy_region.dstOffset.x = 0;
15403 copy_region.dstOffset.y = 0;
15404 copy_region.dstOffset.z = 0;
15405 copy_region.extent.width = 64;
15406 copy_region.extent.height = 64;
15407 copy_region.extent.depth = 1;
15408 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15409 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015410 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015411
15412 m_errorMonitor->VerifyFound();
15413}
15414
15415TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015416 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015418
15419 ASSERT_NO_FATAL_FAILURE(InitState());
15420
15421 VkImageObj src_image(m_device);
15422 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15423 VkImageObj dst_image(m_device);
15424 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15425
Tony Barbour552f6c02016-12-21 14:34:07 -070015426 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015427 VkImageCopy copy_region;
15428 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15429 copy_region.srcSubresource.mipLevel = 0;
15430 copy_region.srcSubresource.baseArrayLayer = 0;
15431 copy_region.srcSubresource.layerCount = 0;
15432 copy_region.srcOffset.x = 0;
15433 copy_region.srcOffset.y = 0;
15434 copy_region.srcOffset.z = 0;
15435 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15436 copy_region.dstSubresource.mipLevel = 0;
15437 copy_region.dstSubresource.baseArrayLayer = 0;
15438 copy_region.dstSubresource.layerCount = 0;
15439 copy_region.dstOffset.x = 0;
15440 copy_region.dstOffset.y = 0;
15441 copy_region.dstOffset.z = 0;
15442 copy_region.extent.width = 64;
15443 copy_region.extent.height = 64;
15444 copy_region.extent.depth = 1;
15445 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15446 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015447 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015448
15449 m_errorMonitor->VerifyFound();
15450}
15451
Karl Schultz6addd812016-02-02 17:17:23 -070015452TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015453 VkResult err;
15454 bool pass;
15455
15456 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015458
15459 ASSERT_NO_FATAL_FAILURE(InitState());
15460
15461 // Create two images of different types and try to copy between them
15462 VkImage srcImage;
15463 VkImage dstImage;
15464 VkDeviceMemory srcMem;
15465 VkDeviceMemory destMem;
15466 VkMemoryRequirements memReqs;
15467
15468 VkImageCreateInfo image_create_info = {};
15469 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15470 image_create_info.pNext = NULL;
15471 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15472 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15473 image_create_info.extent.width = 32;
15474 image_create_info.extent.height = 32;
15475 image_create_info.extent.depth = 1;
15476 image_create_info.mipLevels = 1;
15477 image_create_info.arrayLayers = 1;
15478 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15479 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15480 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15481 image_create_info.flags = 0;
15482
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015483 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015484 ASSERT_VK_SUCCESS(err);
15485
15486 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15487 // Introduce failure by creating second image with a different-sized format.
15488 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15489
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015490 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015491 ASSERT_VK_SUCCESS(err);
15492
15493 // Allocate memory
15494 VkMemoryAllocateInfo memAlloc = {};
15495 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15496 memAlloc.pNext = NULL;
15497 memAlloc.allocationSize = 0;
15498 memAlloc.memoryTypeIndex = 0;
15499
15500 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15501 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015502 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015503 ASSERT_TRUE(pass);
15504 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15505 ASSERT_VK_SUCCESS(err);
15506
15507 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15508 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015509 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015510 ASSERT_TRUE(pass);
15511 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15512 ASSERT_VK_SUCCESS(err);
15513
15514 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15515 ASSERT_VK_SUCCESS(err);
15516 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15517 ASSERT_VK_SUCCESS(err);
15518
Tony Barbour552f6c02016-12-21 14:34:07 -070015519 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015520 VkImageCopy copyRegion;
15521 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15522 copyRegion.srcSubresource.mipLevel = 0;
15523 copyRegion.srcSubresource.baseArrayLayer = 0;
15524 copyRegion.srcSubresource.layerCount = 0;
15525 copyRegion.srcOffset.x = 0;
15526 copyRegion.srcOffset.y = 0;
15527 copyRegion.srcOffset.z = 0;
15528 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15529 copyRegion.dstSubresource.mipLevel = 0;
15530 copyRegion.dstSubresource.baseArrayLayer = 0;
15531 copyRegion.dstSubresource.layerCount = 0;
15532 copyRegion.dstOffset.x = 0;
15533 copyRegion.dstOffset.y = 0;
15534 copyRegion.dstOffset.z = 0;
15535 copyRegion.extent.width = 1;
15536 copyRegion.extent.height = 1;
15537 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015538 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015539 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015540
15541 m_errorMonitor->VerifyFound();
15542
15543 vkDestroyImage(m_device->device(), srcImage, NULL);
15544 vkDestroyImage(m_device->device(), dstImage, NULL);
15545 vkFreeMemory(m_device->device(), srcMem, NULL);
15546 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015547}
15548
Karl Schultz6addd812016-02-02 17:17:23 -070015549TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15550 VkResult err;
15551 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015552
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015553 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15555 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015556
Mike Stroyana3082432015-09-25 13:39:21 -060015557 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015558
15559 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015560 VkImage srcImage;
15561 VkImage dstImage;
15562 VkDeviceMemory srcMem;
15563 VkDeviceMemory destMem;
15564 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015565
15566 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015567 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15568 image_create_info.pNext = NULL;
15569 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15570 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15571 image_create_info.extent.width = 32;
15572 image_create_info.extent.height = 32;
15573 image_create_info.extent.depth = 1;
15574 image_create_info.mipLevels = 1;
15575 image_create_info.arrayLayers = 1;
15576 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15577 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15578 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15579 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015581 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015582 ASSERT_VK_SUCCESS(err);
15583
Karl Schultzbdb75952016-04-19 11:36:49 -060015584 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15585
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015586 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015587 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015588 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015589 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015590
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015591 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015592 ASSERT_VK_SUCCESS(err);
15593
15594 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015595 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015596 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15597 memAlloc.pNext = NULL;
15598 memAlloc.allocationSize = 0;
15599 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015600
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015601 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015602 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015603 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015604 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015605 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015606 ASSERT_VK_SUCCESS(err);
15607
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015608 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015609 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015610 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015611 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015612 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015613 ASSERT_VK_SUCCESS(err);
15614
15615 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15616 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015617 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015618 ASSERT_VK_SUCCESS(err);
15619
Tony Barbour552f6c02016-12-21 14:34:07 -070015620 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015621 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015622 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015623 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015624 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015625 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015626 copyRegion.srcOffset.x = 0;
15627 copyRegion.srcOffset.y = 0;
15628 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015629 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015630 copyRegion.dstSubresource.mipLevel = 0;
15631 copyRegion.dstSubresource.baseArrayLayer = 0;
15632 copyRegion.dstSubresource.layerCount = 0;
15633 copyRegion.dstOffset.x = 0;
15634 copyRegion.dstOffset.y = 0;
15635 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015636 copyRegion.extent.width = 1;
15637 copyRegion.extent.height = 1;
15638 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015639 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015640 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015641
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015642 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015643
Chia-I Wuf7458c52015-10-26 21:10:41 +080015644 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015645 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015646 vkFreeMemory(m_device->device(), srcMem, NULL);
15647 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015648}
15649
Karl Schultz6addd812016-02-02 17:17:23 -070015650TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15651 VkResult err;
15652 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15655 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015656
Mike Stroyana3082432015-09-25 13:39:21 -060015657 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015658
15659 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015660 VkImage srcImage;
15661 VkImage dstImage;
15662 VkDeviceMemory srcMem;
15663 VkDeviceMemory destMem;
15664 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015665
15666 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015667 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15668 image_create_info.pNext = NULL;
15669 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15670 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15671 image_create_info.extent.width = 32;
15672 image_create_info.extent.height = 1;
15673 image_create_info.extent.depth = 1;
15674 image_create_info.mipLevels = 1;
15675 image_create_info.arrayLayers = 1;
15676 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15677 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15678 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15679 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015680
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015681 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015682 ASSERT_VK_SUCCESS(err);
15683
Karl Schultz6addd812016-02-02 17:17:23 -070015684 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015685
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015686 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015687 ASSERT_VK_SUCCESS(err);
15688
15689 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015690 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015691 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15692 memAlloc.pNext = NULL;
15693 memAlloc.allocationSize = 0;
15694 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015695
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015696 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015697 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015698 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015699 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015700 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015701 ASSERT_VK_SUCCESS(err);
15702
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015703 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015704 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015705 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015706 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015707 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015708 ASSERT_VK_SUCCESS(err);
15709
15710 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15711 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015712 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015713 ASSERT_VK_SUCCESS(err);
15714
Tony Barbour552f6c02016-12-21 14:34:07 -070015715 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015716 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015717 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15718 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015719 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015720 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015721 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015722 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015723 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015724 resolveRegion.srcOffset.x = 0;
15725 resolveRegion.srcOffset.y = 0;
15726 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015727 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015728 resolveRegion.dstSubresource.mipLevel = 0;
15729 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015730 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015731 resolveRegion.dstOffset.x = 0;
15732 resolveRegion.dstOffset.y = 0;
15733 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015734 resolveRegion.extent.width = 1;
15735 resolveRegion.extent.height = 1;
15736 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015737 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015738 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015739
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015740 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015741
Chia-I Wuf7458c52015-10-26 21:10:41 +080015742 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015743 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015744 vkFreeMemory(m_device->device(), srcMem, NULL);
15745 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015746}
15747
Karl Schultz6addd812016-02-02 17:17:23 -070015748TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15749 VkResult err;
15750 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015751
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15753 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015754
Mike Stroyana3082432015-09-25 13:39:21 -060015755 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015756
Chris Forbesa7530692016-05-08 12:35:39 +120015757 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015758 VkImage srcImage;
15759 VkImage dstImage;
15760 VkDeviceMemory srcMem;
15761 VkDeviceMemory destMem;
15762 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015763
15764 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015765 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15766 image_create_info.pNext = NULL;
15767 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15768 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15769 image_create_info.extent.width = 32;
15770 image_create_info.extent.height = 1;
15771 image_create_info.extent.depth = 1;
15772 image_create_info.mipLevels = 1;
15773 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015774 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015775 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15776 // Note: Some implementations expect color attachment usage for any
15777 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015778 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015779 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015781 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015782 ASSERT_VK_SUCCESS(err);
15783
Karl Schultz6addd812016-02-02 17:17:23 -070015784 // Note: Some implementations expect color attachment usage for any
15785 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015786 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015788 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015789 ASSERT_VK_SUCCESS(err);
15790
15791 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015792 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015793 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15794 memAlloc.pNext = NULL;
15795 memAlloc.allocationSize = 0;
15796 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015797
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015798 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015799 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015800 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015801 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015802 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015803 ASSERT_VK_SUCCESS(err);
15804
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015805 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015806 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015807 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015808 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015809 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015810 ASSERT_VK_SUCCESS(err);
15811
15812 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15813 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015814 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015815 ASSERT_VK_SUCCESS(err);
15816
Tony Barbour552f6c02016-12-21 14:34:07 -070015817 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015818 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015819 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15820 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015821 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015822 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015823 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015824 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015825 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015826 resolveRegion.srcOffset.x = 0;
15827 resolveRegion.srcOffset.y = 0;
15828 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015829 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015830 resolveRegion.dstSubresource.mipLevel = 0;
15831 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015832 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015833 resolveRegion.dstOffset.x = 0;
15834 resolveRegion.dstOffset.y = 0;
15835 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015836 resolveRegion.extent.width = 1;
15837 resolveRegion.extent.height = 1;
15838 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015839 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015840 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015841
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015842 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015843
Chia-I Wuf7458c52015-10-26 21:10:41 +080015844 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015845 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015846 vkFreeMemory(m_device->device(), srcMem, NULL);
15847 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015848}
15849
Karl Schultz6addd812016-02-02 17:17:23 -070015850TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15851 VkResult err;
15852 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015853
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15855 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015856
Mike Stroyana3082432015-09-25 13:39:21 -060015857 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015858
15859 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015860 VkImage srcImage;
15861 VkImage dstImage;
15862 VkDeviceMemory srcMem;
15863 VkDeviceMemory destMem;
15864 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015865
15866 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015867 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15868 image_create_info.pNext = NULL;
15869 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15870 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15871 image_create_info.extent.width = 32;
15872 image_create_info.extent.height = 1;
15873 image_create_info.extent.depth = 1;
15874 image_create_info.mipLevels = 1;
15875 image_create_info.arrayLayers = 1;
15876 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15877 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15878 // Note: Some implementations expect color attachment usage for any
15879 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015880 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015881 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015883 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015884 ASSERT_VK_SUCCESS(err);
15885
Karl Schultz6addd812016-02-02 17:17:23 -070015886 // Set format to something other than source image
15887 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15888 // Note: Some implementations expect color attachment usage for any
15889 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015890 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015891 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015892
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015893 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015894 ASSERT_VK_SUCCESS(err);
15895
15896 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015897 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015898 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15899 memAlloc.pNext = NULL;
15900 memAlloc.allocationSize = 0;
15901 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015902
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015903 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015904 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015905 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015906 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015907 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015908 ASSERT_VK_SUCCESS(err);
15909
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015910 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015911 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015912 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015913 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015914 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015915 ASSERT_VK_SUCCESS(err);
15916
15917 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15918 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015919 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015920 ASSERT_VK_SUCCESS(err);
15921
Tony Barbour552f6c02016-12-21 14:34:07 -070015922 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015923 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015924 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15925 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015926 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015927 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015928 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015929 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015930 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015931 resolveRegion.srcOffset.x = 0;
15932 resolveRegion.srcOffset.y = 0;
15933 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015934 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015935 resolveRegion.dstSubresource.mipLevel = 0;
15936 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015937 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015938 resolveRegion.dstOffset.x = 0;
15939 resolveRegion.dstOffset.y = 0;
15940 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015941 resolveRegion.extent.width = 1;
15942 resolveRegion.extent.height = 1;
15943 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015944 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015945 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015946
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015947 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015948
Chia-I Wuf7458c52015-10-26 21:10:41 +080015949 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015950 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015951 vkFreeMemory(m_device->device(), srcMem, NULL);
15952 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015953}
15954
Karl Schultz6addd812016-02-02 17:17:23 -070015955TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15956 VkResult err;
15957 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15960 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015961
Mike Stroyana3082432015-09-25 13:39:21 -060015962 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015963
15964 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015965 VkImage srcImage;
15966 VkImage dstImage;
15967 VkDeviceMemory srcMem;
15968 VkDeviceMemory destMem;
15969 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015970
15971 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015972 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15973 image_create_info.pNext = NULL;
15974 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15975 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15976 image_create_info.extent.width = 32;
15977 image_create_info.extent.height = 1;
15978 image_create_info.extent.depth = 1;
15979 image_create_info.mipLevels = 1;
15980 image_create_info.arrayLayers = 1;
15981 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15982 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15983 // Note: Some implementations expect color attachment usage for any
15984 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015985 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015986 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015987
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015988 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015989 ASSERT_VK_SUCCESS(err);
15990
Karl Schultz6addd812016-02-02 17:17:23 -070015991 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15992 // Note: Some implementations expect color attachment usage for any
15993 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015994 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015995 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015996
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015997 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015998 ASSERT_VK_SUCCESS(err);
15999
16000 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016001 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016002 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16003 memAlloc.pNext = NULL;
16004 memAlloc.allocationSize = 0;
16005 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016006
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016007 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016008 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016009 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016010 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016011 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016012 ASSERT_VK_SUCCESS(err);
16013
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016014 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016015 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016016 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016017 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016018 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016019 ASSERT_VK_SUCCESS(err);
16020
16021 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16022 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016023 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016024 ASSERT_VK_SUCCESS(err);
16025
Tony Barbour552f6c02016-12-21 14:34:07 -070016026 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016027 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016028 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16029 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016030 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016031 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016032 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016033 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016034 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016035 resolveRegion.srcOffset.x = 0;
16036 resolveRegion.srcOffset.y = 0;
16037 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016038 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016039 resolveRegion.dstSubresource.mipLevel = 0;
16040 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016041 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016042 resolveRegion.dstOffset.x = 0;
16043 resolveRegion.dstOffset.y = 0;
16044 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016045 resolveRegion.extent.width = 1;
16046 resolveRegion.extent.height = 1;
16047 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016048 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016049 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016050
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016051 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016052
Chia-I Wuf7458c52015-10-26 21:10:41 +080016053 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016054 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016055 vkFreeMemory(m_device->device(), srcMem, NULL);
16056 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016057}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016058
Karl Schultz6addd812016-02-02 17:17:23 -070016059TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016060 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016061 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16062 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016063 // The image format check comes 2nd in validation so we trigger it first,
16064 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016065 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16068 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016069
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016070 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016071
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016072 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016073 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16074 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016075
16076 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016077 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16078 ds_pool_ci.pNext = NULL;
16079 ds_pool_ci.maxSets = 1;
16080 ds_pool_ci.poolSizeCount = 1;
16081 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016082
16083 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016084 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016085 ASSERT_VK_SUCCESS(err);
16086
16087 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016088 dsl_binding.binding = 0;
16089 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16090 dsl_binding.descriptorCount = 1;
16091 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16092 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016093
16094 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016095 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16096 ds_layout_ci.pNext = NULL;
16097 ds_layout_ci.bindingCount = 1;
16098 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016099 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016100 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016101 ASSERT_VK_SUCCESS(err);
16102
16103 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016104 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016105 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016106 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016107 alloc_info.descriptorPool = ds_pool;
16108 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016109 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016110 ASSERT_VK_SUCCESS(err);
16111
Karl Schultz6addd812016-02-02 17:17:23 -070016112 VkImage image_bad;
16113 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016114 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016115 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016116 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016117 const int32_t tex_width = 32;
16118 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016119
16120 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016121 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16122 image_create_info.pNext = NULL;
16123 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16124 image_create_info.format = tex_format_bad;
16125 image_create_info.extent.width = tex_width;
16126 image_create_info.extent.height = tex_height;
16127 image_create_info.extent.depth = 1;
16128 image_create_info.mipLevels = 1;
16129 image_create_info.arrayLayers = 1;
16130 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16131 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016132 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016133 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016135 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016136 ASSERT_VK_SUCCESS(err);
16137 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016138 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16139 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016140 ASSERT_VK_SUCCESS(err);
16141
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016142 // ---Bind image memory---
16143 VkMemoryRequirements img_mem_reqs;
16144 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
16145 VkMemoryAllocateInfo image_alloc_info = {};
16146 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16147 image_alloc_info.pNext = NULL;
16148 image_alloc_info.memoryTypeIndex = 0;
16149 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016150 bool pass =
16151 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 -070016152 ASSERT_TRUE(pass);
16153 VkDeviceMemory mem;
16154 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
16155 ASSERT_VK_SUCCESS(err);
16156 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
16157 ASSERT_VK_SUCCESS(err);
16158 // -----------------------
16159
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016160 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016161 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016162 image_view_create_info.image = image_bad;
16163 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16164 image_view_create_info.format = tex_format_bad;
16165 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16166 image_view_create_info.subresourceRange.baseMipLevel = 0;
16167 image_view_create_info.subresourceRange.layerCount = 1;
16168 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016169 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016170
16171 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016172 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016173
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016174 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016175
Chia-I Wuf7458c52015-10-26 21:10:41 +080016176 vkDestroyImage(m_device->device(), image_bad, NULL);
16177 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016178 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16179 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016180
16181 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016182}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016183
16184TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016185 TEST_DESCRIPTION(
16186 "Call ClearColorImage w/ a depth|stencil image and "
16187 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016188
16189 ASSERT_NO_FATAL_FAILURE(InitState());
16190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16191
Tony Barbour552f6c02016-12-21 14:34:07 -070016192 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016193
16194 // Color image
16195 VkClearColorValue clear_color;
16196 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16197 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16198 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16199 const int32_t img_width = 32;
16200 const int32_t img_height = 32;
16201 VkImageCreateInfo image_create_info = {};
16202 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16203 image_create_info.pNext = NULL;
16204 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16205 image_create_info.format = color_format;
16206 image_create_info.extent.width = img_width;
16207 image_create_info.extent.height = img_height;
16208 image_create_info.extent.depth = 1;
16209 image_create_info.mipLevels = 1;
16210 image_create_info.arrayLayers = 1;
16211 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16212 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16213 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16214
16215 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016216 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016217
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016218 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016219
16220 // Depth/Stencil image
16221 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016222 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016223 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16224 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16225 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16226 ds_image_create_info.extent.width = 64;
16227 ds_image_create_info.extent.height = 64;
16228 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016229 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 -060016230
16231 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016232 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016234 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 -060016235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016238 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016239 &color_range);
16240
16241 m_errorMonitor->VerifyFound();
16242
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16244 "vkCmdClearColorImage called with "
16245 "image created without "
16246 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016247
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016248 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016249 &color_range);
16250
16251 m_errorMonitor->VerifyFound();
16252
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016253 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16255 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016256
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016257 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
16258 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016259
16260 m_errorMonitor->VerifyFound();
16261}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016262#endif // IMAGE_TESTS
Tobin Ehliscde08892015-09-22 10:11:37 -060016263
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016264// WSI Enabled Tests
16265//
Chris Forbes09368e42016-10-13 11:59:22 +130016266#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016267TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
16268
16269#if defined(VK_USE_PLATFORM_XCB_KHR)
16270 VkSurfaceKHR surface = VK_NULL_HANDLE;
16271
16272 VkResult err;
16273 bool pass;
16274 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
16275 VkSwapchainCreateInfoKHR swapchain_create_info = {};
16276 // uint32_t swapchain_image_count = 0;
16277 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
16278 // uint32_t image_index = 0;
16279 // VkPresentInfoKHR present_info = {};
16280
16281 ASSERT_NO_FATAL_FAILURE(InitState());
16282
16283 // Use the create function from one of the VK_KHR_*_surface extension in
16284 // order to create a surface, testing all known errors in the process,
16285 // before successfully creating a surface:
16286 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
16287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
16288 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
16289 pass = (err != VK_SUCCESS);
16290 ASSERT_TRUE(pass);
16291 m_errorMonitor->VerifyFound();
16292
16293 // Next, try to create a surface with the wrong
16294 // VkXcbSurfaceCreateInfoKHR::sType:
16295 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
16296 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16298 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16299 pass = (err != VK_SUCCESS);
16300 ASSERT_TRUE(pass);
16301 m_errorMonitor->VerifyFound();
16302
16303 // Create a native window, and then correctly create a surface:
16304 xcb_connection_t *connection;
16305 xcb_screen_t *screen;
16306 xcb_window_t xcb_window;
16307 xcb_intern_atom_reply_t *atom_wm_delete_window;
16308
16309 const xcb_setup_t *setup;
16310 xcb_screen_iterator_t iter;
16311 int scr;
16312 uint32_t value_mask, value_list[32];
16313 int width = 1;
16314 int height = 1;
16315
16316 connection = xcb_connect(NULL, &scr);
16317 ASSERT_TRUE(connection != NULL);
16318 setup = xcb_get_setup(connection);
16319 iter = xcb_setup_roots_iterator(setup);
16320 while (scr-- > 0)
16321 xcb_screen_next(&iter);
16322 screen = iter.data;
16323
16324 xcb_window = xcb_generate_id(connection);
16325
16326 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
16327 value_list[0] = screen->black_pixel;
16328 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
16329
16330 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
16331 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
16332
16333 /* Magic code that will send notification when window is destroyed */
16334 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
16335 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
16336
16337 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
16338 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
16339 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
16340 free(reply);
16341
16342 xcb_map_window(connection, xcb_window);
16343
16344 // Force the x/y coordinates to 100,100 results are identical in consecutive
16345 // runs
16346 const uint32_t coords[] = { 100, 100 };
16347 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
16348
16349 // Finally, try to correctly create a surface:
16350 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
16351 xcb_create_info.pNext = NULL;
16352 xcb_create_info.flags = 0;
16353 xcb_create_info.connection = connection;
16354 xcb_create_info.window = xcb_window;
16355 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16356 pass = (err == VK_SUCCESS);
16357 ASSERT_TRUE(pass);
16358
16359 // Check if surface supports presentation:
16360
16361 // 1st, do so without having queried the queue families:
16362 VkBool32 supported = false;
16363 // TODO: Get the following error to come out:
16364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16365 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
16366 "function");
16367 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16368 pass = (err != VK_SUCCESS);
16369 // ASSERT_TRUE(pass);
16370 // m_errorMonitor->VerifyFound();
16371
16372 // Next, query a queue family index that's too large:
16373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16374 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
16375 pass = (err != VK_SUCCESS);
16376 ASSERT_TRUE(pass);
16377 m_errorMonitor->VerifyFound();
16378
16379 // Finally, do so correctly:
16380 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16381 // SUPPORTED
16382 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16383 pass = (err == VK_SUCCESS);
16384 ASSERT_TRUE(pass);
16385
16386 // Before proceeding, try to create a swapchain without having called
16387 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
16388 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16389 swapchain_create_info.pNext = NULL;
16390 swapchain_create_info.flags = 0;
16391 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16392 swapchain_create_info.surface = surface;
16393 swapchain_create_info.imageArrayLayers = 1;
16394 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
16395 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
16396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16397 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
16398 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16399 pass = (err != VK_SUCCESS);
16400 ASSERT_TRUE(pass);
16401 m_errorMonitor->VerifyFound();
16402
16403 // Get the surface capabilities:
16404 VkSurfaceCapabilitiesKHR surface_capabilities;
16405
16406 // Do so correctly (only error logged by this entrypoint is if the
16407 // extension isn't enabled):
16408 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
16409 pass = (err == VK_SUCCESS);
16410 ASSERT_TRUE(pass);
16411
16412 // Get the surface formats:
16413 uint32_t surface_format_count;
16414
16415 // First, try without a pointer to surface_format_count:
16416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
16417 "specified as NULL");
16418 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
16419 pass = (err == VK_SUCCESS);
16420 ASSERT_TRUE(pass);
16421 m_errorMonitor->VerifyFound();
16422
16423 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
16424 // correctly done a 1st try (to get the count):
16425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16426 surface_format_count = 0;
16427 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
16428 pass = (err == VK_SUCCESS);
16429 ASSERT_TRUE(pass);
16430 m_errorMonitor->VerifyFound();
16431
16432 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16433 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16434 pass = (err == VK_SUCCESS);
16435 ASSERT_TRUE(pass);
16436
16437 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16438 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
16439
16440 // Next, do a 2nd try with surface_format_count being set too high:
16441 surface_format_count += 5;
16442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16443 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16444 pass = (err == VK_SUCCESS);
16445 ASSERT_TRUE(pass);
16446 m_errorMonitor->VerifyFound();
16447
16448 // Finally, do a correct 1st and 2nd try:
16449 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16450 pass = (err == VK_SUCCESS);
16451 ASSERT_TRUE(pass);
16452 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16453 pass = (err == VK_SUCCESS);
16454 ASSERT_TRUE(pass);
16455
16456 // Get the surface present modes:
16457 uint32_t surface_present_mode_count;
16458
16459 // First, try without a pointer to surface_format_count:
16460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16461 "specified as NULL");
16462
16463 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16464 pass = (err == VK_SUCCESS);
16465 ASSERT_TRUE(pass);
16466 m_errorMonitor->VerifyFound();
16467
16468 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16469 // correctly done a 1st try (to get the count):
16470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16471 surface_present_mode_count = 0;
16472 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16473 (VkPresentModeKHR *)&surface_present_mode_count);
16474 pass = (err == VK_SUCCESS);
16475 ASSERT_TRUE(pass);
16476 m_errorMonitor->VerifyFound();
16477
16478 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16479 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16480 pass = (err == VK_SUCCESS);
16481 ASSERT_TRUE(pass);
16482
16483 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16484 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16485
16486 // Next, do a 2nd try with surface_format_count being set too high:
16487 surface_present_mode_count += 5;
16488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16489 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16490 pass = (err == VK_SUCCESS);
16491 ASSERT_TRUE(pass);
16492 m_errorMonitor->VerifyFound();
16493
16494 // Finally, do a correct 1st and 2nd try:
16495 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16496 pass = (err == VK_SUCCESS);
16497 ASSERT_TRUE(pass);
16498 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16499 pass = (err == VK_SUCCESS);
16500 ASSERT_TRUE(pass);
16501
16502 // Create a swapchain:
16503
16504 // First, try without a pointer to swapchain_create_info:
16505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16506 "specified as NULL");
16507
16508 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16509 pass = (err != VK_SUCCESS);
16510 ASSERT_TRUE(pass);
16511 m_errorMonitor->VerifyFound();
16512
16513 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16514 // sType:
16515 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16517
16518 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16519 pass = (err != VK_SUCCESS);
16520 ASSERT_TRUE(pass);
16521 m_errorMonitor->VerifyFound();
16522
16523 // Next, call with a NULL swapchain pointer:
16524 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16525 swapchain_create_info.pNext = NULL;
16526 swapchain_create_info.flags = 0;
16527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16528 "specified as NULL");
16529
16530 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16531 pass = (err != VK_SUCCESS);
16532 ASSERT_TRUE(pass);
16533 m_errorMonitor->VerifyFound();
16534
16535 // TODO: Enhance swapchain layer so that
16536 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16537
16538 // Next, call with a queue family index that's too large:
16539 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16540 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16541 swapchain_create_info.queueFamilyIndexCount = 2;
16542 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16544 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16545 pass = (err != VK_SUCCESS);
16546 ASSERT_TRUE(pass);
16547 m_errorMonitor->VerifyFound();
16548
16549 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16550 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16551 swapchain_create_info.queueFamilyIndexCount = 1;
16552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16553 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16554 "pCreateInfo->pQueueFamilyIndices).");
16555 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16556 pass = (err != VK_SUCCESS);
16557 ASSERT_TRUE(pass);
16558 m_errorMonitor->VerifyFound();
16559
16560 // Next, call with an invalid imageSharingMode:
16561 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16562 swapchain_create_info.queueFamilyIndexCount = 1;
16563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16564 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16565 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16566 pass = (err != VK_SUCCESS);
16567 ASSERT_TRUE(pass);
16568 m_errorMonitor->VerifyFound();
16569 // Fix for the future:
16570 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16571 // SUPPORTED
16572 swapchain_create_info.queueFamilyIndexCount = 0;
16573 queueFamilyIndex[0] = 0;
16574 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16575
16576 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16577 // Get the images from a swapchain:
16578 // Acquire an image from a swapchain:
16579 // Present an image to a swapchain:
16580 // Destroy the swapchain:
16581
16582 // TODOs:
16583 //
16584 // - Try destroying the device without first destroying the swapchain
16585 //
16586 // - Try destroying the device without first destroying the surface
16587 //
16588 // - Try destroying the surface without first destroying the swapchain
16589
16590 // Destroy the surface:
16591 vkDestroySurfaceKHR(instance(), surface, NULL);
16592
16593 // Tear down the window:
16594 xcb_destroy_window(connection, xcb_window);
16595 xcb_disconnect(connection);
16596
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016597#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016598 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016599#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016600}
Chris Forbes09368e42016-10-13 11:59:22 +130016601#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016602
16603//
16604// POSITIVE VALIDATION TESTS
16605//
16606// These tests do not expect to encounter ANY validation errors pass only if this is true
16607
Tobin Ehlise0006882016-11-03 10:14:28 -060016608TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016609 TEST_DESCRIPTION(
16610 "Perform an image layout transition in a secondary command buffer followed "
16611 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060016612 VkResult err;
16613 m_errorMonitor->ExpectSuccess();
16614 ASSERT_NO_FATAL_FAILURE(InitState());
16615 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16616 // Allocate a secondary and primary cmd buffer
16617 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16618 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16619 command_buffer_allocate_info.commandPool = m_commandPool;
16620 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16621 command_buffer_allocate_info.commandBufferCount = 1;
16622
16623 VkCommandBuffer secondary_command_buffer;
16624 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16625 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16626 VkCommandBuffer primary_command_buffer;
16627 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16628 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16629 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16630 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16631 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16632 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16633 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16634
16635 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16636 ASSERT_VK_SUCCESS(err);
16637 VkImageObj image(m_device);
16638 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16639 ASSERT_TRUE(image.initialized());
16640 VkImageMemoryBarrier img_barrier = {};
16641 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16642 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16643 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16644 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16645 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16646 img_barrier.image = image.handle();
16647 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16648 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16649 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16650 img_barrier.subresourceRange.baseArrayLayer = 0;
16651 img_barrier.subresourceRange.baseMipLevel = 0;
16652 img_barrier.subresourceRange.layerCount = 1;
16653 img_barrier.subresourceRange.levelCount = 1;
16654 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16655 0, nullptr, 1, &img_barrier);
16656 err = vkEndCommandBuffer(secondary_command_buffer);
16657 ASSERT_VK_SUCCESS(err);
16658
16659 // Now update primary cmd buffer to execute secondary and transitions image
16660 command_buffer_begin_info.pInheritanceInfo = nullptr;
16661 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16662 ASSERT_VK_SUCCESS(err);
16663 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16664 VkImageMemoryBarrier img_barrier2 = {};
16665 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16666 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16667 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16668 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16669 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16670 img_barrier2.image = image.handle();
16671 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16672 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16673 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16674 img_barrier2.subresourceRange.baseArrayLayer = 0;
16675 img_barrier2.subresourceRange.baseMipLevel = 0;
16676 img_barrier2.subresourceRange.layerCount = 1;
16677 img_barrier2.subresourceRange.levelCount = 1;
16678 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16679 nullptr, 1, &img_barrier2);
16680 err = vkEndCommandBuffer(primary_command_buffer);
16681 ASSERT_VK_SUCCESS(err);
16682 VkSubmitInfo submit_info = {};
16683 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16684 submit_info.commandBufferCount = 1;
16685 submit_info.pCommandBuffers = &primary_command_buffer;
16686 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16687 ASSERT_VK_SUCCESS(err);
16688 m_errorMonitor->VerifyNotFound();
16689 err = vkDeviceWaitIdle(m_device->device());
16690 ASSERT_VK_SUCCESS(err);
16691 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16692 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16693}
16694
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016695// This is a positive test. No failures are expected.
16696TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016697 TEST_DESCRIPTION(
16698 "Ensure that the vkUpdateDescriptorSets validation code "
16699 "is ignoring VkWriteDescriptorSet members that are not "
16700 "related to the descriptor type specified by "
16701 "VkWriteDescriptorSet::descriptorType. Correct "
16702 "validation behavior will result in the test running to "
16703 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016704
16705 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16706
16707 ASSERT_NO_FATAL_FAILURE(InitState());
16708
16709 // Image Case
16710 {
16711 m_errorMonitor->ExpectSuccess();
16712
16713 VkImage image;
16714 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16715 const int32_t tex_width = 32;
16716 const int32_t tex_height = 32;
16717 VkImageCreateInfo image_create_info = {};
16718 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16719 image_create_info.pNext = NULL;
16720 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16721 image_create_info.format = tex_format;
16722 image_create_info.extent.width = tex_width;
16723 image_create_info.extent.height = tex_height;
16724 image_create_info.extent.depth = 1;
16725 image_create_info.mipLevels = 1;
16726 image_create_info.arrayLayers = 1;
16727 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16728 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16729 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16730 image_create_info.flags = 0;
16731 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16732 ASSERT_VK_SUCCESS(err);
16733
16734 VkMemoryRequirements memory_reqs;
16735 VkDeviceMemory image_memory;
16736 bool pass;
16737 VkMemoryAllocateInfo memory_info = {};
16738 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16739 memory_info.pNext = NULL;
16740 memory_info.allocationSize = 0;
16741 memory_info.memoryTypeIndex = 0;
16742 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16743 memory_info.allocationSize = memory_reqs.size;
16744 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16745 ASSERT_TRUE(pass);
16746 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16747 ASSERT_VK_SUCCESS(err);
16748 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16749 ASSERT_VK_SUCCESS(err);
16750
16751 VkImageViewCreateInfo image_view_create_info = {};
16752 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16753 image_view_create_info.image = image;
16754 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16755 image_view_create_info.format = tex_format;
16756 image_view_create_info.subresourceRange.layerCount = 1;
16757 image_view_create_info.subresourceRange.baseMipLevel = 0;
16758 image_view_create_info.subresourceRange.levelCount = 1;
16759 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16760
16761 VkImageView view;
16762 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16763 ASSERT_VK_SUCCESS(err);
16764
16765 VkDescriptorPoolSize ds_type_count = {};
16766 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16767 ds_type_count.descriptorCount = 1;
16768
16769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16771 ds_pool_ci.pNext = NULL;
16772 ds_pool_ci.maxSets = 1;
16773 ds_pool_ci.poolSizeCount = 1;
16774 ds_pool_ci.pPoolSizes = &ds_type_count;
16775
16776 VkDescriptorPool ds_pool;
16777 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16778 ASSERT_VK_SUCCESS(err);
16779
16780 VkDescriptorSetLayoutBinding dsl_binding = {};
16781 dsl_binding.binding = 0;
16782 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16783 dsl_binding.descriptorCount = 1;
16784 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16785 dsl_binding.pImmutableSamplers = NULL;
16786
16787 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16788 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16789 ds_layout_ci.pNext = NULL;
16790 ds_layout_ci.bindingCount = 1;
16791 ds_layout_ci.pBindings = &dsl_binding;
16792 VkDescriptorSetLayout ds_layout;
16793 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16794 ASSERT_VK_SUCCESS(err);
16795
16796 VkDescriptorSet descriptor_set;
16797 VkDescriptorSetAllocateInfo alloc_info = {};
16798 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16799 alloc_info.descriptorSetCount = 1;
16800 alloc_info.descriptorPool = ds_pool;
16801 alloc_info.pSetLayouts = &ds_layout;
16802 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16803 ASSERT_VK_SUCCESS(err);
16804
16805 VkDescriptorImageInfo image_info = {};
16806 image_info.imageView = view;
16807 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16808
16809 VkWriteDescriptorSet descriptor_write;
16810 memset(&descriptor_write, 0, sizeof(descriptor_write));
16811 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16812 descriptor_write.dstSet = descriptor_set;
16813 descriptor_write.dstBinding = 0;
16814 descriptor_write.descriptorCount = 1;
16815 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16816 descriptor_write.pImageInfo = &image_info;
16817
16818 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16819 // be
16820 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16821 // This will most likely produce a crash if the parameter_validation
16822 // layer
16823 // does not correctly ignore pBufferInfo.
16824 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16825 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16826
16827 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16828
16829 m_errorMonitor->VerifyNotFound();
16830
16831 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16832 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16833 vkDestroyImageView(m_device->device(), view, NULL);
16834 vkDestroyImage(m_device->device(), image, NULL);
16835 vkFreeMemory(m_device->device(), image_memory, NULL);
16836 }
16837
16838 // Buffer Case
16839 {
16840 m_errorMonitor->ExpectSuccess();
16841
16842 VkBuffer buffer;
16843 uint32_t queue_family_index = 0;
16844 VkBufferCreateInfo buffer_create_info = {};
16845 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16846 buffer_create_info.size = 1024;
16847 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16848 buffer_create_info.queueFamilyIndexCount = 1;
16849 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16850
16851 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16852 ASSERT_VK_SUCCESS(err);
16853
16854 VkMemoryRequirements memory_reqs;
16855 VkDeviceMemory buffer_memory;
16856 bool pass;
16857 VkMemoryAllocateInfo memory_info = {};
16858 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16859 memory_info.pNext = NULL;
16860 memory_info.allocationSize = 0;
16861 memory_info.memoryTypeIndex = 0;
16862
16863 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16864 memory_info.allocationSize = memory_reqs.size;
16865 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16866 ASSERT_TRUE(pass);
16867
16868 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16869 ASSERT_VK_SUCCESS(err);
16870 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16871 ASSERT_VK_SUCCESS(err);
16872
16873 VkDescriptorPoolSize ds_type_count = {};
16874 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16875 ds_type_count.descriptorCount = 1;
16876
16877 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16878 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16879 ds_pool_ci.pNext = NULL;
16880 ds_pool_ci.maxSets = 1;
16881 ds_pool_ci.poolSizeCount = 1;
16882 ds_pool_ci.pPoolSizes = &ds_type_count;
16883
16884 VkDescriptorPool ds_pool;
16885 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16886 ASSERT_VK_SUCCESS(err);
16887
16888 VkDescriptorSetLayoutBinding dsl_binding = {};
16889 dsl_binding.binding = 0;
16890 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16891 dsl_binding.descriptorCount = 1;
16892 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16893 dsl_binding.pImmutableSamplers = NULL;
16894
16895 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16896 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16897 ds_layout_ci.pNext = NULL;
16898 ds_layout_ci.bindingCount = 1;
16899 ds_layout_ci.pBindings = &dsl_binding;
16900 VkDescriptorSetLayout ds_layout;
16901 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16902 ASSERT_VK_SUCCESS(err);
16903
16904 VkDescriptorSet descriptor_set;
16905 VkDescriptorSetAllocateInfo alloc_info = {};
16906 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16907 alloc_info.descriptorSetCount = 1;
16908 alloc_info.descriptorPool = ds_pool;
16909 alloc_info.pSetLayouts = &ds_layout;
16910 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16911 ASSERT_VK_SUCCESS(err);
16912
16913 VkDescriptorBufferInfo buffer_info = {};
16914 buffer_info.buffer = buffer;
16915 buffer_info.offset = 0;
16916 buffer_info.range = 1024;
16917
16918 VkWriteDescriptorSet descriptor_write;
16919 memset(&descriptor_write, 0, sizeof(descriptor_write));
16920 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16921 descriptor_write.dstSet = descriptor_set;
16922 descriptor_write.dstBinding = 0;
16923 descriptor_write.descriptorCount = 1;
16924 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16925 descriptor_write.pBufferInfo = &buffer_info;
16926
16927 // Set pImageInfo and pTexelBufferView to invalid values, which should
16928 // be
16929 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16930 // This will most likely produce a crash if the parameter_validation
16931 // layer
16932 // does not correctly ignore pImageInfo.
16933 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16934 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16935
16936 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16937
16938 m_errorMonitor->VerifyNotFound();
16939
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016940 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16941 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16942 vkDestroyBuffer(m_device->device(), buffer, NULL);
16943 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16944 }
16945
16946 // Texel Buffer Case
16947 {
16948 m_errorMonitor->ExpectSuccess();
16949
16950 VkBuffer buffer;
16951 uint32_t queue_family_index = 0;
16952 VkBufferCreateInfo buffer_create_info = {};
16953 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16954 buffer_create_info.size = 1024;
16955 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16956 buffer_create_info.queueFamilyIndexCount = 1;
16957 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16958
16959 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16960 ASSERT_VK_SUCCESS(err);
16961
16962 VkMemoryRequirements memory_reqs;
16963 VkDeviceMemory buffer_memory;
16964 bool pass;
16965 VkMemoryAllocateInfo memory_info = {};
16966 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16967 memory_info.pNext = NULL;
16968 memory_info.allocationSize = 0;
16969 memory_info.memoryTypeIndex = 0;
16970
16971 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16972 memory_info.allocationSize = memory_reqs.size;
16973 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16974 ASSERT_TRUE(pass);
16975
16976 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16977 ASSERT_VK_SUCCESS(err);
16978 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16979 ASSERT_VK_SUCCESS(err);
16980
16981 VkBufferViewCreateInfo buff_view_ci = {};
16982 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16983 buff_view_ci.buffer = buffer;
16984 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16985 buff_view_ci.range = VK_WHOLE_SIZE;
16986 VkBufferView buffer_view;
16987 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16988
16989 VkDescriptorPoolSize ds_type_count = {};
16990 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16991 ds_type_count.descriptorCount = 1;
16992
16993 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16994 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16995 ds_pool_ci.pNext = NULL;
16996 ds_pool_ci.maxSets = 1;
16997 ds_pool_ci.poolSizeCount = 1;
16998 ds_pool_ci.pPoolSizes = &ds_type_count;
16999
17000 VkDescriptorPool ds_pool;
17001 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17002 ASSERT_VK_SUCCESS(err);
17003
17004 VkDescriptorSetLayoutBinding dsl_binding = {};
17005 dsl_binding.binding = 0;
17006 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17007 dsl_binding.descriptorCount = 1;
17008 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17009 dsl_binding.pImmutableSamplers = NULL;
17010
17011 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17012 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17013 ds_layout_ci.pNext = NULL;
17014 ds_layout_ci.bindingCount = 1;
17015 ds_layout_ci.pBindings = &dsl_binding;
17016 VkDescriptorSetLayout ds_layout;
17017 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17018 ASSERT_VK_SUCCESS(err);
17019
17020 VkDescriptorSet descriptor_set;
17021 VkDescriptorSetAllocateInfo alloc_info = {};
17022 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17023 alloc_info.descriptorSetCount = 1;
17024 alloc_info.descriptorPool = ds_pool;
17025 alloc_info.pSetLayouts = &ds_layout;
17026 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17027 ASSERT_VK_SUCCESS(err);
17028
17029 VkWriteDescriptorSet descriptor_write;
17030 memset(&descriptor_write, 0, sizeof(descriptor_write));
17031 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17032 descriptor_write.dstSet = descriptor_set;
17033 descriptor_write.dstBinding = 0;
17034 descriptor_write.descriptorCount = 1;
17035 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17036 descriptor_write.pTexelBufferView = &buffer_view;
17037
17038 // Set pImageInfo and pBufferInfo to invalid values, which should be
17039 // ignored for descriptorType ==
17040 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
17041 // This will most likely produce a crash if the parameter_validation
17042 // layer
17043 // does not correctly ignore pImageInfo and pBufferInfo.
17044 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17045 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17046
17047 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17048
17049 m_errorMonitor->VerifyNotFound();
17050
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017051 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17052 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17053 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
17054 vkDestroyBuffer(m_device->device(), buffer, NULL);
17055 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17056 }
17057}
17058
Tobin Ehlisf7428442016-10-25 07:58:24 -060017059TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
17060 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
17061
17062 ASSERT_NO_FATAL_FAILURE(InitState());
17063 // Create layout where two binding #s are "1"
17064 static const uint32_t NUM_BINDINGS = 3;
17065 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17066 dsl_binding[0].binding = 1;
17067 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17068 dsl_binding[0].descriptorCount = 1;
17069 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17070 dsl_binding[0].pImmutableSamplers = NULL;
17071 dsl_binding[1].binding = 0;
17072 dsl_binding[1].descriptorCount = 1;
17073 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17074 dsl_binding[1].descriptorCount = 1;
17075 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17076 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017077 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060017078 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17079 dsl_binding[2].descriptorCount = 1;
17080 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17081 dsl_binding[2].pImmutableSamplers = NULL;
17082
17083 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17084 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17085 ds_layout_ci.pNext = NULL;
17086 ds_layout_ci.bindingCount = NUM_BINDINGS;
17087 ds_layout_ci.pBindings = dsl_binding;
17088 VkDescriptorSetLayout ds_layout;
17089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
17090 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17091 m_errorMonitor->VerifyFound();
17092}
17093
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017094TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017095 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
17096
17097 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017098
Tony Barbour552f6c02016-12-21 14:34:07 -070017099 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017100
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017101 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
17102
17103 {
17104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
17105 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
17106 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17107 m_errorMonitor->VerifyFound();
17108 }
17109
17110 {
17111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
17112 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
17113 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17114 m_errorMonitor->VerifyFound();
17115 }
17116
17117 {
17118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17119 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
17120 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17121 m_errorMonitor->VerifyFound();
17122 }
17123
17124 {
17125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17126 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
17127 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17128 m_errorMonitor->VerifyFound();
17129 }
17130
17131 {
17132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
17133 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
17134 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17135 m_errorMonitor->VerifyFound();
17136 }
17137
17138 {
17139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
17140 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
17141 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17142 m_errorMonitor->VerifyFound();
17143 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017144
17145 {
17146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17147 VkRect2D scissor = {{-1, 0}, {16, 16}};
17148 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17149 m_errorMonitor->VerifyFound();
17150 }
17151
17152 {
17153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17154 VkRect2D scissor = {{0, -2}, {16, 16}};
17155 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17156 m_errorMonitor->VerifyFound();
17157 }
17158
17159 {
17160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
17161 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
17162 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17163 m_errorMonitor->VerifyFound();
17164 }
17165
17166 {
17167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
17168 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
17169 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17170 m_errorMonitor->VerifyFound();
17171 }
17172
Tony Barbour552f6c02016-12-21 14:34:07 -070017173 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017174}
17175
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017176// This is a positive test. No failures are expected.
17177TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
17178 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
17179 VkResult err;
17180
17181 ASSERT_NO_FATAL_FAILURE(InitState());
17182 m_errorMonitor->ExpectSuccess();
17183 VkDescriptorPoolSize ds_type_count = {};
17184 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17185 ds_type_count.descriptorCount = 2;
17186
17187 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17188 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17189 ds_pool_ci.pNext = NULL;
17190 ds_pool_ci.maxSets = 1;
17191 ds_pool_ci.poolSizeCount = 1;
17192 ds_pool_ci.pPoolSizes = &ds_type_count;
17193
17194 VkDescriptorPool ds_pool;
17195 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17196 ASSERT_VK_SUCCESS(err);
17197
17198 // Create layout with two uniform buffer descriptors w/ empty binding between them
17199 static const uint32_t NUM_BINDINGS = 3;
17200 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17201 dsl_binding[0].binding = 0;
17202 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17203 dsl_binding[0].descriptorCount = 1;
17204 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
17205 dsl_binding[0].pImmutableSamplers = NULL;
17206 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017207 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017208 dsl_binding[2].binding = 2;
17209 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17210 dsl_binding[2].descriptorCount = 1;
17211 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
17212 dsl_binding[2].pImmutableSamplers = NULL;
17213
17214 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17215 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17216 ds_layout_ci.pNext = NULL;
17217 ds_layout_ci.bindingCount = NUM_BINDINGS;
17218 ds_layout_ci.pBindings = dsl_binding;
17219 VkDescriptorSetLayout ds_layout;
17220 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17221 ASSERT_VK_SUCCESS(err);
17222
17223 VkDescriptorSet descriptor_set = {};
17224 VkDescriptorSetAllocateInfo alloc_info = {};
17225 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17226 alloc_info.descriptorSetCount = 1;
17227 alloc_info.descriptorPool = ds_pool;
17228 alloc_info.pSetLayouts = &ds_layout;
17229 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17230 ASSERT_VK_SUCCESS(err);
17231
17232 // Create a buffer to be used for update
17233 VkBufferCreateInfo buff_ci = {};
17234 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17235 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17236 buff_ci.size = 256;
17237 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17238 VkBuffer buffer;
17239 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
17240 ASSERT_VK_SUCCESS(err);
17241 // Have to bind memory to buffer before descriptor update
17242 VkMemoryAllocateInfo mem_alloc = {};
17243 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17244 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017245 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017246 mem_alloc.memoryTypeIndex = 0;
17247
17248 VkMemoryRequirements mem_reqs;
17249 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17250 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
17251 if (!pass) {
17252 vkDestroyBuffer(m_device->device(), buffer, NULL);
17253 return;
17254 }
17255
17256 VkDeviceMemory mem;
17257 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17258 ASSERT_VK_SUCCESS(err);
17259 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17260 ASSERT_VK_SUCCESS(err);
17261
17262 // Only update the descriptor at binding 2
17263 VkDescriptorBufferInfo buff_info = {};
17264 buff_info.buffer = buffer;
17265 buff_info.offset = 0;
17266 buff_info.range = VK_WHOLE_SIZE;
17267 VkWriteDescriptorSet descriptor_write = {};
17268 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17269 descriptor_write.dstBinding = 2;
17270 descriptor_write.descriptorCount = 1;
17271 descriptor_write.pTexelBufferView = nullptr;
17272 descriptor_write.pBufferInfo = &buff_info;
17273 descriptor_write.pImageInfo = nullptr;
17274 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17275 descriptor_write.dstSet = descriptor_set;
17276
17277 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17278
17279 m_errorMonitor->VerifyNotFound();
17280 // Cleanup
17281 vkFreeMemory(m_device->device(), mem, NULL);
17282 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17283 vkDestroyBuffer(m_device->device(), buffer, NULL);
17284 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17285}
17286
17287// This is a positive test. No failures are expected.
17288TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
17289 VkResult err;
17290 bool pass;
17291
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017292 TEST_DESCRIPTION(
17293 "Create a buffer, allocate memory, bind memory, destroy "
17294 "the buffer, create an image, and bind the same memory to "
17295 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017296
17297 m_errorMonitor->ExpectSuccess();
17298
17299 ASSERT_NO_FATAL_FAILURE(InitState());
17300
17301 VkBuffer buffer;
17302 VkImage image;
17303 VkDeviceMemory mem;
17304 VkMemoryRequirements mem_reqs;
17305
17306 VkBufferCreateInfo buf_info = {};
17307 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17308 buf_info.pNext = NULL;
17309 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17310 buf_info.size = 256;
17311 buf_info.queueFamilyIndexCount = 0;
17312 buf_info.pQueueFamilyIndices = NULL;
17313 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17314 buf_info.flags = 0;
17315 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
17316 ASSERT_VK_SUCCESS(err);
17317
17318 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17319
17320 VkMemoryAllocateInfo alloc_info = {};
17321 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17322 alloc_info.pNext = NULL;
17323 alloc_info.memoryTypeIndex = 0;
17324
17325 // Ensure memory is big enough for both bindings
17326 alloc_info.allocationSize = 0x10000;
17327
17328 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17329 if (!pass) {
17330 vkDestroyBuffer(m_device->device(), buffer, NULL);
17331 return;
17332 }
17333
17334 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17335 ASSERT_VK_SUCCESS(err);
17336
17337 uint8_t *pData;
17338 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
17339 ASSERT_VK_SUCCESS(err);
17340
17341 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
17342
17343 vkUnmapMemory(m_device->device(), mem);
17344
17345 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17346 ASSERT_VK_SUCCESS(err);
17347
17348 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
17349 // memory. In fact, it was never used by the GPU.
17350 // Just be be sure, wait for idle.
17351 vkDestroyBuffer(m_device->device(), buffer, NULL);
17352 vkDeviceWaitIdle(m_device->device());
17353
Tobin Ehlis6a005702016-12-28 15:25:56 -070017354 // Use optimal as some platforms report linear support but then fail image creation
17355 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
17356 VkImageFormatProperties image_format_properties;
17357 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
17358 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
17359 if (image_format_properties.maxExtent.width == 0) {
17360 printf("Image format not supported; skipped.\n");
17361 vkFreeMemory(m_device->device(), mem, NULL);
17362 return;
17363 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017364 VkImageCreateInfo image_create_info = {};
17365 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17366 image_create_info.pNext = NULL;
17367 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17368 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
17369 image_create_info.extent.width = 64;
17370 image_create_info.extent.height = 64;
17371 image_create_info.extent.depth = 1;
17372 image_create_info.mipLevels = 1;
17373 image_create_info.arrayLayers = 1;
17374 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070017375 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017376 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
17377 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17378 image_create_info.queueFamilyIndexCount = 0;
17379 image_create_info.pQueueFamilyIndices = NULL;
17380 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17381 image_create_info.flags = 0;
17382
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017383 /* Create a mappable image. It will be the texture if linear images are ok
17384 * to be textures or it will be the staging image if they are not.
17385 */
17386 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17387 ASSERT_VK_SUCCESS(err);
17388
17389 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
17390
Tobin Ehlis6a005702016-12-28 15:25:56 -070017391 VkMemoryAllocateInfo mem_alloc = {};
17392 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17393 mem_alloc.pNext = NULL;
17394 mem_alloc.allocationSize = 0;
17395 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017396 mem_alloc.allocationSize = mem_reqs.size;
17397
17398 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17399 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070017400 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017401 vkDestroyImage(m_device->device(), image, NULL);
17402 return;
17403 }
17404
17405 // VALIDATION FAILURE:
17406 err = vkBindImageMemory(m_device->device(), image, mem, 0);
17407 ASSERT_VK_SUCCESS(err);
17408
17409 m_errorMonitor->VerifyNotFound();
17410
17411 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017412 vkDestroyImage(m_device->device(), image, NULL);
17413}
17414
Tony Barbourab713912017-02-02 14:17:35 -070017415// This is a positive test. No failures are expected.
17416TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
17417 VkResult err;
17418
17419 TEST_DESCRIPTION(
17420 "Call all applicable destroy and free routines with NULL"
17421 "handles, expecting no validation errors");
17422
17423 m_errorMonitor->ExpectSuccess();
17424
17425 ASSERT_NO_FATAL_FAILURE(InitState());
17426 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
17427 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
17428 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
17429 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
17430 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
17431 vkDestroyDevice(VK_NULL_HANDLE, NULL);
17432 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
17433 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
17434 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
17435 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
17436 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
17437 vkDestroyInstance(VK_NULL_HANDLE, NULL);
17438 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
17439 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
17440 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
17441 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
17442 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
17443 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
17444 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
17445 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
17446
17447 VkCommandPool command_pool;
17448 VkCommandPoolCreateInfo pool_create_info{};
17449 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17450 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17451 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17452 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17453 VkCommandBuffer command_buffers[3] = {};
17454 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17455 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17456 command_buffer_allocate_info.commandPool = command_pool;
17457 command_buffer_allocate_info.commandBufferCount = 1;
17458 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17459 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
17460 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
17461 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17462
17463 VkDescriptorPoolSize ds_type_count = {};
17464 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17465 ds_type_count.descriptorCount = 1;
17466
17467 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17468 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17469 ds_pool_ci.pNext = NULL;
17470 ds_pool_ci.maxSets = 1;
17471 ds_pool_ci.poolSizeCount = 1;
17472 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
17473 ds_pool_ci.pPoolSizes = &ds_type_count;
17474
17475 VkDescriptorPool ds_pool;
17476 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17477 ASSERT_VK_SUCCESS(err);
17478
17479 VkDescriptorSetLayoutBinding dsl_binding = {};
17480 dsl_binding.binding = 2;
17481 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17482 dsl_binding.descriptorCount = 1;
17483 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17484 dsl_binding.pImmutableSamplers = NULL;
17485 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17486 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17487 ds_layout_ci.pNext = NULL;
17488 ds_layout_ci.bindingCount = 1;
17489 ds_layout_ci.pBindings = &dsl_binding;
17490 VkDescriptorSetLayout ds_layout;
17491 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17492 ASSERT_VK_SUCCESS(err);
17493
17494 VkDescriptorSet descriptor_sets[3] = {};
17495 VkDescriptorSetAllocateInfo alloc_info = {};
17496 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17497 alloc_info.descriptorSetCount = 1;
17498 alloc_info.descriptorPool = ds_pool;
17499 alloc_info.pSetLayouts = &ds_layout;
17500 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
17501 ASSERT_VK_SUCCESS(err);
17502 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
17503 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17504 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17505
17506 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
17507
17508 m_errorMonitor->VerifyNotFound();
17509}
17510
Tobin Ehlis953e8392016-11-17 10:54:13 -070017511TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
17512 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
17513 // We previously had a bug where dynamic offset of inactive bindings was still being used
17514 VkResult err;
17515 m_errorMonitor->ExpectSuccess();
17516
17517 ASSERT_NO_FATAL_FAILURE(InitState());
17518 ASSERT_NO_FATAL_FAILURE(InitViewport());
17519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17520
17521 VkDescriptorPoolSize ds_type_count = {};
17522 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17523 ds_type_count.descriptorCount = 3;
17524
17525 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17526 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17527 ds_pool_ci.pNext = NULL;
17528 ds_pool_ci.maxSets = 1;
17529 ds_pool_ci.poolSizeCount = 1;
17530 ds_pool_ci.pPoolSizes = &ds_type_count;
17531
17532 VkDescriptorPool ds_pool;
17533 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17534 ASSERT_VK_SUCCESS(err);
17535
17536 const uint32_t BINDING_COUNT = 3;
17537 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017538 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017539 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17540 dsl_binding[0].descriptorCount = 1;
17541 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17542 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017543 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017544 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17545 dsl_binding[1].descriptorCount = 1;
17546 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17547 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017548 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017549 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17550 dsl_binding[2].descriptorCount = 1;
17551 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17552 dsl_binding[2].pImmutableSamplers = NULL;
17553
17554 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17555 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17556 ds_layout_ci.pNext = NULL;
17557 ds_layout_ci.bindingCount = BINDING_COUNT;
17558 ds_layout_ci.pBindings = dsl_binding;
17559 VkDescriptorSetLayout ds_layout;
17560 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17561 ASSERT_VK_SUCCESS(err);
17562
17563 VkDescriptorSet descriptor_set;
17564 VkDescriptorSetAllocateInfo alloc_info = {};
17565 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17566 alloc_info.descriptorSetCount = 1;
17567 alloc_info.descriptorPool = ds_pool;
17568 alloc_info.pSetLayouts = &ds_layout;
17569 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17570 ASSERT_VK_SUCCESS(err);
17571
17572 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17573 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17574 pipeline_layout_ci.pNext = NULL;
17575 pipeline_layout_ci.setLayoutCount = 1;
17576 pipeline_layout_ci.pSetLayouts = &ds_layout;
17577
17578 VkPipelineLayout pipeline_layout;
17579 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17580 ASSERT_VK_SUCCESS(err);
17581
17582 // Create two buffers to update the descriptors with
17583 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17584 uint32_t qfi = 0;
17585 VkBufferCreateInfo buffCI = {};
17586 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17587 buffCI.size = 2048;
17588 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17589 buffCI.queueFamilyIndexCount = 1;
17590 buffCI.pQueueFamilyIndices = &qfi;
17591
17592 VkBuffer dyub1;
17593 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17594 ASSERT_VK_SUCCESS(err);
17595 // buffer2
17596 buffCI.size = 1024;
17597 VkBuffer dyub2;
17598 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17599 ASSERT_VK_SUCCESS(err);
17600 // Allocate memory and bind to buffers
17601 VkMemoryAllocateInfo mem_alloc[2] = {};
17602 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17603 mem_alloc[0].pNext = NULL;
17604 mem_alloc[0].memoryTypeIndex = 0;
17605 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17606 mem_alloc[1].pNext = NULL;
17607 mem_alloc[1].memoryTypeIndex = 0;
17608
17609 VkMemoryRequirements mem_reqs1;
17610 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17611 VkMemoryRequirements mem_reqs2;
17612 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17613 mem_alloc[0].allocationSize = mem_reqs1.size;
17614 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17615 mem_alloc[1].allocationSize = mem_reqs2.size;
17616 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17617 if (!pass) {
17618 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17619 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17620 return;
17621 }
17622
17623 VkDeviceMemory mem1;
17624 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17625 ASSERT_VK_SUCCESS(err);
17626 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17627 ASSERT_VK_SUCCESS(err);
17628 VkDeviceMemory mem2;
17629 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17630 ASSERT_VK_SUCCESS(err);
17631 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17632 ASSERT_VK_SUCCESS(err);
17633 // Update descriptors
17634 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17635 buff_info[0].buffer = dyub1;
17636 buff_info[0].offset = 0;
17637 buff_info[0].range = 256;
17638 buff_info[1].buffer = dyub1;
17639 buff_info[1].offset = 256;
17640 buff_info[1].range = 512;
17641 buff_info[2].buffer = dyub2;
17642 buff_info[2].offset = 0;
17643 buff_info[2].range = 512;
17644
17645 VkWriteDescriptorSet descriptor_write;
17646 memset(&descriptor_write, 0, sizeof(descriptor_write));
17647 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17648 descriptor_write.dstSet = descriptor_set;
17649 descriptor_write.dstBinding = 0;
17650 descriptor_write.descriptorCount = BINDING_COUNT;
17651 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17652 descriptor_write.pBufferInfo = buff_info;
17653
17654 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17655
Tony Barbour552f6c02016-12-21 14:34:07 -070017656 m_commandBuffer->BeginCommandBuffer();
17657 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017658
17659 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017660 char const *vsSource =
17661 "#version 450\n"
17662 "\n"
17663 "out gl_PerVertex { \n"
17664 " vec4 gl_Position;\n"
17665 "};\n"
17666 "void main(){\n"
17667 " gl_Position = vec4(1);\n"
17668 "}\n";
17669 char const *fsSource =
17670 "#version 450\n"
17671 "\n"
17672 "layout(location=0) out vec4 x;\n"
17673 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17674 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17675 "void main(){\n"
17676 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17677 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070017678 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17679 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17680 VkPipelineObj pipe(m_device);
17681 pipe.SetViewport(m_viewports);
17682 pipe.SetScissor(m_scissors);
17683 pipe.AddShader(&vs);
17684 pipe.AddShader(&fs);
17685 pipe.AddColorAttachment();
17686 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17687
17688 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17689 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17690 // we used to have a bug in this case.
17691 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17692 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17693 &descriptor_set, BINDING_COUNT, dyn_off);
17694 Draw(1, 0, 0, 0);
17695 m_errorMonitor->VerifyNotFound();
17696
17697 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17698 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17699 vkFreeMemory(m_device->device(), mem1, NULL);
17700 vkFreeMemory(m_device->device(), mem2, NULL);
17701
17702 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17703 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17704 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17705}
17706
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017707TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017708 TEST_DESCRIPTION(
17709 "Ensure that validations handling of non-coherent memory "
17710 "mapping while using VK_WHOLE_SIZE does not cause access "
17711 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017712 VkResult err;
17713 uint8_t *pData;
17714 ASSERT_NO_FATAL_FAILURE(InitState());
17715
17716 VkDeviceMemory mem;
17717 VkMemoryRequirements mem_reqs;
17718 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017719 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017720 VkMemoryAllocateInfo alloc_info = {};
17721 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17722 alloc_info.pNext = NULL;
17723 alloc_info.memoryTypeIndex = 0;
17724
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017725 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017726 alloc_info.allocationSize = allocation_size;
17727
17728 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17729 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 -070017730 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017731 if (!pass) {
17732 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017733 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17734 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017735 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017736 pass = m_device->phy().set_memory_type(
17737 mem_reqs.memoryTypeBits, &alloc_info,
17738 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17739 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017740 if (!pass) {
17741 return;
17742 }
17743 }
17744 }
17745
17746 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17747 ASSERT_VK_SUCCESS(err);
17748
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017749 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017750 m_errorMonitor->ExpectSuccess();
17751 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17752 ASSERT_VK_SUCCESS(err);
17753 VkMappedMemoryRange mmr = {};
17754 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17755 mmr.memory = mem;
17756 mmr.offset = 0;
17757 mmr.size = VK_WHOLE_SIZE;
17758 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17759 ASSERT_VK_SUCCESS(err);
17760 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17761 ASSERT_VK_SUCCESS(err);
17762 m_errorMonitor->VerifyNotFound();
17763 vkUnmapMemory(m_device->device(), mem);
17764
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017765 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017766 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017767 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017768 ASSERT_VK_SUCCESS(err);
17769 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17770 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017771 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017772 mmr.size = VK_WHOLE_SIZE;
17773 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17774 ASSERT_VK_SUCCESS(err);
17775 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17776 ASSERT_VK_SUCCESS(err);
17777 m_errorMonitor->VerifyNotFound();
17778 vkUnmapMemory(m_device->device(), mem);
17779
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017780 // Map with offset and size
17781 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017782 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017783 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017784 ASSERT_VK_SUCCESS(err);
17785 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17786 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017787 mmr.offset = 4 * atom_size;
17788 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017789 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17790 ASSERT_VK_SUCCESS(err);
17791 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17792 ASSERT_VK_SUCCESS(err);
17793 m_errorMonitor->VerifyNotFound();
17794 vkUnmapMemory(m_device->device(), mem);
17795
17796 // Map without offset and flush WHOLE_SIZE with two separate offsets
17797 m_errorMonitor->ExpectSuccess();
17798 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17799 ASSERT_VK_SUCCESS(err);
17800 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17801 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017802 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017803 mmr.size = VK_WHOLE_SIZE;
17804 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17805 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017806 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017807 mmr.size = VK_WHOLE_SIZE;
17808 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17809 ASSERT_VK_SUCCESS(err);
17810 m_errorMonitor->VerifyNotFound();
17811 vkUnmapMemory(m_device->device(), mem);
17812
17813 vkFreeMemory(m_device->device(), mem, NULL);
17814}
17815
17816// This is a positive test. We used to expect error in this case but spec now allows it
17817TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17818 m_errorMonitor->ExpectSuccess();
17819 vk_testing::Fence testFence;
17820 VkFenceCreateInfo fenceInfo = {};
17821 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17822 fenceInfo.pNext = NULL;
17823
17824 ASSERT_NO_FATAL_FAILURE(InitState());
17825 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017826 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017827 VkResult result = vkResetFences(m_device->device(), 1, fences);
17828 ASSERT_VK_SUCCESS(result);
17829
17830 m_errorMonitor->VerifyNotFound();
17831}
17832
17833TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17834 m_errorMonitor->ExpectSuccess();
17835
17836 ASSERT_NO_FATAL_FAILURE(InitState());
17837 VkResult err;
17838
17839 // Record (empty!) command buffer that can be submitted multiple times
17840 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017841 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17842 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017843 m_commandBuffer->BeginCommandBuffer(&cbbi);
17844 m_commandBuffer->EndCommandBuffer();
17845
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017846 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017847 VkFence fence;
17848 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17849 ASSERT_VK_SUCCESS(err);
17850
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017851 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017852 VkSemaphore s1, s2;
17853 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17854 ASSERT_VK_SUCCESS(err);
17855 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17856 ASSERT_VK_SUCCESS(err);
17857
17858 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017859 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017860 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17861 ASSERT_VK_SUCCESS(err);
17862
17863 // Submit CB again, signaling s2.
17864 si.pSignalSemaphores = &s2;
17865 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17866 ASSERT_VK_SUCCESS(err);
17867
17868 // Wait for fence.
17869 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17870 ASSERT_VK_SUCCESS(err);
17871
17872 // CB is still in flight from second submission, but semaphore s1 is no
17873 // longer in flight. delete it.
17874 vkDestroySemaphore(m_device->device(), s1, nullptr);
17875
17876 m_errorMonitor->VerifyNotFound();
17877
17878 // Force device idle and clean up remaining objects
17879 vkDeviceWaitIdle(m_device->device());
17880 vkDestroySemaphore(m_device->device(), s2, nullptr);
17881 vkDestroyFence(m_device->device(), fence, nullptr);
17882}
17883
17884TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17885 m_errorMonitor->ExpectSuccess();
17886
17887 ASSERT_NO_FATAL_FAILURE(InitState());
17888 VkResult err;
17889
17890 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017891 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017892 VkFence f1;
17893 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17894 ASSERT_VK_SUCCESS(err);
17895
17896 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017897 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017898 VkFence f2;
17899 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17900 ASSERT_VK_SUCCESS(err);
17901
17902 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017903 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017904 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17905
17906 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017907 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017908 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17909
17910 // Should have both retired!
17911 vkDestroyFence(m_device->device(), f1, nullptr);
17912 vkDestroyFence(m_device->device(), f2, nullptr);
17913
17914 m_errorMonitor->VerifyNotFound();
17915}
17916
17917TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017918 TEST_DESCRIPTION(
17919 "Verify that creating an image view from an image with valid usage "
17920 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017921
17922 ASSERT_NO_FATAL_FAILURE(InitState());
17923
17924 m_errorMonitor->ExpectSuccess();
17925 // Verify that we can create a view with usage INPUT_ATTACHMENT
17926 VkImageObj image(m_device);
17927 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17928 ASSERT_TRUE(image.initialized());
17929 VkImageView imageView;
17930 VkImageViewCreateInfo ivci = {};
17931 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17932 ivci.image = image.handle();
17933 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17934 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17935 ivci.subresourceRange.layerCount = 1;
17936 ivci.subresourceRange.baseMipLevel = 0;
17937 ivci.subresourceRange.levelCount = 1;
17938 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17939
17940 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17941 m_errorMonitor->VerifyNotFound();
17942 vkDestroyImageView(m_device->device(), imageView, NULL);
17943}
17944
17945// This is a positive test. No failures are expected.
17946TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017947 TEST_DESCRIPTION(
17948 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17949 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017950
17951 ASSERT_NO_FATAL_FAILURE(InitState());
17952
17953 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017954 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017955
17956 m_errorMonitor->ExpectSuccess();
17957
17958 VkImage image;
17959 VkImageCreateInfo image_create_info = {};
17960 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17961 image_create_info.pNext = NULL;
17962 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17963 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17964 image_create_info.extent.width = 64;
17965 image_create_info.extent.height = 64;
17966 image_create_info.extent.depth = 1;
17967 image_create_info.mipLevels = 1;
17968 image_create_info.arrayLayers = 1;
17969 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17970 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17971 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17972 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17973 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17974 ASSERT_VK_SUCCESS(err);
17975
17976 VkMemoryRequirements memory_reqs;
17977 VkDeviceMemory memory_one, memory_two;
17978 bool pass;
17979 VkMemoryAllocateInfo memory_info = {};
17980 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17981 memory_info.pNext = NULL;
17982 memory_info.allocationSize = 0;
17983 memory_info.memoryTypeIndex = 0;
17984 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17985 // Find an image big enough to allow sparse mapping of 2 memory regions
17986 // Increase the image size until it is at least twice the
17987 // size of the required alignment, to ensure we can bind both
17988 // allocated memory blocks to the image on aligned offsets.
17989 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17990 vkDestroyImage(m_device->device(), image, nullptr);
17991 image_create_info.extent.width *= 2;
17992 image_create_info.extent.height *= 2;
17993 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17994 ASSERT_VK_SUCCESS(err);
17995 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17996 }
17997 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17998 // at the end of the first
17999 memory_info.allocationSize = memory_reqs.alignment;
18000 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18001 ASSERT_TRUE(pass);
18002 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
18003 ASSERT_VK_SUCCESS(err);
18004 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
18005 ASSERT_VK_SUCCESS(err);
18006 VkSparseMemoryBind binds[2];
18007 binds[0].flags = 0;
18008 binds[0].memory = memory_one;
18009 binds[0].memoryOffset = 0;
18010 binds[0].resourceOffset = 0;
18011 binds[0].size = memory_info.allocationSize;
18012 binds[1].flags = 0;
18013 binds[1].memory = memory_two;
18014 binds[1].memoryOffset = 0;
18015 binds[1].resourceOffset = memory_info.allocationSize;
18016 binds[1].size = memory_info.allocationSize;
18017
18018 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
18019 opaqueBindInfo.image = image;
18020 opaqueBindInfo.bindCount = 2;
18021 opaqueBindInfo.pBinds = binds;
18022
18023 VkFence fence = VK_NULL_HANDLE;
18024 VkBindSparseInfo bindSparseInfo = {};
18025 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
18026 bindSparseInfo.imageOpaqueBindCount = 1;
18027 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
18028
18029 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
18030 vkQueueWaitIdle(m_device->m_queue);
18031 vkDestroyImage(m_device->device(), image, NULL);
18032 vkFreeMemory(m_device->device(), memory_one, NULL);
18033 vkFreeMemory(m_device->device(), memory_two, NULL);
18034 m_errorMonitor->VerifyNotFound();
18035}
18036
18037TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018038 TEST_DESCRIPTION(
18039 "Ensure that CmdBeginRenderPass with an attachment's "
18040 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
18041 "the command buffer has prior knowledge of that "
18042 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018043
18044 m_errorMonitor->ExpectSuccess();
18045
18046 ASSERT_NO_FATAL_FAILURE(InitState());
18047
18048 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018049 VkAttachmentDescription attachment = {0,
18050 VK_FORMAT_R8G8B8A8_UNORM,
18051 VK_SAMPLE_COUNT_1_BIT,
18052 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18053 VK_ATTACHMENT_STORE_OP_STORE,
18054 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18055 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18056 VK_IMAGE_LAYOUT_UNDEFINED,
18057 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018058
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018059 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018060
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018061 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018062
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018063 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018064
18065 VkRenderPass rp;
18066 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18067 ASSERT_VK_SUCCESS(err);
18068
18069 // A compatible framebuffer.
18070 VkImageObj image(m_device);
18071 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18072 ASSERT_TRUE(image.initialized());
18073
18074 VkImageViewCreateInfo ivci = {
18075 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18076 nullptr,
18077 0,
18078 image.handle(),
18079 VK_IMAGE_VIEW_TYPE_2D,
18080 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018081 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18082 VK_COMPONENT_SWIZZLE_IDENTITY},
18083 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018084 };
18085 VkImageView view;
18086 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18087 ASSERT_VK_SUCCESS(err);
18088
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018089 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018090 VkFramebuffer fb;
18091 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18092 ASSERT_VK_SUCCESS(err);
18093
18094 // Record a single command buffer which uses this renderpass twice. The
18095 // bug is triggered at the beginning of the second renderpass, when the
18096 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018097 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 -070018098 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018099 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18100 vkCmdEndRenderPass(m_commandBuffer->handle());
18101 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18102
18103 m_errorMonitor->VerifyNotFound();
18104
18105 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018106 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018107
18108 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18109 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18110 vkDestroyImageView(m_device->device(), view, nullptr);
18111}
18112
18113TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018114 TEST_DESCRIPTION(
18115 "This test should pass. Create a Framebuffer and "
18116 "command buffer, bind them together, then destroy "
18117 "command pool and framebuffer and verify there are no "
18118 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018119
18120 m_errorMonitor->ExpectSuccess();
18121
18122 ASSERT_NO_FATAL_FAILURE(InitState());
18123
18124 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018125 VkAttachmentDescription attachment = {0,
18126 VK_FORMAT_R8G8B8A8_UNORM,
18127 VK_SAMPLE_COUNT_1_BIT,
18128 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18129 VK_ATTACHMENT_STORE_OP_STORE,
18130 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18131 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18132 VK_IMAGE_LAYOUT_UNDEFINED,
18133 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018134
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018135 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018136
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018137 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018138
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018139 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018140
18141 VkRenderPass rp;
18142 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18143 ASSERT_VK_SUCCESS(err);
18144
18145 // A compatible framebuffer.
18146 VkImageObj image(m_device);
18147 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18148 ASSERT_TRUE(image.initialized());
18149
18150 VkImageViewCreateInfo ivci = {
18151 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18152 nullptr,
18153 0,
18154 image.handle(),
18155 VK_IMAGE_VIEW_TYPE_2D,
18156 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018157 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18158 VK_COMPONENT_SWIZZLE_IDENTITY},
18159 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018160 };
18161 VkImageView view;
18162 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18163 ASSERT_VK_SUCCESS(err);
18164
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018165 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018166 VkFramebuffer fb;
18167 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18168 ASSERT_VK_SUCCESS(err);
18169
18170 // Explicitly create a command buffer to bind the FB to so that we can then
18171 // destroy the command pool in order to implicitly free command buffer
18172 VkCommandPool command_pool;
18173 VkCommandPoolCreateInfo pool_create_info{};
18174 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18175 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18176 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18177 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18178
18179 VkCommandBuffer command_buffer;
18180 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18181 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18182 command_buffer_allocate_info.commandPool = command_pool;
18183 command_buffer_allocate_info.commandBufferCount = 1;
18184 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18185 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18186
18187 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018188 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 -060018189 VkCommandBufferBeginInfo begin_info{};
18190 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18191 vkBeginCommandBuffer(command_buffer, &begin_info);
18192
18193 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18194 vkCmdEndRenderPass(command_buffer);
18195 vkEndCommandBuffer(command_buffer);
18196 vkDestroyImageView(m_device->device(), view, nullptr);
18197 // Destroy command pool to implicitly free command buffer
18198 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18199 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18200 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18201 m_errorMonitor->VerifyNotFound();
18202}
18203
18204TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018205 TEST_DESCRIPTION(
18206 "Ensure that CmdBeginRenderPass applies the layout "
18207 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018208
18209 m_errorMonitor->ExpectSuccess();
18210
18211 ASSERT_NO_FATAL_FAILURE(InitState());
18212
18213 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018214 VkAttachmentDescription attachment = {0,
18215 VK_FORMAT_R8G8B8A8_UNORM,
18216 VK_SAMPLE_COUNT_1_BIT,
18217 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18218 VK_ATTACHMENT_STORE_OP_STORE,
18219 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18220 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18221 VK_IMAGE_LAYOUT_UNDEFINED,
18222 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018223
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018224 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018225
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018226 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018227
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018228 VkSubpassDependency dep = {0,
18229 0,
18230 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18231 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18232 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18233 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18234 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018235
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018236 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018237
18238 VkResult err;
18239 VkRenderPass rp;
18240 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18241 ASSERT_VK_SUCCESS(err);
18242
18243 // A compatible framebuffer.
18244 VkImageObj image(m_device);
18245 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18246 ASSERT_TRUE(image.initialized());
18247
18248 VkImageViewCreateInfo ivci = {
18249 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18250 nullptr,
18251 0,
18252 image.handle(),
18253 VK_IMAGE_VIEW_TYPE_2D,
18254 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018255 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18256 VK_COMPONENT_SWIZZLE_IDENTITY},
18257 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018258 };
18259 VkImageView view;
18260 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18261 ASSERT_VK_SUCCESS(err);
18262
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018263 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018264 VkFramebuffer fb;
18265 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18266 ASSERT_VK_SUCCESS(err);
18267
18268 // Record a single command buffer which issues a pipeline barrier w/
18269 // image memory barrier for the attachment. This detects the previously
18270 // missing tracking of the subpass layout by throwing a validation error
18271 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018272 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 -070018273 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018274 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18275
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018276 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
18277 nullptr,
18278 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18279 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18280 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18281 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18282 VK_QUEUE_FAMILY_IGNORED,
18283 VK_QUEUE_FAMILY_IGNORED,
18284 image.handle(),
18285 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018286 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018287 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18288 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018289
18290 vkCmdEndRenderPass(m_commandBuffer->handle());
18291 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018292 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018293
18294 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18295 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18296 vkDestroyImageView(m_device->device(), view, nullptr);
18297}
18298
18299TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018300 TEST_DESCRIPTION(
18301 "Validate that when an imageView of a depth/stencil image "
18302 "is used as a depth/stencil framebuffer attachment, the "
18303 "aspectMask is ignored and both depth and stencil image "
18304 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018305
18306 VkFormatProperties format_properties;
18307 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
18308 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
18309 return;
18310 }
18311
18312 m_errorMonitor->ExpectSuccess();
18313
18314 ASSERT_NO_FATAL_FAILURE(InitState());
18315
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018316 VkAttachmentDescription attachment = {0,
18317 VK_FORMAT_D32_SFLOAT_S8_UINT,
18318 VK_SAMPLE_COUNT_1_BIT,
18319 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18320 VK_ATTACHMENT_STORE_OP_STORE,
18321 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18322 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18323 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
18324 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018325
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018326 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018327
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018328 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018329
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018330 VkSubpassDependency dep = {0,
18331 0,
18332 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18333 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18334 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18335 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18336 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018337
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018338 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018339
18340 VkResult err;
18341 VkRenderPass rp;
18342 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18343 ASSERT_VK_SUCCESS(err);
18344
18345 VkImageObj image(m_device);
18346 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018347 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018348 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018349 ASSERT_TRUE(image.initialized());
18350 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
18351
18352 VkImageViewCreateInfo ivci = {
18353 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18354 nullptr,
18355 0,
18356 image.handle(),
18357 VK_IMAGE_VIEW_TYPE_2D,
18358 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018359 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
18360 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018361 };
18362 VkImageView view;
18363 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18364 ASSERT_VK_SUCCESS(err);
18365
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018366 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018367 VkFramebuffer fb;
18368 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18369 ASSERT_VK_SUCCESS(err);
18370
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018371 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 -070018372 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018373 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18374
18375 VkImageMemoryBarrier imb = {};
18376 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18377 imb.pNext = nullptr;
18378 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18379 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18380 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18381 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18382 imb.srcQueueFamilyIndex = 0;
18383 imb.dstQueueFamilyIndex = 0;
18384 imb.image = image.handle();
18385 imb.subresourceRange.aspectMask = 0x6;
18386 imb.subresourceRange.baseMipLevel = 0;
18387 imb.subresourceRange.levelCount = 0x1;
18388 imb.subresourceRange.baseArrayLayer = 0;
18389 imb.subresourceRange.layerCount = 0x1;
18390
18391 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018392 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18393 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018394
18395 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018396 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018397 QueueCommandBuffer(false);
18398 m_errorMonitor->VerifyNotFound();
18399
18400 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18401 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18402 vkDestroyImageView(m_device->device(), view, nullptr);
18403}
18404
18405TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018406 TEST_DESCRIPTION(
18407 "Ensure that layout transitions work correctly without "
18408 "errors, when an attachment reference is "
18409 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018410
18411 m_errorMonitor->ExpectSuccess();
18412
18413 ASSERT_NO_FATAL_FAILURE(InitState());
18414
18415 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018416 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018417
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018418 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018419
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018420 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018421
18422 VkRenderPass rp;
18423 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18424 ASSERT_VK_SUCCESS(err);
18425
18426 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018427 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018428 VkFramebuffer fb;
18429 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18430 ASSERT_VK_SUCCESS(err);
18431
18432 // Record a command buffer which just begins and ends the renderpass. The
18433 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018434 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 -070018435 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018436 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18437 vkCmdEndRenderPass(m_commandBuffer->handle());
18438 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018439 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018440
18441 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18442 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18443}
18444
18445// This is a positive test. No errors are expected.
18446TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018447 TEST_DESCRIPTION(
18448 "Create a stencil-only attachment with a LOAD_OP set to "
18449 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018450 VkResult result = VK_SUCCESS;
18451 VkImageFormatProperties formatProps;
18452 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018453 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
18454 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018455 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
18456 return;
18457 }
18458
18459 ASSERT_NO_FATAL_FAILURE(InitState());
18460 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
18461 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018462 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018463 VkAttachmentDescription att = {};
18464 VkAttachmentReference ref = {};
18465 att.format = depth_stencil_fmt;
18466 att.samples = VK_SAMPLE_COUNT_1_BIT;
18467 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
18468 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18469 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18470 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
18471 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18472 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18473
18474 VkClearValue clear;
18475 clear.depthStencil.depth = 1.0;
18476 clear.depthStencil.stencil = 0;
18477 ref.attachment = 0;
18478 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18479
18480 VkSubpassDescription subpass = {};
18481 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
18482 subpass.flags = 0;
18483 subpass.inputAttachmentCount = 0;
18484 subpass.pInputAttachments = NULL;
18485 subpass.colorAttachmentCount = 0;
18486 subpass.pColorAttachments = NULL;
18487 subpass.pResolveAttachments = NULL;
18488 subpass.pDepthStencilAttachment = &ref;
18489 subpass.preserveAttachmentCount = 0;
18490 subpass.pPreserveAttachments = NULL;
18491
18492 VkRenderPass rp;
18493 VkRenderPassCreateInfo rp_info = {};
18494 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18495 rp_info.attachmentCount = 1;
18496 rp_info.pAttachments = &att;
18497 rp_info.subpassCount = 1;
18498 rp_info.pSubpasses = &subpass;
18499 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
18500 ASSERT_VK_SUCCESS(result);
18501
18502 VkImageView *depthView = m_depthStencil->BindInfo();
18503 VkFramebufferCreateInfo fb_info = {};
18504 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
18505 fb_info.pNext = NULL;
18506 fb_info.renderPass = rp;
18507 fb_info.attachmentCount = 1;
18508 fb_info.pAttachments = depthView;
18509 fb_info.width = 100;
18510 fb_info.height = 100;
18511 fb_info.layers = 1;
18512 VkFramebuffer fb;
18513 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
18514 ASSERT_VK_SUCCESS(result);
18515
18516 VkRenderPassBeginInfo rpbinfo = {};
18517 rpbinfo.clearValueCount = 1;
18518 rpbinfo.pClearValues = &clear;
18519 rpbinfo.pNext = NULL;
18520 rpbinfo.renderPass = rp;
18521 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
18522 rpbinfo.renderArea.extent.width = 100;
18523 rpbinfo.renderArea.extent.height = 100;
18524 rpbinfo.renderArea.offset.x = 0;
18525 rpbinfo.renderArea.offset.y = 0;
18526 rpbinfo.framebuffer = fb;
18527
18528 VkFence fence = {};
18529 VkFenceCreateInfo fence_ci = {};
18530 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18531 fence_ci.pNext = nullptr;
18532 fence_ci.flags = 0;
18533 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
18534 ASSERT_VK_SUCCESS(result);
18535
18536 m_commandBuffer->BeginCommandBuffer();
18537 m_commandBuffer->BeginRenderPass(rpbinfo);
18538 m_commandBuffer->EndRenderPass();
18539 m_commandBuffer->EndCommandBuffer();
18540 m_commandBuffer->QueueCommandBuffer(fence);
18541
18542 VkImageObj destImage(m_device);
18543 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018544 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018545 VkImageMemoryBarrier barrier = {};
18546 VkImageSubresourceRange range;
18547 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18548 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18549 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
18550 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18551 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18552 barrier.image = m_depthStencil->handle();
18553 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18554 range.baseMipLevel = 0;
18555 range.levelCount = 1;
18556 range.baseArrayLayer = 0;
18557 range.layerCount = 1;
18558 barrier.subresourceRange = range;
18559 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18560 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18561 cmdbuf.BeginCommandBuffer();
18562 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 -070018563 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018564 barrier.srcAccessMask = 0;
18565 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18566 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18567 barrier.image = destImage.handle();
18568 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18569 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 -070018570 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018571 VkImageCopy cregion;
18572 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18573 cregion.srcSubresource.mipLevel = 0;
18574 cregion.srcSubresource.baseArrayLayer = 0;
18575 cregion.srcSubresource.layerCount = 1;
18576 cregion.srcOffset.x = 0;
18577 cregion.srcOffset.y = 0;
18578 cregion.srcOffset.z = 0;
18579 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18580 cregion.dstSubresource.mipLevel = 0;
18581 cregion.dstSubresource.baseArrayLayer = 0;
18582 cregion.dstSubresource.layerCount = 1;
18583 cregion.dstOffset.x = 0;
18584 cregion.dstOffset.y = 0;
18585 cregion.dstOffset.z = 0;
18586 cregion.extent.width = 100;
18587 cregion.extent.height = 100;
18588 cregion.extent.depth = 1;
18589 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018590 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018591 cmdbuf.EndCommandBuffer();
18592
18593 VkSubmitInfo submit_info;
18594 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18595 submit_info.pNext = NULL;
18596 submit_info.waitSemaphoreCount = 0;
18597 submit_info.pWaitSemaphores = NULL;
18598 submit_info.pWaitDstStageMask = NULL;
18599 submit_info.commandBufferCount = 1;
18600 submit_info.pCommandBuffers = &cmdbuf.handle();
18601 submit_info.signalSemaphoreCount = 0;
18602 submit_info.pSignalSemaphores = NULL;
18603
18604 m_errorMonitor->ExpectSuccess();
18605 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18606 m_errorMonitor->VerifyNotFound();
18607
18608 vkQueueWaitIdle(m_device->m_queue);
18609 vkDestroyFence(m_device->device(), fence, nullptr);
18610 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18611 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18612}
18613
18614// This is a positive test. No errors should be generated.
18615TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18616 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18617
18618 m_errorMonitor->ExpectSuccess();
18619 ASSERT_NO_FATAL_FAILURE(InitState());
18620
18621 VkEvent event;
18622 VkEventCreateInfo event_create_info{};
18623 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18624 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18625
18626 VkCommandPool command_pool;
18627 VkCommandPoolCreateInfo pool_create_info{};
18628 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18629 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18630 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18631 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18632
18633 VkCommandBuffer command_buffer;
18634 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18635 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18636 command_buffer_allocate_info.commandPool = command_pool;
18637 command_buffer_allocate_info.commandBufferCount = 1;
18638 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18639 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18640
18641 VkQueue queue = VK_NULL_HANDLE;
18642 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18643
18644 {
18645 VkCommandBufferBeginInfo begin_info{};
18646 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18647 vkBeginCommandBuffer(command_buffer, &begin_info);
18648
18649 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 -070018650 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018651 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18652 vkEndCommandBuffer(command_buffer);
18653 }
18654 {
18655 VkSubmitInfo submit_info{};
18656 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18657 submit_info.commandBufferCount = 1;
18658 submit_info.pCommandBuffers = &command_buffer;
18659 submit_info.signalSemaphoreCount = 0;
18660 submit_info.pSignalSemaphores = nullptr;
18661 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18662 }
18663 { vkSetEvent(m_device->device(), event); }
18664
18665 vkQueueWaitIdle(queue);
18666
18667 vkDestroyEvent(m_device->device(), event, nullptr);
18668 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18669 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18670
18671 m_errorMonitor->VerifyNotFound();
18672}
18673// This is a positive test. No errors should be generated.
18674TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18675 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18676
18677 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018678 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018679
18680 m_errorMonitor->ExpectSuccess();
18681
18682 VkQueryPool query_pool;
18683 VkQueryPoolCreateInfo query_pool_create_info{};
18684 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18685 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18686 query_pool_create_info.queryCount = 1;
18687 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18688
18689 VkCommandPool command_pool;
18690 VkCommandPoolCreateInfo pool_create_info{};
18691 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18692 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18693 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18694 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18695
18696 VkCommandBuffer command_buffer;
18697 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18698 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18699 command_buffer_allocate_info.commandPool = command_pool;
18700 command_buffer_allocate_info.commandBufferCount = 1;
18701 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18702 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18703
18704 VkCommandBuffer secondary_command_buffer;
18705 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18706 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18707
18708 VkQueue queue = VK_NULL_HANDLE;
18709 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18710
18711 uint32_t qfi = 0;
18712 VkBufferCreateInfo buff_create_info = {};
18713 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18714 buff_create_info.size = 1024;
18715 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18716 buff_create_info.queueFamilyIndexCount = 1;
18717 buff_create_info.pQueueFamilyIndices = &qfi;
18718
18719 VkResult err;
18720 VkBuffer buffer;
18721 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18722 ASSERT_VK_SUCCESS(err);
18723 VkMemoryAllocateInfo mem_alloc = {};
18724 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18725 mem_alloc.pNext = NULL;
18726 mem_alloc.allocationSize = 1024;
18727 mem_alloc.memoryTypeIndex = 0;
18728
18729 VkMemoryRequirements memReqs;
18730 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18731 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18732 if (!pass) {
18733 vkDestroyBuffer(m_device->device(), buffer, NULL);
18734 return;
18735 }
18736
18737 VkDeviceMemory mem;
18738 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18739 ASSERT_VK_SUCCESS(err);
18740 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18741 ASSERT_VK_SUCCESS(err);
18742
18743 VkCommandBufferInheritanceInfo hinfo = {};
18744 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18745 hinfo.renderPass = VK_NULL_HANDLE;
18746 hinfo.subpass = 0;
18747 hinfo.framebuffer = VK_NULL_HANDLE;
18748 hinfo.occlusionQueryEnable = VK_FALSE;
18749 hinfo.queryFlags = 0;
18750 hinfo.pipelineStatistics = 0;
18751
18752 {
18753 VkCommandBufferBeginInfo begin_info{};
18754 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18755 begin_info.pInheritanceInfo = &hinfo;
18756 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18757
18758 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18759 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18760
18761 vkEndCommandBuffer(secondary_command_buffer);
18762
18763 begin_info.pInheritanceInfo = nullptr;
18764 vkBeginCommandBuffer(command_buffer, &begin_info);
18765
18766 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18767 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18768
18769 vkEndCommandBuffer(command_buffer);
18770 }
18771 {
18772 VkSubmitInfo submit_info{};
18773 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18774 submit_info.commandBufferCount = 1;
18775 submit_info.pCommandBuffers = &command_buffer;
18776 submit_info.signalSemaphoreCount = 0;
18777 submit_info.pSignalSemaphores = nullptr;
18778 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18779 }
18780
18781 vkQueueWaitIdle(queue);
18782
18783 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18784 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18785 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18786 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18787 vkDestroyBuffer(m_device->device(), buffer, NULL);
18788 vkFreeMemory(m_device->device(), mem, NULL);
18789
18790 m_errorMonitor->VerifyNotFound();
18791}
18792
18793// This is a positive test. No errors should be generated.
18794TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18795 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18796
18797 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018798 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018799
18800 m_errorMonitor->ExpectSuccess();
18801
18802 VkQueryPool query_pool;
18803 VkQueryPoolCreateInfo query_pool_create_info{};
18804 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18805 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18806 query_pool_create_info.queryCount = 1;
18807 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18808
18809 VkCommandPool command_pool;
18810 VkCommandPoolCreateInfo pool_create_info{};
18811 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18812 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18813 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18814 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18815
18816 VkCommandBuffer command_buffer[2];
18817 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18818 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18819 command_buffer_allocate_info.commandPool = command_pool;
18820 command_buffer_allocate_info.commandBufferCount = 2;
18821 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18822 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18823
18824 VkQueue queue = VK_NULL_HANDLE;
18825 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18826
18827 uint32_t qfi = 0;
18828 VkBufferCreateInfo buff_create_info = {};
18829 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18830 buff_create_info.size = 1024;
18831 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18832 buff_create_info.queueFamilyIndexCount = 1;
18833 buff_create_info.pQueueFamilyIndices = &qfi;
18834
18835 VkResult err;
18836 VkBuffer buffer;
18837 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18838 ASSERT_VK_SUCCESS(err);
18839 VkMemoryAllocateInfo mem_alloc = {};
18840 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18841 mem_alloc.pNext = NULL;
18842 mem_alloc.allocationSize = 1024;
18843 mem_alloc.memoryTypeIndex = 0;
18844
18845 VkMemoryRequirements memReqs;
18846 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18847 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18848 if (!pass) {
18849 vkDestroyBuffer(m_device->device(), buffer, NULL);
18850 return;
18851 }
18852
18853 VkDeviceMemory mem;
18854 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18855 ASSERT_VK_SUCCESS(err);
18856 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18857 ASSERT_VK_SUCCESS(err);
18858
18859 {
18860 VkCommandBufferBeginInfo begin_info{};
18861 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18862 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18863
18864 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18865 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18866
18867 vkEndCommandBuffer(command_buffer[0]);
18868
18869 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18870
18871 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18872
18873 vkEndCommandBuffer(command_buffer[1]);
18874 }
18875 {
18876 VkSubmitInfo submit_info{};
18877 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18878 submit_info.commandBufferCount = 2;
18879 submit_info.pCommandBuffers = command_buffer;
18880 submit_info.signalSemaphoreCount = 0;
18881 submit_info.pSignalSemaphores = nullptr;
18882 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18883 }
18884
18885 vkQueueWaitIdle(queue);
18886
18887 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18888 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18889 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18890 vkDestroyBuffer(m_device->device(), buffer, NULL);
18891 vkFreeMemory(m_device->device(), mem, NULL);
18892
18893 m_errorMonitor->VerifyNotFound();
18894}
18895
Tony Barbourc46924f2016-11-04 11:49:52 -060018896TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018897 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18898
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018899 ASSERT_NO_FATAL_FAILURE(InitState());
18900 VkEvent event;
18901 VkEventCreateInfo event_create_info{};
18902 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18903 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18904
18905 VkCommandPool command_pool;
18906 VkCommandPoolCreateInfo pool_create_info{};
18907 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18908 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18909 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18910 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18911
18912 VkCommandBuffer command_buffer;
18913 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18914 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18915 command_buffer_allocate_info.commandPool = command_pool;
18916 command_buffer_allocate_info.commandBufferCount = 1;
18917 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18918 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18919
18920 VkQueue queue = VK_NULL_HANDLE;
18921 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18922
18923 {
18924 VkCommandBufferBeginInfo begin_info{};
18925 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18926 vkBeginCommandBuffer(command_buffer, &begin_info);
18927
18928 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018929 vkEndCommandBuffer(command_buffer);
18930 }
18931 {
18932 VkSubmitInfo submit_info{};
18933 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18934 submit_info.commandBufferCount = 1;
18935 submit_info.pCommandBuffers = &command_buffer;
18936 submit_info.signalSemaphoreCount = 0;
18937 submit_info.pSignalSemaphores = nullptr;
18938 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18939 }
18940 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18942 "that is already in use by a "
18943 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018944 vkSetEvent(m_device->device(), event);
18945 m_errorMonitor->VerifyFound();
18946 }
18947
18948 vkQueueWaitIdle(queue);
18949
18950 vkDestroyEvent(m_device->device(), event, nullptr);
18951 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18952 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18953}
18954
18955// This is a positive test. No errors should be generated.
18956TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018957 TEST_DESCRIPTION(
18958 "Two command buffers with two separate fences are each "
18959 "run through a Submit & WaitForFences cycle 3 times. This "
18960 "previously revealed a bug so running this positive test "
18961 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018962 m_errorMonitor->ExpectSuccess();
18963
18964 ASSERT_NO_FATAL_FAILURE(InitState());
18965 VkQueue queue = VK_NULL_HANDLE;
18966 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18967
18968 static const uint32_t NUM_OBJECTS = 2;
18969 static const uint32_t NUM_FRAMES = 3;
18970 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18971 VkFence fences[NUM_OBJECTS] = {};
18972
18973 VkCommandPool cmd_pool;
18974 VkCommandPoolCreateInfo cmd_pool_ci = {};
18975 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18976 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18977 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18978 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18979 ASSERT_VK_SUCCESS(err);
18980
18981 VkCommandBufferAllocateInfo cmd_buf_info = {};
18982 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18983 cmd_buf_info.commandPool = cmd_pool;
18984 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18985 cmd_buf_info.commandBufferCount = 1;
18986
18987 VkFenceCreateInfo fence_ci = {};
18988 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18989 fence_ci.pNext = nullptr;
18990 fence_ci.flags = 0;
18991
18992 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18993 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18994 ASSERT_VK_SUCCESS(err);
18995 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18996 ASSERT_VK_SUCCESS(err);
18997 }
18998
18999 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
19000 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
19001 // Create empty cmd buffer
19002 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
19003 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19004
19005 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
19006 ASSERT_VK_SUCCESS(err);
19007 err = vkEndCommandBuffer(cmd_buffers[obj]);
19008 ASSERT_VK_SUCCESS(err);
19009
19010 VkSubmitInfo submit_info = {};
19011 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19012 submit_info.commandBufferCount = 1;
19013 submit_info.pCommandBuffers = &cmd_buffers[obj];
19014 // Submit cmd buffer and wait for fence
19015 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
19016 ASSERT_VK_SUCCESS(err);
19017 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
19018 ASSERT_VK_SUCCESS(err);
19019 err = vkResetFences(m_device->device(), 1, &fences[obj]);
19020 ASSERT_VK_SUCCESS(err);
19021 }
19022 }
19023 m_errorMonitor->VerifyNotFound();
19024 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
19025 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19026 vkDestroyFence(m_device->device(), fences[i], nullptr);
19027 }
19028}
19029// This is a positive test. No errors should be generated.
19030TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019031 TEST_DESCRIPTION(
19032 "Two command buffers, each in a separate QueueSubmit call "
19033 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019034
19035 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019036 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019037
19038 m_errorMonitor->ExpectSuccess();
19039
19040 VkSemaphore semaphore;
19041 VkSemaphoreCreateInfo semaphore_create_info{};
19042 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19043 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19044
19045 VkCommandPool command_pool;
19046 VkCommandPoolCreateInfo pool_create_info{};
19047 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19048 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19049 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19050 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19051
19052 VkCommandBuffer command_buffer[2];
19053 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19054 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19055 command_buffer_allocate_info.commandPool = command_pool;
19056 command_buffer_allocate_info.commandBufferCount = 2;
19057 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19058 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19059
19060 VkQueue queue = VK_NULL_HANDLE;
19061 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19062
19063 {
19064 VkCommandBufferBeginInfo begin_info{};
19065 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19066 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19067
19068 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 -070019069 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019070
19071 VkViewport viewport{};
19072 viewport.maxDepth = 1.0f;
19073 viewport.minDepth = 0.0f;
19074 viewport.width = 512;
19075 viewport.height = 512;
19076 viewport.x = 0;
19077 viewport.y = 0;
19078 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19079 vkEndCommandBuffer(command_buffer[0]);
19080 }
19081 {
19082 VkCommandBufferBeginInfo begin_info{};
19083 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19084 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19085
19086 VkViewport viewport{};
19087 viewport.maxDepth = 1.0f;
19088 viewport.minDepth = 0.0f;
19089 viewport.width = 512;
19090 viewport.height = 512;
19091 viewport.x = 0;
19092 viewport.y = 0;
19093 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19094 vkEndCommandBuffer(command_buffer[1]);
19095 }
19096 {
19097 VkSubmitInfo submit_info{};
19098 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19099 submit_info.commandBufferCount = 1;
19100 submit_info.pCommandBuffers = &command_buffer[0];
19101 submit_info.signalSemaphoreCount = 1;
19102 submit_info.pSignalSemaphores = &semaphore;
19103 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19104 }
19105 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019106 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019107 VkSubmitInfo submit_info{};
19108 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19109 submit_info.commandBufferCount = 1;
19110 submit_info.pCommandBuffers = &command_buffer[1];
19111 submit_info.waitSemaphoreCount = 1;
19112 submit_info.pWaitSemaphores = &semaphore;
19113 submit_info.pWaitDstStageMask = flags;
19114 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19115 }
19116
19117 vkQueueWaitIdle(m_device->m_queue);
19118
19119 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19120 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19121 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19122
19123 m_errorMonitor->VerifyNotFound();
19124}
19125
19126// This is a positive test. No errors should be generated.
19127TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019128 TEST_DESCRIPTION(
19129 "Two command buffers, each in a separate QueueSubmit call "
19130 "submitted on separate queues, the second having a fence"
19131 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019132
19133 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019134 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019135
19136 m_errorMonitor->ExpectSuccess();
19137
19138 VkFence fence;
19139 VkFenceCreateInfo fence_create_info{};
19140 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19141 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19142
19143 VkSemaphore semaphore;
19144 VkSemaphoreCreateInfo semaphore_create_info{};
19145 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19146 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19147
19148 VkCommandPool command_pool;
19149 VkCommandPoolCreateInfo pool_create_info{};
19150 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19151 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19152 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19153 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19154
19155 VkCommandBuffer command_buffer[2];
19156 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19157 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19158 command_buffer_allocate_info.commandPool = command_pool;
19159 command_buffer_allocate_info.commandBufferCount = 2;
19160 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19161 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19162
19163 VkQueue queue = VK_NULL_HANDLE;
19164 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19165
19166 {
19167 VkCommandBufferBeginInfo begin_info{};
19168 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19169 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19170
19171 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 -070019172 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019173
19174 VkViewport viewport{};
19175 viewport.maxDepth = 1.0f;
19176 viewport.minDepth = 0.0f;
19177 viewport.width = 512;
19178 viewport.height = 512;
19179 viewport.x = 0;
19180 viewport.y = 0;
19181 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19182 vkEndCommandBuffer(command_buffer[0]);
19183 }
19184 {
19185 VkCommandBufferBeginInfo begin_info{};
19186 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19187 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19188
19189 VkViewport viewport{};
19190 viewport.maxDepth = 1.0f;
19191 viewport.minDepth = 0.0f;
19192 viewport.width = 512;
19193 viewport.height = 512;
19194 viewport.x = 0;
19195 viewport.y = 0;
19196 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19197 vkEndCommandBuffer(command_buffer[1]);
19198 }
19199 {
19200 VkSubmitInfo submit_info{};
19201 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19202 submit_info.commandBufferCount = 1;
19203 submit_info.pCommandBuffers = &command_buffer[0];
19204 submit_info.signalSemaphoreCount = 1;
19205 submit_info.pSignalSemaphores = &semaphore;
19206 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19207 }
19208 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019209 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019210 VkSubmitInfo submit_info{};
19211 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19212 submit_info.commandBufferCount = 1;
19213 submit_info.pCommandBuffers = &command_buffer[1];
19214 submit_info.waitSemaphoreCount = 1;
19215 submit_info.pWaitSemaphores = &semaphore;
19216 submit_info.pWaitDstStageMask = flags;
19217 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19218 }
19219
19220 vkQueueWaitIdle(m_device->m_queue);
19221
19222 vkDestroyFence(m_device->device(), fence, nullptr);
19223 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19224 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19225 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19226
19227 m_errorMonitor->VerifyNotFound();
19228}
19229
19230// This is a positive test. No errors should be generated.
19231TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019232 TEST_DESCRIPTION(
19233 "Two command buffers, each in a separate QueueSubmit call "
19234 "submitted on separate queues, the second having a fence"
19235 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019236
19237 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019238 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019239
19240 m_errorMonitor->ExpectSuccess();
19241
19242 VkFence fence;
19243 VkFenceCreateInfo fence_create_info{};
19244 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19245 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19246
19247 VkSemaphore semaphore;
19248 VkSemaphoreCreateInfo semaphore_create_info{};
19249 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19250 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19251
19252 VkCommandPool command_pool;
19253 VkCommandPoolCreateInfo pool_create_info{};
19254 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19255 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19256 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19257 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19258
19259 VkCommandBuffer command_buffer[2];
19260 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19261 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19262 command_buffer_allocate_info.commandPool = command_pool;
19263 command_buffer_allocate_info.commandBufferCount = 2;
19264 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19265 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19266
19267 VkQueue queue = VK_NULL_HANDLE;
19268 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19269
19270 {
19271 VkCommandBufferBeginInfo begin_info{};
19272 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19273 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19274
19275 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 -070019276 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019277
19278 VkViewport viewport{};
19279 viewport.maxDepth = 1.0f;
19280 viewport.minDepth = 0.0f;
19281 viewport.width = 512;
19282 viewport.height = 512;
19283 viewport.x = 0;
19284 viewport.y = 0;
19285 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19286 vkEndCommandBuffer(command_buffer[0]);
19287 }
19288 {
19289 VkCommandBufferBeginInfo begin_info{};
19290 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19291 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19292
19293 VkViewport viewport{};
19294 viewport.maxDepth = 1.0f;
19295 viewport.minDepth = 0.0f;
19296 viewport.width = 512;
19297 viewport.height = 512;
19298 viewport.x = 0;
19299 viewport.y = 0;
19300 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19301 vkEndCommandBuffer(command_buffer[1]);
19302 }
19303 {
19304 VkSubmitInfo submit_info{};
19305 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19306 submit_info.commandBufferCount = 1;
19307 submit_info.pCommandBuffers = &command_buffer[0];
19308 submit_info.signalSemaphoreCount = 1;
19309 submit_info.pSignalSemaphores = &semaphore;
19310 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19311 }
19312 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019313 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019314 VkSubmitInfo submit_info{};
19315 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19316 submit_info.commandBufferCount = 1;
19317 submit_info.pCommandBuffers = &command_buffer[1];
19318 submit_info.waitSemaphoreCount = 1;
19319 submit_info.pWaitSemaphores = &semaphore;
19320 submit_info.pWaitDstStageMask = flags;
19321 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19322 }
19323
19324 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19325 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19326
19327 vkDestroyFence(m_device->device(), fence, nullptr);
19328 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19329 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19330 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19331
19332 m_errorMonitor->VerifyNotFound();
19333}
19334
19335TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019336 ASSERT_NO_FATAL_FAILURE(InitState());
19337 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
19338 printf("Test requires two queues, skipping\n");
19339 return;
19340 }
19341
19342 VkResult err;
19343
19344 m_errorMonitor->ExpectSuccess();
19345
19346 VkQueue q0 = m_device->m_queue;
19347 VkQueue q1 = nullptr;
19348 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
19349 ASSERT_NE(q1, nullptr);
19350
19351 // An (empty) command buffer. We must have work in the first submission --
19352 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019353 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019354 VkCommandPool pool;
19355 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
19356 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019357 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
19358 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019359 VkCommandBuffer cb;
19360 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
19361 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019362 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019363 err = vkBeginCommandBuffer(cb, &cbbi);
19364 ASSERT_VK_SUCCESS(err);
19365 err = vkEndCommandBuffer(cb);
19366 ASSERT_VK_SUCCESS(err);
19367
19368 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019369 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019370 VkSemaphore s;
19371 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
19372 ASSERT_VK_SUCCESS(err);
19373
19374 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019375 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019376
19377 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
19378 ASSERT_VK_SUCCESS(err);
19379
19380 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019381 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019382 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019383
19384 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
19385 ASSERT_VK_SUCCESS(err);
19386
19387 // Wait for q0 idle
19388 err = vkQueueWaitIdle(q0);
19389 ASSERT_VK_SUCCESS(err);
19390
19391 // Command buffer should have been completed (it was on q0); reset the pool.
19392 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
19393
19394 m_errorMonitor->VerifyNotFound();
19395
19396 // Force device completely idle and clean up resources
19397 vkDeviceWaitIdle(m_device->device());
19398 vkDestroyCommandPool(m_device->device(), pool, nullptr);
19399 vkDestroySemaphore(m_device->device(), s, nullptr);
19400}
19401
19402// This is a positive test. No errors should be generated.
19403TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019404 TEST_DESCRIPTION(
19405 "Two command buffers, each in a separate QueueSubmit call "
19406 "submitted on separate queues, the second having a fence, "
19407 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019408
19409 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019410 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019411
19412 m_errorMonitor->ExpectSuccess();
19413
19414 ASSERT_NO_FATAL_FAILURE(InitState());
19415 VkFence fence;
19416 VkFenceCreateInfo fence_create_info{};
19417 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19418 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19419
19420 VkSemaphore semaphore;
19421 VkSemaphoreCreateInfo semaphore_create_info{};
19422 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19423 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19424
19425 VkCommandPool command_pool;
19426 VkCommandPoolCreateInfo pool_create_info{};
19427 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19428 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19429 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19430 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19431
19432 VkCommandBuffer command_buffer[2];
19433 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19434 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19435 command_buffer_allocate_info.commandPool = command_pool;
19436 command_buffer_allocate_info.commandBufferCount = 2;
19437 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19438 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19439
19440 VkQueue queue = VK_NULL_HANDLE;
19441 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19442
19443 {
19444 VkCommandBufferBeginInfo begin_info{};
19445 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19446 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19447
19448 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 -070019449 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019450
19451 VkViewport viewport{};
19452 viewport.maxDepth = 1.0f;
19453 viewport.minDepth = 0.0f;
19454 viewport.width = 512;
19455 viewport.height = 512;
19456 viewport.x = 0;
19457 viewport.y = 0;
19458 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19459 vkEndCommandBuffer(command_buffer[0]);
19460 }
19461 {
19462 VkCommandBufferBeginInfo begin_info{};
19463 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19464 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19465
19466 VkViewport viewport{};
19467 viewport.maxDepth = 1.0f;
19468 viewport.minDepth = 0.0f;
19469 viewport.width = 512;
19470 viewport.height = 512;
19471 viewport.x = 0;
19472 viewport.y = 0;
19473 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19474 vkEndCommandBuffer(command_buffer[1]);
19475 }
19476 {
19477 VkSubmitInfo submit_info{};
19478 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19479 submit_info.commandBufferCount = 1;
19480 submit_info.pCommandBuffers = &command_buffer[0];
19481 submit_info.signalSemaphoreCount = 1;
19482 submit_info.pSignalSemaphores = &semaphore;
19483 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19484 }
19485 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019486 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019487 VkSubmitInfo submit_info{};
19488 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19489 submit_info.commandBufferCount = 1;
19490 submit_info.pCommandBuffers = &command_buffer[1];
19491 submit_info.waitSemaphoreCount = 1;
19492 submit_info.pWaitSemaphores = &semaphore;
19493 submit_info.pWaitDstStageMask = flags;
19494 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19495 }
19496
19497 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19498
19499 vkDestroyFence(m_device->device(), fence, nullptr);
19500 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19501 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19502 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19503
19504 m_errorMonitor->VerifyNotFound();
19505}
19506
19507// This is a positive test. No errors should be generated.
19508TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019509 TEST_DESCRIPTION(
19510 "Two command buffers, each in a separate QueueSubmit call "
19511 "on the same queue, sharing a signal/wait semaphore, the "
19512 "second having a fence, "
19513 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019514
19515 m_errorMonitor->ExpectSuccess();
19516
19517 ASSERT_NO_FATAL_FAILURE(InitState());
19518 VkFence fence;
19519 VkFenceCreateInfo fence_create_info{};
19520 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19521 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19522
19523 VkSemaphore semaphore;
19524 VkSemaphoreCreateInfo semaphore_create_info{};
19525 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19526 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19527
19528 VkCommandPool command_pool;
19529 VkCommandPoolCreateInfo pool_create_info{};
19530 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19531 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19532 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19533 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19534
19535 VkCommandBuffer command_buffer[2];
19536 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19537 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19538 command_buffer_allocate_info.commandPool = command_pool;
19539 command_buffer_allocate_info.commandBufferCount = 2;
19540 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19541 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19542
19543 {
19544 VkCommandBufferBeginInfo begin_info{};
19545 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19546 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19547
19548 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 -070019549 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019550
19551 VkViewport viewport{};
19552 viewport.maxDepth = 1.0f;
19553 viewport.minDepth = 0.0f;
19554 viewport.width = 512;
19555 viewport.height = 512;
19556 viewport.x = 0;
19557 viewport.y = 0;
19558 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19559 vkEndCommandBuffer(command_buffer[0]);
19560 }
19561 {
19562 VkCommandBufferBeginInfo begin_info{};
19563 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19564 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19565
19566 VkViewport viewport{};
19567 viewport.maxDepth = 1.0f;
19568 viewport.minDepth = 0.0f;
19569 viewport.width = 512;
19570 viewport.height = 512;
19571 viewport.x = 0;
19572 viewport.y = 0;
19573 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19574 vkEndCommandBuffer(command_buffer[1]);
19575 }
19576 {
19577 VkSubmitInfo submit_info{};
19578 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19579 submit_info.commandBufferCount = 1;
19580 submit_info.pCommandBuffers = &command_buffer[0];
19581 submit_info.signalSemaphoreCount = 1;
19582 submit_info.pSignalSemaphores = &semaphore;
19583 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19584 }
19585 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019586 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019587 VkSubmitInfo submit_info{};
19588 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19589 submit_info.commandBufferCount = 1;
19590 submit_info.pCommandBuffers = &command_buffer[1];
19591 submit_info.waitSemaphoreCount = 1;
19592 submit_info.pWaitSemaphores = &semaphore;
19593 submit_info.pWaitDstStageMask = flags;
19594 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19595 }
19596
19597 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19598
19599 vkDestroyFence(m_device->device(), fence, nullptr);
19600 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19601 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19602 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19603
19604 m_errorMonitor->VerifyNotFound();
19605}
19606
19607// This is a positive test. No errors should be generated.
19608TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019609 TEST_DESCRIPTION(
19610 "Two command buffers, each in a separate QueueSubmit call "
19611 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19612 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019613
19614 m_errorMonitor->ExpectSuccess();
19615
19616 ASSERT_NO_FATAL_FAILURE(InitState());
19617 VkFence fence;
19618 VkFenceCreateInfo fence_create_info{};
19619 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19620 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19621
19622 VkCommandPool command_pool;
19623 VkCommandPoolCreateInfo pool_create_info{};
19624 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19625 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19626 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19627 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19628
19629 VkCommandBuffer command_buffer[2];
19630 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19631 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19632 command_buffer_allocate_info.commandPool = command_pool;
19633 command_buffer_allocate_info.commandBufferCount = 2;
19634 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19635 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19636
19637 {
19638 VkCommandBufferBeginInfo begin_info{};
19639 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19640 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19641
19642 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 -070019643 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019644
19645 VkViewport viewport{};
19646 viewport.maxDepth = 1.0f;
19647 viewport.minDepth = 0.0f;
19648 viewport.width = 512;
19649 viewport.height = 512;
19650 viewport.x = 0;
19651 viewport.y = 0;
19652 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19653 vkEndCommandBuffer(command_buffer[0]);
19654 }
19655 {
19656 VkCommandBufferBeginInfo begin_info{};
19657 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19658 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19659
19660 VkViewport viewport{};
19661 viewport.maxDepth = 1.0f;
19662 viewport.minDepth = 0.0f;
19663 viewport.width = 512;
19664 viewport.height = 512;
19665 viewport.x = 0;
19666 viewport.y = 0;
19667 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19668 vkEndCommandBuffer(command_buffer[1]);
19669 }
19670 {
19671 VkSubmitInfo submit_info{};
19672 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19673 submit_info.commandBufferCount = 1;
19674 submit_info.pCommandBuffers = &command_buffer[0];
19675 submit_info.signalSemaphoreCount = 0;
19676 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19677 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19678 }
19679 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019680 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019681 VkSubmitInfo submit_info{};
19682 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19683 submit_info.commandBufferCount = 1;
19684 submit_info.pCommandBuffers = &command_buffer[1];
19685 submit_info.waitSemaphoreCount = 0;
19686 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19687 submit_info.pWaitDstStageMask = flags;
19688 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19689 }
19690
19691 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19692
19693 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19694 ASSERT_VK_SUCCESS(err);
19695
19696 vkDestroyFence(m_device->device(), fence, nullptr);
19697 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19698 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19699
19700 m_errorMonitor->VerifyNotFound();
19701}
19702
19703// This is a positive test. No errors should be generated.
19704TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019705 TEST_DESCRIPTION(
19706 "Two command buffers, each in a separate QueueSubmit call "
19707 "on the same queue, the second having a fence, followed "
19708 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019709
19710 m_errorMonitor->ExpectSuccess();
19711
19712 ASSERT_NO_FATAL_FAILURE(InitState());
19713 VkFence fence;
19714 VkFenceCreateInfo fence_create_info{};
19715 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19716 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19717
19718 VkCommandPool command_pool;
19719 VkCommandPoolCreateInfo pool_create_info{};
19720 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19721 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19722 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19723 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19724
19725 VkCommandBuffer command_buffer[2];
19726 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19727 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19728 command_buffer_allocate_info.commandPool = command_pool;
19729 command_buffer_allocate_info.commandBufferCount = 2;
19730 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19731 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19732
19733 {
19734 VkCommandBufferBeginInfo begin_info{};
19735 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19736 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19737
19738 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 -070019739 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019740
19741 VkViewport viewport{};
19742 viewport.maxDepth = 1.0f;
19743 viewport.minDepth = 0.0f;
19744 viewport.width = 512;
19745 viewport.height = 512;
19746 viewport.x = 0;
19747 viewport.y = 0;
19748 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19749 vkEndCommandBuffer(command_buffer[0]);
19750 }
19751 {
19752 VkCommandBufferBeginInfo begin_info{};
19753 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19754 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19755
19756 VkViewport viewport{};
19757 viewport.maxDepth = 1.0f;
19758 viewport.minDepth = 0.0f;
19759 viewport.width = 512;
19760 viewport.height = 512;
19761 viewport.x = 0;
19762 viewport.y = 0;
19763 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19764 vkEndCommandBuffer(command_buffer[1]);
19765 }
19766 {
19767 VkSubmitInfo submit_info{};
19768 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19769 submit_info.commandBufferCount = 1;
19770 submit_info.pCommandBuffers = &command_buffer[0];
19771 submit_info.signalSemaphoreCount = 0;
19772 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19773 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19774 }
19775 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019776 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019777 VkSubmitInfo submit_info{};
19778 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19779 submit_info.commandBufferCount = 1;
19780 submit_info.pCommandBuffers = &command_buffer[1];
19781 submit_info.waitSemaphoreCount = 0;
19782 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19783 submit_info.pWaitDstStageMask = flags;
19784 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19785 }
19786
19787 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19788
19789 vkDestroyFence(m_device->device(), fence, nullptr);
19790 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19791 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19792
19793 m_errorMonitor->VerifyNotFound();
19794}
19795
19796// This is a positive test. No errors should be generated.
19797TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019798 TEST_DESCRIPTION(
19799 "Two command buffers each in a separate SubmitInfo sent in a single "
19800 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019801 ASSERT_NO_FATAL_FAILURE(InitState());
19802
19803 m_errorMonitor->ExpectSuccess();
19804
19805 VkFence fence;
19806 VkFenceCreateInfo fence_create_info{};
19807 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19808 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19809
19810 VkSemaphore semaphore;
19811 VkSemaphoreCreateInfo semaphore_create_info{};
19812 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19813 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19814
19815 VkCommandPool command_pool;
19816 VkCommandPoolCreateInfo pool_create_info{};
19817 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19818 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19819 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19820 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19821
19822 VkCommandBuffer command_buffer[2];
19823 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19824 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19825 command_buffer_allocate_info.commandPool = command_pool;
19826 command_buffer_allocate_info.commandBufferCount = 2;
19827 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19828 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19829
19830 {
19831 VkCommandBufferBeginInfo begin_info{};
19832 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19833 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19834
19835 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 -070019836 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019837
19838 VkViewport viewport{};
19839 viewport.maxDepth = 1.0f;
19840 viewport.minDepth = 0.0f;
19841 viewport.width = 512;
19842 viewport.height = 512;
19843 viewport.x = 0;
19844 viewport.y = 0;
19845 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19846 vkEndCommandBuffer(command_buffer[0]);
19847 }
19848 {
19849 VkCommandBufferBeginInfo begin_info{};
19850 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19851 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19852
19853 VkViewport viewport{};
19854 viewport.maxDepth = 1.0f;
19855 viewport.minDepth = 0.0f;
19856 viewport.width = 512;
19857 viewport.height = 512;
19858 viewport.x = 0;
19859 viewport.y = 0;
19860 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19861 vkEndCommandBuffer(command_buffer[1]);
19862 }
19863 {
19864 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019865 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019866
19867 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19868 submit_info[0].pNext = NULL;
19869 submit_info[0].commandBufferCount = 1;
19870 submit_info[0].pCommandBuffers = &command_buffer[0];
19871 submit_info[0].signalSemaphoreCount = 1;
19872 submit_info[0].pSignalSemaphores = &semaphore;
19873 submit_info[0].waitSemaphoreCount = 0;
19874 submit_info[0].pWaitSemaphores = NULL;
19875 submit_info[0].pWaitDstStageMask = 0;
19876
19877 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19878 submit_info[1].pNext = NULL;
19879 submit_info[1].commandBufferCount = 1;
19880 submit_info[1].pCommandBuffers = &command_buffer[1];
19881 submit_info[1].waitSemaphoreCount = 1;
19882 submit_info[1].pWaitSemaphores = &semaphore;
19883 submit_info[1].pWaitDstStageMask = flags;
19884 submit_info[1].signalSemaphoreCount = 0;
19885 submit_info[1].pSignalSemaphores = NULL;
19886 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19887 }
19888
19889 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19890
19891 vkDestroyFence(m_device->device(), fence, nullptr);
19892 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19893 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19894 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19895
19896 m_errorMonitor->VerifyNotFound();
19897}
19898
19899TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19900 m_errorMonitor->ExpectSuccess();
19901
19902 ASSERT_NO_FATAL_FAILURE(InitState());
19903 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19904
Tony Barbour552f6c02016-12-21 14:34:07 -070019905 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019906
19907 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19908 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19909 m_errorMonitor->VerifyNotFound();
19910 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19911 m_errorMonitor->VerifyNotFound();
19912 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19913 m_errorMonitor->VerifyNotFound();
19914
19915 m_commandBuffer->EndCommandBuffer();
19916 m_errorMonitor->VerifyNotFound();
19917}
19918
19919TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019920 TEST_DESCRIPTION(
19921 "Positive test where we create a renderpass with an "
19922 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19923 "has a valid layout, and a second subpass then uses a "
19924 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019925 m_errorMonitor->ExpectSuccess();
19926 ASSERT_NO_FATAL_FAILURE(InitState());
19927
19928 VkAttachmentReference attach[2] = {};
19929 attach[0].attachment = 0;
19930 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19931 attach[1].attachment = 0;
19932 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19933 VkSubpassDescription subpasses[2] = {};
19934 // First subpass clears DS attach on load
19935 subpasses[0].pDepthStencilAttachment = &attach[0];
19936 // 2nd subpass reads in DS as input attachment
19937 subpasses[1].inputAttachmentCount = 1;
19938 subpasses[1].pInputAttachments = &attach[1];
19939 VkAttachmentDescription attach_desc = {};
19940 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19941 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19942 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19943 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19944 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19945 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19946 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19947 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19948 VkRenderPassCreateInfo rpci = {};
19949 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19950 rpci.attachmentCount = 1;
19951 rpci.pAttachments = &attach_desc;
19952 rpci.subpassCount = 2;
19953 rpci.pSubpasses = subpasses;
19954
19955 // Now create RenderPass and verify no errors
19956 VkRenderPass rp;
19957 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19958 m_errorMonitor->VerifyNotFound();
19959
19960 vkDestroyRenderPass(m_device->device(), rp, NULL);
19961}
19962
19963TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019964 TEST_DESCRIPTION(
19965 "Test that pipeline validation accepts matrices passed "
19966 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019967 m_errorMonitor->ExpectSuccess();
19968
19969 ASSERT_NO_FATAL_FAILURE(InitState());
19970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19971
19972 VkVertexInputBindingDescription input_binding;
19973 memset(&input_binding, 0, sizeof(input_binding));
19974
19975 VkVertexInputAttributeDescription input_attribs[2];
19976 memset(input_attribs, 0, sizeof(input_attribs));
19977
19978 for (int i = 0; i < 2; i++) {
19979 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19980 input_attribs[i].location = i;
19981 }
19982
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019983 char const *vsSource =
19984 "#version 450\n"
19985 "\n"
19986 "layout(location=0) in mat2x4 x;\n"
19987 "out gl_PerVertex {\n"
19988 " vec4 gl_Position;\n"
19989 "};\n"
19990 "void main(){\n"
19991 " gl_Position = x[0] + x[1];\n"
19992 "}\n";
19993 char const *fsSource =
19994 "#version 450\n"
19995 "\n"
19996 "layout(location=0) out vec4 color;\n"
19997 "void main(){\n"
19998 " color = vec4(1);\n"
19999 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020000
20001 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20002 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20003
20004 VkPipelineObj pipe(m_device);
20005 pipe.AddColorAttachment();
20006 pipe.AddShader(&vs);
20007 pipe.AddShader(&fs);
20008
20009 pipe.AddVertexInputBindings(&input_binding, 1);
20010 pipe.AddVertexInputAttribs(input_attribs, 2);
20011
20012 VkDescriptorSetObj descriptorSet(m_device);
20013 descriptorSet.AppendDummy();
20014 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20015
20016 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20017
20018 /* expect success */
20019 m_errorMonitor->VerifyNotFound();
20020}
20021
20022TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
20023 m_errorMonitor->ExpectSuccess();
20024
20025 ASSERT_NO_FATAL_FAILURE(InitState());
20026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20027
20028 VkVertexInputBindingDescription input_binding;
20029 memset(&input_binding, 0, sizeof(input_binding));
20030
20031 VkVertexInputAttributeDescription input_attribs[2];
20032 memset(input_attribs, 0, sizeof(input_attribs));
20033
20034 for (int i = 0; i < 2; i++) {
20035 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20036 input_attribs[i].location = i;
20037 }
20038
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020039 char const *vsSource =
20040 "#version 450\n"
20041 "\n"
20042 "layout(location=0) in vec4 x[2];\n"
20043 "out gl_PerVertex {\n"
20044 " vec4 gl_Position;\n"
20045 "};\n"
20046 "void main(){\n"
20047 " gl_Position = x[0] + x[1];\n"
20048 "}\n";
20049 char const *fsSource =
20050 "#version 450\n"
20051 "\n"
20052 "layout(location=0) out vec4 color;\n"
20053 "void main(){\n"
20054 " color = vec4(1);\n"
20055 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020056
20057 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20058 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20059
20060 VkPipelineObj pipe(m_device);
20061 pipe.AddColorAttachment();
20062 pipe.AddShader(&vs);
20063 pipe.AddShader(&fs);
20064
20065 pipe.AddVertexInputBindings(&input_binding, 1);
20066 pipe.AddVertexInputAttribs(input_attribs, 2);
20067
20068 VkDescriptorSetObj descriptorSet(m_device);
20069 descriptorSet.AppendDummy();
20070 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20071
20072 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20073
20074 m_errorMonitor->VerifyNotFound();
20075}
20076
20077TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020078 TEST_DESCRIPTION(
20079 "Test that pipeline validation accepts consuming a vertex attribute "
20080 "through multiple vertex shader inputs, each consuming a different "
20081 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020082 m_errorMonitor->ExpectSuccess();
20083
20084 ASSERT_NO_FATAL_FAILURE(InitState());
20085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20086
20087 VkVertexInputBindingDescription input_binding;
20088 memset(&input_binding, 0, sizeof(input_binding));
20089
20090 VkVertexInputAttributeDescription input_attribs[3];
20091 memset(input_attribs, 0, sizeof(input_attribs));
20092
20093 for (int i = 0; i < 3; i++) {
20094 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20095 input_attribs[i].location = i;
20096 }
20097
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020098 char const *vsSource =
20099 "#version 450\n"
20100 "\n"
20101 "layout(location=0) in vec4 x;\n"
20102 "layout(location=1) in vec3 y1;\n"
20103 "layout(location=1, component=3) in float y2;\n"
20104 "layout(location=2) in vec4 z;\n"
20105 "out gl_PerVertex {\n"
20106 " vec4 gl_Position;\n"
20107 "};\n"
20108 "void main(){\n"
20109 " gl_Position = x + vec4(y1, y2) + z;\n"
20110 "}\n";
20111 char const *fsSource =
20112 "#version 450\n"
20113 "\n"
20114 "layout(location=0) out vec4 color;\n"
20115 "void main(){\n"
20116 " color = vec4(1);\n"
20117 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020118
20119 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20120 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20121
20122 VkPipelineObj pipe(m_device);
20123 pipe.AddColorAttachment();
20124 pipe.AddShader(&vs);
20125 pipe.AddShader(&fs);
20126
20127 pipe.AddVertexInputBindings(&input_binding, 1);
20128 pipe.AddVertexInputAttribs(input_attribs, 3);
20129
20130 VkDescriptorSetObj descriptorSet(m_device);
20131 descriptorSet.AppendDummy();
20132 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20133
20134 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20135
20136 m_errorMonitor->VerifyNotFound();
20137}
20138
20139TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
20140 m_errorMonitor->ExpectSuccess();
20141
20142 ASSERT_NO_FATAL_FAILURE(InitState());
20143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20144
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020145 char const *vsSource =
20146 "#version 450\n"
20147 "out gl_PerVertex {\n"
20148 " vec4 gl_Position;\n"
20149 "};\n"
20150 "void main(){\n"
20151 " gl_Position = vec4(0);\n"
20152 "}\n";
20153 char const *fsSource =
20154 "#version 450\n"
20155 "\n"
20156 "layout(location=0) out vec4 color;\n"
20157 "void main(){\n"
20158 " color = vec4(1);\n"
20159 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020160
20161 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20162 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20163
20164 VkPipelineObj pipe(m_device);
20165 pipe.AddColorAttachment();
20166 pipe.AddShader(&vs);
20167 pipe.AddShader(&fs);
20168
20169 VkDescriptorSetObj descriptorSet(m_device);
20170 descriptorSet.AppendDummy();
20171 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20172
20173 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20174
20175 m_errorMonitor->VerifyNotFound();
20176}
20177
20178TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020179 TEST_DESCRIPTION(
20180 "Test that pipeline validation accepts the relaxed type matching rules "
20181 "set out in 14.1.3: fundamental type must match, and producer side must "
20182 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020183 m_errorMonitor->ExpectSuccess();
20184
20185 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
20186
20187 ASSERT_NO_FATAL_FAILURE(InitState());
20188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20189
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020190 char const *vsSource =
20191 "#version 450\n"
20192 "out gl_PerVertex {\n"
20193 " vec4 gl_Position;\n"
20194 "};\n"
20195 "layout(location=0) out vec3 x;\n"
20196 "layout(location=1) out ivec3 y;\n"
20197 "layout(location=2) out vec3 z;\n"
20198 "void main(){\n"
20199 " gl_Position = vec4(0);\n"
20200 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
20201 "}\n";
20202 char const *fsSource =
20203 "#version 450\n"
20204 "\n"
20205 "layout(location=0) out vec4 color;\n"
20206 "layout(location=0) in float x;\n"
20207 "layout(location=1) flat in int y;\n"
20208 "layout(location=2) in vec2 z;\n"
20209 "void main(){\n"
20210 " color = vec4(1 + x + y + z.x);\n"
20211 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020212
20213 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20214 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20215
20216 VkPipelineObj pipe(m_device);
20217 pipe.AddColorAttachment();
20218 pipe.AddShader(&vs);
20219 pipe.AddShader(&fs);
20220
20221 VkDescriptorSetObj descriptorSet(m_device);
20222 descriptorSet.AppendDummy();
20223 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20224
20225 VkResult err = VK_SUCCESS;
20226 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20227 ASSERT_VK_SUCCESS(err);
20228
20229 m_errorMonitor->VerifyNotFound();
20230}
20231
20232TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020233 TEST_DESCRIPTION(
20234 "Test that pipeline validation accepts per-vertex variables "
20235 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020236 m_errorMonitor->ExpectSuccess();
20237
20238 ASSERT_NO_FATAL_FAILURE(InitState());
20239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20240
20241 if (!m_device->phy().features().tessellationShader) {
20242 printf("Device does not support tessellation shaders; skipped.\n");
20243 return;
20244 }
20245
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020246 char const *vsSource =
20247 "#version 450\n"
20248 "void main(){}\n";
20249 char const *tcsSource =
20250 "#version 450\n"
20251 "layout(location=0) out int x[];\n"
20252 "layout(vertices=3) out;\n"
20253 "void main(){\n"
20254 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
20255 " gl_TessLevelInner[0] = 1;\n"
20256 " x[gl_InvocationID] = gl_InvocationID;\n"
20257 "}\n";
20258 char const *tesSource =
20259 "#version 450\n"
20260 "layout(triangles, equal_spacing, cw) in;\n"
20261 "layout(location=0) in int x[];\n"
20262 "out gl_PerVertex { vec4 gl_Position; };\n"
20263 "void main(){\n"
20264 " gl_Position.xyz = gl_TessCoord;\n"
20265 " gl_Position.w = x[0] + x[1] + x[2];\n"
20266 "}\n";
20267 char const *fsSource =
20268 "#version 450\n"
20269 "layout(location=0) out vec4 color;\n"
20270 "void main(){\n"
20271 " color = vec4(1);\n"
20272 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020273
20274 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20275 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
20276 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
20277 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20278
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020279 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
20280 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020281
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020282 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020283
20284 VkPipelineObj pipe(m_device);
20285 pipe.SetInputAssembly(&iasci);
20286 pipe.SetTessellation(&tsci);
20287 pipe.AddColorAttachment();
20288 pipe.AddShader(&vs);
20289 pipe.AddShader(&tcs);
20290 pipe.AddShader(&tes);
20291 pipe.AddShader(&fs);
20292
20293 VkDescriptorSetObj descriptorSet(m_device);
20294 descriptorSet.AppendDummy();
20295 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20296
20297 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20298
20299 m_errorMonitor->VerifyNotFound();
20300}
20301
20302TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020303 TEST_DESCRIPTION(
20304 "Test that pipeline validation accepts a user-defined "
20305 "interface block passed into the geometry shader. This "
20306 "is interesting because the 'extra' array level is not "
20307 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020308 m_errorMonitor->ExpectSuccess();
20309
20310 ASSERT_NO_FATAL_FAILURE(InitState());
20311 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20312
20313 if (!m_device->phy().features().geometryShader) {
20314 printf("Device does not support geometry shaders; skipped.\n");
20315 return;
20316 }
20317
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020318 char const *vsSource =
20319 "#version 450\n"
20320 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
20321 "void main(){\n"
20322 " vs_out.x = vec4(1);\n"
20323 "}\n";
20324 char const *gsSource =
20325 "#version 450\n"
20326 "layout(triangles) in;\n"
20327 "layout(triangle_strip, max_vertices=3) out;\n"
20328 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
20329 "out gl_PerVertex { vec4 gl_Position; };\n"
20330 "void main() {\n"
20331 " gl_Position = gs_in[0].x;\n"
20332 " EmitVertex();\n"
20333 "}\n";
20334 char const *fsSource =
20335 "#version 450\n"
20336 "layout(location=0) out vec4 color;\n"
20337 "void main(){\n"
20338 " color = vec4(1);\n"
20339 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020340
20341 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20342 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
20343 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20344
20345 VkPipelineObj pipe(m_device);
20346 pipe.AddColorAttachment();
20347 pipe.AddShader(&vs);
20348 pipe.AddShader(&gs);
20349 pipe.AddShader(&fs);
20350
20351 VkDescriptorSetObj descriptorSet(m_device);
20352 descriptorSet.AppendDummy();
20353 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20354
20355 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20356
20357 m_errorMonitor->VerifyNotFound();
20358}
20359
20360TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020361 TEST_DESCRIPTION(
20362 "Test that pipeline validation accepts basic use of 64bit vertex "
20363 "attributes. This is interesting because they consume multiple "
20364 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020365 m_errorMonitor->ExpectSuccess();
20366
20367 ASSERT_NO_FATAL_FAILURE(InitState());
20368 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20369
20370 if (!m_device->phy().features().shaderFloat64) {
20371 printf("Device does not support 64bit vertex attributes; skipped.\n");
20372 return;
20373 }
20374
20375 VkVertexInputBindingDescription input_bindings[1];
20376 memset(input_bindings, 0, sizeof(input_bindings));
20377
20378 VkVertexInputAttributeDescription input_attribs[4];
20379 memset(input_attribs, 0, sizeof(input_attribs));
20380 input_attribs[0].location = 0;
20381 input_attribs[0].offset = 0;
20382 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20383 input_attribs[1].location = 2;
20384 input_attribs[1].offset = 32;
20385 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20386 input_attribs[2].location = 4;
20387 input_attribs[2].offset = 64;
20388 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20389 input_attribs[3].location = 6;
20390 input_attribs[3].offset = 96;
20391 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20392
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020393 char const *vsSource =
20394 "#version 450\n"
20395 "\n"
20396 "layout(location=0) in dmat4 x;\n"
20397 "out gl_PerVertex {\n"
20398 " vec4 gl_Position;\n"
20399 "};\n"
20400 "void main(){\n"
20401 " gl_Position = vec4(x[0][0]);\n"
20402 "}\n";
20403 char const *fsSource =
20404 "#version 450\n"
20405 "\n"
20406 "layout(location=0) out vec4 color;\n"
20407 "void main(){\n"
20408 " color = vec4(1);\n"
20409 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020410
20411 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20412 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20413
20414 VkPipelineObj pipe(m_device);
20415 pipe.AddColorAttachment();
20416 pipe.AddShader(&vs);
20417 pipe.AddShader(&fs);
20418
20419 pipe.AddVertexInputBindings(input_bindings, 1);
20420 pipe.AddVertexInputAttribs(input_attribs, 4);
20421
20422 VkDescriptorSetObj descriptorSet(m_device);
20423 descriptorSet.AppendDummy();
20424 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20425
20426 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20427
20428 m_errorMonitor->VerifyNotFound();
20429}
20430
20431TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
20432 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
20433 m_errorMonitor->ExpectSuccess();
20434
20435 ASSERT_NO_FATAL_FAILURE(InitState());
20436
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020437 char const *vsSource =
20438 "#version 450\n"
20439 "\n"
20440 "out gl_PerVertex {\n"
20441 " vec4 gl_Position;\n"
20442 "};\n"
20443 "void main(){\n"
20444 " gl_Position = vec4(1);\n"
20445 "}\n";
20446 char const *fsSource =
20447 "#version 450\n"
20448 "\n"
20449 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
20450 "layout(location=0) out vec4 color;\n"
20451 "void main() {\n"
20452 " color = subpassLoad(x);\n"
20453 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020454
20455 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20456 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20457
20458 VkPipelineObj pipe(m_device);
20459 pipe.AddShader(&vs);
20460 pipe.AddShader(&fs);
20461 pipe.AddColorAttachment();
20462 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20463
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020464 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
20465 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020466 VkDescriptorSetLayout dsl;
20467 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20468 ASSERT_VK_SUCCESS(err);
20469
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020470 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020471 VkPipelineLayout pl;
20472 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20473 ASSERT_VK_SUCCESS(err);
20474
20475 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020476 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20477 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20478 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
20479 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20480 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 -060020481 };
20482 VkAttachmentReference color = {
20483 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20484 };
20485 VkAttachmentReference input = {
20486 1, VK_IMAGE_LAYOUT_GENERAL,
20487 };
20488
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020489 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020490
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020491 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020492 VkRenderPass rp;
20493 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20494 ASSERT_VK_SUCCESS(err);
20495
20496 // should be OK. would go wrong here if it's going to...
20497 pipe.CreateVKPipeline(pl, rp);
20498
20499 m_errorMonitor->VerifyNotFound();
20500
20501 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20502 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20503 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20504}
20505
20506TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020507 TEST_DESCRIPTION(
20508 "Test that pipeline validation accepts a compute pipeline which declares a "
20509 "descriptor-backed resource which is not provided, but the shader does not "
20510 "statically use it. This is interesting because it requires compute pipelines "
20511 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020512 m_errorMonitor->ExpectSuccess();
20513
20514 ASSERT_NO_FATAL_FAILURE(InitState());
20515
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020516 char const *csSource =
20517 "#version 450\n"
20518 "\n"
20519 "layout(local_size_x=1) in;\n"
20520 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
20521 "void main(){\n"
20522 " // x is not used.\n"
20523 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020524
20525 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20526
20527 VkDescriptorSetObj descriptorSet(m_device);
20528 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20529
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020530 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20531 nullptr,
20532 0,
20533 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20534 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20535 descriptorSet.GetPipelineLayout(),
20536 VK_NULL_HANDLE,
20537 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020538
20539 VkPipeline pipe;
20540 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20541
20542 m_errorMonitor->VerifyNotFound();
20543
20544 if (err == VK_SUCCESS) {
20545 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20546 }
20547}
20548
20549TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020550 TEST_DESCRIPTION(
20551 "Test that pipeline validation accepts a shader consuming only the "
20552 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020553 m_errorMonitor->ExpectSuccess();
20554
20555 ASSERT_NO_FATAL_FAILURE(InitState());
20556
20557 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020558 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20559 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20560 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020561 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020562 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020563 VkDescriptorSetLayout dsl;
20564 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20565 ASSERT_VK_SUCCESS(err);
20566
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020567 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020568 VkPipelineLayout pl;
20569 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20570 ASSERT_VK_SUCCESS(err);
20571
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020572 char const *csSource =
20573 "#version 450\n"
20574 "\n"
20575 "layout(local_size_x=1) in;\n"
20576 "layout(set=0, binding=0) uniform sampler s;\n"
20577 "layout(set=0, binding=1) uniform texture2D t;\n"
20578 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20579 "void main() {\n"
20580 " x = texture(sampler2D(t, s), vec2(0));\n"
20581 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020582 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20583
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020584 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20585 nullptr,
20586 0,
20587 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20588 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20589 pl,
20590 VK_NULL_HANDLE,
20591 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020592
20593 VkPipeline pipe;
20594 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20595
20596 m_errorMonitor->VerifyNotFound();
20597
20598 if (err == VK_SUCCESS) {
20599 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20600 }
20601
20602 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20603 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20604}
20605
20606TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020607 TEST_DESCRIPTION(
20608 "Test that pipeline validation accepts a shader consuming only the "
20609 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020610 m_errorMonitor->ExpectSuccess();
20611
20612 ASSERT_NO_FATAL_FAILURE(InitState());
20613
20614 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020615 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20616 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20617 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020618 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020619 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020620 VkDescriptorSetLayout dsl;
20621 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20622 ASSERT_VK_SUCCESS(err);
20623
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020624 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020625 VkPipelineLayout pl;
20626 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20627 ASSERT_VK_SUCCESS(err);
20628
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020629 char const *csSource =
20630 "#version 450\n"
20631 "\n"
20632 "layout(local_size_x=1) in;\n"
20633 "layout(set=0, binding=0) uniform texture2D t;\n"
20634 "layout(set=0, binding=1) uniform sampler s;\n"
20635 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20636 "void main() {\n"
20637 " x = texture(sampler2D(t, s), vec2(0));\n"
20638 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020639 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20640
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020641 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20642 nullptr,
20643 0,
20644 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20645 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20646 pl,
20647 VK_NULL_HANDLE,
20648 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020649
20650 VkPipeline pipe;
20651 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20652
20653 m_errorMonitor->VerifyNotFound();
20654
20655 if (err == VK_SUCCESS) {
20656 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20657 }
20658
20659 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20660 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20661}
20662
20663TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020664 TEST_DESCRIPTION(
20665 "Test that pipeline validation accepts a shader consuming "
20666 "both the sampler and the image of a combined image+sampler "
20667 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020668 m_errorMonitor->ExpectSuccess();
20669
20670 ASSERT_NO_FATAL_FAILURE(InitState());
20671
20672 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020673 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20674 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020675 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020676 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020677 VkDescriptorSetLayout dsl;
20678 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20679 ASSERT_VK_SUCCESS(err);
20680
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020681 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020682 VkPipelineLayout pl;
20683 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20684 ASSERT_VK_SUCCESS(err);
20685
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020686 char const *csSource =
20687 "#version 450\n"
20688 "\n"
20689 "layout(local_size_x=1) in;\n"
20690 "layout(set=0, binding=0) uniform texture2D t;\n"
20691 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20692 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20693 "void main() {\n"
20694 " x = texture(sampler2D(t, s), vec2(0));\n"
20695 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020696 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20697
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020698 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20699 nullptr,
20700 0,
20701 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20702 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20703 pl,
20704 VK_NULL_HANDLE,
20705 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020706
20707 VkPipeline pipe;
20708 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20709
20710 m_errorMonitor->VerifyNotFound();
20711
20712 if (err == VK_SUCCESS) {
20713 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20714 }
20715
20716 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20717 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20718}
20719
20720TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20721 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20722
20723 ASSERT_NO_FATAL_FAILURE(InitState());
20724
20725 // Positive test to check parameter_validation and unique_objects support
20726 // for NV_dedicated_allocation
20727 uint32_t extension_count = 0;
20728 bool supports_nv_dedicated_allocation = false;
20729 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20730 ASSERT_VK_SUCCESS(err);
20731
20732 if (extension_count > 0) {
20733 std::vector<VkExtensionProperties> available_extensions(extension_count);
20734
20735 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20736 ASSERT_VK_SUCCESS(err);
20737
20738 for (const auto &extension_props : available_extensions) {
20739 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20740 supports_nv_dedicated_allocation = true;
20741 }
20742 }
20743 }
20744
20745 if (supports_nv_dedicated_allocation) {
20746 m_errorMonitor->ExpectSuccess();
20747
20748 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20749 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20750 dedicated_buffer_create_info.pNext = nullptr;
20751 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20752
20753 uint32_t queue_family_index = 0;
20754 VkBufferCreateInfo buffer_create_info = {};
20755 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20756 buffer_create_info.pNext = &dedicated_buffer_create_info;
20757 buffer_create_info.size = 1024;
20758 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20759 buffer_create_info.queueFamilyIndexCount = 1;
20760 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20761
20762 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070020763 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020764 ASSERT_VK_SUCCESS(err);
20765
20766 VkMemoryRequirements memory_reqs;
20767 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20768
20769 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20770 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20771 dedicated_memory_info.pNext = nullptr;
20772 dedicated_memory_info.buffer = buffer;
20773 dedicated_memory_info.image = VK_NULL_HANDLE;
20774
20775 VkMemoryAllocateInfo memory_info = {};
20776 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20777 memory_info.pNext = &dedicated_memory_info;
20778 memory_info.allocationSize = memory_reqs.size;
20779
20780 bool pass;
20781 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20782 ASSERT_TRUE(pass);
20783
20784 VkDeviceMemory buffer_memory;
20785 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20786 ASSERT_VK_SUCCESS(err);
20787
20788 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20789 ASSERT_VK_SUCCESS(err);
20790
20791 vkDestroyBuffer(m_device->device(), buffer, NULL);
20792 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20793
20794 m_errorMonitor->VerifyNotFound();
20795 }
20796}
20797
20798TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20799 VkResult err;
20800
20801 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20802
20803 ASSERT_NO_FATAL_FAILURE(InitState());
20804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20805
20806 std::vector<const char *> device_extension_names;
20807 auto features = m_device->phy().features();
20808 // Artificially disable support for non-solid fill modes
20809 features.fillModeNonSolid = false;
20810 // The sacrificial device object
20811 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20812
20813 VkRenderpassObj render_pass(&test_device);
20814
20815 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20816 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20817 pipeline_layout_ci.setLayoutCount = 0;
20818 pipeline_layout_ci.pSetLayouts = NULL;
20819
20820 VkPipelineLayout pipeline_layout;
20821 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20822 ASSERT_VK_SUCCESS(err);
20823
20824 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20825 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20826 rs_ci.pNext = nullptr;
20827 rs_ci.lineWidth = 1.0f;
20828 rs_ci.rasterizerDiscardEnable = true;
20829
20830 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20831 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20832
20833 // Set polygonMode=FILL. No error is expected
20834 m_errorMonitor->ExpectSuccess();
20835 {
20836 VkPipelineObj pipe(&test_device);
20837 pipe.AddShader(&vs);
20838 pipe.AddShader(&fs);
20839 pipe.AddColorAttachment();
20840 // Set polygonMode to a good value
20841 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20842 pipe.SetRasterization(&rs_ci);
20843 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20844 }
20845 m_errorMonitor->VerifyNotFound();
20846
20847 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20848}
20849
20850TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20851 VkResult err;
20852 ASSERT_NO_FATAL_FAILURE(InitState());
20853 ASSERT_NO_FATAL_FAILURE(InitViewport());
20854 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20855
20856 VkPipelineLayout pipeline_layout;
20857 VkPushConstantRange pc_range = {};
20858 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20859 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20860 pipeline_layout_ci.pushConstantRangeCount = 1;
20861 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20862
20863 //
20864 // Check for invalid push constant ranges in pipeline layouts.
20865 //
20866 struct PipelineLayoutTestCase {
20867 VkPushConstantRange const range;
20868 char const *msg;
20869 };
20870
20871 // Check for overlapping ranges
20872 const uint32_t ranges_per_test = 5;
20873 struct OverlappingRangeTestCase {
20874 VkPushConstantRange const ranges[ranges_per_test];
20875 char const *msg;
20876 };
20877
20878 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020879 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
20880 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
20881 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
20882 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
20883 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
20884 ""},
20885 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
20886 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
20887 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
20888 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
20889 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
20890 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020891 for (const auto &iter : overlapping_range_tests_pos) {
20892 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20893 m_errorMonitor->ExpectSuccess();
20894 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20895 m_errorMonitor->VerifyNotFound();
20896 if (VK_SUCCESS == err) {
20897 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20898 }
20899 }
20900
20901 //
20902 // CmdPushConstants tests
20903 //
20904 const uint8_t dummy_values[100] = {};
20905
Tony Barbour552f6c02016-12-21 14:34:07 -070020906 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020907
20908 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020909 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
20910 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
20911 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
20912 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
20913 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
20914 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020915
20916 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20917 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020918 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
20919 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 56, 24},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020920 };
20921
20922 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20923 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20924 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20925 ASSERT_VK_SUCCESS(err);
20926 for (const auto &iter : cmd_overlap_tests_pos) {
20927 m_errorMonitor->ExpectSuccess();
20928 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020929 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020930 m_errorMonitor->VerifyNotFound();
20931 }
20932 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20933
Tony Barbour552f6c02016-12-21 14:34:07 -070020934 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020935}
20936
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020937#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020938TEST_F(VkPositiveLayerTest, LongFenceChain)
20939{
20940 m_errorMonitor->ExpectSuccess();
20941
20942 ASSERT_NO_FATAL_FAILURE(InitState());
20943 VkResult err;
20944
20945 std::vector<VkFence> fences;
20946
20947 const int chainLength = 32768;
20948
20949 for (int i = 0; i < chainLength; i++) {
20950 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20951 VkFence fence;
20952 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20953 ASSERT_VK_SUCCESS(err);
20954
20955 fences.push_back(fence);
20956
20957 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20958 0, nullptr, 0, nullptr };
20959 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20960 ASSERT_VK_SUCCESS(err);
20961
20962 }
20963
20964 // BOOM, stack overflow.
20965 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20966
20967 for (auto fence : fences)
20968 vkDestroyFence(m_device->device(), fence, nullptr);
20969
20970 m_errorMonitor->VerifyNotFound();
20971}
20972#endif
20973
Cody Northrop1242dfd2016-07-13 17:24:59 -060020974#if defined(ANDROID) && defined(VALIDATION_APK)
20975static bool initialized = false;
20976static bool active = false;
20977
20978// Convert Intents to argv
20979// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020980std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020981 std::vector<std::string> args;
20982 JavaVM &vm = *app.activity->vm;
20983 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020984 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020985
20986 JNIEnv &env = *p_env;
20987 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020988 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020989 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020990 jmethodID get_string_extra_method =
20991 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020992 jvalue get_string_extra_args;
20993 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020994 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020995
20996 std::string args_str;
20997 if (extra_str) {
20998 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20999 args_str = extra_utf;
21000 env.ReleaseStringUTFChars(extra_str, extra_utf);
21001 env.DeleteLocalRef(extra_str);
21002 }
21003
21004 env.DeleteLocalRef(get_string_extra_args.l);
21005 env.DeleteLocalRef(intent);
21006 vm.DetachCurrentThread();
21007
21008 // split args_str
21009 std::stringstream ss(args_str);
21010 std::string arg;
21011 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021012 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021013 }
21014
21015 return args;
21016}
21017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021018static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021020static void processCommand(struct android_app *app, int32_t cmd) {
21021 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021022 case APP_CMD_INIT_WINDOW: {
21023 if (app->window) {
21024 initialized = true;
21025 }
21026 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021027 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021028 case APP_CMD_GAINED_FOCUS: {
21029 active = true;
21030 break;
21031 }
21032 case APP_CMD_LOST_FOCUS: {
21033 active = false;
21034 break;
21035 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021036 }
21037}
21038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021039void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021040 app_dummy();
21041
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021042 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060021043
21044 int vulkanSupport = InitVulkan();
21045 if (vulkanSupport == 0) {
21046 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
21047 return;
21048 }
21049
21050 app->onAppCmd = processCommand;
21051 app->onInputEvent = processInput;
21052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021053 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021054 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021055 struct android_poll_source *source;
21056 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021057 if (source) {
21058 source->process(app, source);
21059 }
21060
21061 if (app->destroyRequested != 0) {
21062 VkTestFramework::Finish();
21063 return;
21064 }
21065 }
21066
21067 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021068 // Use the following key to send arguments to gtest, i.e.
21069 // --es args "--gtest_filter=-VkLayerTest.foo"
21070 const char key[] = "args";
21071 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021072
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021073 std::string filter = "";
21074 if (args.size() > 0) {
21075 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
21076 filter += args[0];
21077 } else {
21078 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
21079 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021081 int argc = 2;
21082 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
21083 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021085 // Route output to files until we can override the gtest output
21086 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
21087 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021089 ::testing::InitGoogleTest(&argc, argv);
21090 VkTestFramework::InitArgs(&argc, argv);
21091 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021093 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060021094
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021095 if (result != 0) {
21096 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
21097 } else {
21098 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
21099 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021100
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021101 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060021102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021103 fclose(stdout);
21104 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021106 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021108 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021109 }
21110 }
21111}
21112#endif
21113
Tony Barbour300a6082015-04-07 13:44:53 -060021114int main(int argc, char **argv) {
21115 int result;
21116
Cody Northrop8e54a402016-03-08 22:25:52 -070021117#ifdef ANDROID
21118 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021119 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070021120#endif
21121
Tony Barbour300a6082015-04-07 13:44:53 -060021122 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060021123 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060021124
21125 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
21126
21127 result = RUN_ALL_TESTS();
21128
Tony Barbour6918cd52015-04-09 12:58:51 -060021129 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060021130 return result;
21131}