blob: ed6b0e085a8a19c914af30c67a01f0efc2e0b0a5 [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);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003257 // Create a renderPass with two color attachments
3258 VkAttachmentReference attachments[2] = {};
3259 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3260 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3261
3262 VkSubpassDescription subpass = {};
3263 subpass.pColorAttachments = attachments;
3264 subpass.colorAttachmentCount = 2;
3265
3266 VkRenderPassCreateInfo rpci = {};
3267 rpci.subpassCount = 1;
3268 rpci.pSubpasses = &subpass;
3269 rpci.attachmentCount = 1;
3270
3271 VkAttachmentDescription attach_desc = {};
3272 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3273 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3274 attach_desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3275 attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3276
3277 rpci.pAttachments = &attach_desc;
3278 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3279
3280 VkRenderPass renderpass;
3281 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003282 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003283 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003284
Cody Northropc31a84f2016-08-22 10:41:47 -06003285 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3286 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3287 att_state1.blendEnable = VK_TRUE;
3288 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3289 att_state2.blendEnable = VK_FALSE;
3290 pipeline.AddColorAttachment(0, &att_state1);
3291 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003292 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003293 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003294 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003295}
3296
Chris Forbes26ec2122016-11-29 08:58:33 +13003297#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003298TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3299 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3300 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003301 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003302
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3304 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003305
3306 // Create a renderPass with a single color attachment
3307 VkAttachmentReference attach = {};
3308 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3309 VkSubpassDescription subpass = {};
3310 VkRenderPassCreateInfo rpci = {};
3311 rpci.subpassCount = 1;
3312 rpci.pSubpasses = &subpass;
3313 rpci.attachmentCount = 1;
3314 VkAttachmentDescription attach_desc = {};
3315 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3316 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3317 rpci.pAttachments = &attach_desc;
3318 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3319 VkRenderPass rp;
3320 subpass.pDepthStencilAttachment = &attach;
3321 subpass.pColorAttachments = NULL;
3322 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3323 m_errorMonitor->VerifyFound();
3324}
Chris Forbes26ec2122016-11-29 08:58:33 +13003325#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003326
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003327TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003328 TEST_DESCRIPTION(
3329 "Create a framebuffer where a subpass has a preserve "
3330 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003331
3332 ASSERT_NO_FATAL_FAILURE(InitState());
3333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3334
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003336
3337 VkAttachmentReference color_attach = {};
3338 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3339 color_attach.attachment = 0;
3340 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3341 VkSubpassDescription subpass = {};
3342 subpass.colorAttachmentCount = 1;
3343 subpass.pColorAttachments = &color_attach;
3344 subpass.preserveAttachmentCount = 1;
3345 subpass.pPreserveAttachments = &preserve_attachment;
3346
3347 VkRenderPassCreateInfo rpci = {};
3348 rpci.subpassCount = 1;
3349 rpci.pSubpasses = &subpass;
3350 rpci.attachmentCount = 1;
3351 VkAttachmentDescription attach_desc = {};
3352 attach_desc.format = VK_FORMAT_UNDEFINED;
3353 rpci.pAttachments = &attach_desc;
3354 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3355 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003356 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003357
3358 m_errorMonitor->VerifyFound();
3359
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003360 if (result == VK_SUCCESS) {
3361 vkDestroyRenderPass(m_device->device(), rp, NULL);
3362 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003363}
3364
Chris Forbesc5389742016-06-29 11:49:23 +12003365TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003366 TEST_DESCRIPTION(
3367 "Ensure that CreateRenderPass produces a validation error "
3368 "when the source of a subpass multisample resolve "
3369 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003370
Chris Forbesc5389742016-06-29 11:49:23 +12003371 ASSERT_NO_FATAL_FAILURE(InitState());
3372
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3374 "Subpass 0 requests multisample resolve from attachment 0 which has "
3375 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003376
3377 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003378 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3379 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3380 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3381 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3382 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3383 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003384 };
3385
3386 VkAttachmentReference color = {
3387 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3388 };
3389
3390 VkAttachmentReference resolve = {
3391 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3392 };
3393
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003394 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003395
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003396 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003397
3398 VkRenderPass rp;
3399 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3400
3401 m_errorMonitor->VerifyFound();
3402
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003403 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003404}
3405
3406TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003407 TEST_DESCRIPTION(
3408 "Ensure CreateRenderPass produces a validation error "
3409 "when a subpass multisample resolve operation is "
3410 "requested, and the destination of that resolve has "
3411 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003412
Chris Forbesc5389742016-06-29 11:49:23 +12003413 ASSERT_NO_FATAL_FAILURE(InitState());
3414
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3416 "Subpass 0 requests multisample resolve into attachment 1, which "
3417 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003418
3419 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003420 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3421 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3422 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3423 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3424 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3425 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003426 };
3427
3428 VkAttachmentReference color = {
3429 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3430 };
3431
3432 VkAttachmentReference resolve = {
3433 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3434 };
3435
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003436 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003437
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003438 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003439
3440 VkRenderPass rp;
3441 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3442
3443 m_errorMonitor->VerifyFound();
3444
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003445 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003446}
3447
Chris Forbes3f128ef2016-06-29 14:58:53 +12003448TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003449 TEST_DESCRIPTION(
3450 "Ensure CreateRenderPass produces a validation error "
3451 "when the color and depth attachments used by a subpass "
3452 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003453
Chris Forbes3f128ef2016-06-29 14:58:53 +12003454 ASSERT_NO_FATAL_FAILURE(InitState());
3455
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3457 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003458
3459 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003460 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3461 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3462 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3463 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3464 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3465 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003466 };
3467
3468 VkAttachmentReference color[] = {
3469 {
3470 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3471 },
3472 {
3473 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3474 },
3475 };
3476
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003477 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003478
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003479 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003480
3481 VkRenderPass rp;
3482 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3483
3484 m_errorMonitor->VerifyFound();
3485
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003486 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003487}
3488
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003489TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003490 TEST_DESCRIPTION(
3491 "Hit errors when attempting to create a framebuffer :\n"
3492 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3493 " 2. Use a color image as depthStencil attachment\n"
3494 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3495 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3496 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3497 " 6. Framebuffer attachment where dimensions don't match\n"
3498 " 7. Framebuffer attachment w/o identity swizzle\n"
3499 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003500
3501 ASSERT_NO_FATAL_FAILURE(InitState());
3502 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3503
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3505 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3506 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003507
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003508 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003509 VkAttachmentReference attach = {};
3510 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3511 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003512 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003513 VkRenderPassCreateInfo rpci = {};
3514 rpci.subpassCount = 1;
3515 rpci.pSubpasses = &subpass;
3516 rpci.attachmentCount = 1;
3517 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003518 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003519 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003520 rpci.pAttachments = &attach_desc;
3521 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3522 VkRenderPass rp;
3523 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3524 ASSERT_VK_SUCCESS(err);
3525
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003526 VkImageView ivs[2];
3527 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3528 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003529 VkFramebufferCreateInfo fb_info = {};
3530 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3531 fb_info.pNext = NULL;
3532 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003533 // Set mis-matching attachmentCount
3534 fb_info.attachmentCount = 2;
3535 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003536 fb_info.width = 100;
3537 fb_info.height = 100;
3538 fb_info.layers = 1;
3539
3540 VkFramebuffer fb;
3541 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3542
3543 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003544 if (err == VK_SUCCESS) {
3545 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3546 }
3547 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003548
3549 // Create a renderPass with a depth-stencil attachment created with
3550 // IMAGE_USAGE_COLOR_ATTACHMENT
3551 // Add our color attachment to pDepthStencilAttachment
3552 subpass.pDepthStencilAttachment = &attach;
3553 subpass.pColorAttachments = NULL;
3554 VkRenderPass rp_ds;
3555 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3556 ASSERT_VK_SUCCESS(err);
3557 // Set correct attachment count, but attachment has COLOR usage bit set
3558 fb_info.attachmentCount = 1;
3559 fb_info.renderPass = rp_ds;
3560
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003562 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3563
3564 m_errorMonitor->VerifyFound();
3565 if (err == VK_SUCCESS) {
3566 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3567 }
3568 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003569
3570 // Create new renderpass with alternate attachment format from fb
3571 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3572 subpass.pDepthStencilAttachment = NULL;
3573 subpass.pColorAttachments = &attach;
3574 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3575 ASSERT_VK_SUCCESS(err);
3576
3577 // Cause error due to mis-matched formats between rp & fb
3578 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3579 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3581 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003582 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3583
3584 m_errorMonitor->VerifyFound();
3585 if (err == VK_SUCCESS) {
3586 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3587 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003588 vkDestroyRenderPass(m_device->device(), rp, NULL);
3589
3590 // Create new renderpass with alternate sample count from fb
3591 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3592 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3593 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3594 ASSERT_VK_SUCCESS(err);
3595
3596 // Cause error due to mis-matched sample count between rp & fb
3597 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3599 " has VK_SAMPLE_COUNT_1_BIT samples "
3600 "that do not match the "
3601 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003602 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3603
3604 m_errorMonitor->VerifyFound();
3605 if (err == VK_SUCCESS) {
3606 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3607 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003608
3609 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003610
3611 // Create a custom imageView with non-1 mip levels
3612 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003613 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 -06003614 ASSERT_TRUE(image.initialized());
3615
3616 VkImageView view;
3617 VkImageViewCreateInfo ivci = {};
3618 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3619 ivci.image = image.handle();
3620 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3621 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3622 ivci.subresourceRange.layerCount = 1;
3623 ivci.subresourceRange.baseMipLevel = 0;
3624 // Set level count 2 (only 1 is allowed for FB attachment)
3625 ivci.subresourceRange.levelCount = 2;
3626 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3627 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3628 ASSERT_VK_SUCCESS(err);
3629 // Re-create renderpass to have matching sample count
3630 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3631 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3632 ASSERT_VK_SUCCESS(err);
3633
3634 fb_info.renderPass = rp;
3635 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003637 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3638
3639 m_errorMonitor->VerifyFound();
3640 if (err == VK_SUCCESS) {
3641 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3642 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003643 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003644 // Update view to original color buffer and grow FB dimensions too big
3645 fb_info.pAttachments = ivs;
3646 fb_info.height = 1024;
3647 fb_info.width = 1024;
3648 fb_info.layers = 2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3650 " Attachment dimensions must be at "
3651 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003652 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3653
3654 m_errorMonitor->VerifyFound();
3655 if (err == VK_SUCCESS) {
3656 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3657 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003658 // Create view attachment with non-identity swizzle
3659 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3660 ivci.image = image.handle();
3661 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3662 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3663 ivci.subresourceRange.layerCount = 1;
3664 ivci.subresourceRange.baseMipLevel = 0;
3665 ivci.subresourceRange.levelCount = 1;
3666 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3667 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3668 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3669 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3670 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3671 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3672 ASSERT_VK_SUCCESS(err);
3673
3674 fb_info.pAttachments = &view;
3675 fb_info.height = 100;
3676 fb_info.width = 100;
3677 fb_info.layers = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3679 " has non-identy swizzle. All "
3680 "framebuffer attachments must have "
3681 "been created with the identity "
3682 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003683 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3684
3685 m_errorMonitor->VerifyFound();
3686 if (err == VK_SUCCESS) {
3687 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3688 }
3689 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003690 // reset attachment to color attachment
3691 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003692
3693 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003694 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003695 fb_info.height = 100;
3696 fb_info.layers = 1;
3697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
3698 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3699
3700 m_errorMonitor->VerifyFound();
3701 if (err == VK_SUCCESS) {
3702 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3703 }
3704
3705 // Request fb that exceeds max height
3706 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003707 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003708 fb_info.layers = 1;
3709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
3710 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3711
3712 m_errorMonitor->VerifyFound();
3713 if (err == VK_SUCCESS) {
3714 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3715 }
3716
3717 // Request fb that exceeds max layers
3718 fb_info.width = 100;
3719 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003720 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003722 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3723
3724 m_errorMonitor->VerifyFound();
3725 if (err == VK_SUCCESS) {
3726 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3727 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003728
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003729 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003730}
3731
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003732TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003733 TEST_DESCRIPTION(
3734 "Run a simple draw calls to validate failure when Depth Bias dynamic "
3735 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003736
Cody Northropc31a84f2016-08-22 10:41:47 -06003737 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003738 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3740 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003741 m_errorMonitor->VerifyFound();
3742}
3743
3744TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003745 TEST_DESCRIPTION(
3746 "Run a simple draw calls to validate failure when Line Width dynamic "
3747 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003748
Cody Northropc31a84f2016-08-22 10:41:47 -06003749 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003750 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3752 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003753 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003754}
3755
3756TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003757 TEST_DESCRIPTION(
3758 "Run a simple draw calls to validate failure when Viewport dynamic "
3759 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003760
Cody Northropc31a84f2016-08-22 10:41:47 -06003761 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003762 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3764 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003765 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003766 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003767}
3768
3769TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003770 TEST_DESCRIPTION(
3771 "Run a simple draw calls to validate failure when Scissor dynamic "
3772 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003773
Cody Northropc31a84f2016-08-22 10:41:47 -06003774 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003775 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3777 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003778 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003779 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003780}
3781
Cortd713fe82016-07-27 09:51:27 -07003782TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003783 TEST_DESCRIPTION(
3784 "Run a simple draw calls to validate failure when Blend Constants "
3785 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003786
3787 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003788 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3790 "Dynamic blend constants state not set for this command buffer");
3791 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003792 m_errorMonitor->VerifyFound();
3793}
3794
3795TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003796 TEST_DESCRIPTION(
3797 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
3798 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003799
3800 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003801 if (!m_device->phy().features().depthBounds) {
3802 printf("Device does not support depthBounds test; skipped.\n");
3803 return;
3804 }
3805 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3807 "Dynamic depth bounds state not set for this command buffer");
3808 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003809 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003810}
3811
3812TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003813 TEST_DESCRIPTION(
3814 "Run a simple draw calls to validate failure when Stencil Read dynamic "
3815 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003816
3817 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003818 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3820 "Dynamic stencil read mask state not set for this command buffer");
3821 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003822 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003823}
3824
3825TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003826 TEST_DESCRIPTION(
3827 "Run a simple draw calls to validate failure when Stencil Write dynamic"
3828 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003829
3830 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003831 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3833 "Dynamic stencil write mask state not set for this command buffer");
3834 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003835 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003836}
3837
3838TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003839 TEST_DESCRIPTION(
3840 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
3841 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003842
3843 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003844 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3846 "Dynamic stencil reference state not set for this command buffer");
3847 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003848 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003849}
3850
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003851TEST_F(VkLayerTest, IndexBufferNotBound) {
3852 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003853
3854 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3856 "Index buffer object not bound to this command buffer when Indexed ");
3857 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003858 m_errorMonitor->VerifyFound();
3859}
3860
Karl Schultz6addd812016-02-02 17:17:23 -07003861TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3863 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3864 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003865
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003866 ASSERT_NO_FATAL_FAILURE(InitState());
3867 ASSERT_NO_FATAL_FAILURE(InitViewport());
3868 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3869
Karl Schultz6addd812016-02-02 17:17:23 -07003870 // We luck out b/c by default the framework creates CB w/ the
3871 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07003872 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003873 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07003874 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003875
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003876 // Bypass framework since it does the waits automatically
3877 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003878 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003879 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3880 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003881 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003882 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003883 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003884 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003885 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003886 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003887 submit_info.pSignalSemaphores = NULL;
3888
Chris Forbes40028e22016-06-13 09:59:34 +12003889 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003890 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003891 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003892
Karl Schultz6addd812016-02-02 17:17:23 -07003893 // Cause validation error by re-submitting cmd buffer that should only be
3894 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003895 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003896 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003897
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003898 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003899}
3900
Karl Schultz6addd812016-02-02 17:17:23 -07003901TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003902 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003903 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003904
3905 ASSERT_NO_FATAL_FAILURE(InitState());
3906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003907
Karl Schultz6addd812016-02-02 17:17:23 -07003908 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3909 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003910 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003911 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003912 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003913
3914 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003915 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3916 ds_pool_ci.pNext = NULL;
3917 ds_pool_ci.flags = 0;
3918 ds_pool_ci.maxSets = 1;
3919 ds_pool_ci.poolSizeCount = 1;
3920 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003921
3922 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003923 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003924 ASSERT_VK_SUCCESS(err);
3925
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003926 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3927 dsl_binding_samp.binding = 0;
3928 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3929 dsl_binding_samp.descriptorCount = 1;
3930 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3931 dsl_binding_samp.pImmutableSamplers = NULL;
3932
3933 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3934 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3935 ds_layout_ci.pNext = NULL;
3936 ds_layout_ci.bindingCount = 1;
3937 ds_layout_ci.pBindings = &dsl_binding_samp;
3938
3939 VkDescriptorSetLayout ds_layout_samp;
3940 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3941 ASSERT_VK_SUCCESS(err);
3942
3943 // Try to allocate 2 sets when pool only has 1 set
3944 VkDescriptorSet descriptor_sets[2];
3945 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3946 VkDescriptorSetAllocateInfo alloc_info = {};
3947 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3948 alloc_info.descriptorSetCount = 2;
3949 alloc_info.descriptorPool = ds_pool;
3950 alloc_info.pSetLayouts = set_layouts;
3951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3952 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3953 m_errorMonitor->VerifyFound();
3954
3955 alloc_info.descriptorSetCount = 1;
3956 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003957 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003958 dsl_binding.binding = 0;
3959 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3960 dsl_binding.descriptorCount = 1;
3961 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3962 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003963
Karl Schultz6addd812016-02-02 17:17:23 -07003964 ds_layout_ci.bindingCount = 1;
3965 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003966
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003967 VkDescriptorSetLayout ds_layout_ub;
3968 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003969 ASSERT_VK_SUCCESS(err);
3970
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003971 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003972 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003973 alloc_info.pSetLayouts = &ds_layout_ub;
3974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3975 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003976
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003977 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003978
Karl Schultz2825ab92016-12-02 08:23:14 -07003979 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003980 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003981 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003982}
3983
Karl Schultz6addd812016-02-02 17:17:23 -07003984TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3985 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003986
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07003987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003988
Tobin Ehlise735c692015-10-08 13:13:50 -06003989 ASSERT_NO_FATAL_FAILURE(InitState());
3990 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003991
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003992 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003993 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3994 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003995
3996 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003997 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3998 ds_pool_ci.pNext = NULL;
3999 ds_pool_ci.maxSets = 1;
4000 ds_pool_ci.poolSizeCount = 1;
4001 ds_pool_ci.flags = 0;
4002 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4003 // app can only call vkResetDescriptorPool on this pool.;
4004 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004005
4006 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004007 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004008 ASSERT_VK_SUCCESS(err);
4009
4010 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004011 dsl_binding.binding = 0;
4012 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4013 dsl_binding.descriptorCount = 1;
4014 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4015 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004016
4017 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004018 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4019 ds_layout_ci.pNext = NULL;
4020 ds_layout_ci.bindingCount = 1;
4021 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004022
4023 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004024 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004025 ASSERT_VK_SUCCESS(err);
4026
4027 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004028 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004029 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004030 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004031 alloc_info.descriptorPool = ds_pool;
4032 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004033 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004034 ASSERT_VK_SUCCESS(err);
4035
4036 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004037 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004038
Chia-I Wuf7458c52015-10-26 21:10:41 +08004039 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4040 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004041}
4042
Karl Schultz6addd812016-02-02 17:17:23 -07004043TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004044 // Attempt to clear Descriptor Pool with bad object.
4045 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004046
4047 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004049 uint64_t fake_pool_handle = 0xbaad6001;
4050 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4051 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004052 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004053}
4054
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004055TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004056 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4057 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004058 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004059 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004060
4061 uint64_t fake_set_handle = 0xbaad6001;
4062 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004063 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004065
4066 ASSERT_NO_FATAL_FAILURE(InitState());
4067
4068 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4069 layout_bindings[0].binding = 0;
4070 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4071 layout_bindings[0].descriptorCount = 1;
4072 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4073 layout_bindings[0].pImmutableSamplers = NULL;
4074
4075 VkDescriptorSetLayout descriptor_set_layout;
4076 VkDescriptorSetLayoutCreateInfo dslci = {};
4077 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4078 dslci.pNext = NULL;
4079 dslci.bindingCount = 1;
4080 dslci.pBindings = layout_bindings;
4081 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004082 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004083
4084 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 = &descriptor_set_layout;
4090 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004091 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004092
Tony Barbour552f6c02016-12-21 14:34:07 -07004093 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004094 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4095 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004096 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004097 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004098 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4099 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004100}
4101
Karl Schultz6addd812016-02-02 17:17:23 -07004102TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004103 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4104 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004105 uint64_t fake_layout_handle = 0xbaad6001;
4106 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004108 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004109 VkPipelineLayout pipeline_layout;
4110 VkPipelineLayoutCreateInfo plci = {};
4111 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4112 plci.pNext = NULL;
4113 plci.setLayoutCount = 1;
4114 plci.pSetLayouts = &bad_layout;
4115 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4116
4117 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004118}
4119
Mark Muellerd4914412016-06-13 17:52:06 -06004120TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004121 TEST_DESCRIPTION(
4122 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4123 "1) A uniform buffer update must have a valid buffer index."
4124 "2) When using an array of descriptors in a single WriteDescriptor,"
4125 " the descriptor types and stageflags must all be the same."
4126 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004127
Mike Weiblena6666382017-01-05 15:16:11 -07004128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004129
4130 ASSERT_NO_FATAL_FAILURE(InitState());
4131 VkDescriptorPoolSize ds_type_count[4] = {};
4132 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4133 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004134 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004135 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004136 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004137 ds_type_count[2].descriptorCount = 1;
4138 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4139 ds_type_count[3].descriptorCount = 1;
4140
4141 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4142 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4143 ds_pool_ci.maxSets = 1;
4144 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4145 ds_pool_ci.pPoolSizes = ds_type_count;
4146
4147 VkDescriptorPool ds_pool;
4148 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4149 ASSERT_VK_SUCCESS(err);
4150
Mark Muellerb9896722016-06-16 09:54:29 -06004151 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004152 layout_binding[0].binding = 0;
4153 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4154 layout_binding[0].descriptorCount = 1;
4155 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4156 layout_binding[0].pImmutableSamplers = NULL;
4157
4158 layout_binding[1].binding = 1;
4159 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4160 layout_binding[1].descriptorCount = 1;
4161 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4162 layout_binding[1].pImmutableSamplers = NULL;
4163
4164 VkSamplerCreateInfo sampler_ci = {};
4165 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4166 sampler_ci.pNext = NULL;
4167 sampler_ci.magFilter = VK_FILTER_NEAREST;
4168 sampler_ci.minFilter = VK_FILTER_NEAREST;
4169 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4170 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4171 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4172 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4173 sampler_ci.mipLodBias = 1.0;
4174 sampler_ci.anisotropyEnable = VK_FALSE;
4175 sampler_ci.maxAnisotropy = 1;
4176 sampler_ci.compareEnable = VK_FALSE;
4177 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4178 sampler_ci.minLod = 1.0;
4179 sampler_ci.maxLod = 1.0;
4180 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4181 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4182 VkSampler sampler;
4183
4184 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4185 ASSERT_VK_SUCCESS(err);
4186
4187 layout_binding[2].binding = 2;
4188 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4189 layout_binding[2].descriptorCount = 1;
4190 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4191 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4192
Mark Muellerd4914412016-06-13 17:52:06 -06004193 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4194 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4195 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4196 ds_layout_ci.pBindings = layout_binding;
4197 VkDescriptorSetLayout ds_layout;
4198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4199 ASSERT_VK_SUCCESS(err);
4200
4201 VkDescriptorSetAllocateInfo alloc_info = {};
4202 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4203 alloc_info.descriptorSetCount = 1;
4204 alloc_info.descriptorPool = ds_pool;
4205 alloc_info.pSetLayouts = &ds_layout;
4206 VkDescriptorSet descriptorSet;
4207 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4208 ASSERT_VK_SUCCESS(err);
4209
4210 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4211 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4212 pipeline_layout_ci.pNext = NULL;
4213 pipeline_layout_ci.setLayoutCount = 1;
4214 pipeline_layout_ci.pSetLayouts = &ds_layout;
4215
4216 VkPipelineLayout pipeline_layout;
4217 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4218 ASSERT_VK_SUCCESS(err);
4219
Mark Mueller5c838ce2016-06-16 09:54:29 -06004220 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004221 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4222 descriptor_write.dstSet = descriptorSet;
4223 descriptor_write.dstBinding = 0;
4224 descriptor_write.descriptorCount = 1;
4225 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4226
Mark Mueller5c838ce2016-06-16 09:54:29 -06004227 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004228 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4229 m_errorMonitor->VerifyFound();
4230
4231 // Create a buffer to update the descriptor with
4232 uint32_t qfi = 0;
4233 VkBufferCreateInfo buffCI = {};
4234 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4235 buffCI.size = 1024;
4236 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4237 buffCI.queueFamilyIndexCount = 1;
4238 buffCI.pQueueFamilyIndices = &qfi;
4239
4240 VkBuffer dyub;
4241 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4242 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004243
Tony Barboure132c5f2016-12-12 11:50:20 -07004244 VkDeviceMemory mem;
4245 VkMemoryRequirements mem_reqs;
4246 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4247
4248 VkMemoryAllocateInfo mem_alloc_info = {};
4249 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4250 mem_alloc_info.allocationSize = mem_reqs.size;
4251 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4252 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4253 ASSERT_VK_SUCCESS(err);
4254
4255 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4256 ASSERT_VK_SUCCESS(err);
4257
4258 VkDescriptorBufferInfo buffInfo[2] = {};
4259 buffInfo[0].buffer = dyub;
4260 buffInfo[0].offset = 0;
4261 buffInfo[0].range = 1024;
4262 buffInfo[1].buffer = dyub;
4263 buffInfo[1].offset = 0;
4264 buffInfo[1].range = 1024;
4265 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004266 descriptor_write.descriptorCount = 2;
4267
Mark Mueller5c838ce2016-06-16 09:54:29 -06004268 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004270 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4271 m_errorMonitor->VerifyFound();
4272
Mark Mueller5c838ce2016-06-16 09:54:29 -06004273 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4274 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004275 descriptor_write.dstBinding = 1;
4276 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004277
Mark Mueller5c838ce2016-06-16 09:54:29 -06004278 // Make pImageInfo index non-null to avoid complaints of it missing
4279 VkDescriptorImageInfo imageInfo = {};
4280 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4281 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004283 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4284 m_errorMonitor->VerifyFound();
4285
Mark Muellerd4914412016-06-13 17:52:06 -06004286 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004287 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004288 vkDestroySampler(m_device->device(), sampler, NULL);
4289 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4290 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4291 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4292}
4293
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004294TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004295 TEST_DESCRIPTION(
4296 "Attempt to draw with a command buffer that is invalid "
4297 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004298 ASSERT_NO_FATAL_FAILURE(InitState());
4299
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004300 VkBuffer buffer;
4301 VkDeviceMemory mem;
4302 VkMemoryRequirements mem_reqs;
4303
4304 VkBufferCreateInfo buf_info = {};
4305 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004306 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004307 buf_info.size = 256;
4308 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4309 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4310 ASSERT_VK_SUCCESS(err);
4311
4312 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4313
4314 VkMemoryAllocateInfo alloc_info = {};
4315 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4316 alloc_info.allocationSize = 256;
4317 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004318 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 -06004319 if (!pass) {
4320 vkDestroyBuffer(m_device->device(), buffer, NULL);
4321 return;
4322 }
4323 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4324 ASSERT_VK_SUCCESS(err);
4325
4326 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4327 ASSERT_VK_SUCCESS(err);
4328
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004329 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004330 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004331 m_commandBuffer->EndCommandBuffer();
4332
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004334 // Destroy buffer dependency prior to submit to cause ERROR
4335 vkDestroyBuffer(m_device->device(), buffer, NULL);
4336
4337 VkSubmitInfo submit_info = {};
4338 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4339 submit_info.commandBufferCount = 1;
4340 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4341 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4342
4343 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004344 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004345 vkFreeMemory(m_device->handle(), mem, NULL);
4346}
4347
Tobin Ehlisea413442016-09-28 10:23:59 -06004348TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4349 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4350
4351 ASSERT_NO_FATAL_FAILURE(InitState());
4352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4353
4354 VkDescriptorPoolSize ds_type_count;
4355 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4356 ds_type_count.descriptorCount = 1;
4357
4358 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4359 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4360 ds_pool_ci.maxSets = 1;
4361 ds_pool_ci.poolSizeCount = 1;
4362 ds_pool_ci.pPoolSizes = &ds_type_count;
4363
4364 VkDescriptorPool ds_pool;
4365 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4366 ASSERT_VK_SUCCESS(err);
4367
4368 VkDescriptorSetLayoutBinding layout_binding;
4369 layout_binding.binding = 0;
4370 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4371 layout_binding.descriptorCount = 1;
4372 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4373 layout_binding.pImmutableSamplers = NULL;
4374
4375 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4376 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4377 ds_layout_ci.bindingCount = 1;
4378 ds_layout_ci.pBindings = &layout_binding;
4379 VkDescriptorSetLayout ds_layout;
4380 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4381 ASSERT_VK_SUCCESS(err);
4382
4383 VkDescriptorSetAllocateInfo alloc_info = {};
4384 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4385 alloc_info.descriptorSetCount = 1;
4386 alloc_info.descriptorPool = ds_pool;
4387 alloc_info.pSetLayouts = &ds_layout;
4388 VkDescriptorSet descriptor_set;
4389 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4390 ASSERT_VK_SUCCESS(err);
4391
4392 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4393 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4394 pipeline_layout_ci.pNext = NULL;
4395 pipeline_layout_ci.setLayoutCount = 1;
4396 pipeline_layout_ci.pSetLayouts = &ds_layout;
4397
4398 VkPipelineLayout pipeline_layout;
4399 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4400 ASSERT_VK_SUCCESS(err);
4401
4402 VkBuffer buffer;
4403 uint32_t queue_family_index = 0;
4404 VkBufferCreateInfo buffer_create_info = {};
4405 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4406 buffer_create_info.size = 1024;
4407 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4408 buffer_create_info.queueFamilyIndexCount = 1;
4409 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4410
4411 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4412 ASSERT_VK_SUCCESS(err);
4413
4414 VkMemoryRequirements memory_reqs;
4415 VkDeviceMemory buffer_memory;
4416
4417 VkMemoryAllocateInfo memory_info = {};
4418 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4419 memory_info.allocationSize = 0;
4420 memory_info.memoryTypeIndex = 0;
4421
4422 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4423 memory_info.allocationSize = memory_reqs.size;
4424 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4425 ASSERT_TRUE(pass);
4426
4427 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4428 ASSERT_VK_SUCCESS(err);
4429 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4430 ASSERT_VK_SUCCESS(err);
4431
4432 VkBufferView view;
4433 VkBufferViewCreateInfo bvci = {};
4434 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4435 bvci.buffer = buffer;
4436 bvci.format = VK_FORMAT_R8_UNORM;
4437 bvci.range = VK_WHOLE_SIZE;
4438
4439 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4440 ASSERT_VK_SUCCESS(err);
4441
4442 VkWriteDescriptorSet descriptor_write = {};
4443 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4444 descriptor_write.dstSet = descriptor_set;
4445 descriptor_write.dstBinding = 0;
4446 descriptor_write.descriptorCount = 1;
4447 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4448 descriptor_write.pTexelBufferView = &view;
4449
4450 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4451
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004452 char const *vsSource =
4453 "#version 450\n"
4454 "\n"
4455 "out gl_PerVertex { \n"
4456 " vec4 gl_Position;\n"
4457 "};\n"
4458 "void main(){\n"
4459 " gl_Position = vec4(1);\n"
4460 "}\n";
4461 char const *fsSource =
4462 "#version 450\n"
4463 "\n"
4464 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4465 "layout(location=0) out vec4 x;\n"
4466 "void main(){\n"
4467 " x = imageLoad(s, 0);\n"
4468 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004469 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4470 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4471 VkPipelineObj pipe(m_device);
4472 pipe.AddShader(&vs);
4473 pipe.AddShader(&fs);
4474 pipe.AddColorAttachment();
4475 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4476
4477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4479
Tony Barbour552f6c02016-12-21 14:34:07 -07004480 m_commandBuffer->BeginCommandBuffer();
4481 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4482
Tobin Ehlisea413442016-09-28 10:23:59 -06004483 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4484 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4485 VkRect2D scissor = {{0, 0}, {16, 16}};
4486 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4487 // Bind pipeline to cmd buffer
4488 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4489 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4490 &descriptor_set, 0, nullptr);
4491 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004492 m_commandBuffer->EndRenderPass();
4493 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004494
4495 // Delete BufferView in order to invalidate cmd buffer
4496 vkDestroyBufferView(m_device->device(), view, NULL);
4497 // Now attempt submit of cmd buffer
4498 VkSubmitInfo submit_info = {};
4499 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4500 submit_info.commandBufferCount = 1;
4501 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4502 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4503 m_errorMonitor->VerifyFound();
4504
4505 // Clean-up
4506 vkDestroyBuffer(m_device->device(), buffer, NULL);
4507 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4508 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4509 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4510 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4511}
4512
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004513TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004514 TEST_DESCRIPTION(
4515 "Attempt to draw with a command buffer that is invalid "
4516 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004517 ASSERT_NO_FATAL_FAILURE(InitState());
4518
4519 VkImage image;
4520 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4521 VkImageCreateInfo image_create_info = {};
4522 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4523 image_create_info.pNext = NULL;
4524 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4525 image_create_info.format = tex_format;
4526 image_create_info.extent.width = 32;
4527 image_create_info.extent.height = 32;
4528 image_create_info.extent.depth = 1;
4529 image_create_info.mipLevels = 1;
4530 image_create_info.arrayLayers = 1;
4531 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4532 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004533 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004534 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004535 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004536 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004537 // Have to bind memory to image before recording cmd in cmd buffer using it
4538 VkMemoryRequirements mem_reqs;
4539 VkDeviceMemory image_mem;
4540 bool pass;
4541 VkMemoryAllocateInfo mem_alloc = {};
4542 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4543 mem_alloc.pNext = NULL;
4544 mem_alloc.memoryTypeIndex = 0;
4545 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4546 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004547 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004548 ASSERT_TRUE(pass);
4549 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4550 ASSERT_VK_SUCCESS(err);
4551 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4552 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004553
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004554 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004555 VkClearColorValue ccv;
4556 ccv.float32[0] = 1.0f;
4557 ccv.float32[1] = 1.0f;
4558 ccv.float32[2] = 1.0f;
4559 ccv.float32[3] = 1.0f;
4560 VkImageSubresourceRange isr = {};
4561 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004562 isr.baseArrayLayer = 0;
4563 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004564 isr.layerCount = 1;
4565 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004566 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004567 m_commandBuffer->EndCommandBuffer();
4568
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004570 // Destroy image dependency prior to submit to cause ERROR
4571 vkDestroyImage(m_device->device(), image, NULL);
4572
4573 VkSubmitInfo submit_info = {};
4574 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4575 submit_info.commandBufferCount = 1;
4576 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4577 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4578
4579 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004580 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004581}
4582
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004583TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004584 TEST_DESCRIPTION(
4585 "Attempt to draw with a command buffer that is invalid "
4586 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004587 VkFormatProperties format_properties;
4588 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004589 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4590 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004591 return;
4592 }
4593
4594 ASSERT_NO_FATAL_FAILURE(InitState());
4595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4596
4597 VkImageCreateInfo image_ci = {};
4598 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4599 image_ci.pNext = NULL;
4600 image_ci.imageType = VK_IMAGE_TYPE_2D;
4601 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4602 image_ci.extent.width = 32;
4603 image_ci.extent.height = 32;
4604 image_ci.extent.depth = 1;
4605 image_ci.mipLevels = 1;
4606 image_ci.arrayLayers = 1;
4607 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4608 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004609 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004610 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4611 image_ci.flags = 0;
4612 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004613 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004614
4615 VkMemoryRequirements memory_reqs;
4616 VkDeviceMemory image_memory;
4617 bool pass;
4618 VkMemoryAllocateInfo memory_info = {};
4619 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4620 memory_info.pNext = NULL;
4621 memory_info.allocationSize = 0;
4622 memory_info.memoryTypeIndex = 0;
4623 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4624 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004625 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004626 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004627 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004628 ASSERT_VK_SUCCESS(err);
4629 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4630 ASSERT_VK_SUCCESS(err);
4631
4632 VkImageViewCreateInfo ivci = {
4633 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4634 nullptr,
4635 0,
4636 image,
4637 VK_IMAGE_VIEW_TYPE_2D,
4638 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004639 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004640 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4641 };
4642 VkImageView view;
4643 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4644 ASSERT_VK_SUCCESS(err);
4645
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004646 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004647 VkFramebuffer fb;
4648 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4649 ASSERT_VK_SUCCESS(err);
4650
4651 // Just use default renderpass with our framebuffer
4652 m_renderPassBeginInfo.framebuffer = fb;
4653 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004654 m_commandBuffer->BeginCommandBuffer();
4655 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4656 m_commandBuffer->EndRenderPass();
4657 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004658 // Destroy image attached to framebuffer to invalidate cmd buffer
4659 vkDestroyImage(m_device->device(), image, NULL);
4660 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004662 QueueCommandBuffer(false);
4663 m_errorMonitor->VerifyFound();
4664
4665 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4666 vkDestroyImageView(m_device->device(), view, nullptr);
4667 vkFreeMemory(m_device->device(), image_memory, nullptr);
4668}
4669
Tobin Ehlisb329f992016-10-12 13:20:29 -06004670TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4671 TEST_DESCRIPTION("Delete in-use framebuffer.");
4672 VkFormatProperties format_properties;
4673 VkResult err = VK_SUCCESS;
4674 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4675
4676 ASSERT_NO_FATAL_FAILURE(InitState());
4677 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4678
4679 VkImageObj image(m_device);
4680 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4681 ASSERT_TRUE(image.initialized());
4682 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4683
4684 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4685 VkFramebuffer fb;
4686 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4687 ASSERT_VK_SUCCESS(err);
4688
4689 // Just use default renderpass with our framebuffer
4690 m_renderPassBeginInfo.framebuffer = fb;
4691 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004692 m_commandBuffer->BeginCommandBuffer();
4693 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4694 m_commandBuffer->EndRenderPass();
4695 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06004696 // Submit cmd buffer to put it in-flight
4697 VkSubmitInfo submit_info = {};
4698 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4699 submit_info.commandBufferCount = 1;
4700 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4701 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4702 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06004704 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4705 m_errorMonitor->VerifyFound();
4706 // Wait for queue to complete so we can safely destroy everything
4707 vkQueueWaitIdle(m_device->m_queue);
4708 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4709}
4710
Tobin Ehlis88becd72016-09-21 14:33:41 -06004711TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4712 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4713 VkFormatProperties format_properties;
4714 VkResult err = VK_SUCCESS;
4715 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004716
4717 ASSERT_NO_FATAL_FAILURE(InitState());
4718 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4719
4720 VkImageCreateInfo image_ci = {};
4721 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4722 image_ci.pNext = NULL;
4723 image_ci.imageType = VK_IMAGE_TYPE_2D;
4724 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4725 image_ci.extent.width = 256;
4726 image_ci.extent.height = 256;
4727 image_ci.extent.depth = 1;
4728 image_ci.mipLevels = 1;
4729 image_ci.arrayLayers = 1;
4730 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4731 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004732 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004733 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4734 image_ci.flags = 0;
4735 VkImage image;
4736 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4737
4738 VkMemoryRequirements memory_reqs;
4739 VkDeviceMemory image_memory;
4740 bool pass;
4741 VkMemoryAllocateInfo memory_info = {};
4742 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4743 memory_info.pNext = NULL;
4744 memory_info.allocationSize = 0;
4745 memory_info.memoryTypeIndex = 0;
4746 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4747 memory_info.allocationSize = memory_reqs.size;
4748 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4749 ASSERT_TRUE(pass);
4750 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4751 ASSERT_VK_SUCCESS(err);
4752 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4753 ASSERT_VK_SUCCESS(err);
4754
4755 VkImageViewCreateInfo ivci = {
4756 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4757 nullptr,
4758 0,
4759 image,
4760 VK_IMAGE_VIEW_TYPE_2D,
4761 VK_FORMAT_B8G8R8A8_UNORM,
4762 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4763 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4764 };
4765 VkImageView view;
4766 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4767 ASSERT_VK_SUCCESS(err);
4768
4769 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4770 VkFramebuffer fb;
4771 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4772 ASSERT_VK_SUCCESS(err);
4773
4774 // Just use default renderpass with our framebuffer
4775 m_renderPassBeginInfo.framebuffer = fb;
4776 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004777 m_commandBuffer->BeginCommandBuffer();
4778 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4779 m_commandBuffer->EndRenderPass();
4780 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06004781 // Submit cmd buffer to put it (and attached imageView) in-flight
4782 VkSubmitInfo submit_info = {};
4783 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4784 submit_info.commandBufferCount = 1;
4785 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4786 // Submit cmd buffer to put framebuffer and children in-flight
4787 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4788 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004790 vkDestroyImage(m_device->device(), image, NULL);
4791 m_errorMonitor->VerifyFound();
4792 // Wait for queue to complete so we can safely destroy image and other objects
4793 vkQueueWaitIdle(m_device->m_queue);
4794 vkDestroyImage(m_device->device(), image, NULL);
4795 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4796 vkDestroyImageView(m_device->device(), view, nullptr);
4797 vkFreeMemory(m_device->device(), image_memory, nullptr);
4798}
4799
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004800TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4801 TEST_DESCRIPTION("Delete in-use renderPass.");
4802
4803 ASSERT_NO_FATAL_FAILURE(InitState());
4804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4805
4806 // Create simple renderpass
4807 VkAttachmentReference attach = {};
4808 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4809 VkSubpassDescription subpass = {};
4810 subpass.pColorAttachments = &attach;
4811 VkRenderPassCreateInfo rpci = {};
4812 rpci.subpassCount = 1;
4813 rpci.pSubpasses = &subpass;
4814 rpci.attachmentCount = 1;
4815 VkAttachmentDescription attach_desc = {};
4816 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4817 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4818 rpci.pAttachments = &attach_desc;
4819 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4820 VkRenderPass rp;
4821 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4822 ASSERT_VK_SUCCESS(err);
4823
4824 // Create a pipeline that uses the given renderpass
4825 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4826 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4827
4828 VkPipelineLayout pipeline_layout;
4829 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4830 ASSERT_VK_SUCCESS(err);
4831
4832 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4833 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4834 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004835 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004836 vp_state_ci.pViewports = &vp;
4837 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004838 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004839 vp_state_ci.pScissors = &scissors;
4840
4841 VkPipelineShaderStageCreateInfo shaderStages[2];
4842 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4843
4844 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004845 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 -06004846 // but add it to be able to run on more devices
4847 shaderStages[0] = vs.GetStageCreateInfo();
4848 shaderStages[1] = fs.GetStageCreateInfo();
4849
4850 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4851 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4852
4853 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4854 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4855 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4856
4857 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4858 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4859 rs_ci.rasterizerDiscardEnable = true;
4860 rs_ci.lineWidth = 1.0f;
4861
4862 VkPipelineColorBlendAttachmentState att = {};
4863 att.blendEnable = VK_FALSE;
4864 att.colorWriteMask = 0xf;
4865
4866 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4867 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4868 cb_ci.attachmentCount = 1;
4869 cb_ci.pAttachments = &att;
4870
4871 VkGraphicsPipelineCreateInfo gp_ci = {};
4872 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4873 gp_ci.stageCount = 2;
4874 gp_ci.pStages = shaderStages;
4875 gp_ci.pVertexInputState = &vi_ci;
4876 gp_ci.pInputAssemblyState = &ia_ci;
4877 gp_ci.pViewportState = &vp_state_ci;
4878 gp_ci.pRasterizationState = &rs_ci;
4879 gp_ci.pColorBlendState = &cb_ci;
4880 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4881 gp_ci.layout = pipeline_layout;
4882 gp_ci.renderPass = rp;
4883
4884 VkPipelineCacheCreateInfo pc_ci = {};
4885 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4886
4887 VkPipeline pipeline;
4888 VkPipelineCache pipe_cache;
4889 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4890 ASSERT_VK_SUCCESS(err);
4891
4892 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4893 ASSERT_VK_SUCCESS(err);
4894 // Bind pipeline to cmd buffer, will also bind renderpass
4895 m_commandBuffer->BeginCommandBuffer();
4896 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4897 m_commandBuffer->EndCommandBuffer();
4898
4899 VkSubmitInfo submit_info = {};
4900 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4901 submit_info.commandBufferCount = 1;
4902 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4903 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4904
4905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4906 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4907 m_errorMonitor->VerifyFound();
4908
4909 // Wait for queue to complete so we can safely destroy everything
4910 vkQueueWaitIdle(m_device->m_queue);
4911 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4912 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4913 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4914 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4915}
4916
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004917TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004918 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004919 ASSERT_NO_FATAL_FAILURE(InitState());
4920
4921 VkImage image;
4922 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4923 VkImageCreateInfo image_create_info = {};
4924 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4925 image_create_info.pNext = NULL;
4926 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4927 image_create_info.format = tex_format;
4928 image_create_info.extent.width = 32;
4929 image_create_info.extent.height = 32;
4930 image_create_info.extent.depth = 1;
4931 image_create_info.mipLevels = 1;
4932 image_create_info.arrayLayers = 1;
4933 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4934 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004935 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004936 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004937 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004938 ASSERT_VK_SUCCESS(err);
4939 // Have to bind memory to image before recording cmd in cmd buffer using it
4940 VkMemoryRequirements mem_reqs;
4941 VkDeviceMemory image_mem;
4942 bool pass;
4943 VkMemoryAllocateInfo mem_alloc = {};
4944 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4945 mem_alloc.pNext = NULL;
4946 mem_alloc.memoryTypeIndex = 0;
4947 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4948 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004950 ASSERT_TRUE(pass);
4951 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4952 ASSERT_VK_SUCCESS(err);
4953
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004954 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004956 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004957
4958 m_commandBuffer->BeginCommandBuffer();
4959 VkClearColorValue ccv;
4960 ccv.float32[0] = 1.0f;
4961 ccv.float32[1] = 1.0f;
4962 ccv.float32[2] = 1.0f;
4963 ccv.float32[3] = 1.0f;
4964 VkImageSubresourceRange isr = {};
4965 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4966 isr.baseArrayLayer = 0;
4967 isr.baseMipLevel = 0;
4968 isr.layerCount = 1;
4969 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004970 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004971 m_commandBuffer->EndCommandBuffer();
4972
4973 m_errorMonitor->VerifyFound();
4974 vkDestroyImage(m_device->device(), image, NULL);
4975 vkFreeMemory(m_device->device(), image_mem, nullptr);
4976}
4977
4978TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004979 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004980 ASSERT_NO_FATAL_FAILURE(InitState());
4981
4982 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004983 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 -06004984 VK_IMAGE_TILING_OPTIMAL, 0);
4985 ASSERT_TRUE(image.initialized());
4986
4987 VkBuffer buffer;
4988 VkDeviceMemory mem;
4989 VkMemoryRequirements mem_reqs;
4990
4991 VkBufferCreateInfo buf_info = {};
4992 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004993 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004994 buf_info.size = 256;
4995 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4996 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4997 ASSERT_VK_SUCCESS(err);
4998
4999 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5000
5001 VkMemoryAllocateInfo alloc_info = {};
5002 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5003 alloc_info.allocationSize = 256;
5004 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005005 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 -06005006 if (!pass) {
5007 vkDestroyBuffer(m_device->device(), buffer, NULL);
5008 return;
5009 }
5010 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5011 ASSERT_VK_SUCCESS(err);
5012
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005013 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005015 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005016 VkBufferImageCopy region = {};
5017 region.bufferRowLength = 128;
5018 region.bufferImageHeight = 128;
5019 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5020
5021 region.imageSubresource.layerCount = 1;
5022 region.imageExtent.height = 4;
5023 region.imageExtent.width = 4;
5024 region.imageExtent.depth = 1;
5025 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005026 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5027 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005028 m_commandBuffer->EndCommandBuffer();
5029
5030 m_errorMonitor->VerifyFound();
5031
5032 vkDestroyBuffer(m_device->device(), buffer, NULL);
5033 vkFreeMemory(m_device->handle(), mem, NULL);
5034}
5035
Tobin Ehlis85940f52016-07-07 16:57:21 -06005036TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005037 TEST_DESCRIPTION(
5038 "Attempt to draw with a command buffer that is invalid "
5039 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005040 ASSERT_NO_FATAL_FAILURE(InitState());
5041
5042 VkEvent event;
5043 VkEventCreateInfo evci = {};
5044 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5045 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5046 ASSERT_VK_SUCCESS(result);
5047
5048 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005049 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005050 m_commandBuffer->EndCommandBuffer();
5051
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005053 // Destroy event dependency prior to submit to cause ERROR
5054 vkDestroyEvent(m_device->device(), event, NULL);
5055
5056 VkSubmitInfo submit_info = {};
5057 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5058 submit_info.commandBufferCount = 1;
5059 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5060 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5061
5062 m_errorMonitor->VerifyFound();
5063}
5064
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005065TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005066 TEST_DESCRIPTION(
5067 "Attempt to draw with a command buffer that is invalid "
5068 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005069 ASSERT_NO_FATAL_FAILURE(InitState());
5070
5071 VkQueryPool query_pool;
5072 VkQueryPoolCreateInfo qpci{};
5073 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5074 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5075 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005076 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005077 ASSERT_VK_SUCCESS(result);
5078
5079 m_commandBuffer->BeginCommandBuffer();
5080 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5081 m_commandBuffer->EndCommandBuffer();
5082
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005084 // Destroy query pool dependency prior to submit to cause ERROR
5085 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5086
5087 VkSubmitInfo submit_info = {};
5088 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5089 submit_info.commandBufferCount = 1;
5090 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5091 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5092
5093 m_errorMonitor->VerifyFound();
5094}
5095
Tobin Ehlis24130d92016-07-08 15:50:53 -06005096TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005097 TEST_DESCRIPTION(
5098 "Attempt to draw with a command buffer that is invalid "
5099 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005100 ASSERT_NO_FATAL_FAILURE(InitState());
5101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5102
5103 VkResult err;
5104
5105 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5106 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5107
5108 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005109 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005110 ASSERT_VK_SUCCESS(err);
5111
5112 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5113 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5114 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005115 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005116 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005117 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005118 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005119 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005120
5121 VkPipelineShaderStageCreateInfo shaderStages[2];
5122 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005124 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005125 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 -06005126 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005127 shaderStages[0] = vs.GetStageCreateInfo();
5128 shaderStages[1] = fs.GetStageCreateInfo();
5129
5130 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5131 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5132
5133 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5134 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5135 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5136
5137 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5138 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005139 rs_ci.rasterizerDiscardEnable = true;
5140 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005141
5142 VkPipelineColorBlendAttachmentState att = {};
5143 att.blendEnable = VK_FALSE;
5144 att.colorWriteMask = 0xf;
5145
5146 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5147 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5148 cb_ci.attachmentCount = 1;
5149 cb_ci.pAttachments = &att;
5150
5151 VkGraphicsPipelineCreateInfo gp_ci = {};
5152 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5153 gp_ci.stageCount = 2;
5154 gp_ci.pStages = shaderStages;
5155 gp_ci.pVertexInputState = &vi_ci;
5156 gp_ci.pInputAssemblyState = &ia_ci;
5157 gp_ci.pViewportState = &vp_state_ci;
5158 gp_ci.pRasterizationState = &rs_ci;
5159 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005160 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5161 gp_ci.layout = pipeline_layout;
5162 gp_ci.renderPass = renderPass();
5163
5164 VkPipelineCacheCreateInfo pc_ci = {};
5165 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5166
5167 VkPipeline pipeline;
5168 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005169 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005170 ASSERT_VK_SUCCESS(err);
5171
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005172 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005173 ASSERT_VK_SUCCESS(err);
5174
5175 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005176 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005177 m_commandBuffer->EndCommandBuffer();
5178 // Now destroy pipeline in order to cause error when submitting
5179 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5180
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005182
5183 VkSubmitInfo submit_info = {};
5184 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5185 submit_info.commandBufferCount = 1;
5186 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5187 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5188
5189 m_errorMonitor->VerifyFound();
5190 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5191 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5192}
5193
Tobin Ehlis31289162016-08-17 14:57:58 -06005194TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005195 TEST_DESCRIPTION(
5196 "Attempt to draw with a command buffer that is invalid "
5197 "due to a bound descriptor set with a buffer dependency "
5198 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005199 ASSERT_NO_FATAL_FAILURE(InitState());
5200 ASSERT_NO_FATAL_FAILURE(InitViewport());
5201 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5202
5203 VkDescriptorPoolSize ds_type_count = {};
5204 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5205 ds_type_count.descriptorCount = 1;
5206
5207 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5208 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5209 ds_pool_ci.pNext = NULL;
5210 ds_pool_ci.maxSets = 1;
5211 ds_pool_ci.poolSizeCount = 1;
5212 ds_pool_ci.pPoolSizes = &ds_type_count;
5213
5214 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005215 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005216 ASSERT_VK_SUCCESS(err);
5217
5218 VkDescriptorSetLayoutBinding dsl_binding = {};
5219 dsl_binding.binding = 0;
5220 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5221 dsl_binding.descriptorCount = 1;
5222 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5223 dsl_binding.pImmutableSamplers = NULL;
5224
5225 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5226 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5227 ds_layout_ci.pNext = NULL;
5228 ds_layout_ci.bindingCount = 1;
5229 ds_layout_ci.pBindings = &dsl_binding;
5230 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005231 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005232 ASSERT_VK_SUCCESS(err);
5233
5234 VkDescriptorSet descriptorSet;
5235 VkDescriptorSetAllocateInfo alloc_info = {};
5236 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5237 alloc_info.descriptorSetCount = 1;
5238 alloc_info.descriptorPool = ds_pool;
5239 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005240 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005241 ASSERT_VK_SUCCESS(err);
5242
5243 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5244 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5245 pipeline_layout_ci.pNext = NULL;
5246 pipeline_layout_ci.setLayoutCount = 1;
5247 pipeline_layout_ci.pSetLayouts = &ds_layout;
5248
5249 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005250 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005251 ASSERT_VK_SUCCESS(err);
5252
5253 // Create a buffer to update the descriptor with
5254 uint32_t qfi = 0;
5255 VkBufferCreateInfo buffCI = {};
5256 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5257 buffCI.size = 1024;
5258 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5259 buffCI.queueFamilyIndexCount = 1;
5260 buffCI.pQueueFamilyIndices = &qfi;
5261
5262 VkBuffer buffer;
5263 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5264 ASSERT_VK_SUCCESS(err);
5265 // Allocate memory and bind to buffer so we can make it to the appropriate
5266 // error
5267 VkMemoryAllocateInfo mem_alloc = {};
5268 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5269 mem_alloc.pNext = NULL;
5270 mem_alloc.allocationSize = 1024;
5271 mem_alloc.memoryTypeIndex = 0;
5272
5273 VkMemoryRequirements memReqs;
5274 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005275 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005276 if (!pass) {
5277 vkDestroyBuffer(m_device->device(), buffer, NULL);
5278 return;
5279 }
5280
5281 VkDeviceMemory mem;
5282 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5283 ASSERT_VK_SUCCESS(err);
5284 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5285 ASSERT_VK_SUCCESS(err);
5286 // Correctly update descriptor to avoid "NOT_UPDATED" error
5287 VkDescriptorBufferInfo buffInfo = {};
5288 buffInfo.buffer = buffer;
5289 buffInfo.offset = 0;
5290 buffInfo.range = 1024;
5291
5292 VkWriteDescriptorSet descriptor_write;
5293 memset(&descriptor_write, 0, sizeof(descriptor_write));
5294 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5295 descriptor_write.dstSet = descriptorSet;
5296 descriptor_write.dstBinding = 0;
5297 descriptor_write.descriptorCount = 1;
5298 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5299 descriptor_write.pBufferInfo = &buffInfo;
5300
5301 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5302
5303 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005304 char const *vsSource =
5305 "#version 450\n"
5306 "\n"
5307 "out gl_PerVertex { \n"
5308 " vec4 gl_Position;\n"
5309 "};\n"
5310 "void main(){\n"
5311 " gl_Position = vec4(1);\n"
5312 "}\n";
5313 char const *fsSource =
5314 "#version 450\n"
5315 "\n"
5316 "layout(location=0) out vec4 x;\n"
5317 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5318 "void main(){\n"
5319 " x = vec4(bar.y);\n"
5320 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005321 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5322 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5323 VkPipelineObj pipe(m_device);
5324 pipe.AddShader(&vs);
5325 pipe.AddShader(&fs);
5326 pipe.AddColorAttachment();
5327 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5328
Tony Barbour552f6c02016-12-21 14:34:07 -07005329 m_commandBuffer->BeginCommandBuffer();
5330 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005331 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5332 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5333 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005334
5335 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5336 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5337
Tobin Ehlis31289162016-08-17 14:57:58 -06005338 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005339 m_commandBuffer->EndRenderPass();
5340 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005342 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5343 vkDestroyBuffer(m_device->device(), buffer, NULL);
5344 // Attempt to submit cmd buffer
5345 VkSubmitInfo submit_info = {};
5346 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5347 submit_info.commandBufferCount = 1;
5348 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5349 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5350 m_errorMonitor->VerifyFound();
5351 // Cleanup
5352 vkFreeMemory(m_device->device(), mem, NULL);
5353
5354 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5355 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5356 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5357}
5358
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005359TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005360 TEST_DESCRIPTION(
5361 "Attempt to draw with a command buffer that is invalid "
5362 "due to a bound descriptor sets with a combined image "
5363 "sampler having their image, sampler, and descriptor set "
5364 "each respectively destroyed and then attempting to "
5365 "submit associated cmd buffers. Attempt to destroy a "
5366 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005367 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005368 ASSERT_NO_FATAL_FAILURE(InitViewport());
5369 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5370
5371 VkDescriptorPoolSize ds_type_count = {};
5372 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5373 ds_type_count.descriptorCount = 1;
5374
5375 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5376 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5377 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005378 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005379 ds_pool_ci.maxSets = 1;
5380 ds_pool_ci.poolSizeCount = 1;
5381 ds_pool_ci.pPoolSizes = &ds_type_count;
5382
5383 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005384 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005385 ASSERT_VK_SUCCESS(err);
5386
5387 VkDescriptorSetLayoutBinding dsl_binding = {};
5388 dsl_binding.binding = 0;
5389 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5390 dsl_binding.descriptorCount = 1;
5391 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5392 dsl_binding.pImmutableSamplers = NULL;
5393
5394 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5395 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5396 ds_layout_ci.pNext = NULL;
5397 ds_layout_ci.bindingCount = 1;
5398 ds_layout_ci.pBindings = &dsl_binding;
5399 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005400 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005401 ASSERT_VK_SUCCESS(err);
5402
5403 VkDescriptorSet descriptorSet;
5404 VkDescriptorSetAllocateInfo alloc_info = {};
5405 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5406 alloc_info.descriptorSetCount = 1;
5407 alloc_info.descriptorPool = ds_pool;
5408 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005409 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005410 ASSERT_VK_SUCCESS(err);
5411
5412 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5413 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5414 pipeline_layout_ci.pNext = NULL;
5415 pipeline_layout_ci.setLayoutCount = 1;
5416 pipeline_layout_ci.pSetLayouts = &ds_layout;
5417
5418 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005419 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005420 ASSERT_VK_SUCCESS(err);
5421
5422 // Create images to update the descriptor with
5423 VkImage image;
5424 VkImage image2;
5425 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5426 const int32_t tex_width = 32;
5427 const int32_t tex_height = 32;
5428 VkImageCreateInfo image_create_info = {};
5429 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5430 image_create_info.pNext = NULL;
5431 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5432 image_create_info.format = tex_format;
5433 image_create_info.extent.width = tex_width;
5434 image_create_info.extent.height = tex_height;
5435 image_create_info.extent.depth = 1;
5436 image_create_info.mipLevels = 1;
5437 image_create_info.arrayLayers = 1;
5438 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5439 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5440 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5441 image_create_info.flags = 0;
5442 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5443 ASSERT_VK_SUCCESS(err);
5444 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5445 ASSERT_VK_SUCCESS(err);
5446
5447 VkMemoryRequirements memory_reqs;
5448 VkDeviceMemory image_memory;
5449 bool pass;
5450 VkMemoryAllocateInfo memory_info = {};
5451 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5452 memory_info.pNext = NULL;
5453 memory_info.allocationSize = 0;
5454 memory_info.memoryTypeIndex = 0;
5455 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5456 // Allocate enough memory for both images
5457 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005458 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005459 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005460 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005461 ASSERT_VK_SUCCESS(err);
5462 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5463 ASSERT_VK_SUCCESS(err);
5464 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005465 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005466 ASSERT_VK_SUCCESS(err);
5467
5468 VkImageViewCreateInfo image_view_create_info = {};
5469 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5470 image_view_create_info.image = image;
5471 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5472 image_view_create_info.format = tex_format;
5473 image_view_create_info.subresourceRange.layerCount = 1;
5474 image_view_create_info.subresourceRange.baseMipLevel = 0;
5475 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005476 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005477
5478 VkImageView view;
5479 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005480 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005481 ASSERT_VK_SUCCESS(err);
5482 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005483 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005484 ASSERT_VK_SUCCESS(err);
5485 // Create Samplers
5486 VkSamplerCreateInfo sampler_ci = {};
5487 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5488 sampler_ci.pNext = NULL;
5489 sampler_ci.magFilter = VK_FILTER_NEAREST;
5490 sampler_ci.minFilter = VK_FILTER_NEAREST;
5491 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5492 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5493 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5494 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5495 sampler_ci.mipLodBias = 1.0;
5496 sampler_ci.anisotropyEnable = VK_FALSE;
5497 sampler_ci.maxAnisotropy = 1;
5498 sampler_ci.compareEnable = VK_FALSE;
5499 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5500 sampler_ci.minLod = 1.0;
5501 sampler_ci.maxLod = 1.0;
5502 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5503 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5504 VkSampler sampler;
5505 VkSampler sampler2;
5506 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5507 ASSERT_VK_SUCCESS(err);
5508 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5509 ASSERT_VK_SUCCESS(err);
5510 // Update descriptor with image and sampler
5511 VkDescriptorImageInfo img_info = {};
5512 img_info.sampler = sampler;
5513 img_info.imageView = view;
5514 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5515
5516 VkWriteDescriptorSet descriptor_write;
5517 memset(&descriptor_write, 0, sizeof(descriptor_write));
5518 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5519 descriptor_write.dstSet = descriptorSet;
5520 descriptor_write.dstBinding = 0;
5521 descriptor_write.descriptorCount = 1;
5522 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5523 descriptor_write.pImageInfo = &img_info;
5524
5525 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5526
5527 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005528 char const *vsSource =
5529 "#version 450\n"
5530 "\n"
5531 "out gl_PerVertex { \n"
5532 " vec4 gl_Position;\n"
5533 "};\n"
5534 "void main(){\n"
5535 " gl_Position = vec4(1);\n"
5536 "}\n";
5537 char const *fsSource =
5538 "#version 450\n"
5539 "\n"
5540 "layout(set=0, binding=0) uniform sampler2D s;\n"
5541 "layout(location=0) out vec4 x;\n"
5542 "void main(){\n"
5543 " x = texture(s, vec2(1));\n"
5544 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005545 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5546 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5547 VkPipelineObj pipe(m_device);
5548 pipe.AddShader(&vs);
5549 pipe.AddShader(&fs);
5550 pipe.AddColorAttachment();
5551 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5552
5553 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005555 m_commandBuffer->BeginCommandBuffer();
5556 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005557 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5558 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5559 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005560 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5561 VkRect2D scissor = {{0, 0}, {16, 16}};
5562 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5563 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005564 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005565 m_commandBuffer->EndRenderPass();
5566 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005567 // Destroy sampler invalidates the cmd buffer, causing error on submit
5568 vkDestroySampler(m_device->device(), sampler, NULL);
5569 // Attempt to submit cmd buffer
5570 VkSubmitInfo submit_info = {};
5571 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5572 submit_info.commandBufferCount = 1;
5573 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5574 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5575 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005576
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005577 // Now re-update descriptor with valid sampler and delete image
5578 img_info.sampler = sampler2;
5579 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005580
5581 VkCommandBufferBeginInfo info = {};
5582 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5583 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5584
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005586 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005587 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005588 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5589 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5590 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005591 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5592 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005593 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005594 m_commandBuffer->EndRenderPass();
5595 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005596 // Destroy image invalidates the cmd buffer, causing error on submit
5597 vkDestroyImage(m_device->device(), image, NULL);
5598 // Attempt to submit cmd buffer
5599 submit_info = {};
5600 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5601 submit_info.commandBufferCount = 1;
5602 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5603 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5604 m_errorMonitor->VerifyFound();
5605 // Now update descriptor to be valid, but then free descriptor
5606 img_info.imageView = view2;
5607 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005608 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005609 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005610 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5611 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5612 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005613 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5614 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005615 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005616 m_commandBuffer->EndRenderPass();
5617 m_commandBuffer->EndCommandBuffer();
Dave Houltonfbf52152017-01-06 12:55:29 -07005618
5619 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005621 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005622 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005623
5624 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07005625 // 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 -07005626 vkQueueWaitIdle(m_device->m_queue);
5627 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5628
5629 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005630 submit_info = {};
5631 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5632 submit_info.commandBufferCount = 1;
5633 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005635 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5636 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005637
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005638 // Cleanup
5639 vkFreeMemory(m_device->device(), image_memory, NULL);
5640 vkDestroySampler(m_device->device(), sampler2, NULL);
5641 vkDestroyImage(m_device->device(), image2, NULL);
5642 vkDestroyImageView(m_device->device(), view, NULL);
5643 vkDestroyImageView(m_device->device(), view2, NULL);
5644 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5645 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5646 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5647}
5648
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005649TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5650 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5651 ASSERT_NO_FATAL_FAILURE(InitState());
5652 ASSERT_NO_FATAL_FAILURE(InitViewport());
5653 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5654
5655 VkDescriptorPoolSize ds_type_count = {};
5656 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5657 ds_type_count.descriptorCount = 1;
5658
5659 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5660 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5661 ds_pool_ci.pNext = NULL;
5662 ds_pool_ci.maxSets = 1;
5663 ds_pool_ci.poolSizeCount = 1;
5664 ds_pool_ci.pPoolSizes = &ds_type_count;
5665
5666 VkDescriptorPool ds_pool;
5667 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5668 ASSERT_VK_SUCCESS(err);
5669
5670 VkDescriptorSetLayoutBinding dsl_binding = {};
5671 dsl_binding.binding = 0;
5672 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5673 dsl_binding.descriptorCount = 1;
5674 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5675 dsl_binding.pImmutableSamplers = NULL;
5676
5677 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5678 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5679 ds_layout_ci.pNext = NULL;
5680 ds_layout_ci.bindingCount = 1;
5681 ds_layout_ci.pBindings = &dsl_binding;
5682 VkDescriptorSetLayout ds_layout;
5683 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5684 ASSERT_VK_SUCCESS(err);
5685
5686 VkDescriptorSet descriptor_set;
5687 VkDescriptorSetAllocateInfo alloc_info = {};
5688 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5689 alloc_info.descriptorSetCount = 1;
5690 alloc_info.descriptorPool = ds_pool;
5691 alloc_info.pSetLayouts = &ds_layout;
5692 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5693 ASSERT_VK_SUCCESS(err);
5694
5695 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5696 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5697 pipeline_layout_ci.pNext = NULL;
5698 pipeline_layout_ci.setLayoutCount = 1;
5699 pipeline_layout_ci.pSetLayouts = &ds_layout;
5700
5701 VkPipelineLayout pipeline_layout;
5702 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5703 ASSERT_VK_SUCCESS(err);
5704
5705 // Create image to update the descriptor with
5706 VkImageObj image(m_device);
5707 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5708 ASSERT_TRUE(image.initialized());
5709
5710 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5711 // Create Sampler
5712 VkSamplerCreateInfo sampler_ci = {};
5713 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5714 sampler_ci.pNext = NULL;
5715 sampler_ci.magFilter = VK_FILTER_NEAREST;
5716 sampler_ci.minFilter = VK_FILTER_NEAREST;
5717 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5718 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5719 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5720 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5721 sampler_ci.mipLodBias = 1.0;
5722 sampler_ci.anisotropyEnable = VK_FALSE;
5723 sampler_ci.maxAnisotropy = 1;
5724 sampler_ci.compareEnable = VK_FALSE;
5725 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5726 sampler_ci.minLod = 1.0;
5727 sampler_ci.maxLod = 1.0;
5728 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5729 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5730 VkSampler sampler;
5731 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5732 ASSERT_VK_SUCCESS(err);
5733 // Update descriptor with image and sampler
5734 VkDescriptorImageInfo img_info = {};
5735 img_info.sampler = sampler;
5736 img_info.imageView = view;
5737 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5738
5739 VkWriteDescriptorSet descriptor_write;
5740 memset(&descriptor_write, 0, sizeof(descriptor_write));
5741 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5742 descriptor_write.dstSet = descriptor_set;
5743 descriptor_write.dstBinding = 0;
5744 descriptor_write.descriptorCount = 1;
5745 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5746 descriptor_write.pImageInfo = &img_info;
5747
5748 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5749
5750 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005751 char const *vsSource =
5752 "#version 450\n"
5753 "\n"
5754 "out gl_PerVertex { \n"
5755 " vec4 gl_Position;\n"
5756 "};\n"
5757 "void main(){\n"
5758 " gl_Position = vec4(1);\n"
5759 "}\n";
5760 char const *fsSource =
5761 "#version 450\n"
5762 "\n"
5763 "layout(set=0, binding=0) uniform sampler2D s;\n"
5764 "layout(location=0) out vec4 x;\n"
5765 "void main(){\n"
5766 " x = texture(s, vec2(1));\n"
5767 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005768 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5769 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5770 VkPipelineObj pipe(m_device);
5771 pipe.AddShader(&vs);
5772 pipe.AddShader(&fs);
5773 pipe.AddColorAttachment();
5774 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5775
Tony Barbour552f6c02016-12-21 14:34:07 -07005776 m_commandBuffer->BeginCommandBuffer();
5777 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005778 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5779 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5780 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005781
5782 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5783 VkRect2D scissor = {{0, 0}, {16, 16}};
5784 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5785 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
5786
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005787 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005788 m_commandBuffer->EndRenderPass();
5789 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005790 // Submit cmd buffer to put pool in-flight
5791 VkSubmitInfo submit_info = {};
5792 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5793 submit_info.commandBufferCount = 1;
5794 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5795 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5796 // Destroy pool while in-flight, causing error
5797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5798 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5799 m_errorMonitor->VerifyFound();
5800 vkQueueWaitIdle(m_device->m_queue);
5801 // Cleanup
5802 vkDestroySampler(m_device->device(), sampler, NULL);
5803 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5804 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5805 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005806 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005807}
5808
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005809TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5810 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5811 ASSERT_NO_FATAL_FAILURE(InitState());
5812 ASSERT_NO_FATAL_FAILURE(InitViewport());
5813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5814
5815 VkDescriptorPoolSize ds_type_count = {};
5816 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5817 ds_type_count.descriptorCount = 1;
5818
5819 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5820 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5821 ds_pool_ci.pNext = NULL;
5822 ds_pool_ci.maxSets = 1;
5823 ds_pool_ci.poolSizeCount = 1;
5824 ds_pool_ci.pPoolSizes = &ds_type_count;
5825
5826 VkDescriptorPool ds_pool;
5827 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5828 ASSERT_VK_SUCCESS(err);
5829
5830 VkDescriptorSetLayoutBinding dsl_binding = {};
5831 dsl_binding.binding = 0;
5832 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5833 dsl_binding.descriptorCount = 1;
5834 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5835 dsl_binding.pImmutableSamplers = NULL;
5836
5837 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5838 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5839 ds_layout_ci.pNext = NULL;
5840 ds_layout_ci.bindingCount = 1;
5841 ds_layout_ci.pBindings = &dsl_binding;
5842 VkDescriptorSetLayout ds_layout;
5843 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5844 ASSERT_VK_SUCCESS(err);
5845
5846 VkDescriptorSet descriptorSet;
5847 VkDescriptorSetAllocateInfo alloc_info = {};
5848 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5849 alloc_info.descriptorSetCount = 1;
5850 alloc_info.descriptorPool = ds_pool;
5851 alloc_info.pSetLayouts = &ds_layout;
5852 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5853 ASSERT_VK_SUCCESS(err);
5854
5855 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5856 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5857 pipeline_layout_ci.pNext = NULL;
5858 pipeline_layout_ci.setLayoutCount = 1;
5859 pipeline_layout_ci.pSetLayouts = &ds_layout;
5860
5861 VkPipelineLayout pipeline_layout;
5862 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5863 ASSERT_VK_SUCCESS(err);
5864
5865 // Create images to update the descriptor with
5866 VkImage image;
5867 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5868 const int32_t tex_width = 32;
5869 const int32_t tex_height = 32;
5870 VkImageCreateInfo image_create_info = {};
5871 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5872 image_create_info.pNext = NULL;
5873 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5874 image_create_info.format = tex_format;
5875 image_create_info.extent.width = tex_width;
5876 image_create_info.extent.height = tex_height;
5877 image_create_info.extent.depth = 1;
5878 image_create_info.mipLevels = 1;
5879 image_create_info.arrayLayers = 1;
5880 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5881 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5882 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5883 image_create_info.flags = 0;
5884 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5885 ASSERT_VK_SUCCESS(err);
5886 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5887 VkMemoryRequirements memory_reqs;
5888 VkDeviceMemory image_memory;
5889 bool pass;
5890 VkMemoryAllocateInfo memory_info = {};
5891 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5892 memory_info.pNext = NULL;
5893 memory_info.allocationSize = 0;
5894 memory_info.memoryTypeIndex = 0;
5895 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5896 // Allocate enough memory for image
5897 memory_info.allocationSize = memory_reqs.size;
5898 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5899 ASSERT_TRUE(pass);
5900 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5901 ASSERT_VK_SUCCESS(err);
5902 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5903 ASSERT_VK_SUCCESS(err);
5904
5905 VkImageViewCreateInfo image_view_create_info = {};
5906 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5907 image_view_create_info.image = image;
5908 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5909 image_view_create_info.format = tex_format;
5910 image_view_create_info.subresourceRange.layerCount = 1;
5911 image_view_create_info.subresourceRange.baseMipLevel = 0;
5912 image_view_create_info.subresourceRange.levelCount = 1;
5913 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5914
5915 VkImageView view;
5916 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5917 ASSERT_VK_SUCCESS(err);
5918 // Create Samplers
5919 VkSamplerCreateInfo sampler_ci = {};
5920 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5921 sampler_ci.pNext = NULL;
5922 sampler_ci.magFilter = VK_FILTER_NEAREST;
5923 sampler_ci.minFilter = VK_FILTER_NEAREST;
5924 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5925 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5926 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5927 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5928 sampler_ci.mipLodBias = 1.0;
5929 sampler_ci.anisotropyEnable = VK_FALSE;
5930 sampler_ci.maxAnisotropy = 1;
5931 sampler_ci.compareEnable = VK_FALSE;
5932 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5933 sampler_ci.minLod = 1.0;
5934 sampler_ci.maxLod = 1.0;
5935 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5936 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5937 VkSampler sampler;
5938 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5939 ASSERT_VK_SUCCESS(err);
5940 // Update descriptor with image and sampler
5941 VkDescriptorImageInfo img_info = {};
5942 img_info.sampler = sampler;
5943 img_info.imageView = view;
5944 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5945
5946 VkWriteDescriptorSet descriptor_write;
5947 memset(&descriptor_write, 0, sizeof(descriptor_write));
5948 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5949 descriptor_write.dstSet = descriptorSet;
5950 descriptor_write.dstBinding = 0;
5951 descriptor_write.descriptorCount = 1;
5952 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5953 descriptor_write.pImageInfo = &img_info;
5954 // Break memory binding and attempt update
5955 vkFreeMemory(m_device->device(), image_memory, nullptr);
5956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005957 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5959 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5960 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5961 m_errorMonitor->VerifyFound();
5962 // Cleanup
5963 vkDestroyImage(m_device->device(), image, NULL);
5964 vkDestroySampler(m_device->device(), sampler, NULL);
5965 vkDestroyImageView(m_device->device(), view, NULL);
5966 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5967 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5968 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5969}
5970
Karl Schultz6addd812016-02-02 17:17:23 -07005971TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005972 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5973 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005974 // Create a valid cmd buffer
5975 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005976 uint64_t fake_pipeline_handle = 0xbaad6001;
5977 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005978 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005979 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5980
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07005982 m_commandBuffer->BeginCommandBuffer();
5983 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005984 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005985 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005986
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005987 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005988 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 -06005989 Draw(1, 0, 0, 0);
5990 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005991
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005992 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005993 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 -07005994 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005995 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5996 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005997}
5998
Karl Schultz6addd812016-02-02 17:17:23 -07005999TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006000 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006001 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006002
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006004
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006005 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006006 ASSERT_NO_FATAL_FAILURE(InitViewport());
6007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006008 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006009 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6010 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006011
6012 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006013 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6014 ds_pool_ci.pNext = NULL;
6015 ds_pool_ci.maxSets = 1;
6016 ds_pool_ci.poolSizeCount = 1;
6017 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006018
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006019 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006020 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006021 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006022
Tony Barboureb254902015-07-15 12:50:33 -06006023 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006024 dsl_binding.binding = 0;
6025 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6026 dsl_binding.descriptorCount = 1;
6027 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6028 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006029
Tony Barboureb254902015-07-15 12:50:33 -06006030 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006031 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6032 ds_layout_ci.pNext = NULL;
6033 ds_layout_ci.bindingCount = 1;
6034 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006035 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006036 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006037 ASSERT_VK_SUCCESS(err);
6038
6039 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006040 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006041 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006042 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006043 alloc_info.descriptorPool = ds_pool;
6044 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006045 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006046 ASSERT_VK_SUCCESS(err);
6047
Tony Barboureb254902015-07-15 12:50:33 -06006048 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006049 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6050 pipeline_layout_ci.pNext = NULL;
6051 pipeline_layout_ci.setLayoutCount = 1;
6052 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006053
6054 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006055 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006056 ASSERT_VK_SUCCESS(err);
6057
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006058 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006059 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006060 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006061 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006062
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006063 VkPipelineObj pipe(m_device);
6064 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006065 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006066 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006067 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006068
Tony Barbour552f6c02016-12-21 14:34:07 -07006069 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006070 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6071 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6072 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006073
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006074 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006075
Chia-I Wuf7458c52015-10-26 21:10:41 +08006076 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6077 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6078 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006079}
6080
Karl Schultz6addd812016-02-02 17:17:23 -07006081TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006082 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006083 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006084
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006086
6087 ASSERT_NO_FATAL_FAILURE(InitState());
6088 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006089 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6090 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006091
6092 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006093 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6094 ds_pool_ci.pNext = NULL;
6095 ds_pool_ci.maxSets = 1;
6096 ds_pool_ci.poolSizeCount = 1;
6097 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006098
6099 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006100 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006101 ASSERT_VK_SUCCESS(err);
6102
6103 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006104 dsl_binding.binding = 0;
6105 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6106 dsl_binding.descriptorCount = 1;
6107 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6108 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006109
6110 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006111 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6112 ds_layout_ci.pNext = NULL;
6113 ds_layout_ci.bindingCount = 1;
6114 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006115 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006116 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006117 ASSERT_VK_SUCCESS(err);
6118
6119 VkDescriptorSet descriptorSet;
6120 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006121 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006122 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006123 alloc_info.descriptorPool = ds_pool;
6124 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006125 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006126 ASSERT_VK_SUCCESS(err);
6127
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006128 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006129 VkWriteDescriptorSet descriptor_write;
6130 memset(&descriptor_write, 0, sizeof(descriptor_write));
6131 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6132 descriptor_write.dstSet = descriptorSet;
6133 descriptor_write.dstBinding = 0;
6134 descriptor_write.descriptorCount = 1;
6135 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6136 descriptor_write.pTexelBufferView = &view;
6137
6138 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6139
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006140 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006141
6142 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6143 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6144}
6145
Mark Youngd339ba32016-05-30 13:28:35 -06006146TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006147 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 -06006148
6149 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006151 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006152
6153 ASSERT_NO_FATAL_FAILURE(InitState());
6154
6155 // Create a buffer with no bound memory and then attempt to create
6156 // a buffer view.
6157 VkBufferCreateInfo buff_ci = {};
6158 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006159 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006160 buff_ci.size = 256;
6161 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6162 VkBuffer buffer;
6163 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6164 ASSERT_VK_SUCCESS(err);
6165
6166 VkBufferViewCreateInfo buff_view_ci = {};
6167 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6168 buff_view_ci.buffer = buffer;
6169 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6170 buff_view_ci.range = VK_WHOLE_SIZE;
6171 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006172 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006173
6174 m_errorMonitor->VerifyFound();
6175 vkDestroyBuffer(m_device->device(), buffer, NULL);
6176 // If last error is success, it still created the view, so delete it.
6177 if (err == VK_SUCCESS) {
6178 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6179 }
6180}
6181
Karl Schultz6addd812016-02-02 17:17:23 -07006182TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6183 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6184 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006185 // 1. No dynamicOffset supplied
6186 // 2. Too many dynamicOffsets supplied
6187 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006188 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6190 " requires 1 dynamicOffsets, but only "
6191 "0 dynamicOffsets are left in "
6192 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006193
6194 ASSERT_NO_FATAL_FAILURE(InitState());
6195 ASSERT_NO_FATAL_FAILURE(InitViewport());
6196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6197
6198 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006199 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6200 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006201
6202 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006203 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6204 ds_pool_ci.pNext = NULL;
6205 ds_pool_ci.maxSets = 1;
6206 ds_pool_ci.poolSizeCount = 1;
6207 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006208
6209 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006210 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006211 ASSERT_VK_SUCCESS(err);
6212
6213 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006214 dsl_binding.binding = 0;
6215 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6216 dsl_binding.descriptorCount = 1;
6217 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6218 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006219
6220 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006221 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6222 ds_layout_ci.pNext = NULL;
6223 ds_layout_ci.bindingCount = 1;
6224 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006225 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006226 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006227 ASSERT_VK_SUCCESS(err);
6228
6229 VkDescriptorSet descriptorSet;
6230 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006231 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006232 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006233 alloc_info.descriptorPool = ds_pool;
6234 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006235 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006236 ASSERT_VK_SUCCESS(err);
6237
6238 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006239 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6240 pipeline_layout_ci.pNext = NULL;
6241 pipeline_layout_ci.setLayoutCount = 1;
6242 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006243
6244 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006245 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006246 ASSERT_VK_SUCCESS(err);
6247
6248 // Create a buffer to update the descriptor with
6249 uint32_t qfi = 0;
6250 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006251 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6252 buffCI.size = 1024;
6253 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6254 buffCI.queueFamilyIndexCount = 1;
6255 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006256
6257 VkBuffer dyub;
6258 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6259 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006260 // Allocate memory and bind to buffer so we can make it to the appropriate
6261 // error
6262 VkMemoryAllocateInfo mem_alloc = {};
6263 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6264 mem_alloc.pNext = NULL;
6265 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006266 mem_alloc.memoryTypeIndex = 0;
6267
6268 VkMemoryRequirements memReqs;
6269 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006270 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006271 if (!pass) {
6272 vkDestroyBuffer(m_device->device(), dyub, NULL);
6273 return;
6274 }
6275
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006276 VkDeviceMemory mem;
6277 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6278 ASSERT_VK_SUCCESS(err);
6279 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6280 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006281 // Correctly update descriptor to avoid "NOT_UPDATED" error
6282 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006283 buffInfo.buffer = dyub;
6284 buffInfo.offset = 0;
6285 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006286
6287 VkWriteDescriptorSet descriptor_write;
6288 memset(&descriptor_write, 0, sizeof(descriptor_write));
6289 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6290 descriptor_write.dstSet = descriptorSet;
6291 descriptor_write.dstBinding = 0;
6292 descriptor_write.descriptorCount = 1;
6293 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6294 descriptor_write.pBufferInfo = &buffInfo;
6295
6296 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6297
Tony Barbour552f6c02016-12-21 14:34:07 -07006298 m_commandBuffer->BeginCommandBuffer();
6299 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006300 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6301 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006302 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006303 uint32_t pDynOff[2] = {512, 756};
6304 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6306 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6307 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6308 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006309 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006310 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6312 " dynamic offset 512 combined with "
6313 "offset 0 and range 1024 that "
6314 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006315 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006316 char const *vsSource =
6317 "#version 450\n"
6318 "\n"
6319 "out gl_PerVertex { \n"
6320 " vec4 gl_Position;\n"
6321 "};\n"
6322 "void main(){\n"
6323 " gl_Position = vec4(1);\n"
6324 "}\n";
6325 char const *fsSource =
6326 "#version 450\n"
6327 "\n"
6328 "layout(location=0) out vec4 x;\n"
6329 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6330 "void main(){\n"
6331 " x = vec4(bar.y);\n"
6332 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006333 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6334 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6335 VkPipelineObj pipe(m_device);
6336 pipe.AddShader(&vs);
6337 pipe.AddShader(&fs);
6338 pipe.AddColorAttachment();
6339 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6340
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006341 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6342 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6343 VkRect2D scissor = {{0, 0}, {16, 16}};
6344 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6345
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006346 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006347 // This update should succeed, but offset size of 512 will overstep buffer
6348 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006349 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6350 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006351 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006352 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006353
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006354 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006355 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006356
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006357 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006358 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006359 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6360}
6361
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006362TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006363 TEST_DESCRIPTION(
6364 "Attempt to update a descriptor with a non-sparse buffer "
6365 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006366 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006368 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6370 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006371
6372 ASSERT_NO_FATAL_FAILURE(InitState());
6373 ASSERT_NO_FATAL_FAILURE(InitViewport());
6374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6375
6376 VkDescriptorPoolSize ds_type_count = {};
6377 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6378 ds_type_count.descriptorCount = 1;
6379
6380 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6381 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6382 ds_pool_ci.pNext = NULL;
6383 ds_pool_ci.maxSets = 1;
6384 ds_pool_ci.poolSizeCount = 1;
6385 ds_pool_ci.pPoolSizes = &ds_type_count;
6386
6387 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006388 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006389 ASSERT_VK_SUCCESS(err);
6390
6391 VkDescriptorSetLayoutBinding dsl_binding = {};
6392 dsl_binding.binding = 0;
6393 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6394 dsl_binding.descriptorCount = 1;
6395 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6396 dsl_binding.pImmutableSamplers = NULL;
6397
6398 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6399 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6400 ds_layout_ci.pNext = NULL;
6401 ds_layout_ci.bindingCount = 1;
6402 ds_layout_ci.pBindings = &dsl_binding;
6403 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006404 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006405 ASSERT_VK_SUCCESS(err);
6406
6407 VkDescriptorSet descriptorSet;
6408 VkDescriptorSetAllocateInfo alloc_info = {};
6409 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6410 alloc_info.descriptorSetCount = 1;
6411 alloc_info.descriptorPool = ds_pool;
6412 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006413 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006414 ASSERT_VK_SUCCESS(err);
6415
6416 // Create a buffer to update the descriptor with
6417 uint32_t qfi = 0;
6418 VkBufferCreateInfo buffCI = {};
6419 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6420 buffCI.size = 1024;
6421 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6422 buffCI.queueFamilyIndexCount = 1;
6423 buffCI.pQueueFamilyIndices = &qfi;
6424
6425 VkBuffer dyub;
6426 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6427 ASSERT_VK_SUCCESS(err);
6428
6429 // Attempt to update descriptor without binding memory to it
6430 VkDescriptorBufferInfo buffInfo = {};
6431 buffInfo.buffer = dyub;
6432 buffInfo.offset = 0;
6433 buffInfo.range = 1024;
6434
6435 VkWriteDescriptorSet descriptor_write;
6436 memset(&descriptor_write, 0, sizeof(descriptor_write));
6437 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6438 descriptor_write.dstSet = descriptorSet;
6439 descriptor_write.dstBinding = 0;
6440 descriptor_write.descriptorCount = 1;
6441 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6442 descriptor_write.pBufferInfo = &buffInfo;
6443
6444 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6445 m_errorMonitor->VerifyFound();
6446
6447 vkDestroyBuffer(m_device->device(), dyub, NULL);
6448 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6449 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6450}
6451
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006452TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006453 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006454 ASSERT_NO_FATAL_FAILURE(InitState());
6455 ASSERT_NO_FATAL_FAILURE(InitViewport());
6456 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6457
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006458 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006459 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006460 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6461 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6462 pipeline_layout_ci.pushConstantRangeCount = 1;
6463 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6464
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006465 //
6466 // Check for invalid push constant ranges in pipeline layouts.
6467 //
6468 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006469 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006470 char const *msg;
6471 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006472
Karl Schultzc81037d2016-05-12 08:11:23 -06006473 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6474 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6475 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6476 "vkCreatePipelineLayout() call has push constants index 0 with "
6477 "size 0."},
6478 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6479 "vkCreatePipelineLayout() call has push constants index 0 with "
6480 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006481 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006482 "vkCreatePipelineLayout() call has push constants index 0 with "
6483 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006484 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006485 "vkCreatePipelineLayout() call has push constants index 0 with "
6486 "size 0."},
6487 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6488 "vkCreatePipelineLayout() call has push constants index 0 with "
6489 "offset 1. Offset must"},
6490 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6491 "vkCreatePipelineLayout() call has push constants index 0 "
6492 "with offset "},
6493 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6494 "vkCreatePipelineLayout() call has push constants "
6495 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006496 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006497 "vkCreatePipelineLayout() call has push constants index 0 "
6498 "with offset "},
6499 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6500 "vkCreatePipelineLayout() call has push "
6501 "constants index 0 with offset "},
6502 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6503 "vkCreatePipelineLayout() call has push "
6504 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006505 }};
6506
6507 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006508 for (const auto &iter : range_tests) {
6509 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6511 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006512 m_errorMonitor->VerifyFound();
6513 if (VK_SUCCESS == err) {
6514 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6515 }
6516 }
6517
6518 // Check for invalid stage flag
6519 pc_range.offset = 0;
6520 pc_range.size = 16;
6521 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006522 m_errorMonitor->SetDesiredFailureMsg(
6523 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6524 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006525 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006526 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006527 if (VK_SUCCESS == err) {
6528 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6529 }
6530
6531 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006532 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006533 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006534 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006535 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006536 };
6537
Karl Schultzc81037d2016-05-12 08:11:23 -06006538 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006539 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6540 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6541 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6542 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6543 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006544 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 1:[0, 4)",
6545 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 2:[0, 4)",
6546 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 3:[0, 4)",
6547 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 4:[0, 4)",
6548 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 2:[0, 4)",
6549 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 3:[0, 4)",
6550 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 4:[0, 4)",
6551 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 3:[0, 4)",
6552 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 4:[0, 4)",
6553 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[0, 4), 4:[0, 4)"}},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006554 {
6555 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6556 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6557 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6558 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6559 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006560 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006561 },
6562 {
6563 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6564 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6565 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6566 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6567 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006568 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006569 },
6570 {
6571 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6572 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6573 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6574 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6575 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006576 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006577 },
6578 {
6579 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6580 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6581 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6582 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6583 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006584 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 2:[4, 100)",
6585 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[32, 36), 2:[4, 100)",
6586 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 3:[40, 48)",
6587 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 4:[52, 56)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006588 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006589
Karl Schultzc81037d2016-05-12 08:11:23 -06006590 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006591 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006592 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006594 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006595 m_errorMonitor->VerifyFound();
6596 if (VK_SUCCESS == err) {
6597 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6598 }
6599 }
6600
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006601 //
6602 // CmdPushConstants tests
6603 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006604 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006605
6606 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006607 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6608 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006609 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006610 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6611 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006612 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006613 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6614 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006615 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006616 "vkCmdPushConstants() call has push constants with offset 1. "
6617 "Offset must be a multiple of 4."},
6618 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6619 "vkCmdPushConstants() call has push constants with offset 1. "
6620 "Offset must be a multiple of 4."},
6621 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6622 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6623 "0x1 not within flag-matching ranges in pipeline layout"},
6624 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6625 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6626 "0x1 not within flag-matching ranges in pipeline layout"},
6627 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6628 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6629 "0x1 not within flag-matching ranges in pipeline layout"},
6630 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6631 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6632 "0x1 not within flag-matching ranges in pipeline layout"},
6633 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6634 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6635 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006636 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006637 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6638 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006639 }};
6640
Tony Barbour552f6c02016-12-21 14:34:07 -07006641 m_commandBuffer->BeginCommandBuffer();
6642 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006643
6644 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006645 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006646 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006647 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006648 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006649 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006650 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006651 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006652 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6654 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006655 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006656 m_errorMonitor->VerifyFound();
6657 }
6658
6659 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006661 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006662 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006663 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006664
Karl Schultzc81037d2016-05-12 08:11:23 -06006665 // overlapping range tests with cmd
6666 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6667 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6668 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6669 "0x1 not within flag-matching ranges in pipeline layout"},
6670 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6671 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6672 "0x1 not within flag-matching ranges in pipeline layout"},
6673 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6674 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6675 "0x1 not within flag-matching ranges in pipeline layout"},
6676 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006677 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006678 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006679 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6680 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006681 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006682 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006683 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006684 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006685 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006686 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6688 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006689 iter.range.size, dummy_values);
6690 m_errorMonitor->VerifyFound();
6691 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006692 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6693
Tony Barbour552f6c02016-12-21 14:34:07 -07006694 m_commandBuffer->EndRenderPass();
6695 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006696}
6697
Karl Schultz6addd812016-02-02 17:17:23 -07006698TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006699 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006700 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006701
6702 ASSERT_NO_FATAL_FAILURE(InitState());
6703 ASSERT_NO_FATAL_FAILURE(InitViewport());
6704 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6705
6706 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6707 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006708 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6709 ds_type_count[0].descriptorCount = 10;
6710 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6711 ds_type_count[1].descriptorCount = 2;
6712 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6713 ds_type_count[2].descriptorCount = 2;
6714 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6715 ds_type_count[3].descriptorCount = 5;
6716 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6717 // type
6718 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6719 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6720 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006721
6722 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006723 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6724 ds_pool_ci.pNext = NULL;
6725 ds_pool_ci.maxSets = 5;
6726 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6727 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006728
6729 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006730 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006731 ASSERT_VK_SUCCESS(err);
6732
6733 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6734 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006735 dsl_binding[0].binding = 0;
6736 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6737 dsl_binding[0].descriptorCount = 5;
6738 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6739 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006740
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006741 // Create layout identical to set0 layout but w/ different stageFlags
6742 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006743 dsl_fs_stage_only.binding = 0;
6744 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6745 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006746 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6747 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006748 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006749 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006750 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6751 ds_layout_ci.pNext = NULL;
6752 ds_layout_ci.bindingCount = 1;
6753 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006754 static const uint32_t NUM_LAYOUTS = 4;
6755 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006756 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006757 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6758 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006759 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006760 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006761 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006762 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006763 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006764 dsl_binding[0].binding = 0;
6765 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006766 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006767 dsl_binding[1].binding = 1;
6768 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6769 dsl_binding[1].descriptorCount = 2;
6770 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6771 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006772 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006773 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006774 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006775 ASSERT_VK_SUCCESS(err);
6776 dsl_binding[0].binding = 0;
6777 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006778 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006779 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006780 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006781 ASSERT_VK_SUCCESS(err);
6782 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006783 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006784 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006785 ASSERT_VK_SUCCESS(err);
6786
6787 static const uint32_t NUM_SETS = 4;
6788 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6789 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006790 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006791 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006792 alloc_info.descriptorPool = ds_pool;
6793 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006794 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006795 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006796 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006797 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006798 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006799 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006800 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006801
6802 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006803 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6804 pipeline_layout_ci.pNext = NULL;
6805 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6806 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006807
6808 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006809 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006810 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006811 // Create pipelineLayout with only one setLayout
6812 pipeline_layout_ci.setLayoutCount = 1;
6813 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006814 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006815 ASSERT_VK_SUCCESS(err);
6816 // Create pipelineLayout with 2 descriptor setLayout at index 0
6817 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6818 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006819 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006820 ASSERT_VK_SUCCESS(err);
6821 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6822 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6823 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006824 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006825 ASSERT_VK_SUCCESS(err);
6826 // Create pipelineLayout with UB type, but stageFlags for FS only
6827 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6828 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006829 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006830 ASSERT_VK_SUCCESS(err);
6831 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6832 VkDescriptorSetLayout pl_bad_s0[2] = {};
6833 pl_bad_s0[0] = ds_layout_fs_only;
6834 pl_bad_s0[1] = ds_layout[1];
6835 pipeline_layout_ci.setLayoutCount = 2;
6836 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6837 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006838 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006839 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006840
Tobin Ehlis88452832015-12-03 09:40:56 -07006841 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006842 char const *vsSource =
6843 "#version 450\n"
6844 "\n"
6845 "out gl_PerVertex {\n"
6846 " vec4 gl_Position;\n"
6847 "};\n"
6848 "void main(){\n"
6849 " gl_Position = vec4(1);\n"
6850 "}\n";
6851 char const *fsSource =
6852 "#version 450\n"
6853 "\n"
6854 "layout(location=0) out vec4 x;\n"
6855 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6856 "void main(){\n"
6857 " x = vec4(bar.y);\n"
6858 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006859 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6860 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006861 VkPipelineObj pipe(m_device);
6862 pipe.AddShader(&vs);
6863 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006864 pipe.AddColorAttachment();
6865 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006866
Tony Barbour552f6c02016-12-21 14:34:07 -07006867 m_commandBuffer->BeginCommandBuffer();
6868 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07006869
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006870 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006871 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6872 // of PSO
6873 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6874 // cmd_pipeline.c
6875 // due to the fact that cmd_alloc_dset_data() has not been called in
6876 // cmd_bind_graphics_pipeline()
6877 // TODO : Want to cause various binding incompatibility issues here to test
6878 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006879 // First cause various verify_layout_compatibility() fails
6880 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006881 // verify_set_layout_compatibility fail cases:
6882 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006884 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6885 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006886 m_errorMonitor->VerifyFound();
6887
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006888 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6890 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6891 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006892 m_errorMonitor->VerifyFound();
6893
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006894 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006895 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6896 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6898 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6899 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006900 m_errorMonitor->VerifyFound();
6901
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006902 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6903 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6905 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6906 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006907 m_errorMonitor->VerifyFound();
6908
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006909 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6910 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6912 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6913 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6914 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006915 m_errorMonitor->VerifyFound();
6916
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006917 // Cause INFO messages due to disturbing previously bound Sets
6918 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006919 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6920 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006921 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6923 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6924 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006925 m_errorMonitor->VerifyFound();
6926
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006927 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6928 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006929 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6931 " newly bound as set #0 so set #1 and "
6932 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006933 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6934 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006935 m_errorMonitor->VerifyFound();
6936
Tobin Ehlis10fad692016-07-07 12:00:36 -06006937 // Now that we're done actively using the pipelineLayout that gfx pipeline
6938 // was created with, we should be able to delete it. Do that now to verify
6939 // that validation obeys pipelineLayout lifetime
6940 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6941
Tobin Ehlis88452832015-12-03 09:40:56 -07006942 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006943 // 1. Error due to not binding required set (we actually use same code as
6944 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006945 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6946 &descriptorSet[0], 0, NULL);
6947 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6948 &descriptorSet[1], 0, NULL);
6949 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 -07006950
6951 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6952 VkRect2D scissor = {{0, 0}, {16, 16}};
6953 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6954 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6955
Tobin Ehlis88452832015-12-03 09:40:56 -07006956 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006957 m_errorMonitor->VerifyFound();
6958
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006959 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006960 // 2. Error due to bound set not being compatible with PSO's
6961 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006962 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6963 &descriptorSet[0], 0, NULL);
6964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006965 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006966 m_errorMonitor->VerifyFound();
6967
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006968 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006969 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006970 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6971 }
6972 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006973 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6974 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6975}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006976
Karl Schultz6addd812016-02-02 17:17:23 -07006977TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6979 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006980
6981 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006982 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006983 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006984 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006985
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006986 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006987}
6988
Karl Schultz6addd812016-02-02 17:17:23 -07006989TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6990 VkResult err;
6991 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006992
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006994
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006995 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006996
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006997 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006998 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006999 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007000 cmd.commandPool = m_commandPool;
7001 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007002 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007003
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007004 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007005 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007006
7007 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007008 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007009 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7010
7011 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007012 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007013 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007014 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 -07007015 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007016
7017 // The error should be caught by validation of the BeginCommandBuffer call
7018 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7019
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007020 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007021 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007022}
7023
Karl Schultz6addd812016-02-02 17:17:23 -07007024TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007025 // Cause error due to Begin while recording CB
7026 // Then cause 2 errors for attempting to reset CB w/o having
7027 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7028 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007030
7031 ASSERT_NO_FATAL_FAILURE(InitState());
7032
7033 // Calls AllocateCommandBuffers
7034 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7035
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007036 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007037 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007038 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7039 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007040 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7041 cmd_buf_info.pNext = NULL;
7042 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007043 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007044
7045 // Begin CB to transition to recording state
7046 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7047 // Can't re-begin. This should trigger error
7048 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007049 m_errorMonitor->VerifyFound();
7050
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007052 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007053 // Reset attempt will trigger error due to incorrect CommandPool state
7054 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007055 m_errorMonitor->VerifyFound();
7056
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007058 // Transition CB to RECORDED state
7059 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7060 // Now attempting to Begin will implicitly reset, which triggers error
7061 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007062 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007063}
7064
Karl Schultz6addd812016-02-02 17:17:23 -07007065TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007066 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007067 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007068
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7070 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007071
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007072 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007073 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007074
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007075 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007076 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7077 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007078
7079 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007080 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7081 ds_pool_ci.pNext = NULL;
7082 ds_pool_ci.maxSets = 1;
7083 ds_pool_ci.poolSizeCount = 1;
7084 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007085
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007086 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007087 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007088 ASSERT_VK_SUCCESS(err);
7089
Tony Barboureb254902015-07-15 12:50:33 -06007090 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007091 dsl_binding.binding = 0;
7092 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7093 dsl_binding.descriptorCount = 1;
7094 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7095 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007096
Tony Barboureb254902015-07-15 12:50:33 -06007097 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007098 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7099 ds_layout_ci.pNext = NULL;
7100 ds_layout_ci.bindingCount = 1;
7101 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007102
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007103 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007104 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007105 ASSERT_VK_SUCCESS(err);
7106
7107 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007108 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007109 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007110 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007111 alloc_info.descriptorPool = ds_pool;
7112 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007113 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007114 ASSERT_VK_SUCCESS(err);
7115
Tony Barboureb254902015-07-15 12:50:33 -06007116 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007117 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7118 pipeline_layout_ci.setLayoutCount = 1;
7119 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007120
7121 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007122 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007123 ASSERT_VK_SUCCESS(err);
7124
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007125 VkViewport vp = {}; // Just need dummy vp to point to
7126 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007127
7128 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007129 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7130 vp_state_ci.scissorCount = 1;
7131 vp_state_ci.pScissors = &sc;
7132 vp_state_ci.viewportCount = 1;
7133 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007134
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007135 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7136 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7137 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7138 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7139 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7140 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007141 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007142 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007143 rs_state_ci.lineWidth = 1.0f;
7144
7145 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7146 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7147 vi_ci.pNext = nullptr;
7148 vi_ci.vertexBindingDescriptionCount = 0;
7149 vi_ci.pVertexBindingDescriptions = nullptr;
7150 vi_ci.vertexAttributeDescriptionCount = 0;
7151 vi_ci.pVertexAttributeDescriptions = nullptr;
7152
7153 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7154 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7155 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7156
7157 VkPipelineShaderStageCreateInfo shaderStages[2];
7158 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7159
7160 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7161 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7162 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
7163 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007164
Tony Barboureb254902015-07-15 12:50:33 -06007165 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007166 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7167 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007168 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007169 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7170 gp_ci.layout = pipeline_layout;
7171 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007172 gp_ci.pVertexInputState = &vi_ci;
7173 gp_ci.pInputAssemblyState = &ia_ci;
7174
7175 gp_ci.stageCount = 1;
7176 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007177
7178 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007179 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7180 pc_ci.initialDataSize = 0;
7181 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007182
7183 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007184 VkPipelineCache pipelineCache;
7185
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007186 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007187 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007188 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007189 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007190
Chia-I Wuf7458c52015-10-26 21:10:41 +08007191 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7192 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7193 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7194 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007195}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007196
Tobin Ehlis912df022015-09-17 08:46:18 -06007197/*// TODO : This test should be good, but needs Tess support in compiler to run
7198TEST_F(VkLayerTest, InvalidPatchControlPoints)
7199{
7200 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007201 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007202
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007204 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7205primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007206
Tobin Ehlis912df022015-09-17 08:46:18 -06007207 ASSERT_NO_FATAL_FAILURE(InitState());
7208 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007209
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007210 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007211 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007212 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007213
7214 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7215 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7216 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007217 ds_pool_ci.poolSizeCount = 1;
7218 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007219
7220 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007221 err = vkCreateDescriptorPool(m_device->device(),
7222VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007223 ASSERT_VK_SUCCESS(err);
7224
7225 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007226 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007227 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007228 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007229 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7230 dsl_binding.pImmutableSamplers = NULL;
7231
7232 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007233 ds_layout_ci.sType =
7234VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007235 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007236 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007237 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007238
7239 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007240 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7241&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007242 ASSERT_VK_SUCCESS(err);
7243
7244 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007245 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7246VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007247 ASSERT_VK_SUCCESS(err);
7248
7249 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007250 pipeline_layout_ci.sType =
7251VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007252 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007253 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007254 pipeline_layout_ci.pSetLayouts = &ds_layout;
7255
7256 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007257 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7258&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007259 ASSERT_VK_SUCCESS(err);
7260
7261 VkPipelineShaderStageCreateInfo shaderStages[3];
7262 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7263
Karl Schultz6addd812016-02-02 17:17:23 -07007264 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7265this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007266 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007267 VkShaderObj
7268tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7269this);
7270 VkShaderObj
7271te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7272this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007273
Karl Schultz6addd812016-02-02 17:17:23 -07007274 shaderStages[0].sType =
7275VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007276 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007277 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007278 shaderStages[1].sType =
7279VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007280 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007281 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007282 shaderStages[2].sType =
7283VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007284 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007285 shaderStages[2].shader = te.handle();
7286
7287 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007288 iaCI.sType =
7289VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007290 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007291
7292 VkPipelineTessellationStateCreateInfo tsCI = {};
7293 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7294 tsCI.patchControlPoints = 0; // This will cause an error
7295
7296 VkGraphicsPipelineCreateInfo gp_ci = {};
7297 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7298 gp_ci.pNext = NULL;
7299 gp_ci.stageCount = 3;
7300 gp_ci.pStages = shaderStages;
7301 gp_ci.pVertexInputState = NULL;
7302 gp_ci.pInputAssemblyState = &iaCI;
7303 gp_ci.pTessellationState = &tsCI;
7304 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007305 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007306 gp_ci.pMultisampleState = NULL;
7307 gp_ci.pDepthStencilState = NULL;
7308 gp_ci.pColorBlendState = NULL;
7309 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7310 gp_ci.layout = pipeline_layout;
7311 gp_ci.renderPass = renderPass();
7312
7313 VkPipelineCacheCreateInfo pc_ci = {};
7314 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7315 pc_ci.pNext = NULL;
7316 pc_ci.initialSize = 0;
7317 pc_ci.initialData = 0;
7318 pc_ci.maxSize = 0;
7319
7320 VkPipeline pipeline;
7321 VkPipelineCache pipelineCache;
7322
Karl Schultz6addd812016-02-02 17:17:23 -07007323 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7324&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007325 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007326 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7327&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007328
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007329 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007330
Chia-I Wuf7458c52015-10-26 21:10:41 +08007331 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7332 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7333 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7334 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007335}
7336*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007337
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007338TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007339 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007340
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007341 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007342
Tobin Ehlise68360f2015-10-01 11:15:13 -06007343 ASSERT_NO_FATAL_FAILURE(InitState());
7344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007345
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007346 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007347 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7348 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007349
7350 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007351 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7352 ds_pool_ci.maxSets = 1;
7353 ds_pool_ci.poolSizeCount = 1;
7354 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007355
7356 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007357 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007358 ASSERT_VK_SUCCESS(err);
7359
7360 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007361 dsl_binding.binding = 0;
7362 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7363 dsl_binding.descriptorCount = 1;
7364 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007365
7366 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007367 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7368 ds_layout_ci.bindingCount = 1;
7369 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007370
7371 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007372 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007373 ASSERT_VK_SUCCESS(err);
7374
7375 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007376 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007377 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007378 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007379 alloc_info.descriptorPool = ds_pool;
7380 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007381 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007382 ASSERT_VK_SUCCESS(err);
7383
7384 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007385 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7386 pipeline_layout_ci.setLayoutCount = 1;
7387 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007388
7389 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007390 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007391 ASSERT_VK_SUCCESS(err);
7392
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007393 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007394 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007395 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007396 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007397 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007398 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007399
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007400 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7401 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7402 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7403 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7404 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7405 rs_state_ci.depthClampEnable = VK_FALSE;
7406 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7407 rs_state_ci.depthBiasEnable = VK_FALSE;
7408
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007409 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7410 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7411 vi_ci.pNext = nullptr;
7412 vi_ci.vertexBindingDescriptionCount = 0;
7413 vi_ci.pVertexBindingDescriptions = nullptr;
7414 vi_ci.vertexAttributeDescriptionCount = 0;
7415 vi_ci.pVertexAttributeDescriptions = nullptr;
7416
7417 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7418 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7419 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7420
7421 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7422 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7423 pipe_ms_state_ci.pNext = NULL;
7424 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7425 pipe_ms_state_ci.sampleShadingEnable = 0;
7426 pipe_ms_state_ci.minSampleShading = 1.0;
7427 pipe_ms_state_ci.pSampleMask = NULL;
7428
Cody Northropeb3a6c12015-10-05 14:44:45 -06007429 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007430 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007431
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007432 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007433 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007434 shaderStages[0] = vs.GetStageCreateInfo();
7435 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007436
7437 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007438 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7439 gp_ci.stageCount = 2;
7440 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007441 gp_ci.pVertexInputState = &vi_ci;
7442 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007443 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007444 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007445 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007446 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7447 gp_ci.layout = pipeline_layout;
7448 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007449
7450 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007451 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007452
7453 VkPipeline pipeline;
7454 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007455 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007456 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007457
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007458 if (!m_device->phy().features().multiViewport) {
7459 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7460
7461 // Check case where multiViewport is disabled and viewport count is not 1
7462 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7465 vp_state_ci.scissorCount = 0;
7466 vp_state_ci.viewportCount = 0;
7467 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7468 m_errorMonitor->VerifyFound();
7469 } else {
7470 if (m_device->props.limits.maxViewports == 1) {
7471 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7472 } else {
7473 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7474
7475 // Check is that viewportcount and scissorcount match
7476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7477 vp_state_ci.scissorCount = 1;
7478 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7479 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7480 m_errorMonitor->VerifyFound();
7481
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007482 // Check case where multiViewport is enabled and viewport count is greater than max
7483 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7486 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7487 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7488 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7489 m_errorMonitor->VerifyFound();
7490 }
7491 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007492
Chia-I Wuf7458c52015-10-26 21:10:41 +08007493 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7494 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7495 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7496 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007497}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007498
7499// 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
7500// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007501TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007502 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007503
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007504 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7505
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007507
Tobin Ehlise68360f2015-10-01 11:15:13 -06007508 ASSERT_NO_FATAL_FAILURE(InitState());
7509 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007510
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007511 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007512 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7513 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007514
7515 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007516 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7517 ds_pool_ci.maxSets = 1;
7518 ds_pool_ci.poolSizeCount = 1;
7519 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007520
7521 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007522 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007523 ASSERT_VK_SUCCESS(err);
7524
7525 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007526 dsl_binding.binding = 0;
7527 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7528 dsl_binding.descriptorCount = 1;
7529 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007530
7531 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007532 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7533 ds_layout_ci.bindingCount = 1;
7534 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007535
7536 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007537 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007538 ASSERT_VK_SUCCESS(err);
7539
7540 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007541 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007542 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007543 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007544 alloc_info.descriptorPool = ds_pool;
7545 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007546 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007547 ASSERT_VK_SUCCESS(err);
7548
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007549 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7550 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7551 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7552
7553 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7554 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7555 vi_ci.pNext = nullptr;
7556 vi_ci.vertexBindingDescriptionCount = 0;
7557 vi_ci.pVertexBindingDescriptions = nullptr;
7558 vi_ci.vertexAttributeDescriptionCount = 0;
7559 vi_ci.pVertexAttributeDescriptions = nullptr;
7560
7561 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7562 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7563 pipe_ms_state_ci.pNext = NULL;
7564 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7565 pipe_ms_state_ci.sampleShadingEnable = 0;
7566 pipe_ms_state_ci.minSampleShading = 1.0;
7567 pipe_ms_state_ci.pSampleMask = NULL;
7568
Tobin Ehlise68360f2015-10-01 11:15:13 -06007569 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007570 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7571 pipeline_layout_ci.setLayoutCount = 1;
7572 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007573
7574 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007575 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007576 ASSERT_VK_SUCCESS(err);
7577
7578 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7579 // Set scissor as dynamic to avoid second error
7580 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007581 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7582 dyn_state_ci.dynamicStateCount = 1;
7583 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007584
Cody Northropeb3a6c12015-10-05 14:44:45 -06007585 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007586 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007587
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007588 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007589 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7590 // 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 +08007591 shaderStages[0] = vs.GetStageCreateInfo();
7592 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007593
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007594 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7595 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7596 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7597 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7598 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7599 rs_state_ci.depthClampEnable = VK_FALSE;
7600 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7601 rs_state_ci.depthBiasEnable = VK_FALSE;
7602
Tobin Ehlise68360f2015-10-01 11:15:13 -06007603 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007604 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7605 gp_ci.stageCount = 2;
7606 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007607 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007608 // Not setting VP state w/o dynamic vp state should cause validation error
7609 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007610 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007611 gp_ci.pVertexInputState = &vi_ci;
7612 gp_ci.pInputAssemblyState = &ia_ci;
7613 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007614 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7615 gp_ci.layout = pipeline_layout;
7616 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007617
7618 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007619 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007620
7621 VkPipeline pipeline;
7622 VkPipelineCache pipelineCache;
7623
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007624 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007625 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007626 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007627
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007628 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007629
Chia-I Wuf7458c52015-10-26 21:10:41 +08007630 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7631 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7632 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7633 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007634}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007635
7636// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7637// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007638TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7639 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007640
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007642
Tobin Ehlise68360f2015-10-01 11:15:13 -06007643 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007644
7645 if (!m_device->phy().features().multiViewport) {
7646 printf("Device does not support multiple viewports/scissors; skipped.\n");
7647 return;
7648 }
7649
Tobin Ehlise68360f2015-10-01 11:15:13 -06007650 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007651
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007652 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007653 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7654 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007655
7656 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007657 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7658 ds_pool_ci.maxSets = 1;
7659 ds_pool_ci.poolSizeCount = 1;
7660 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007661
7662 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007663 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007664 ASSERT_VK_SUCCESS(err);
7665
7666 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007667 dsl_binding.binding = 0;
7668 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7669 dsl_binding.descriptorCount = 1;
7670 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007671
7672 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007673 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7674 ds_layout_ci.bindingCount = 1;
7675 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007676
7677 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007678 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007679 ASSERT_VK_SUCCESS(err);
7680
7681 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007682 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007683 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007684 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007685 alloc_info.descriptorPool = ds_pool;
7686 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007687 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007688 ASSERT_VK_SUCCESS(err);
7689
7690 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007691 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7692 pipeline_layout_ci.setLayoutCount = 1;
7693 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007694
7695 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007696 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007697 ASSERT_VK_SUCCESS(err);
7698
7699 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007700 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7701 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007702 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007703 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007704 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007705
7706 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7707 // Set scissor as dynamic to avoid that error
7708 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007709 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7710 dyn_state_ci.dynamicStateCount = 1;
7711 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007712
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007713 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7714 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7715 pipe_ms_state_ci.pNext = NULL;
7716 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7717 pipe_ms_state_ci.sampleShadingEnable = 0;
7718 pipe_ms_state_ci.minSampleShading = 1.0;
7719 pipe_ms_state_ci.pSampleMask = NULL;
7720
Cody Northropeb3a6c12015-10-05 14:44:45 -06007721 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007722 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007724 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007725 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7726 // 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 +08007727 shaderStages[0] = vs.GetStageCreateInfo();
7728 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007729
Cody Northropf6622dc2015-10-06 10:33:21 -06007730 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7731 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7732 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007733 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007734 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007735 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007736 vi_ci.pVertexAttributeDescriptions = nullptr;
7737
7738 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7739 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7740 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7741
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007742 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007743 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007744 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007745 rs_ci.pNext = nullptr;
7746
Mark Youngc89c6312016-03-31 16:03:20 -06007747 VkPipelineColorBlendAttachmentState att = {};
7748 att.blendEnable = VK_FALSE;
7749 att.colorWriteMask = 0xf;
7750
Cody Northropf6622dc2015-10-06 10:33:21 -06007751 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7752 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7753 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007754 cb_ci.attachmentCount = 1;
7755 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007756
Tobin Ehlise68360f2015-10-01 11:15:13 -06007757 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007758 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7759 gp_ci.stageCount = 2;
7760 gp_ci.pStages = shaderStages;
7761 gp_ci.pVertexInputState = &vi_ci;
7762 gp_ci.pInputAssemblyState = &ia_ci;
7763 gp_ci.pViewportState = &vp_state_ci;
7764 gp_ci.pRasterizationState = &rs_ci;
7765 gp_ci.pColorBlendState = &cb_ci;
7766 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007767 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007768 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7769 gp_ci.layout = pipeline_layout;
7770 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007771
7772 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007773 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007774
7775 VkPipeline pipeline;
7776 VkPipelineCache pipelineCache;
7777
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007778 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007779 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007780 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007781
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007782 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007783
Tobin Ehlisd332f282015-10-02 11:00:56 -06007784 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007785 // First need to successfully create the PSO from above by setting
7786 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007787 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 -07007788
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007789 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07007790 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007791 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007792 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007793 m_commandBuffer->BeginCommandBuffer();
7794 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007795 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007796 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007797 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007798 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007799 Draw(1, 0, 0, 0);
7800
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007801 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007802
7803 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7804 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7805 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7806 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007807 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007808}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007809
7810// 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 -07007811// viewportCount
7812TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7813 VkResult err;
7814
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007816
7817 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007818
7819 if (!m_device->phy().features().multiViewport) {
7820 printf("Device does not support multiple viewports/scissors; skipped.\n");
7821 return;
7822 }
7823
Karl Schultz6addd812016-02-02 17:17:23 -07007824 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7825
7826 VkDescriptorPoolSize ds_type_count = {};
7827 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7828 ds_type_count.descriptorCount = 1;
7829
7830 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7831 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7832 ds_pool_ci.maxSets = 1;
7833 ds_pool_ci.poolSizeCount = 1;
7834 ds_pool_ci.pPoolSizes = &ds_type_count;
7835
7836 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007837 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007838 ASSERT_VK_SUCCESS(err);
7839
7840 VkDescriptorSetLayoutBinding dsl_binding = {};
7841 dsl_binding.binding = 0;
7842 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7843 dsl_binding.descriptorCount = 1;
7844 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7845
7846 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7847 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7848 ds_layout_ci.bindingCount = 1;
7849 ds_layout_ci.pBindings = &dsl_binding;
7850
7851 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007852 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007853 ASSERT_VK_SUCCESS(err);
7854
7855 VkDescriptorSet descriptorSet;
7856 VkDescriptorSetAllocateInfo alloc_info = {};
7857 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7858 alloc_info.descriptorSetCount = 1;
7859 alloc_info.descriptorPool = ds_pool;
7860 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007861 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007862 ASSERT_VK_SUCCESS(err);
7863
7864 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7865 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7866 pipeline_layout_ci.setLayoutCount = 1;
7867 pipeline_layout_ci.pSetLayouts = &ds_layout;
7868
7869 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007870 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007871 ASSERT_VK_SUCCESS(err);
7872
7873 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7874 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7875 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007876 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007877 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007878 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007879
7880 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7881 // Set scissor as dynamic to avoid that error
7882 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7883 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7884 dyn_state_ci.dynamicStateCount = 1;
7885 dyn_state_ci.pDynamicStates = &vp_state;
7886
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007887 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7888 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7889 pipe_ms_state_ci.pNext = NULL;
7890 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7891 pipe_ms_state_ci.sampleShadingEnable = 0;
7892 pipe_ms_state_ci.minSampleShading = 1.0;
7893 pipe_ms_state_ci.pSampleMask = NULL;
7894
Karl Schultz6addd812016-02-02 17:17:23 -07007895 VkPipelineShaderStageCreateInfo shaderStages[2];
7896 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7897
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007898 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007899 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7900 // 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 -07007901 shaderStages[0] = vs.GetStageCreateInfo();
7902 shaderStages[1] = fs.GetStageCreateInfo();
7903
7904 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7905 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7906 vi_ci.pNext = nullptr;
7907 vi_ci.vertexBindingDescriptionCount = 0;
7908 vi_ci.pVertexBindingDescriptions = nullptr;
7909 vi_ci.vertexAttributeDescriptionCount = 0;
7910 vi_ci.pVertexAttributeDescriptions = nullptr;
7911
7912 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7913 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7914 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7915
7916 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7917 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007918 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007919 rs_ci.pNext = nullptr;
7920
Mark Youngc89c6312016-03-31 16:03:20 -06007921 VkPipelineColorBlendAttachmentState att = {};
7922 att.blendEnable = VK_FALSE;
7923 att.colorWriteMask = 0xf;
7924
Karl Schultz6addd812016-02-02 17:17:23 -07007925 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7926 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7927 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007928 cb_ci.attachmentCount = 1;
7929 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007930
7931 VkGraphicsPipelineCreateInfo gp_ci = {};
7932 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7933 gp_ci.stageCount = 2;
7934 gp_ci.pStages = shaderStages;
7935 gp_ci.pVertexInputState = &vi_ci;
7936 gp_ci.pInputAssemblyState = &ia_ci;
7937 gp_ci.pViewportState = &vp_state_ci;
7938 gp_ci.pRasterizationState = &rs_ci;
7939 gp_ci.pColorBlendState = &cb_ci;
7940 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007941 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007942 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7943 gp_ci.layout = pipeline_layout;
7944 gp_ci.renderPass = renderPass();
7945
7946 VkPipelineCacheCreateInfo pc_ci = {};
7947 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7948
7949 VkPipeline pipeline;
7950 VkPipelineCache pipelineCache;
7951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007952 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007953 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007954 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007955
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007956 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007957
7958 // Now hit second fail case where we set scissor w/ different count than PSO
7959 // First need to successfully create the PSO from above by setting
7960 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7962 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007963
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007964 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06007965 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007966 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007967 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007968 m_commandBuffer->BeginCommandBuffer();
7969 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007970 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007971 VkViewport viewports[1] = {};
7972 viewports[0].width = 8;
7973 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007974 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007975 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007976 Draw(1, 0, 0, 0);
7977
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007978 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007979
Chia-I Wuf7458c52015-10-26 21:10:41 +08007980 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7981 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7982 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7983 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007984 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007985}
7986
Mark Young7394fdd2016-03-31 14:56:43 -06007987TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7988 VkResult err;
7989
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007991
7992 ASSERT_NO_FATAL_FAILURE(InitState());
7993 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7994
7995 VkDescriptorPoolSize ds_type_count = {};
7996 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7997 ds_type_count.descriptorCount = 1;
7998
7999 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8000 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8001 ds_pool_ci.maxSets = 1;
8002 ds_pool_ci.poolSizeCount = 1;
8003 ds_pool_ci.pPoolSizes = &ds_type_count;
8004
8005 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008006 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008007 ASSERT_VK_SUCCESS(err);
8008
8009 VkDescriptorSetLayoutBinding dsl_binding = {};
8010 dsl_binding.binding = 0;
8011 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8012 dsl_binding.descriptorCount = 1;
8013 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8014
8015 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8016 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8017 ds_layout_ci.bindingCount = 1;
8018 ds_layout_ci.pBindings = &dsl_binding;
8019
8020 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008021 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008022 ASSERT_VK_SUCCESS(err);
8023
8024 VkDescriptorSet descriptorSet;
8025 VkDescriptorSetAllocateInfo alloc_info = {};
8026 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8027 alloc_info.descriptorSetCount = 1;
8028 alloc_info.descriptorPool = ds_pool;
8029 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008030 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008031 ASSERT_VK_SUCCESS(err);
8032
8033 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8034 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8035 pipeline_layout_ci.setLayoutCount = 1;
8036 pipeline_layout_ci.pSetLayouts = &ds_layout;
8037
8038 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008039 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008040 ASSERT_VK_SUCCESS(err);
8041
8042 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8043 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8044 vp_state_ci.scissorCount = 1;
8045 vp_state_ci.pScissors = NULL;
8046 vp_state_ci.viewportCount = 1;
8047 vp_state_ci.pViewports = NULL;
8048
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008049 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008050 // Set scissor as dynamic to avoid that error
8051 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8052 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8053 dyn_state_ci.dynamicStateCount = 2;
8054 dyn_state_ci.pDynamicStates = dynamic_states;
8055
8056 VkPipelineShaderStageCreateInfo shaderStages[2];
8057 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8058
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008059 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8060 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008061 this); // TODO - We shouldn't need a fragment shader
8062 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008063 shaderStages[0] = vs.GetStageCreateInfo();
8064 shaderStages[1] = fs.GetStageCreateInfo();
8065
8066 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8067 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8068 vi_ci.pNext = nullptr;
8069 vi_ci.vertexBindingDescriptionCount = 0;
8070 vi_ci.pVertexBindingDescriptions = nullptr;
8071 vi_ci.vertexAttributeDescriptionCount = 0;
8072 vi_ci.pVertexAttributeDescriptions = nullptr;
8073
8074 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8075 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8076 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8077
8078 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8079 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8080 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008081 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008082
Mark Young47107952016-05-02 15:59:55 -06008083 // Check too low (line width of -1.0f).
8084 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008085
8086 VkPipelineColorBlendAttachmentState att = {};
8087 att.blendEnable = VK_FALSE;
8088 att.colorWriteMask = 0xf;
8089
8090 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8091 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8092 cb_ci.pNext = nullptr;
8093 cb_ci.attachmentCount = 1;
8094 cb_ci.pAttachments = &att;
8095
8096 VkGraphicsPipelineCreateInfo gp_ci = {};
8097 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8098 gp_ci.stageCount = 2;
8099 gp_ci.pStages = shaderStages;
8100 gp_ci.pVertexInputState = &vi_ci;
8101 gp_ci.pInputAssemblyState = &ia_ci;
8102 gp_ci.pViewportState = &vp_state_ci;
8103 gp_ci.pRasterizationState = &rs_ci;
8104 gp_ci.pColorBlendState = &cb_ci;
8105 gp_ci.pDynamicState = &dyn_state_ci;
8106 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8107 gp_ci.layout = pipeline_layout;
8108 gp_ci.renderPass = renderPass();
8109
8110 VkPipelineCacheCreateInfo pc_ci = {};
8111 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8112
8113 VkPipeline pipeline;
8114 VkPipelineCache pipelineCache;
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);
Mark Young7394fdd2016-03-31 14:56:43 -06008119
8120 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008121 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008122
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008124
8125 // Check too high (line width of 65536.0f).
8126 rs_ci.lineWidth = 65536.0f;
8127
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008128 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008129 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008130 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008131
8132 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008133 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008134
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008136
8137 dyn_state_ci.dynamicStateCount = 3;
8138
8139 rs_ci.lineWidth = 1.0f;
8140
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008141 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008142 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008143 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008144 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008145 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008146
8147 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008148 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008149 m_errorMonitor->VerifyFound();
8150
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008152
8153 // Check too high with dynamic setting.
8154 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8155 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008156 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008157
8158 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8159 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8160 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8161 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008162 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008163}
8164
Karl Schultz6addd812016-02-02 17:17:23 -07008165TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008166 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008168 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008169
8170 ASSERT_NO_FATAL_FAILURE(InitState());
8171 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008172
Tony Barbour552f6c02016-12-21 14:34:07 -07008173 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008174 // Don't care about RenderPass handle b/c error should be flagged before
8175 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008176 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008177
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008178 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008179}
8180
Karl Schultz6addd812016-02-02 17:17:23 -07008181TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008182 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8184 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008185
8186 ASSERT_NO_FATAL_FAILURE(InitState());
8187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008188
Tony Barbour552f6c02016-12-21 14:34:07 -07008189 m_commandBuffer->BeginCommandBuffer();
8190 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008191 // Just create a dummy Renderpass that's non-NULL so we can get to the
8192 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008193 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008194
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008195 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008196}
8197
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008198TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008199 TEST_DESCRIPTION(
8200 "Begin a renderPass where clearValueCount is less than"
8201 "the number of renderPass attachments that use loadOp"
8202 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008203
8204 ASSERT_NO_FATAL_FAILURE(InitState());
8205 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8206
8207 // Create a renderPass with a single attachment that uses loadOp CLEAR
8208 VkAttachmentReference attach = {};
8209 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8210 VkSubpassDescription subpass = {};
8211 subpass.inputAttachmentCount = 1;
8212 subpass.pInputAttachments = &attach;
8213 VkRenderPassCreateInfo rpci = {};
8214 rpci.subpassCount = 1;
8215 rpci.pSubpasses = &subpass;
8216 rpci.attachmentCount = 1;
8217 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008218 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008219 // Set loadOp to CLEAR
8220 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8221 rpci.pAttachments = &attach_desc;
8222 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8223 VkRenderPass rp;
8224 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8225
8226 VkCommandBufferInheritanceInfo hinfo = {};
8227 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8228 hinfo.renderPass = VK_NULL_HANDLE;
8229 hinfo.subpass = 0;
8230 hinfo.framebuffer = VK_NULL_HANDLE;
8231 hinfo.occlusionQueryEnable = VK_FALSE;
8232 hinfo.queryFlags = 0;
8233 hinfo.pipelineStatistics = 0;
8234 VkCommandBufferBeginInfo info = {};
8235 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8236 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8237 info.pInheritanceInfo = &hinfo;
8238
8239 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8240 VkRenderPassBeginInfo rp_begin = {};
8241 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8242 rp_begin.pNext = NULL;
8243 rp_begin.renderPass = renderPass();
8244 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008245 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008246
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008248
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008249 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008250
8251 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008252
8253 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008254}
8255
Slawomir Cygan0808f392016-11-28 17:53:23 +01008256TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008257 TEST_DESCRIPTION(
8258 "Begin a renderPass where clearValueCount is greater than"
8259 "the number of renderPass attachments that use loadOp"
8260 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008261
8262 ASSERT_NO_FATAL_FAILURE(InitState());
8263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8264
8265 // Create a renderPass with a single attachment that uses loadOp CLEAR
8266 VkAttachmentReference attach = {};
8267 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8268 VkSubpassDescription subpass = {};
8269 subpass.inputAttachmentCount = 1;
8270 subpass.pInputAttachments = &attach;
8271 VkRenderPassCreateInfo rpci = {};
8272 rpci.subpassCount = 1;
8273 rpci.pSubpasses = &subpass;
8274 rpci.attachmentCount = 1;
8275 VkAttachmentDescription attach_desc = {};
8276 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8277 // Set loadOp to CLEAR
8278 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8279 rpci.pAttachments = &attach_desc;
8280 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8281 VkRenderPass rp;
8282 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8283
8284 VkCommandBufferBeginInfo info = {};
8285 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8286 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8287
8288 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8289 VkRenderPassBeginInfo rp_begin = {};
8290 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8291 rp_begin.pNext = NULL;
8292 rp_begin.renderPass = renderPass();
8293 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008294 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008295
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8297 " has a clearValueCount of"
8298 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008299
8300 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8301
8302 m_errorMonitor->VerifyFound();
8303
8304 vkDestroyRenderPass(m_device->device(), rp, NULL);
8305}
8306
Cody Northrop3bb4d962016-05-09 16:15:57 -06008307TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008308 TEST_DESCRIPTION("End a command buffer with an active render pass");
8309
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8311 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008312
8313 ASSERT_NO_FATAL_FAILURE(InitState());
8314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8315
Tony Barbour552f6c02016-12-21 14:34:07 -07008316 m_commandBuffer->BeginCommandBuffer();
8317 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8318 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008319
8320 m_errorMonitor->VerifyFound();
8321
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008322 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8323 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008324}
8325
Karl Schultz6addd812016-02-02 17:17:23 -07008326TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008327 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8329 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008330
8331 ASSERT_NO_FATAL_FAILURE(InitState());
8332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008333
Tony Barbour552f6c02016-12-21 14:34:07 -07008334 m_commandBuffer->BeginCommandBuffer();
8335 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008336
8337 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008338 vk_testing::Buffer dstBuffer;
8339 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008340
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008341 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008342
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008343 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008344}
8345
Karl Schultz6addd812016-02-02 17:17:23 -07008346TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008347 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8349 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008350
8351 ASSERT_NO_FATAL_FAILURE(InitState());
8352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008353
Tony Barbour552f6c02016-12-21 14:34:07 -07008354 m_commandBuffer->BeginCommandBuffer();
8355 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008356
8357 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008358 vk_testing::Buffer dstBuffer;
8359 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008360
Karl Schultz6addd812016-02-02 17:17:23 -07008361 VkDeviceSize dstOffset = 0;
8362 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008363 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008364
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008365 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008366
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008367 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008368}
8369
Karl Schultz6addd812016-02-02 17:17:23 -07008370TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008371 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8373 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008374
8375 ASSERT_NO_FATAL_FAILURE(InitState());
8376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008377
Tony Barbour552f6c02016-12-21 14:34:07 -07008378 m_commandBuffer->BeginCommandBuffer();
8379 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008380
Michael Lentine0a369f62016-02-03 16:51:46 -06008381 VkClearColorValue clear_color;
8382 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008383 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8384 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8385 const int32_t tex_width = 32;
8386 const int32_t tex_height = 32;
8387 VkImageCreateInfo image_create_info = {};
8388 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8389 image_create_info.pNext = NULL;
8390 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8391 image_create_info.format = tex_format;
8392 image_create_info.extent.width = tex_width;
8393 image_create_info.extent.height = tex_height;
8394 image_create_info.extent.depth = 1;
8395 image_create_info.mipLevels = 1;
8396 image_create_info.arrayLayers = 1;
8397 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8398 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8399 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008400
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008401 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008402 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008403
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008404 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008405
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008406 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008407
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008408 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008409}
8410
Karl Schultz6addd812016-02-02 17:17:23 -07008411TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008412 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8414 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008415
8416 ASSERT_NO_FATAL_FAILURE(InitState());
8417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008418
Tony Barbour552f6c02016-12-21 14:34:07 -07008419 m_commandBuffer->BeginCommandBuffer();
8420 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008421
8422 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008423 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008424 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8425 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8426 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8427 image_create_info.extent.width = 64;
8428 image_create_info.extent.height = 64;
8429 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8430 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008431
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008432 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008433 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008434
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008435 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008436
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008437 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8438 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008439
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008440 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008441}
8442
Karl Schultz6addd812016-02-02 17:17:23 -07008443TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008444 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008445 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008446
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8448 "vkCmdClearAttachments(): This call "
8449 "must be issued inside an active "
8450 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008451
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008452 ASSERT_NO_FATAL_FAILURE(InitState());
8453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008454
8455 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008456 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008457 ASSERT_VK_SUCCESS(err);
8458
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008459 VkClearAttachment color_attachment;
8460 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8461 color_attachment.clearValue.color.float32[0] = 0;
8462 color_attachment.clearValue.color.float32[1] = 0;
8463 color_attachment.clearValue.color.float32[2] = 0;
8464 color_attachment.clearValue.color.float32[3] = 0;
8465 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008466 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008467 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008468
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008469 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008470}
8471
Chris Forbes3b97e932016-09-07 11:29:24 +12008472TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008473 TEST_DESCRIPTION(
8474 "Test that an error is produced when CmdNextSubpass is "
8475 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008476
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8478 "vkCmdNextSubpass(): Attempted to advance "
8479 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008480
8481 ASSERT_NO_FATAL_FAILURE(InitState());
8482 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8483
Tony Barbour552f6c02016-12-21 14:34:07 -07008484 m_commandBuffer->BeginCommandBuffer();
8485 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008486
8487 // error here.
8488 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8489 m_errorMonitor->VerifyFound();
8490
Tony Barbour552f6c02016-12-21 14:34:07 -07008491 m_commandBuffer->EndRenderPass();
8492 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008493}
8494
Chris Forbes6d624702016-09-07 13:57:05 +12008495TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008496 TEST_DESCRIPTION(
8497 "Test that an error is produced when CmdEndRenderPass is "
8498 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008499
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8501 "vkCmdEndRenderPass(): Called before reaching "
8502 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008503
8504 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008505 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8506 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008507
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008508 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008509
8510 VkRenderPass rp;
8511 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8512 ASSERT_VK_SUCCESS(err);
8513
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008514 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008515
8516 VkFramebuffer fb;
8517 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8518 ASSERT_VK_SUCCESS(err);
8519
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008520 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008521
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008522 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 +12008523
8524 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8525
8526 // Error here.
8527 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8528 m_errorMonitor->VerifyFound();
8529
8530 // Clean up.
8531 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8532 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8533}
8534
Karl Schultz9e66a292016-04-21 15:57:51 -06008535TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8536 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8538 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008539
8540 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008541 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008542
8543 VkBufferMemoryBarrier buf_barrier = {};
8544 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8545 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8546 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8547 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8548 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8549 buf_barrier.buffer = VK_NULL_HANDLE;
8550 buf_barrier.offset = 0;
8551 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008552 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8553 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008554
8555 m_errorMonitor->VerifyFound();
8556}
8557
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008558TEST_F(VkLayerTest, InvalidBarriers) {
8559 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8560
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008562
8563 ASSERT_NO_FATAL_FAILURE(InitState());
8564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8565
8566 VkMemoryBarrier mem_barrier = {};
8567 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8568 mem_barrier.pNext = NULL;
8569 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8570 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008571 m_commandBuffer->BeginCommandBuffer();
8572 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008573 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008574 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008575 &mem_barrier, 0, nullptr, 0, nullptr);
8576 m_errorMonitor->VerifyFound();
8577
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008579 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008580 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 -06008581 ASSERT_TRUE(image.initialized());
8582 VkImageMemoryBarrier img_barrier = {};
8583 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8584 img_barrier.pNext = NULL;
8585 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8586 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8587 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8588 // New layout can't be UNDEFINED
8589 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8590 img_barrier.image = image.handle();
8591 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8592 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8593 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8594 img_barrier.subresourceRange.baseArrayLayer = 0;
8595 img_barrier.subresourceRange.baseMipLevel = 0;
8596 img_barrier.subresourceRange.layerCount = 1;
8597 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008598 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8599 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008600 m_errorMonitor->VerifyFound();
8601 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8602
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8604 "Subresource must have the sum of the "
8605 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008606 // baseArrayLayer + layerCount must be <= image's arrayLayers
8607 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008608 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8609 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008610 m_errorMonitor->VerifyFound();
8611 img_barrier.subresourceRange.baseArrayLayer = 0;
8612
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008614 // baseMipLevel + levelCount must be <= image's mipLevels
8615 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008616 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8617 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008618 m_errorMonitor->VerifyFound();
8619 img_barrier.subresourceRange.baseMipLevel = 0;
8620
Mike Weiblen7053aa32017-01-25 15:21:10 -07008621 // levelCount must be non-zero.
8622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8623 img_barrier.subresourceRange.levelCount = 0;
8624 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8625 nullptr, 0, nullptr, 1, &img_barrier);
8626 m_errorMonitor->VerifyFound();
8627 img_barrier.subresourceRange.levelCount = 1;
8628
8629 // layerCount must be non-zero.
8630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8631 img_barrier.subresourceRange.layerCount = 0;
8632 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8633 nullptr, 0, nullptr, 1, &img_barrier);
8634 m_errorMonitor->VerifyFound();
8635 img_barrier.subresourceRange.layerCount = 1;
8636
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008637 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 -06008638 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008639 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8640 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008641 VkBufferMemoryBarrier buf_barrier = {};
8642 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8643 buf_barrier.pNext = NULL;
8644 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8645 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8646 buf_barrier.buffer = buffer.handle();
8647 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8648 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8649 buf_barrier.offset = 0;
8650 buf_barrier.size = VK_WHOLE_SIZE;
8651 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008652 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8653 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008654 m_errorMonitor->VerifyFound();
8655 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8656
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008658 buf_barrier.offset = 257;
8659 // Offset greater than total size
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, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008662 m_errorMonitor->VerifyFound();
8663 buf_barrier.offset = 0;
8664
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008666 buf_barrier.size = 257;
8667 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008668 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8669 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008670 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008671
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008672 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008673 m_errorMonitor->SetDesiredFailureMsg(
8674 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008675 "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 -06008676 VkDepthStencilObj ds_image(m_device);
8677 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8678 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008679 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8680 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008681 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008682
8683 // Not having DEPTH or STENCIL set is an error
8684 img_barrier.subresourceRange.aspectMask = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008685 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8686 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008687 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07008688
8689 // Having anything other than DEPTH or STENCIL is an error
8690 m_errorMonitor->SetDesiredFailureMsg(
8691 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8692 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8693 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
8694 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8695 nullptr, 0, nullptr, 1, &img_barrier);
8696 m_errorMonitor->VerifyFound();
8697
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008698 // Now test depth-only
8699 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008700 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8701 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008702 VkDepthStencilObj d_image(m_device);
8703 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8704 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008705 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008706 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008707 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008708
8709 // DEPTH bit must be set
8710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8711 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8712 img_barrier.subresourceRange.aspectMask = 0;
8713 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8714 0, nullptr, 0, nullptr, 1, &img_barrier);
8715 m_errorMonitor->VerifyFound();
8716
8717 // No bits other than DEPTH may be set
8718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8719 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8720 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008721 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8722 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008723 m_errorMonitor->VerifyFound();
8724 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008725
8726 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008727 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8728 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8730 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008731 VkDepthStencilObj s_image(m_device);
8732 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8733 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008734 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008735 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008736 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008737 // Use of COLOR aspect on depth image is error
8738 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_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,
8740 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008741 m_errorMonitor->VerifyFound();
8742 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008743
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008744 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008745 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008746 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 -06008747 ASSERT_TRUE(c_image.initialized());
8748 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8749 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8750 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008751
8752 // COLOR bit must be set
8753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8754 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8755 img_barrier.subresourceRange.aspectMask = 0;
8756 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8757 nullptr, 0, nullptr, 1, &img_barrier);
8758 m_errorMonitor->VerifyFound();
8759
8760 // No bits other than COLOR may be set
8761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8762 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
8763 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008764 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8765 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008766 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008767
8768 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8769
8770 // Create command pool with incompatible queueflags
8771 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8772 uint32_t queue_family_index = UINT32_MAX;
8773 for (uint32_t i = 0; i < queue_props.size(); i++) {
8774 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8775 queue_family_index = i;
8776 break;
8777 }
8778 }
8779 if (queue_family_index == UINT32_MAX) {
8780 printf("No non-compute queue found; skipped.\n");
8781 return;
8782 }
8783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8784
8785 VkCommandPool command_pool;
8786 VkCommandPoolCreateInfo pool_create_info{};
8787 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8788 pool_create_info.queueFamilyIndex = queue_family_index;
8789 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8790 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8791
8792 // Allocate a command buffer
8793 VkCommandBuffer bad_command_buffer;
8794 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8795 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8796 command_buffer_allocate_info.commandPool = command_pool;
8797 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8798 command_buffer_allocate_info.commandBufferCount = 1;
8799 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8800
8801 VkCommandBufferBeginInfo cbbi = {};
8802 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8803 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8804 buf_barrier.offset = 0;
8805 buf_barrier.size = VK_WHOLE_SIZE;
8806 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8807 &buf_barrier, 0, nullptr);
8808 m_errorMonitor->VerifyFound();
8809
8810 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8811 vkEndCommandBuffer(bad_command_buffer);
8812 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8813 printf("The non-compute queue does not support graphics; skipped.\n");
8814 return;
8815 }
8816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8817 VkEvent event;
8818 VkEventCreateInfo event_create_info{};
8819 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8820 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8821 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8822 nullptr, 0, nullptr);
8823 m_errorMonitor->VerifyFound();
8824
8825 vkEndCommandBuffer(bad_command_buffer);
8826 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008827}
8828
Tony Barbour18ba25c2016-09-29 13:42:40 -06008829TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8830 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8831
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06008833 ASSERT_NO_FATAL_FAILURE(InitState());
8834 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008835 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 -06008836 ASSERT_TRUE(image.initialized());
8837
8838 VkImageMemoryBarrier barrier = {};
8839 VkImageSubresourceRange range;
8840 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8841 barrier.srcAccessMask = 0;
8842 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8843 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8844 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8845 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8846 barrier.image = image.handle();
8847 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8848 range.baseMipLevel = 0;
8849 range.levelCount = 1;
8850 range.baseArrayLayer = 0;
8851 range.layerCount = 1;
8852 barrier.subresourceRange = range;
8853 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8854 cmdbuf.BeginCommandBuffer();
8855 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8856 &barrier);
8857 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8858 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8859 barrier.srcAccessMask = 0;
8860 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8861 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8862 &barrier);
8863
8864 m_errorMonitor->VerifyFound();
8865}
8866
Karl Schultz6addd812016-02-02 17:17:23 -07008867TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008868 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008869 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008870
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008872
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008873 ASSERT_NO_FATAL_FAILURE(InitState());
8874 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008875 uint32_t qfi = 0;
8876 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008877 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8878 buffCI.size = 1024;
8879 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8880 buffCI.queueFamilyIndexCount = 1;
8881 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008882
8883 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008884 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008885 ASSERT_VK_SUCCESS(err);
8886
Tony Barbour552f6c02016-12-21 14:34:07 -07008887 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008888 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008889 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8890 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008891 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008892 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008893
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008894 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008895
Chia-I Wuf7458c52015-10-26 21:10:41 +08008896 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008897}
8898
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008899TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8900 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8902 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8903 "of the indices specified when the device was created, via the "
8904 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008905
8906 ASSERT_NO_FATAL_FAILURE(InitState());
8907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8908 VkBufferCreateInfo buffCI = {};
8909 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8910 buffCI.size = 1024;
8911 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8912 buffCI.queueFamilyIndexCount = 1;
8913 // Introduce failure by specifying invalid queue_family_index
8914 uint32_t qfi = 777;
8915 buffCI.pQueueFamilyIndices = &qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008916 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008917
8918 VkBuffer ib;
8919 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8920
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008921 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008922 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008923}
8924
Karl Schultz6addd812016-02-02 17:17:23 -07008925TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008926 TEST_DESCRIPTION(
8927 "Attempt vkCmdExecuteCommands with a primary command buffer"
8928 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008929
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008930 ASSERT_NO_FATAL_FAILURE(InitState());
8931 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008932
Chris Forbesf29a84f2016-10-06 18:39:28 +13008933 // An empty primary command buffer
8934 VkCommandBufferObj cb(m_device, m_commandPool);
8935 cb.BeginCommandBuffer();
8936 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008937
Chris Forbesf29a84f2016-10-06 18:39:28 +13008938 m_commandBuffer->BeginCommandBuffer();
8939 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8940 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008941
Chris Forbesf29a84f2016-10-06 18:39:28 +13008942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8943 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008944 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008945}
8946
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008947TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008948 TEST_DESCRIPTION(
8949 "Attempt to update descriptor sets for images and buffers "
8950 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008951 VkResult err;
8952
8953 ASSERT_NO_FATAL_FAILURE(InitState());
8954 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8955 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8956 ds_type_count[i].type = VkDescriptorType(i);
8957 ds_type_count[i].descriptorCount = 1;
8958 }
8959 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8960 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8961 ds_pool_ci.pNext = NULL;
8962 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8963 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8964 ds_pool_ci.pPoolSizes = ds_type_count;
8965
8966 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008967 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008968 ASSERT_VK_SUCCESS(err);
8969
8970 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008971 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008972 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8973 dsl_binding[i].binding = 0;
8974 dsl_binding[i].descriptorType = VkDescriptorType(i);
8975 dsl_binding[i].descriptorCount = 1;
8976 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8977 dsl_binding[i].pImmutableSamplers = NULL;
8978 }
8979
8980 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8981 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8982 ds_layout_ci.pNext = NULL;
8983 ds_layout_ci.bindingCount = 1;
8984 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8985 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8986 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008987 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008988 ASSERT_VK_SUCCESS(err);
8989 }
8990 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8991 VkDescriptorSetAllocateInfo alloc_info = {};
8992 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8993 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8994 alloc_info.descriptorPool = ds_pool;
8995 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008996 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008997 ASSERT_VK_SUCCESS(err);
8998
8999 // Create a buffer & bufferView to be used for invalid updates
9000 VkBufferCreateInfo buff_ci = {};
9001 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009002 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009003 buff_ci.size = 256;
9004 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009005 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009006 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9007 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009008
9009 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9010 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9011 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9012 ASSERT_VK_SUCCESS(err);
9013
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009014 VkMemoryRequirements mem_reqs;
9015 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9016 VkMemoryAllocateInfo mem_alloc_info = {};
9017 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9018 mem_alloc_info.pNext = NULL;
9019 mem_alloc_info.memoryTypeIndex = 0;
9020 mem_alloc_info.allocationSize = mem_reqs.size;
9021 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9022 if (!pass) {
9023 vkDestroyBuffer(m_device->device(), buffer, NULL);
9024 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9025 return;
9026 }
9027 VkDeviceMemory mem;
9028 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9029 ASSERT_VK_SUCCESS(err);
9030 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9031 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009032
9033 VkBufferViewCreateInfo buff_view_ci = {};
9034 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9035 buff_view_ci.buffer = buffer;
9036 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9037 buff_view_ci.range = VK_WHOLE_SIZE;
9038 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009039 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009040 ASSERT_VK_SUCCESS(err);
9041
Tony Barbour415497c2017-01-24 10:06:09 -07009042 // Now get resources / view for storage_texel_buffer
9043 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9044 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9045 if (!pass) {
9046 vkDestroyBuffer(m_device->device(), buffer, NULL);
9047 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9048 vkFreeMemory(m_device->device(), mem, NULL);
9049 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9050 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9051 return;
9052 }
9053 VkDeviceMemory storage_texel_buffer_mem;
9054 VkBufferView storage_texel_buffer_view;
9055 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9056 ASSERT_VK_SUCCESS(err);
9057 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9058 ASSERT_VK_SUCCESS(err);
9059 buff_view_ci.buffer = storage_texel_buffer;
9060 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9061 ASSERT_VK_SUCCESS(err);
9062
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009063 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009064 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009065 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009066 image_ci.format = VK_FORMAT_UNDEFINED;
9067 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9068 VkFormat format = static_cast<VkFormat>(f);
9069 VkFormatProperties fProps = m_device->format_properties(format);
9070 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9071 image_ci.format = format;
9072 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9073 break;
9074 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9075 image_ci.format = format;
9076 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9077 break;
9078 }
9079 }
9080 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9081 return;
9082 }
9083
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009084 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9085 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009086 image_ci.extent.width = 64;
9087 image_ci.extent.height = 64;
9088 image_ci.extent.depth = 1;
9089 image_ci.mipLevels = 1;
9090 image_ci.arrayLayers = 1;
9091 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009092 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009093 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009094 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9095 VkImage image;
9096 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9097 ASSERT_VK_SUCCESS(err);
9098 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009099 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009100
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009101 VkMemoryAllocateInfo mem_alloc = {};
9102 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9103 mem_alloc.pNext = NULL;
9104 mem_alloc.allocationSize = 0;
9105 mem_alloc.memoryTypeIndex = 0;
9106 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9107 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009108 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009109 ASSERT_TRUE(pass);
9110 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9111 ASSERT_VK_SUCCESS(err);
9112 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9113 ASSERT_VK_SUCCESS(err);
9114 // Now create view for image
9115 VkImageViewCreateInfo image_view_ci = {};
9116 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9117 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009118 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009119 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9120 image_view_ci.subresourceRange.layerCount = 1;
9121 image_view_ci.subresourceRange.baseArrayLayer = 0;
9122 image_view_ci.subresourceRange.levelCount = 1;
9123 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9124 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009125 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009126 ASSERT_VK_SUCCESS(err);
9127
9128 VkDescriptorBufferInfo buff_info = {};
9129 buff_info.buffer = buffer;
9130 VkDescriptorImageInfo img_info = {};
9131 img_info.imageView = image_view;
9132 VkWriteDescriptorSet descriptor_write = {};
9133 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9134 descriptor_write.dstBinding = 0;
9135 descriptor_write.descriptorCount = 1;
9136 descriptor_write.pTexelBufferView = &buff_view;
9137 descriptor_write.pBufferInfo = &buff_info;
9138 descriptor_write.pImageInfo = &img_info;
9139
9140 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009141 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009142 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9143 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9144 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9145 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9146 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9147 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9148 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9149 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9150 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9151 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9152 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009153 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009154 // Start loop at 1 as SAMPLER desc type has no usage bit error
9155 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009156 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9157 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9158 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9159 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009160 descriptor_write.descriptorType = VkDescriptorType(i);
9161 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009163
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009164 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009165
9166 m_errorMonitor->VerifyFound();
9167 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009168 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9169 descriptor_write.pTexelBufferView = &buff_view;
9170 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009171 }
Tony Barbour415497c2017-01-24 10:06:09 -07009172
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009173 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9174 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009175 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009176 vkDestroyImageView(m_device->device(), image_view, NULL);
9177 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009178 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009179 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009180 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009181 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009182 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009183 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9184}
9185
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009186TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009187 TEST_DESCRIPTION(
9188 "Attempt to update buffer descriptor set that has incorrect "
9189 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9190 "1. offset value greater than buffer size\n"
9191 "2. range value of 0\n"
9192 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009193 VkResult err;
9194
9195 ASSERT_NO_FATAL_FAILURE(InitState());
9196 VkDescriptorPoolSize ds_type_count = {};
9197 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9198 ds_type_count.descriptorCount = 1;
9199
9200 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9201 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9202 ds_pool_ci.pNext = NULL;
9203 ds_pool_ci.maxSets = 1;
9204 ds_pool_ci.poolSizeCount = 1;
9205 ds_pool_ci.pPoolSizes = &ds_type_count;
9206
9207 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009208 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009209 ASSERT_VK_SUCCESS(err);
9210
9211 // Create layout with single uniform buffer descriptor
9212 VkDescriptorSetLayoutBinding dsl_binding = {};
9213 dsl_binding.binding = 0;
9214 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9215 dsl_binding.descriptorCount = 1;
9216 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9217 dsl_binding.pImmutableSamplers = NULL;
9218
9219 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9220 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9221 ds_layout_ci.pNext = NULL;
9222 ds_layout_ci.bindingCount = 1;
9223 ds_layout_ci.pBindings = &dsl_binding;
9224 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009225 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009226 ASSERT_VK_SUCCESS(err);
9227
9228 VkDescriptorSet descriptor_set = {};
9229 VkDescriptorSetAllocateInfo alloc_info = {};
9230 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9231 alloc_info.descriptorSetCount = 1;
9232 alloc_info.descriptorPool = ds_pool;
9233 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009234 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009235 ASSERT_VK_SUCCESS(err);
9236
9237 // Create a buffer to be used for invalid updates
9238 VkBufferCreateInfo buff_ci = {};
9239 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9240 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9241 buff_ci.size = 256;
9242 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9243 VkBuffer buffer;
9244 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9245 ASSERT_VK_SUCCESS(err);
9246 // Have to bind memory to buffer before descriptor update
9247 VkMemoryAllocateInfo mem_alloc = {};
9248 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9249 mem_alloc.pNext = NULL;
9250 mem_alloc.allocationSize = 256;
9251 mem_alloc.memoryTypeIndex = 0;
9252
9253 VkMemoryRequirements mem_reqs;
9254 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009255 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009256 if (!pass) {
9257 vkDestroyBuffer(m_device->device(), buffer, NULL);
9258 return;
9259 }
9260
9261 VkDeviceMemory mem;
9262 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9263 ASSERT_VK_SUCCESS(err);
9264 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9265 ASSERT_VK_SUCCESS(err);
9266
9267 VkDescriptorBufferInfo buff_info = {};
9268 buff_info.buffer = buffer;
9269 // First make offset 1 larger than buffer size
9270 buff_info.offset = 257;
9271 buff_info.range = VK_WHOLE_SIZE;
9272 VkWriteDescriptorSet descriptor_write = {};
9273 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9274 descriptor_write.dstBinding = 0;
9275 descriptor_write.descriptorCount = 1;
9276 descriptor_write.pTexelBufferView = nullptr;
9277 descriptor_write.pBufferInfo = &buff_info;
9278 descriptor_write.pImageInfo = nullptr;
9279
9280 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9281 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009283
9284 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9285
9286 m_errorMonitor->VerifyFound();
9287 // Now cause error due to range of 0
9288 buff_info.offset = 0;
9289 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009291
9292 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9293
9294 m_errorMonitor->VerifyFound();
9295 // Now cause error due to range exceeding buffer size - offset
9296 buff_info.offset = 128;
9297 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009299
9300 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9301
9302 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009303 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009304 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9305 vkDestroyBuffer(m_device->device(), buffer, NULL);
9306 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9307 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9308}
9309
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009310TEST_F(VkLayerTest, DSAspectBitsErrors) {
9311 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9312 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009313 TEST_DESCRIPTION(
9314 "Attempt to update descriptor sets for images "
9315 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009316 VkResult err;
9317
9318 ASSERT_NO_FATAL_FAILURE(InitState());
9319 VkDescriptorPoolSize ds_type_count = {};
9320 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9321 ds_type_count.descriptorCount = 1;
9322
9323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9325 ds_pool_ci.pNext = NULL;
9326 ds_pool_ci.maxSets = 5;
9327 ds_pool_ci.poolSizeCount = 1;
9328 ds_pool_ci.pPoolSizes = &ds_type_count;
9329
9330 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009331 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009332 ASSERT_VK_SUCCESS(err);
9333
9334 VkDescriptorSetLayoutBinding dsl_binding = {};
9335 dsl_binding.binding = 0;
9336 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9337 dsl_binding.descriptorCount = 1;
9338 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9339 dsl_binding.pImmutableSamplers = NULL;
9340
9341 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9342 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9343 ds_layout_ci.pNext = NULL;
9344 ds_layout_ci.bindingCount = 1;
9345 ds_layout_ci.pBindings = &dsl_binding;
9346 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009347 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009348 ASSERT_VK_SUCCESS(err);
9349
9350 VkDescriptorSet descriptor_set = {};
9351 VkDescriptorSetAllocateInfo alloc_info = {};
9352 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9353 alloc_info.descriptorSetCount = 1;
9354 alloc_info.descriptorPool = ds_pool;
9355 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009356 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009357 ASSERT_VK_SUCCESS(err);
9358
9359 // Create an image to be used for invalid updates
9360 VkImageCreateInfo image_ci = {};
9361 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9362 image_ci.imageType = VK_IMAGE_TYPE_2D;
9363 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9364 image_ci.extent.width = 64;
9365 image_ci.extent.height = 64;
9366 image_ci.extent.depth = 1;
9367 image_ci.mipLevels = 1;
9368 image_ci.arrayLayers = 1;
9369 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9370 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9371 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9372 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9373 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9374 VkImage image;
9375 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9376 ASSERT_VK_SUCCESS(err);
9377 // Bind memory to image
9378 VkMemoryRequirements mem_reqs;
9379 VkDeviceMemory image_mem;
9380 bool pass;
9381 VkMemoryAllocateInfo mem_alloc = {};
9382 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9383 mem_alloc.pNext = NULL;
9384 mem_alloc.allocationSize = 0;
9385 mem_alloc.memoryTypeIndex = 0;
9386 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9387 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009388 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009389 ASSERT_TRUE(pass);
9390 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9391 ASSERT_VK_SUCCESS(err);
9392 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9393 ASSERT_VK_SUCCESS(err);
9394 // Now create view for image
9395 VkImageViewCreateInfo image_view_ci = {};
9396 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9397 image_view_ci.image = image;
9398 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9399 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9400 image_view_ci.subresourceRange.layerCount = 1;
9401 image_view_ci.subresourceRange.baseArrayLayer = 0;
9402 image_view_ci.subresourceRange.levelCount = 1;
9403 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009404 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009405
9406 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009407 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009408 ASSERT_VK_SUCCESS(err);
9409
9410 VkDescriptorImageInfo img_info = {};
9411 img_info.imageView = image_view;
9412 VkWriteDescriptorSet descriptor_write = {};
9413 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9414 descriptor_write.dstBinding = 0;
9415 descriptor_write.descriptorCount = 1;
9416 descriptor_write.pTexelBufferView = NULL;
9417 descriptor_write.pBufferInfo = NULL;
9418 descriptor_write.pImageInfo = &img_info;
9419 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9420 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009421 const char *error_msg =
9422 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9423 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009425
9426 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9427
9428 m_errorMonitor->VerifyFound();
9429 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9430 vkDestroyImage(m_device->device(), image, NULL);
9431 vkFreeMemory(m_device->device(), image_mem, NULL);
9432 vkDestroyImageView(m_device->device(), image_view, NULL);
9433 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9434 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9435}
9436
Karl Schultz6addd812016-02-02 17:17:23 -07009437TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009438 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009439 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009440
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9442 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9443 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009444
Tobin Ehlis3b780662015-05-28 12:11:26 -06009445 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009446 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009447 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009448 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9449 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009450
9451 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009452 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9453 ds_pool_ci.pNext = NULL;
9454 ds_pool_ci.maxSets = 1;
9455 ds_pool_ci.poolSizeCount = 1;
9456 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009457
Tobin Ehlis3b780662015-05-28 12:11:26 -06009458 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009459 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009460 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009461 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009462 dsl_binding.binding = 0;
9463 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9464 dsl_binding.descriptorCount = 1;
9465 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9466 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009467
Tony Barboureb254902015-07-15 12:50:33 -06009468 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009469 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9470 ds_layout_ci.pNext = NULL;
9471 ds_layout_ci.bindingCount = 1;
9472 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009473
Tobin Ehlis3b780662015-05-28 12:11:26 -06009474 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009475 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009476 ASSERT_VK_SUCCESS(err);
9477
9478 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009479 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009480 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009481 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009482 alloc_info.descriptorPool = ds_pool;
9483 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009484 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009485 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009486
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009487 VkSamplerCreateInfo sampler_ci = {};
9488 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9489 sampler_ci.pNext = NULL;
9490 sampler_ci.magFilter = VK_FILTER_NEAREST;
9491 sampler_ci.minFilter = VK_FILTER_NEAREST;
9492 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9493 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9494 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9495 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9496 sampler_ci.mipLodBias = 1.0;
9497 sampler_ci.anisotropyEnable = VK_FALSE;
9498 sampler_ci.maxAnisotropy = 1;
9499 sampler_ci.compareEnable = VK_FALSE;
9500 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9501 sampler_ci.minLod = 1.0;
9502 sampler_ci.maxLod = 1.0;
9503 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9504 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9505 VkSampler sampler;
9506 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9507 ASSERT_VK_SUCCESS(err);
9508
9509 VkDescriptorImageInfo info = {};
9510 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009511
9512 VkWriteDescriptorSet descriptor_write;
9513 memset(&descriptor_write, 0, sizeof(descriptor_write));
9514 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009515 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009516 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009517 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009518 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009519 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009520
9521 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9522
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009523 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009524
Chia-I Wuf7458c52015-10-26 21:10:41 +08009525 vkDestroySampler(m_device->device(), sampler, NULL);
9526 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9527 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009528}
9529
Karl Schultz6addd812016-02-02 17:17:23 -07009530TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009531 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009532 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009533
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009535
Tobin Ehlis3b780662015-05-28 12:11:26 -06009536 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009537 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009538 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009539 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9540 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009541
9542 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009543 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9544 ds_pool_ci.pNext = NULL;
9545 ds_pool_ci.maxSets = 1;
9546 ds_pool_ci.poolSizeCount = 1;
9547 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009548
Tobin Ehlis3b780662015-05-28 12:11:26 -06009549 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009550 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009551 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009552
Tony Barboureb254902015-07-15 12:50:33 -06009553 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009554 dsl_binding.binding = 0;
9555 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9556 dsl_binding.descriptorCount = 1;
9557 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9558 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009559
9560 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009561 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9562 ds_layout_ci.pNext = NULL;
9563 ds_layout_ci.bindingCount = 1;
9564 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009565
Tobin Ehlis3b780662015-05-28 12:11:26 -06009566 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009567 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009568 ASSERT_VK_SUCCESS(err);
9569
9570 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009571 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009572 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009573 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009574 alloc_info.descriptorPool = ds_pool;
9575 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009576 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009577 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009578
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009579 // Correctly update descriptor to avoid "NOT_UPDATED" error
9580 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009581 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009582 buff_info.offset = 0;
9583 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009584
9585 VkWriteDescriptorSet descriptor_write;
9586 memset(&descriptor_write, 0, sizeof(descriptor_write));
9587 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009588 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009589 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009590 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009591 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9592 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009593
9594 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9595
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009596 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009597
Chia-I Wuf7458c52015-10-26 21:10:41 +08009598 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9599 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009600}
9601
Karl Schultz6addd812016-02-02 17:17:23 -07009602TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009603 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009604 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009605
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009607
Tobin Ehlis3b780662015-05-28 12:11:26 -06009608 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009609 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009610 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009611 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9612 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009613
9614 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009615 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9616 ds_pool_ci.pNext = NULL;
9617 ds_pool_ci.maxSets = 1;
9618 ds_pool_ci.poolSizeCount = 1;
9619 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009620
Tobin Ehlis3b780662015-05-28 12:11:26 -06009621 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009622 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
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 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009626 dsl_binding.binding = 0;
9627 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9628 dsl_binding.descriptorCount = 1;
9629 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9630 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009631
9632 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009633 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9634 ds_layout_ci.pNext = NULL;
9635 ds_layout_ci.bindingCount = 1;
9636 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009637 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009638 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009639 ASSERT_VK_SUCCESS(err);
9640
9641 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009642 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009643 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009644 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009645 alloc_info.descriptorPool = ds_pool;
9646 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009647 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009648 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009649
Tony Barboureb254902015-07-15 12:50:33 -06009650 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009651 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9652 sampler_ci.pNext = NULL;
9653 sampler_ci.magFilter = VK_FILTER_NEAREST;
9654 sampler_ci.minFilter = VK_FILTER_NEAREST;
9655 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9656 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9657 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9658 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9659 sampler_ci.mipLodBias = 1.0;
9660 sampler_ci.anisotropyEnable = VK_FALSE;
9661 sampler_ci.maxAnisotropy = 1;
9662 sampler_ci.compareEnable = VK_FALSE;
9663 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9664 sampler_ci.minLod = 1.0;
9665 sampler_ci.maxLod = 1.0;
9666 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9667 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009668
Tobin Ehlis3b780662015-05-28 12:11:26 -06009669 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009670 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009671 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009672
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009673 VkDescriptorImageInfo info = {};
9674 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009675
9676 VkWriteDescriptorSet descriptor_write;
9677 memset(&descriptor_write, 0, sizeof(descriptor_write));
9678 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009679 descriptor_write.dstSet = descriptorSet;
9680 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009681 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009682 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009683 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009684 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009685
9686 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9687
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009688 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009689
Chia-I Wuf7458c52015-10-26 21:10:41 +08009690 vkDestroySampler(m_device->device(), sampler, NULL);
9691 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9692 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009693}
9694
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009695TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9696 // Create layout w/ empty binding and attempt to update it
9697 VkResult err;
9698
9699 ASSERT_NO_FATAL_FAILURE(InitState());
9700
9701 VkDescriptorPoolSize ds_type_count = {};
9702 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9703 ds_type_count.descriptorCount = 1;
9704
9705 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9706 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9707 ds_pool_ci.pNext = NULL;
9708 ds_pool_ci.maxSets = 1;
9709 ds_pool_ci.poolSizeCount = 1;
9710 ds_pool_ci.pPoolSizes = &ds_type_count;
9711
9712 VkDescriptorPool ds_pool;
9713 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9714 ASSERT_VK_SUCCESS(err);
9715
9716 VkDescriptorSetLayoutBinding dsl_binding = {};
9717 dsl_binding.binding = 0;
9718 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9719 dsl_binding.descriptorCount = 0;
9720 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9721 dsl_binding.pImmutableSamplers = NULL;
9722
9723 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9724 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9725 ds_layout_ci.pNext = NULL;
9726 ds_layout_ci.bindingCount = 1;
9727 ds_layout_ci.pBindings = &dsl_binding;
9728 VkDescriptorSetLayout ds_layout;
9729 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9730 ASSERT_VK_SUCCESS(err);
9731
9732 VkDescriptorSet descriptor_set;
9733 VkDescriptorSetAllocateInfo alloc_info = {};
9734 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9735 alloc_info.descriptorSetCount = 1;
9736 alloc_info.descriptorPool = ds_pool;
9737 alloc_info.pSetLayouts = &ds_layout;
9738 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9739 ASSERT_VK_SUCCESS(err);
9740
9741 VkSamplerCreateInfo sampler_ci = {};
9742 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9743 sampler_ci.magFilter = VK_FILTER_NEAREST;
9744 sampler_ci.minFilter = VK_FILTER_NEAREST;
9745 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9746 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9747 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9748 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9749 sampler_ci.mipLodBias = 1.0;
9750 sampler_ci.maxAnisotropy = 1;
9751 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9752 sampler_ci.minLod = 1.0;
9753 sampler_ci.maxLod = 1.0;
9754 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9755
9756 VkSampler sampler;
9757 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9758 ASSERT_VK_SUCCESS(err);
9759
9760 VkDescriptorImageInfo info = {};
9761 info.sampler = sampler;
9762
9763 VkWriteDescriptorSet descriptor_write;
9764 memset(&descriptor_write, 0, sizeof(descriptor_write));
9765 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9766 descriptor_write.dstSet = descriptor_set;
9767 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009768 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009769 // This is the wrong type, but empty binding error will be flagged first
9770 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9771 descriptor_write.pImageInfo = &info;
9772
9773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9774 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9775 m_errorMonitor->VerifyFound();
9776
9777 vkDestroySampler(m_device->device(), sampler, NULL);
9778 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9779 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9780}
9781
Karl Schultz6addd812016-02-02 17:17:23 -07009782TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9783 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9784 // types
9785 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009786
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009787 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 -06009788
Tobin Ehlis3b780662015-05-28 12:11:26 -06009789 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009790
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009791 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009792 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9793 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009794
9795 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009796 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9797 ds_pool_ci.pNext = NULL;
9798 ds_pool_ci.maxSets = 1;
9799 ds_pool_ci.poolSizeCount = 1;
9800 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009801
Tobin Ehlis3b780662015-05-28 12:11:26 -06009802 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009803 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009804 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009805 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009806 dsl_binding.binding = 0;
9807 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9808 dsl_binding.descriptorCount = 1;
9809 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9810 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009811
Tony Barboureb254902015-07-15 12:50:33 -06009812 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009813 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9814 ds_layout_ci.pNext = NULL;
9815 ds_layout_ci.bindingCount = 1;
9816 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009817
Tobin Ehlis3b780662015-05-28 12:11:26 -06009818 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009819 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009820 ASSERT_VK_SUCCESS(err);
9821
9822 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009823 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009824 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009825 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009826 alloc_info.descriptorPool = ds_pool;
9827 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009828 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009829 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009830
Tony Barboureb254902015-07-15 12:50:33 -06009831 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009832 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9833 sampler_ci.pNext = NULL;
9834 sampler_ci.magFilter = VK_FILTER_NEAREST;
9835 sampler_ci.minFilter = VK_FILTER_NEAREST;
9836 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9837 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9838 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9839 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9840 sampler_ci.mipLodBias = 1.0;
9841 sampler_ci.anisotropyEnable = VK_FALSE;
9842 sampler_ci.maxAnisotropy = 1;
9843 sampler_ci.compareEnable = VK_FALSE;
9844 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9845 sampler_ci.minLod = 1.0;
9846 sampler_ci.maxLod = 1.0;
9847 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9848 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009849 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009850 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009851 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009852
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009853 VkDescriptorImageInfo info = {};
9854 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009855
9856 VkWriteDescriptorSet descriptor_write;
9857 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009858 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009859 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009860 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009861 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009862 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009863 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009864
9865 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9866
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009867 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009868
Chia-I Wuf7458c52015-10-26 21:10:41 +08009869 vkDestroySampler(m_device->device(), sampler, NULL);
9870 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9871 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009872}
9873
Karl Schultz6addd812016-02-02 17:17:23 -07009874TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009875 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009876 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009877
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009879
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009880 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009881 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9882 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009883 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009884 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9885 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009886
9887 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009888 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9889 ds_pool_ci.pNext = NULL;
9890 ds_pool_ci.maxSets = 1;
9891 ds_pool_ci.poolSizeCount = 1;
9892 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009893
9894 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009896 ASSERT_VK_SUCCESS(err);
9897
9898 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009899 dsl_binding.binding = 0;
9900 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9901 dsl_binding.descriptorCount = 1;
9902 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9903 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009904
9905 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009906 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9907 ds_layout_ci.pNext = NULL;
9908 ds_layout_ci.bindingCount = 1;
9909 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009910 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009911 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009912 ASSERT_VK_SUCCESS(err);
9913
9914 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009915 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009916 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009917 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009918 alloc_info.descriptorPool = ds_pool;
9919 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009920 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009921 ASSERT_VK_SUCCESS(err);
9922
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009923 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009924
9925 VkDescriptorImageInfo descriptor_info;
9926 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9927 descriptor_info.sampler = sampler;
9928
9929 VkWriteDescriptorSet descriptor_write;
9930 memset(&descriptor_write, 0, sizeof(descriptor_write));
9931 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009932 descriptor_write.dstSet = descriptorSet;
9933 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009934 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009935 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9936 descriptor_write.pImageInfo = &descriptor_info;
9937
9938 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9939
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009940 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009941
Chia-I Wuf7458c52015-10-26 21:10:41 +08009942 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9943 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009944}
9945
Karl Schultz6addd812016-02-02 17:17:23 -07009946TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9947 // Create a single combined Image/Sampler descriptor and send it an invalid
9948 // imageView
9949 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009950
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009952
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009953 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009954 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009955 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9956 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009957
9958 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009959 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9960 ds_pool_ci.pNext = NULL;
9961 ds_pool_ci.maxSets = 1;
9962 ds_pool_ci.poolSizeCount = 1;
9963 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009964
9965 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009966 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009967 ASSERT_VK_SUCCESS(err);
9968
9969 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009970 dsl_binding.binding = 0;
9971 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9972 dsl_binding.descriptorCount = 1;
9973 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9974 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009975
9976 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009977 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9978 ds_layout_ci.pNext = NULL;
9979 ds_layout_ci.bindingCount = 1;
9980 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009981 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009982 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009983 ASSERT_VK_SUCCESS(err);
9984
9985 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009986 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009987 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009988 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009989 alloc_info.descriptorPool = ds_pool;
9990 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009991 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009992 ASSERT_VK_SUCCESS(err);
9993
9994 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009995 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9996 sampler_ci.pNext = NULL;
9997 sampler_ci.magFilter = VK_FILTER_NEAREST;
9998 sampler_ci.minFilter = VK_FILTER_NEAREST;
9999 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10000 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10001 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10002 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10003 sampler_ci.mipLodBias = 1.0;
10004 sampler_ci.anisotropyEnable = VK_FALSE;
10005 sampler_ci.maxAnisotropy = 1;
10006 sampler_ci.compareEnable = VK_FALSE;
10007 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10008 sampler_ci.minLod = 1.0;
10009 sampler_ci.maxLod = 1.0;
10010 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10011 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010012
10013 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010014 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010015 ASSERT_VK_SUCCESS(err);
10016
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010017 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010018
10019 VkDescriptorImageInfo descriptor_info;
10020 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10021 descriptor_info.sampler = sampler;
10022 descriptor_info.imageView = view;
10023
10024 VkWriteDescriptorSet descriptor_write;
10025 memset(&descriptor_write, 0, sizeof(descriptor_write));
10026 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010027 descriptor_write.dstSet = descriptorSet;
10028 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010029 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010030 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10031 descriptor_write.pImageInfo = &descriptor_info;
10032
10033 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10034
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010035 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010036
Chia-I Wuf7458c52015-10-26 21:10:41 +080010037 vkDestroySampler(m_device->device(), sampler, NULL);
10038 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10039 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010040}
10041
Karl Schultz6addd812016-02-02 17:17:23 -070010042TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10043 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10044 // into the other
10045 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010046
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10048 " binding #1 with type "
10049 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10050 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010051
Tobin Ehlis04356f92015-10-27 16:35:27 -060010052 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010053 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010054 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010055 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10056 ds_type_count[0].descriptorCount = 1;
10057 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10058 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010059
10060 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010061 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10062 ds_pool_ci.pNext = NULL;
10063 ds_pool_ci.maxSets = 1;
10064 ds_pool_ci.poolSizeCount = 2;
10065 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010066
10067 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010068 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010069 ASSERT_VK_SUCCESS(err);
10070 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010071 dsl_binding[0].binding = 0;
10072 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10073 dsl_binding[0].descriptorCount = 1;
10074 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10075 dsl_binding[0].pImmutableSamplers = NULL;
10076 dsl_binding[1].binding = 1;
10077 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10078 dsl_binding[1].descriptorCount = 1;
10079 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10080 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010081
10082 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010083 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10084 ds_layout_ci.pNext = NULL;
10085 ds_layout_ci.bindingCount = 2;
10086 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010087
10088 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010089 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010090 ASSERT_VK_SUCCESS(err);
10091
10092 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010093 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010094 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010095 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010096 alloc_info.descriptorPool = ds_pool;
10097 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010098 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010099 ASSERT_VK_SUCCESS(err);
10100
10101 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010102 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10103 sampler_ci.pNext = NULL;
10104 sampler_ci.magFilter = VK_FILTER_NEAREST;
10105 sampler_ci.minFilter = VK_FILTER_NEAREST;
10106 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10107 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10108 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10109 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10110 sampler_ci.mipLodBias = 1.0;
10111 sampler_ci.anisotropyEnable = VK_FALSE;
10112 sampler_ci.maxAnisotropy = 1;
10113 sampler_ci.compareEnable = VK_FALSE;
10114 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10115 sampler_ci.minLod = 1.0;
10116 sampler_ci.maxLod = 1.0;
10117 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10118 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010119
10120 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010121 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010122 ASSERT_VK_SUCCESS(err);
10123
10124 VkDescriptorImageInfo info = {};
10125 info.sampler = sampler;
10126
10127 VkWriteDescriptorSet descriptor_write;
10128 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10129 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010130 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010131 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010132 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010133 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10134 descriptor_write.pImageInfo = &info;
10135 // This write update should succeed
10136 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10137 // Now perform a copy update that fails due to type mismatch
10138 VkCopyDescriptorSet copy_ds_update;
10139 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10140 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10141 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010142 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010143 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010144 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10145 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010146 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10147
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010148 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010149 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010150 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 -060010151 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10152 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10153 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010154 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010155 copy_ds_update.dstSet = descriptorSet;
10156 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010157 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010158 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10159
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010160 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010161
Tobin Ehlis04356f92015-10-27 16:35:27 -060010162 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10164 " binding#1 with offset index of 1 plus "
10165 "update array offset of 0 and update of "
10166 "5 descriptors oversteps total number "
10167 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010168
Tobin Ehlis04356f92015-10-27 16:35:27 -060010169 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10170 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10171 copy_ds_update.srcSet = descriptorSet;
10172 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010173 copy_ds_update.dstSet = descriptorSet;
10174 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010175 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010176 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10177
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010178 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010179
Chia-I Wuf7458c52015-10-26 21:10:41 +080010180 vkDestroySampler(m_device->device(), sampler, NULL);
10181 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10182 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010183}
10184
Karl Schultz6addd812016-02-02 17:17:23 -070010185TEST_F(VkLayerTest, NumSamplesMismatch) {
10186 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10187 // sampleCount
10188 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010189
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010191
Tobin Ehlis3b780662015-05-28 12:11:26 -060010192 ASSERT_NO_FATAL_FAILURE(InitState());
10193 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010194 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010195 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010196 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010197
10198 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010199 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10200 ds_pool_ci.pNext = NULL;
10201 ds_pool_ci.maxSets = 1;
10202 ds_pool_ci.poolSizeCount = 1;
10203 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010204
Tobin Ehlis3b780662015-05-28 12:11:26 -060010205 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010206 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010207 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010208
Tony Barboureb254902015-07-15 12:50:33 -060010209 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010210 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010211 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010212 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010213 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10214 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010215
Tony Barboureb254902015-07-15 12:50:33 -060010216 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10217 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10218 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010219 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010220 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010221
Tobin Ehlis3b780662015-05-28 12:11:26 -060010222 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010223 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010224 ASSERT_VK_SUCCESS(err);
10225
10226 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010227 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010228 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010229 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010230 alloc_info.descriptorPool = ds_pool;
10231 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010232 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010233 ASSERT_VK_SUCCESS(err);
10234
Tony Barboureb254902015-07-15 12:50:33 -060010235 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010236 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010237 pipe_ms_state_ci.pNext = NULL;
10238 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10239 pipe_ms_state_ci.sampleShadingEnable = 0;
10240 pipe_ms_state_ci.minSampleShading = 1.0;
10241 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010242
Tony Barboureb254902015-07-15 12:50:33 -060010243 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010244 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10245 pipeline_layout_ci.pNext = NULL;
10246 pipeline_layout_ci.setLayoutCount = 1;
10247 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010248
10249 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010250 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010251 ASSERT_VK_SUCCESS(err);
10252
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010253 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010254 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 -060010255 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010256 VkPipelineObj pipe(m_device);
10257 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010258 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010259 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010260 pipe.SetMSAA(&pipe_ms_state_ci);
10261 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010262
Tony Barbour552f6c02016-12-21 14:34:07 -070010263 m_commandBuffer->BeginCommandBuffer();
10264 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010265 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010266
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010267 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10268 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10269 VkRect2D scissor = {{0, 0}, {16, 16}};
10270 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10271
Mark Young29927482016-05-04 14:38:51 -060010272 // Render triangle (the error should trigger on the attempt to draw).
10273 Draw(3, 1, 0, 0);
10274
10275 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010276 m_commandBuffer->EndRenderPass();
10277 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010278
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010279 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010280
Chia-I Wuf7458c52015-10-26 21:10:41 +080010281 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10282 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10283 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010284}
Mark Young29927482016-05-04 14:38:51 -060010285
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010286TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010287 TEST_DESCRIPTION(
10288 "Hit RenderPass incompatible cases. "
10289 "Initial case is drawing with an active renderpass that's "
10290 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010291 VkResult err;
10292
10293 ASSERT_NO_FATAL_FAILURE(InitState());
10294 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10295
10296 VkDescriptorSetLayoutBinding dsl_binding = {};
10297 dsl_binding.binding = 0;
10298 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10299 dsl_binding.descriptorCount = 1;
10300 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10301 dsl_binding.pImmutableSamplers = NULL;
10302
10303 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10304 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10305 ds_layout_ci.pNext = NULL;
10306 ds_layout_ci.bindingCount = 1;
10307 ds_layout_ci.pBindings = &dsl_binding;
10308
10309 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010310 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010311 ASSERT_VK_SUCCESS(err);
10312
10313 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10314 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10315 pipeline_layout_ci.pNext = NULL;
10316 pipeline_layout_ci.setLayoutCount = 1;
10317 pipeline_layout_ci.pSetLayouts = &ds_layout;
10318
10319 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010320 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010321 ASSERT_VK_SUCCESS(err);
10322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010323 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010324 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 -060010325 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010326 // Create a renderpass that will be incompatible with default renderpass
10327 VkAttachmentReference attach = {};
10328 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10329 VkAttachmentReference color_att = {};
10330 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10331 VkSubpassDescription subpass = {};
10332 subpass.inputAttachmentCount = 1;
10333 subpass.pInputAttachments = &attach;
10334 subpass.colorAttachmentCount = 1;
10335 subpass.pColorAttachments = &color_att;
10336 VkRenderPassCreateInfo rpci = {};
10337 rpci.subpassCount = 1;
10338 rpci.pSubpasses = &subpass;
10339 rpci.attachmentCount = 1;
10340 VkAttachmentDescription attach_desc = {};
10341 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010342 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10343 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010344 rpci.pAttachments = &attach_desc;
10345 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10346 VkRenderPass rp;
10347 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10348 VkPipelineObj pipe(m_device);
10349 pipe.AddShader(&vs);
10350 pipe.AddShader(&fs);
10351 pipe.AddColorAttachment();
10352 VkViewport view_port = {};
10353 m_viewports.push_back(view_port);
10354 pipe.SetViewport(m_viewports);
10355 VkRect2D rect = {};
10356 m_scissors.push_back(rect);
10357 pipe.SetScissor(m_scissors);
10358 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10359
10360 VkCommandBufferInheritanceInfo cbii = {};
10361 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10362 cbii.renderPass = rp;
10363 cbii.subpass = 0;
10364 VkCommandBufferBeginInfo cbbi = {};
10365 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10366 cbbi.pInheritanceInfo = &cbii;
10367 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10368 VkRenderPassBeginInfo rpbi = {};
10369 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10370 rpbi.framebuffer = m_framebuffer;
10371 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010372 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10373 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010376 // Render triangle (the error should trigger on the attempt to draw).
10377 Draw(3, 1, 0, 0);
10378
10379 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010380 m_commandBuffer->EndRenderPass();
10381 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010382
10383 m_errorMonitor->VerifyFound();
10384
10385 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10386 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10387 vkDestroyRenderPass(m_device->device(), rp, NULL);
10388}
10389
Mark Youngc89c6312016-03-31 16:03:20 -060010390TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10391 // Create Pipeline where the number of blend attachments doesn't match the
10392 // number of color attachments. In this case, we don't add any color
10393 // blend attachments even though we have a color attachment.
10394 VkResult err;
10395
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010397
10398 ASSERT_NO_FATAL_FAILURE(InitState());
10399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10400 VkDescriptorPoolSize ds_type_count = {};
10401 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10402 ds_type_count.descriptorCount = 1;
10403
10404 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10405 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10406 ds_pool_ci.pNext = NULL;
10407 ds_pool_ci.maxSets = 1;
10408 ds_pool_ci.poolSizeCount = 1;
10409 ds_pool_ci.pPoolSizes = &ds_type_count;
10410
10411 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010412 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010413 ASSERT_VK_SUCCESS(err);
10414
10415 VkDescriptorSetLayoutBinding dsl_binding = {};
10416 dsl_binding.binding = 0;
10417 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10418 dsl_binding.descriptorCount = 1;
10419 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10420 dsl_binding.pImmutableSamplers = NULL;
10421
10422 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10423 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10424 ds_layout_ci.pNext = NULL;
10425 ds_layout_ci.bindingCount = 1;
10426 ds_layout_ci.pBindings = &dsl_binding;
10427
10428 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010429 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010430 ASSERT_VK_SUCCESS(err);
10431
10432 VkDescriptorSet descriptorSet;
10433 VkDescriptorSetAllocateInfo alloc_info = {};
10434 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10435 alloc_info.descriptorSetCount = 1;
10436 alloc_info.descriptorPool = ds_pool;
10437 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010438 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010439 ASSERT_VK_SUCCESS(err);
10440
10441 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010442 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010443 pipe_ms_state_ci.pNext = NULL;
10444 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10445 pipe_ms_state_ci.sampleShadingEnable = 0;
10446 pipe_ms_state_ci.minSampleShading = 1.0;
10447 pipe_ms_state_ci.pSampleMask = NULL;
10448
10449 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10450 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10451 pipeline_layout_ci.pNext = NULL;
10452 pipeline_layout_ci.setLayoutCount = 1;
10453 pipeline_layout_ci.pSetLayouts = &ds_layout;
10454
10455 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010456 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010457 ASSERT_VK_SUCCESS(err);
10458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010459 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010460 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 -060010461 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010462 VkPipelineObj pipe(m_device);
10463 pipe.AddShader(&vs);
10464 pipe.AddShader(&fs);
10465 pipe.SetMSAA(&pipe_ms_state_ci);
10466 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010467 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010468
10469 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10470 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10471 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10472}
Mark Young29927482016-05-04 14:38:51 -060010473
Mark Muellerd4914412016-06-13 17:52:06 -060010474TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010475 TEST_DESCRIPTION(
10476 "Points to a wrong colorAttachment index in a VkClearAttachment "
10477 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010478 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010480
10481 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10482 m_errorMonitor->VerifyFound();
10483}
10484
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010485TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010486 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10487 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010488
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010489 ASSERT_NO_FATAL_FAILURE(InitState());
10490 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010491
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010492 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010493 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10494 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010495
10496 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010497 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10498 ds_pool_ci.pNext = NULL;
10499 ds_pool_ci.maxSets = 1;
10500 ds_pool_ci.poolSizeCount = 1;
10501 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010502
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010503 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010504 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010505 ASSERT_VK_SUCCESS(err);
10506
Tony Barboureb254902015-07-15 12:50:33 -060010507 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010508 dsl_binding.binding = 0;
10509 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10510 dsl_binding.descriptorCount = 1;
10511 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10512 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010513
Tony Barboureb254902015-07-15 12:50:33 -060010514 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010515 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10516 ds_layout_ci.pNext = NULL;
10517 ds_layout_ci.bindingCount = 1;
10518 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010519
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010520 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010521 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010522 ASSERT_VK_SUCCESS(err);
10523
10524 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010525 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010526 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010527 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010528 alloc_info.descriptorPool = ds_pool;
10529 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010530 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010531 ASSERT_VK_SUCCESS(err);
10532
Tony Barboureb254902015-07-15 12:50:33 -060010533 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010534 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010535 pipe_ms_state_ci.pNext = NULL;
10536 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10537 pipe_ms_state_ci.sampleShadingEnable = 0;
10538 pipe_ms_state_ci.minSampleShading = 1.0;
10539 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010540
Tony Barboureb254902015-07-15 12:50:33 -060010541 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010542 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10543 pipeline_layout_ci.pNext = NULL;
10544 pipeline_layout_ci.setLayoutCount = 1;
10545 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010546
10547 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010548 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010549 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010550
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010551 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010552 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010553 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010554 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010555
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010556 VkPipelineObj pipe(m_device);
10557 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010558 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010559 pipe.SetMSAA(&pipe_ms_state_ci);
10560 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010561
Tony Barbour552f6c02016-12-21 14:34:07 -070010562 m_commandBuffer->BeginCommandBuffer();
10563 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010564
Karl Schultz6addd812016-02-02 17:17:23 -070010565 // Main thing we care about for this test is that the VkImage obj we're
10566 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010567 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010568 VkClearAttachment color_attachment;
10569 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10570 color_attachment.clearValue.color.float32[0] = 1.0;
10571 color_attachment.clearValue.color.float32[1] = 1.0;
10572 color_attachment.clearValue.color.float32[2] = 1.0;
10573 color_attachment.clearValue.color.float32[3] = 1.0;
10574 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010575 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010576
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010577 // Call for full-sized FB Color attachment prior to issuing a Draw
10578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070010579 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010580 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010581 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010582
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010583 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
10584 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
10585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
10586 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
10587 m_errorMonitor->VerifyFound();
10588
10589 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
10590 clear_rect.layerCount = 2;
10591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
10592 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010593 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010594
Chia-I Wuf7458c52015-10-26 21:10:41 +080010595 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10596 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10597 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010598}
10599
Karl Schultz6addd812016-02-02 17:17:23 -070010600TEST_F(VkLayerTest, VtxBufferBadIndex) {
10601 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010602
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10604 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010605
Tobin Ehlis502480b2015-06-24 15:53:07 -060010606 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010607 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010608 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010609
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010610 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010611 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10612 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010613
10614 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010615 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10616 ds_pool_ci.pNext = NULL;
10617 ds_pool_ci.maxSets = 1;
10618 ds_pool_ci.poolSizeCount = 1;
10619 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010620
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010621 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010622 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010623 ASSERT_VK_SUCCESS(err);
10624
Tony Barboureb254902015-07-15 12:50:33 -060010625 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010626 dsl_binding.binding = 0;
10627 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10628 dsl_binding.descriptorCount = 1;
10629 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10630 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010631
Tony Barboureb254902015-07-15 12:50:33 -060010632 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010633 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10634 ds_layout_ci.pNext = NULL;
10635 ds_layout_ci.bindingCount = 1;
10636 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010637
Tobin Ehlis502480b2015-06-24 15:53:07 -060010638 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010639 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010640 ASSERT_VK_SUCCESS(err);
10641
10642 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010643 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010644 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010645 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010646 alloc_info.descriptorPool = ds_pool;
10647 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010648 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010649 ASSERT_VK_SUCCESS(err);
10650
Tony Barboureb254902015-07-15 12:50:33 -060010651 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010652 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010653 pipe_ms_state_ci.pNext = NULL;
10654 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10655 pipe_ms_state_ci.sampleShadingEnable = 0;
10656 pipe_ms_state_ci.minSampleShading = 1.0;
10657 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010658
Tony Barboureb254902015-07-15 12:50:33 -060010659 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010660 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10661 pipeline_layout_ci.pNext = NULL;
10662 pipeline_layout_ci.setLayoutCount = 1;
10663 pipeline_layout_ci.pSetLayouts = &ds_layout;
10664 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010665
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010666 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010667 ASSERT_VK_SUCCESS(err);
10668
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010669 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010670 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 -060010671 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010672 VkPipelineObj pipe(m_device);
10673 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010674 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010675 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010676 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010677 pipe.SetViewport(m_viewports);
10678 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010679 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010680
Tony Barbour552f6c02016-12-21 14:34:07 -070010681 m_commandBuffer->BeginCommandBuffer();
10682 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010683 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010684 // Don't care about actual data, just need to get to draw to flag error
10685 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010686 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010687 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010688 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010689
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010690 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010691
Chia-I Wuf7458c52015-10-26 21:10:41 +080010692 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10693 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10694 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010695}
Mark Muellerdfe37552016-07-07 14:47:42 -060010696
Mark Mueller2ee294f2016-08-04 12:59:48 -060010697TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010698 TEST_DESCRIPTION(
10699 "Use an invalid count in a vkEnumeratePhysicalDevices call."
10700 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010701 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010702
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010703 const char *invalid_queueFamilyIndex_message =
10704 "Invalid queue create request in vkCreateDevice(). Invalid "
10705 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010706
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010707 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010708
Mark Mueller880fce52016-08-17 15:23:23 -060010709 // The following test fails with recent NVidia drivers.
10710 // By the time core_validation is reached, the NVidia
10711 // driver has sanitized the invalid condition and core_validation
10712 // is not introduced to the failure condition. This is not the case
10713 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010714 // uint32_t count = static_cast<uint32_t>(~0);
10715 // VkPhysicalDevice physical_device;
10716 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10717 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010718
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010720 float queue_priority = 0.0;
10721
10722 VkDeviceQueueCreateInfo queue_create_info = {};
10723 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10724 queue_create_info.queueCount = 1;
10725 queue_create_info.pQueuePriorities = &queue_priority;
10726 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10727
10728 VkPhysicalDeviceFeatures features = m_device->phy().features();
10729 VkDevice testDevice;
10730 VkDeviceCreateInfo device_create_info = {};
10731 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10732 device_create_info.queueCreateInfoCount = 1;
10733 device_create_info.pQueueCreateInfos = &queue_create_info;
10734 device_create_info.pEnabledFeatures = &features;
10735 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10736 m_errorMonitor->VerifyFound();
10737
10738 queue_create_info.queueFamilyIndex = 1;
10739
10740 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10741 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10742 for (unsigned i = 0; i < feature_count; i++) {
10743 if (VK_FALSE == feature_array[i]) {
10744 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010746 device_create_info.pEnabledFeatures = &features;
10747 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10748 m_errorMonitor->VerifyFound();
10749 break;
10750 }
10751 }
10752}
10753
Tobin Ehlis16edf082016-11-21 12:33:49 -070010754TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10755 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10756
10757 ASSERT_NO_FATAL_FAILURE(InitState());
10758
10759 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10760 std::vector<VkDeviceQueueCreateInfo> queue_info;
10761 queue_info.reserve(queue_props.size());
10762 std::vector<std::vector<float>> queue_priorities;
10763 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10764 VkDeviceQueueCreateInfo qi{};
10765 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10766 qi.queueFamilyIndex = i;
10767 qi.queueCount = queue_props[i].queueCount;
10768 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10769 qi.pQueuePriorities = queue_priorities[i].data();
10770 queue_info.push_back(qi);
10771 }
10772
10773 std::vector<const char *> device_extension_names;
10774
10775 VkDevice local_device;
10776 VkDeviceCreateInfo device_create_info = {};
10777 auto features = m_device->phy().features();
10778 // Intentionally disable pipeline stats
10779 features.pipelineStatisticsQuery = VK_FALSE;
10780 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10781 device_create_info.pNext = NULL;
10782 device_create_info.queueCreateInfoCount = queue_info.size();
10783 device_create_info.pQueueCreateInfos = queue_info.data();
10784 device_create_info.enabledLayerCount = 0;
10785 device_create_info.ppEnabledLayerNames = NULL;
10786 device_create_info.pEnabledFeatures = &features;
10787 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10788 ASSERT_VK_SUCCESS(err);
10789
10790 VkQueryPoolCreateInfo qpci{};
10791 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10792 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10793 qpci.queryCount = 1;
10794 VkQueryPool query_pool;
10795
10796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10797 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10798 m_errorMonitor->VerifyFound();
10799
10800 vkDestroyDevice(local_device, nullptr);
10801}
10802
Mark Mueller2ee294f2016-08-04 12:59:48 -060010803TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010804 TEST_DESCRIPTION(
10805 "Use an invalid queue index in a vkCmdWaitEvents call."
10806 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060010807
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010808 const char *invalid_queue_index =
10809 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10810 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10811 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010813 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010814
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010816
10817 ASSERT_NO_FATAL_FAILURE(InitState());
10818
10819 VkEvent event;
10820 VkEventCreateInfo event_create_info{};
10821 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10822 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10823
Mark Mueller2ee294f2016-08-04 12:59:48 -060010824 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010825 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010826
Tony Barbour552f6c02016-12-21 14:34:07 -070010827 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010828
10829 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010830 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 -060010831 ASSERT_TRUE(image.initialized());
10832 VkImageMemoryBarrier img_barrier = {};
10833 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10834 img_barrier.pNext = NULL;
10835 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10836 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10837 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10838 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10839 img_barrier.image = image.handle();
10840 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010841
10842 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10843 // that layer validation catches the case when it is not.
10844 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010845 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10846 img_barrier.subresourceRange.baseArrayLayer = 0;
10847 img_barrier.subresourceRange.baseMipLevel = 0;
10848 img_barrier.subresourceRange.layerCount = 1;
10849 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010850 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10851 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010852 m_errorMonitor->VerifyFound();
10853
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010855
10856 VkQueryPool query_pool;
10857 VkQueryPoolCreateInfo query_pool_create_info = {};
10858 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10859 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10860 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010861 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010862
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010863 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010864 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10865
10866 vkEndCommandBuffer(m_commandBuffer->handle());
10867 m_errorMonitor->VerifyFound();
10868
10869 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10870 vkDestroyEvent(m_device->device(), event, nullptr);
10871}
10872
Mark Muellerdfe37552016-07-07 14:47:42 -060010873TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010874 TEST_DESCRIPTION(
10875 "Submit a command buffer using deleted vertex buffer, "
10876 "delete a buffer twice, use an invalid offset for each "
10877 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060010878
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010879 const char *deleted_buffer_in_command_buffer =
10880 "Cannot submit cmd buffer "
10881 "using deleted buffer ";
10882 const char *invalid_offset_message =
10883 "vkBindBufferMemory(): "
10884 "memoryOffset is 0x";
10885 const char *invalid_storage_buffer_offset_message =
10886 "vkBindBufferMemory(): "
10887 "storage memoryOffset "
10888 "is 0x";
10889 const char *invalid_texel_buffer_offset_message =
10890 "vkBindBufferMemory(): "
10891 "texel memoryOffset "
10892 "is 0x";
10893 const char *invalid_uniform_buffer_offset_message =
10894 "vkBindBufferMemory(): "
10895 "uniform memoryOffset "
10896 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010897
10898 ASSERT_NO_FATAL_FAILURE(InitState());
10899 ASSERT_NO_FATAL_FAILURE(InitViewport());
10900 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10901
10902 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010903 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010904 pipe_ms_state_ci.pNext = NULL;
10905 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10906 pipe_ms_state_ci.sampleShadingEnable = 0;
10907 pipe_ms_state_ci.minSampleShading = 1.0;
10908 pipe_ms_state_ci.pSampleMask = nullptr;
10909
10910 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10911 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10912 VkPipelineLayout pipeline_layout;
10913
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010914 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010915 ASSERT_VK_SUCCESS(err);
10916
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010917 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10918 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010919 VkPipelineObj pipe(m_device);
10920 pipe.AddShader(&vs);
10921 pipe.AddShader(&fs);
10922 pipe.AddColorAttachment();
10923 pipe.SetMSAA(&pipe_ms_state_ci);
10924 pipe.SetViewport(m_viewports);
10925 pipe.SetScissor(m_scissors);
10926 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10927
Tony Barbour552f6c02016-12-21 14:34:07 -070010928 m_commandBuffer->BeginCommandBuffer();
10929 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010930 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010931
10932 {
10933 // Create and bind a vertex buffer in a reduced scope, which will cause
10934 // it to be deleted upon leaving this scope
10935 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010936 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010937 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10938 draw_verticies.AddVertexInputToPipe(pipe);
10939 }
10940
10941 Draw(1, 0, 0, 0);
10942
Tony Barbour552f6c02016-12-21 14:34:07 -070010943 m_commandBuffer->EndRenderPass();
10944 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060010945
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010947 QueueCommandBuffer(false);
10948 m_errorMonitor->VerifyFound();
10949
10950 {
10951 // Create and bind a vertex buffer in a reduced scope, and delete it
10952 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010953 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010955 buffer_test.TestDoubleDestroy();
10956 }
10957 m_errorMonitor->VerifyFound();
10958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010959 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010960 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10962 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10963 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010964 m_errorMonitor->VerifyFound();
10965 }
10966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010967 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10968 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010969 // Create and bind a memory buffer with an invalid offset again,
10970 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10972 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10973 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010974 m_errorMonitor->VerifyFound();
10975 }
10976
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010977 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010978 // Create and bind a memory buffer with an invalid offset again, but
10979 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10981 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10982 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010983 m_errorMonitor->VerifyFound();
10984 }
10985
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010986 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010987 // Create and bind a memory buffer with an invalid offset again, but
10988 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10990 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10991 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010992 m_errorMonitor->VerifyFound();
10993 }
10994
10995 {
10996 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010998 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10999 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011000 m_errorMonitor->VerifyFound();
11001 }
11002
11003 {
11004 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011006 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11007 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011008 }
11009 m_errorMonitor->VerifyFound();
11010
11011 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11012}
11013
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011014// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11015TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011016 TEST_DESCRIPTION(
11017 "Hit all possible validation checks associated with the "
11018 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11019 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011020 // 3 in ValidateCmdBufImageLayouts
11021 // * -1 Attempt to submit cmd buf w/ deleted image
11022 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11023 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011024
11025 ASSERT_NO_FATAL_FAILURE(InitState());
11026 // Create src & dst images to use for copy operations
11027 VkImage src_image;
11028 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011029 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011030
11031 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11032 const int32_t tex_width = 32;
11033 const int32_t tex_height = 32;
11034
11035 VkImageCreateInfo image_create_info = {};
11036 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11037 image_create_info.pNext = NULL;
11038 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11039 image_create_info.format = tex_format;
11040 image_create_info.extent.width = tex_width;
11041 image_create_info.extent.height = tex_height;
11042 image_create_info.extent.depth = 1;
11043 image_create_info.mipLevels = 1;
11044 image_create_info.arrayLayers = 4;
11045 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11046 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11047 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011048 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011049 image_create_info.flags = 0;
11050
11051 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11052 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011053 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011054 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11055 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011056 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11057 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11058 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11059 ASSERT_VK_SUCCESS(err);
11060
11061 // Allocate memory
11062 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011063 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011064 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011065 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11066 mem_alloc.pNext = NULL;
11067 mem_alloc.allocationSize = 0;
11068 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011069
11070 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011071 mem_alloc.allocationSize = img_mem_reqs.size;
11072 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011073 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011074 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011075 ASSERT_VK_SUCCESS(err);
11076
11077 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011078 mem_alloc.allocationSize = img_mem_reqs.size;
11079 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011080 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011081 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011082 ASSERT_VK_SUCCESS(err);
11083
11084 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011085 mem_alloc.allocationSize = img_mem_reqs.size;
11086 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011087 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011088 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011089 ASSERT_VK_SUCCESS(err);
11090
11091 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11092 ASSERT_VK_SUCCESS(err);
11093 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11094 ASSERT_VK_SUCCESS(err);
11095 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11096 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011097
Tony Barbour552f6c02016-12-21 14:34:07 -070011098 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011099 VkImageCopy copy_region;
11100 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11101 copy_region.srcSubresource.mipLevel = 0;
11102 copy_region.srcSubresource.baseArrayLayer = 0;
11103 copy_region.srcSubresource.layerCount = 1;
11104 copy_region.srcOffset.x = 0;
11105 copy_region.srcOffset.y = 0;
11106 copy_region.srcOffset.z = 0;
11107 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11108 copy_region.dstSubresource.mipLevel = 0;
11109 copy_region.dstSubresource.baseArrayLayer = 0;
11110 copy_region.dstSubresource.layerCount = 1;
11111 copy_region.dstOffset.x = 0;
11112 copy_region.dstOffset.y = 0;
11113 copy_region.dstOffset.z = 0;
11114 copy_region.extent.width = 1;
11115 copy_region.extent.height = 1;
11116 copy_region.extent.depth = 1;
11117
11118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11119 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
11120 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 -060011121 m_errorMonitor->VerifyFound();
11122 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11124 "Cannot copy from an image whose source layout is "
11125 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11126 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011127 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 -060011128 m_errorMonitor->VerifyFound();
11129 // Final src error is due to bad layout type
11130 m_errorMonitor->SetDesiredFailureMsg(
11131 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11132 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011133 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 -060011134 m_errorMonitor->VerifyFound();
11135 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11137 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011138 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 -060011139 m_errorMonitor->VerifyFound();
11140 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11142 "Cannot copy from an image whose dest layout is "
11143 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11144 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011145 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 -060011146 m_errorMonitor->VerifyFound();
11147 m_errorMonitor->SetDesiredFailureMsg(
11148 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11149 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011150 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 -060011151 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011152
Cort3b021012016-12-07 12:00:57 -080011153 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11154 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11155 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11156 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11157 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11158 transfer_dst_image_barrier[0].srcAccessMask = 0;
11159 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11160 transfer_dst_image_barrier[0].image = dst_image;
11161 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11162 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11163 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11164 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11165 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11166 transfer_dst_image_barrier[0].image = depth_image;
11167 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11168 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11169 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11170
11171 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011172 VkClearColorValue color_clear_value = {};
11173 VkImageSubresourceRange clear_range;
11174 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11175 clear_range.baseMipLevel = 0;
11176 clear_range.baseArrayLayer = 0;
11177 clear_range.layerCount = 1;
11178 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011179
Cort3b021012016-12-07 12:00:57 -080011180 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11181 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011184 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011185 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011186 // Fail due to provided layout not matching actual current layout for color clear.
11187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011188 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011189 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011190
Cort530cf382016-12-08 09:59:47 -080011191 VkClearDepthStencilValue depth_clear_value = {};
11192 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011193
11194 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11195 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011198 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011199 m_errorMonitor->VerifyFound();
11200 // Fail due to provided layout not matching actual current layout for depth clear.
11201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011202 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011203 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011204
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011205 // Now cause error due to bad image layout transition in PipelineBarrier
11206 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011207 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011208 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011209 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011210 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011211 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11212 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011213 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11215 "You cannot transition the layout of aspect 1 from "
11216 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11217 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011218 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11219 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011220 m_errorMonitor->VerifyFound();
11221
11222 // Finally some layout errors at RenderPass create time
11223 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11224 VkAttachmentReference attach = {};
11225 // perf warning for GENERAL layout w/ non-DS input attachment
11226 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11227 VkSubpassDescription subpass = {};
11228 subpass.inputAttachmentCount = 1;
11229 subpass.pInputAttachments = &attach;
11230 VkRenderPassCreateInfo rpci = {};
11231 rpci.subpassCount = 1;
11232 rpci.pSubpasses = &subpass;
11233 rpci.attachmentCount = 1;
11234 VkAttachmentDescription attach_desc = {};
11235 attach_desc.format = VK_FORMAT_UNDEFINED;
11236 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011237 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011238 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11240 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011241 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11242 m_errorMonitor->VerifyFound();
11243 // error w/ non-general layout
11244 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11245
11246 m_errorMonitor->SetDesiredFailureMsg(
11247 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11248 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11249 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11250 m_errorMonitor->VerifyFound();
11251 subpass.inputAttachmentCount = 0;
11252 subpass.colorAttachmentCount = 1;
11253 subpass.pColorAttachments = &attach;
11254 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11255 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11257 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011258 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11259 m_errorMonitor->VerifyFound();
11260 // error w/ non-color opt or GENERAL layout for color attachment
11261 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11262 m_errorMonitor->SetDesiredFailureMsg(
11263 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11264 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11265 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11266 m_errorMonitor->VerifyFound();
11267 subpass.colorAttachmentCount = 0;
11268 subpass.pDepthStencilAttachment = &attach;
11269 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11270 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11272 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011273 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11274 m_errorMonitor->VerifyFound();
11275 // error w/ non-ds opt or GENERAL layout for color attachment
11276 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11278 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11279 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011280 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11281 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011282 // For this error we need a valid renderpass so create default one
11283 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11284 attach.attachment = 0;
11285 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11286 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11287 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11288 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11289 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11290 // Can't do a CLEAR load on READ_ONLY initialLayout
11291 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11292 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11293 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11295 " with invalid first layout "
11296 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11297 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011298 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11299 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011300
Cort3b021012016-12-07 12:00:57 -080011301 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11302 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11303 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011304 vkDestroyImage(m_device->device(), src_image, NULL);
11305 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011306 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011307}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011308
Tobin Ehlise0936662016-10-11 08:10:51 -060011309TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11310 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11311 VkResult err;
11312
11313 ASSERT_NO_FATAL_FAILURE(InitState());
11314
11315 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11316 VkImageTiling tiling;
11317 VkFormatProperties format_properties;
11318 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11319 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11320 tiling = VK_IMAGE_TILING_LINEAR;
11321 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11322 tiling = VK_IMAGE_TILING_OPTIMAL;
11323 } else {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011324 printf(
11325 "Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11326 "skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011327 return;
11328 }
11329
11330 VkDescriptorPoolSize ds_type = {};
11331 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11332 ds_type.descriptorCount = 1;
11333
11334 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11335 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11336 ds_pool_ci.maxSets = 1;
11337 ds_pool_ci.poolSizeCount = 1;
11338 ds_pool_ci.pPoolSizes = &ds_type;
11339 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11340
11341 VkDescriptorPool ds_pool;
11342 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11343 ASSERT_VK_SUCCESS(err);
11344
11345 VkDescriptorSetLayoutBinding dsl_binding = {};
11346 dsl_binding.binding = 0;
11347 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11348 dsl_binding.descriptorCount = 1;
11349 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11350 dsl_binding.pImmutableSamplers = NULL;
11351
11352 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11353 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11354 ds_layout_ci.pNext = NULL;
11355 ds_layout_ci.bindingCount = 1;
11356 ds_layout_ci.pBindings = &dsl_binding;
11357
11358 VkDescriptorSetLayout ds_layout;
11359 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11360 ASSERT_VK_SUCCESS(err);
11361
11362 VkDescriptorSetAllocateInfo alloc_info = {};
11363 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11364 alloc_info.descriptorSetCount = 1;
11365 alloc_info.descriptorPool = ds_pool;
11366 alloc_info.pSetLayouts = &ds_layout;
11367 VkDescriptorSet descriptor_set;
11368 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11369 ASSERT_VK_SUCCESS(err);
11370
11371 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11372 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11373 pipeline_layout_ci.pNext = NULL;
11374 pipeline_layout_ci.setLayoutCount = 1;
11375 pipeline_layout_ci.pSetLayouts = &ds_layout;
11376 VkPipelineLayout pipeline_layout;
11377 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11378 ASSERT_VK_SUCCESS(err);
11379
11380 VkImageObj image(m_device);
11381 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11382 ASSERT_TRUE(image.initialized());
11383 VkImageView view = image.targetView(tex_format);
11384
11385 VkDescriptorImageInfo image_info = {};
11386 image_info.imageView = view;
11387 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11388
11389 VkWriteDescriptorSet descriptor_write = {};
11390 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11391 descriptor_write.dstSet = descriptor_set;
11392 descriptor_write.dstBinding = 0;
11393 descriptor_write.descriptorCount = 1;
11394 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11395 descriptor_write.pImageInfo = &image_info;
11396
11397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11398 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11399 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11400 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11401 m_errorMonitor->VerifyFound();
11402
11403 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11404 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11405 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11406 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11407}
11408
Mark Mueller93b938f2016-08-18 10:27:40 -060011409TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011410 TEST_DESCRIPTION(
11411 "Use vkCmdExecuteCommands with invalid state "
11412 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011413
11414 ASSERT_NO_FATAL_FAILURE(InitState());
11415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11416
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011417 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011418 const char *simultaneous_use_message2 =
11419 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11420 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011421
11422 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011423 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011424 command_buffer_allocate_info.commandPool = m_commandPool;
11425 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11426 command_buffer_allocate_info.commandBufferCount = 1;
11427
11428 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011429 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011430 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11431 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011432 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011433 command_buffer_inheritance_info.renderPass = m_renderPass;
11434 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011435
Mark Mueller93b938f2016-08-18 10:27:40 -060011436 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011437 command_buffer_begin_info.flags =
11438 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011439 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11440
11441 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11442 vkEndCommandBuffer(secondary_command_buffer);
11443
Mark Mueller93b938f2016-08-18 10:27:40 -060011444 VkSubmitInfo submit_info = {};
11445 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11446 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011447 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011448
Mark Mueller4042b652016-09-05 22:52:21 -060011449 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011450 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11452 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011453 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011454 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011455 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11456 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011457
Dave Houltonfbf52152017-01-06 12:55:29 -070011458 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060011459 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070011460 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060011461
Mark Mueller4042b652016-09-05 22:52:21 -060011462 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011463 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011464 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11467 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011468 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011469 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11470 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011471
11472 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011473}
11474
Tobin Ehlisb093da82017-01-19 12:05:27 -070011475TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011476 TEST_DESCRIPTION(
11477 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
11478 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070011479
11480 ASSERT_NO_FATAL_FAILURE(InitState());
11481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11482
11483 std::vector<const char *> device_extension_names;
11484 auto features = m_device->phy().features();
11485 // Make sure gs & ts are disabled
11486 features.geometryShader = false;
11487 features.tessellationShader = false;
11488 // The sacrificial device object
11489 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11490
11491 VkCommandPoolCreateInfo pool_create_info{};
11492 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
11493 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
11494
11495 VkCommandPool command_pool;
11496 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
11497
11498 VkCommandBufferAllocateInfo cmd = {};
11499 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11500 cmd.pNext = NULL;
11501 cmd.commandPool = command_pool;
11502 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
11503 cmd.commandBufferCount = 1;
11504
11505 VkCommandBuffer cmd_buffer;
11506 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
11507 ASSERT_VK_SUCCESS(err);
11508
11509 VkEvent event;
11510 VkEventCreateInfo evci = {};
11511 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11512 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
11513 ASSERT_VK_SUCCESS(result);
11514
11515 VkCommandBufferBeginInfo cbbi = {};
11516 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11517 vkBeginCommandBuffer(cmd_buffer, &cbbi);
11518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
11519 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
11520 m_errorMonitor->VerifyFound();
11521
11522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
11523 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
11524 m_errorMonitor->VerifyFound();
11525
11526 vkDestroyEvent(test_device.handle(), event, NULL);
11527 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
11528}
11529
Mark Mueller917f6bc2016-08-30 10:57:19 -060011530TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011531 TEST_DESCRIPTION(
11532 "Use vkCmdExecuteCommands with invalid state "
11533 "in primary and secondary command buffers. "
11534 "Delete objects that are inuse. Call VkQueueSubmit "
11535 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011536
11537 ASSERT_NO_FATAL_FAILURE(InitState());
11538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11539
Tony Barbour552f6c02016-12-21 14:34:07 -070011540 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011541
11542 VkEvent event;
11543 VkEventCreateInfo event_create_info = {};
11544 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11545 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011546 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011547
Tony Barbour552f6c02016-12-21 14:34:07 -070011548 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011549 vkDestroyEvent(m_device->device(), event, nullptr);
11550
11551 VkSubmitInfo submit_info = {};
11552 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11553 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011554 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b082d72017-01-27 11:34:28 -070011555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted event 0x");
11556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You are submitting command buffer 0x");
Mark Muellerc8d441e2016-08-23 17:36:00 -060011557 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11558 m_errorMonitor->VerifyFound();
11559
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011560 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060011561 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11562
11563 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11564
Mark Mueller917f6bc2016-08-30 10:57:19 -060011565 VkSemaphoreCreateInfo semaphore_create_info = {};
11566 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11567 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011568 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011569 VkFenceCreateInfo fence_create_info = {};
11570 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11571 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011572 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011573
11574 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011575 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011576 descriptor_pool_type_count.descriptorCount = 1;
11577
11578 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11579 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11580 descriptor_pool_create_info.maxSets = 1;
11581 descriptor_pool_create_info.poolSizeCount = 1;
11582 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011583 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011584
11585 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011586 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011587
11588 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011589 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011590 descriptorset_layout_binding.descriptorCount = 1;
11591 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11592
11593 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011594 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011595 descriptorset_layout_create_info.bindingCount = 1;
11596 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11597
11598 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011599 ASSERT_VK_SUCCESS(
11600 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011601
11602 VkDescriptorSet descriptorset;
11603 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011604 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011605 descriptorset_allocate_info.descriptorSetCount = 1;
11606 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11607 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011608 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011609
Mark Mueller4042b652016-09-05 22:52:21 -060011610 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11611
11612 VkDescriptorBufferInfo buffer_info = {};
11613 buffer_info.buffer = buffer_test.GetBuffer();
11614 buffer_info.offset = 0;
11615 buffer_info.range = 1024;
11616
11617 VkWriteDescriptorSet write_descriptor_set = {};
11618 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11619 write_descriptor_set.dstSet = descriptorset;
11620 write_descriptor_set.descriptorCount = 1;
11621 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11622 write_descriptor_set.pBufferInfo = &buffer_info;
11623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011624 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011626 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11627 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011628
11629 VkPipelineObj pipe(m_device);
11630 pipe.AddColorAttachment();
11631 pipe.AddShader(&vs);
11632 pipe.AddShader(&fs);
11633
11634 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011635 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011636 pipeline_layout_create_info.setLayoutCount = 1;
11637 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11638
11639 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011640 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011641
11642 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11643
Tony Barbour552f6c02016-12-21 14:34:07 -070011644 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011645 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011646
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011647 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11648 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11649 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011650
Tony Barbour552f6c02016-12-21 14:34:07 -070011651 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011652
Mark Mueller917f6bc2016-08-30 10:57:19 -060011653 submit_info.signalSemaphoreCount = 1;
11654 submit_info.pSignalSemaphores = &semaphore;
11655 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011656 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060011657
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011659 vkDestroyEvent(m_device->device(), event, nullptr);
11660 m_errorMonitor->VerifyFound();
11661
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011663 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11664 m_errorMonitor->VerifyFound();
11665
Jeremy Hayes08369882017-02-02 10:31:06 -070011666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011667 vkDestroyFence(m_device->device(), fence, nullptr);
11668 m_errorMonitor->VerifyFound();
11669
Tobin Ehlis122207b2016-09-01 08:50:06 -070011670 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011671 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11672 vkDestroyFence(m_device->device(), fence, nullptr);
11673 vkDestroyEvent(m_device->device(), event, nullptr);
11674 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011675 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011676 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11677}
11678
Tobin Ehlis2adda372016-09-01 08:51:06 -070011679TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11680 TEST_DESCRIPTION("Delete in-use query pool.");
11681
11682 ASSERT_NO_FATAL_FAILURE(InitState());
11683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11684
11685 VkQueryPool query_pool;
11686 VkQueryPoolCreateInfo query_pool_ci{};
11687 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11688 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11689 query_pool_ci.queryCount = 1;
11690 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011691 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011692 // Reset query pool to create binding with cmd buffer
11693 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11694
Tony Barbour552f6c02016-12-21 14:34:07 -070011695 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011696
11697 VkSubmitInfo submit_info = {};
11698 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11699 submit_info.commandBufferCount = 1;
11700 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11701 // Submit cmd buffer and then destroy query pool while in-flight
11702 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11703
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011705 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11706 m_errorMonitor->VerifyFound();
11707
11708 vkQueueWaitIdle(m_device->m_queue);
11709 // Now that cmd buffer done we can safely destroy query_pool
11710 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11711}
11712
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011713TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11714 TEST_DESCRIPTION("Delete in-use pipeline.");
11715
11716 ASSERT_NO_FATAL_FAILURE(InitState());
11717 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11718
11719 // Empty pipeline layout used for binding PSO
11720 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11721 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11722 pipeline_layout_ci.setLayoutCount = 0;
11723 pipeline_layout_ci.pSetLayouts = NULL;
11724
11725 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011726 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011727 ASSERT_VK_SUCCESS(err);
11728
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011730 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011731 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11732 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011733 // Store pipeline handle so we can actually delete it before test finishes
11734 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011735 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011736 VkPipelineObj pipe(m_device);
11737 pipe.AddShader(&vs);
11738 pipe.AddShader(&fs);
11739 pipe.AddColorAttachment();
11740 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11741 delete_this_pipeline = pipe.handle();
11742
Tony Barbour552f6c02016-12-21 14:34:07 -070011743 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011744 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011745 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011746
Tony Barbour552f6c02016-12-21 14:34:07 -070011747 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011748
11749 VkSubmitInfo submit_info = {};
11750 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11751 submit_info.commandBufferCount = 1;
11752 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11753 // Submit cmd buffer and then pipeline destroyed while in-flight
11754 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011755 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011756 m_errorMonitor->VerifyFound();
11757 // Make sure queue finished and then actually delete pipeline
11758 vkQueueWaitIdle(m_device->m_queue);
11759 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11760 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11761}
11762
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011763TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11764 TEST_DESCRIPTION("Delete in-use imageView.");
11765
11766 ASSERT_NO_FATAL_FAILURE(InitState());
11767 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11768
11769 VkDescriptorPoolSize ds_type_count;
11770 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11771 ds_type_count.descriptorCount = 1;
11772
11773 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11774 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11775 ds_pool_ci.maxSets = 1;
11776 ds_pool_ci.poolSizeCount = 1;
11777 ds_pool_ci.pPoolSizes = &ds_type_count;
11778
11779 VkDescriptorPool ds_pool;
11780 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11781 ASSERT_VK_SUCCESS(err);
11782
11783 VkSamplerCreateInfo sampler_ci = {};
11784 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11785 sampler_ci.pNext = NULL;
11786 sampler_ci.magFilter = VK_FILTER_NEAREST;
11787 sampler_ci.minFilter = VK_FILTER_NEAREST;
11788 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11789 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11790 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11791 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11792 sampler_ci.mipLodBias = 1.0;
11793 sampler_ci.anisotropyEnable = VK_FALSE;
11794 sampler_ci.maxAnisotropy = 1;
11795 sampler_ci.compareEnable = VK_FALSE;
11796 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11797 sampler_ci.minLod = 1.0;
11798 sampler_ci.maxLod = 1.0;
11799 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11800 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11801 VkSampler sampler;
11802
11803 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11804 ASSERT_VK_SUCCESS(err);
11805
11806 VkDescriptorSetLayoutBinding layout_binding;
11807 layout_binding.binding = 0;
11808 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11809 layout_binding.descriptorCount = 1;
11810 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11811 layout_binding.pImmutableSamplers = NULL;
11812
11813 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11814 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11815 ds_layout_ci.bindingCount = 1;
11816 ds_layout_ci.pBindings = &layout_binding;
11817 VkDescriptorSetLayout ds_layout;
11818 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11819 ASSERT_VK_SUCCESS(err);
11820
11821 VkDescriptorSetAllocateInfo alloc_info = {};
11822 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11823 alloc_info.descriptorSetCount = 1;
11824 alloc_info.descriptorPool = ds_pool;
11825 alloc_info.pSetLayouts = &ds_layout;
11826 VkDescriptorSet descriptor_set;
11827 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11828 ASSERT_VK_SUCCESS(err);
11829
11830 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11831 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11832 pipeline_layout_ci.pNext = NULL;
11833 pipeline_layout_ci.setLayoutCount = 1;
11834 pipeline_layout_ci.pSetLayouts = &ds_layout;
11835
11836 VkPipelineLayout pipeline_layout;
11837 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11838 ASSERT_VK_SUCCESS(err);
11839
11840 VkImageObj image(m_device);
11841 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11842 ASSERT_TRUE(image.initialized());
11843
11844 VkImageView view;
11845 VkImageViewCreateInfo ivci = {};
11846 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11847 ivci.image = image.handle();
11848 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11849 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11850 ivci.subresourceRange.layerCount = 1;
11851 ivci.subresourceRange.baseMipLevel = 0;
11852 ivci.subresourceRange.levelCount = 1;
11853 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11854
11855 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11856 ASSERT_VK_SUCCESS(err);
11857
11858 VkDescriptorImageInfo image_info{};
11859 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11860 image_info.imageView = view;
11861 image_info.sampler = sampler;
11862
11863 VkWriteDescriptorSet descriptor_write = {};
11864 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11865 descriptor_write.dstSet = descriptor_set;
11866 descriptor_write.dstBinding = 0;
11867 descriptor_write.descriptorCount = 1;
11868 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11869 descriptor_write.pImageInfo = &image_info;
11870
11871 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11872
11873 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011874 char const *vsSource =
11875 "#version 450\n"
11876 "\n"
11877 "out gl_PerVertex { \n"
11878 " vec4 gl_Position;\n"
11879 "};\n"
11880 "void main(){\n"
11881 " gl_Position = vec4(1);\n"
11882 "}\n";
11883 char const *fsSource =
11884 "#version 450\n"
11885 "\n"
11886 "layout(set=0, binding=0) uniform sampler2D s;\n"
11887 "layout(location=0) out vec4 x;\n"
11888 "void main(){\n"
11889 " x = texture(s, vec2(1));\n"
11890 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011891 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11892 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11893 VkPipelineObj pipe(m_device);
11894 pipe.AddShader(&vs);
11895 pipe.AddShader(&fs);
11896 pipe.AddColorAttachment();
11897 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11898
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011900
Tony Barbour552f6c02016-12-21 14:34:07 -070011901 m_commandBuffer->BeginCommandBuffer();
11902 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011903 // Bind pipeline to cmd buffer
11904 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11905 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11906 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070011907
11908 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11909 VkRect2D scissor = {{0, 0}, {16, 16}};
11910 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11911 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11912
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011913 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011914 m_commandBuffer->EndRenderPass();
11915 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011916 // Submit cmd buffer then destroy sampler
11917 VkSubmitInfo submit_info = {};
11918 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11919 submit_info.commandBufferCount = 1;
11920 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11921 // Submit cmd buffer and then destroy imageView while in-flight
11922 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11923
11924 vkDestroyImageView(m_device->device(), view, nullptr);
11925 m_errorMonitor->VerifyFound();
11926 vkQueueWaitIdle(m_device->m_queue);
11927 // Now we can actually destroy imageView
11928 vkDestroyImageView(m_device->device(), view, NULL);
11929 vkDestroySampler(m_device->device(), sampler, nullptr);
11930 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11931 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11932 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11933}
11934
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011935TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11936 TEST_DESCRIPTION("Delete in-use bufferView.");
11937
11938 ASSERT_NO_FATAL_FAILURE(InitState());
11939 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11940
11941 VkDescriptorPoolSize ds_type_count;
11942 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11943 ds_type_count.descriptorCount = 1;
11944
11945 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11946 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11947 ds_pool_ci.maxSets = 1;
11948 ds_pool_ci.poolSizeCount = 1;
11949 ds_pool_ci.pPoolSizes = &ds_type_count;
11950
11951 VkDescriptorPool ds_pool;
11952 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11953 ASSERT_VK_SUCCESS(err);
11954
11955 VkDescriptorSetLayoutBinding layout_binding;
11956 layout_binding.binding = 0;
11957 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11958 layout_binding.descriptorCount = 1;
11959 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11960 layout_binding.pImmutableSamplers = NULL;
11961
11962 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11963 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11964 ds_layout_ci.bindingCount = 1;
11965 ds_layout_ci.pBindings = &layout_binding;
11966 VkDescriptorSetLayout ds_layout;
11967 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11968 ASSERT_VK_SUCCESS(err);
11969
11970 VkDescriptorSetAllocateInfo alloc_info = {};
11971 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11972 alloc_info.descriptorSetCount = 1;
11973 alloc_info.descriptorPool = ds_pool;
11974 alloc_info.pSetLayouts = &ds_layout;
11975 VkDescriptorSet descriptor_set;
11976 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11977 ASSERT_VK_SUCCESS(err);
11978
11979 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11980 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11981 pipeline_layout_ci.pNext = NULL;
11982 pipeline_layout_ci.setLayoutCount = 1;
11983 pipeline_layout_ci.pSetLayouts = &ds_layout;
11984
11985 VkPipelineLayout pipeline_layout;
11986 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11987 ASSERT_VK_SUCCESS(err);
11988
11989 VkBuffer buffer;
11990 uint32_t queue_family_index = 0;
11991 VkBufferCreateInfo buffer_create_info = {};
11992 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11993 buffer_create_info.size = 1024;
11994 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11995 buffer_create_info.queueFamilyIndexCount = 1;
11996 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11997
11998 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11999 ASSERT_VK_SUCCESS(err);
12000
12001 VkMemoryRequirements memory_reqs;
12002 VkDeviceMemory buffer_memory;
12003
12004 VkMemoryAllocateInfo memory_info = {};
12005 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12006 memory_info.allocationSize = 0;
12007 memory_info.memoryTypeIndex = 0;
12008
12009 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12010 memory_info.allocationSize = memory_reqs.size;
12011 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12012 ASSERT_TRUE(pass);
12013
12014 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12015 ASSERT_VK_SUCCESS(err);
12016 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12017 ASSERT_VK_SUCCESS(err);
12018
12019 VkBufferView view;
12020 VkBufferViewCreateInfo bvci = {};
12021 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12022 bvci.buffer = buffer;
12023 bvci.format = VK_FORMAT_R8_UNORM;
12024 bvci.range = VK_WHOLE_SIZE;
12025
12026 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12027 ASSERT_VK_SUCCESS(err);
12028
12029 VkWriteDescriptorSet descriptor_write = {};
12030 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12031 descriptor_write.dstSet = descriptor_set;
12032 descriptor_write.dstBinding = 0;
12033 descriptor_write.descriptorCount = 1;
12034 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12035 descriptor_write.pTexelBufferView = &view;
12036
12037 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12038
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012039 char const *vsSource =
12040 "#version 450\n"
12041 "\n"
12042 "out gl_PerVertex { \n"
12043 " vec4 gl_Position;\n"
12044 "};\n"
12045 "void main(){\n"
12046 " gl_Position = vec4(1);\n"
12047 "}\n";
12048 char const *fsSource =
12049 "#version 450\n"
12050 "\n"
12051 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12052 "layout(location=0) out vec4 x;\n"
12053 "void main(){\n"
12054 " x = imageLoad(s, 0);\n"
12055 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012056 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12057 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12058 VkPipelineObj pipe(m_device);
12059 pipe.AddShader(&vs);
12060 pipe.AddShader(&fs);
12061 pipe.AddColorAttachment();
12062 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12063
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012065
Tony Barbour552f6c02016-12-21 14:34:07 -070012066 m_commandBuffer->BeginCommandBuffer();
12067 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012068 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12069 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12070 VkRect2D scissor = {{0, 0}, {16, 16}};
12071 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12072 // Bind pipeline to cmd buffer
12073 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12074 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12075 &descriptor_set, 0, nullptr);
12076 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012077 m_commandBuffer->EndRenderPass();
12078 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012079
12080 VkSubmitInfo submit_info = {};
12081 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12082 submit_info.commandBufferCount = 1;
12083 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12084 // Submit cmd buffer and then destroy bufferView while in-flight
12085 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12086
12087 vkDestroyBufferView(m_device->device(), view, nullptr);
12088 m_errorMonitor->VerifyFound();
12089 vkQueueWaitIdle(m_device->m_queue);
12090 // Now we can actually destroy bufferView
12091 vkDestroyBufferView(m_device->device(), view, NULL);
12092 vkDestroyBuffer(m_device->device(), buffer, NULL);
12093 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12094 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12095 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12096 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12097}
12098
Tobin Ehlis209532e2016-09-07 13:52:18 -060012099TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12100 TEST_DESCRIPTION("Delete in-use sampler.");
12101
12102 ASSERT_NO_FATAL_FAILURE(InitState());
12103 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12104
12105 VkDescriptorPoolSize ds_type_count;
12106 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12107 ds_type_count.descriptorCount = 1;
12108
12109 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12110 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12111 ds_pool_ci.maxSets = 1;
12112 ds_pool_ci.poolSizeCount = 1;
12113 ds_pool_ci.pPoolSizes = &ds_type_count;
12114
12115 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012116 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012117 ASSERT_VK_SUCCESS(err);
12118
12119 VkSamplerCreateInfo sampler_ci = {};
12120 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12121 sampler_ci.pNext = NULL;
12122 sampler_ci.magFilter = VK_FILTER_NEAREST;
12123 sampler_ci.minFilter = VK_FILTER_NEAREST;
12124 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12125 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12126 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12127 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12128 sampler_ci.mipLodBias = 1.0;
12129 sampler_ci.anisotropyEnable = VK_FALSE;
12130 sampler_ci.maxAnisotropy = 1;
12131 sampler_ci.compareEnable = VK_FALSE;
12132 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12133 sampler_ci.minLod = 1.0;
12134 sampler_ci.maxLod = 1.0;
12135 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12136 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12137 VkSampler sampler;
12138
12139 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12140 ASSERT_VK_SUCCESS(err);
12141
12142 VkDescriptorSetLayoutBinding layout_binding;
12143 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012144 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012145 layout_binding.descriptorCount = 1;
12146 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12147 layout_binding.pImmutableSamplers = NULL;
12148
12149 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12150 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12151 ds_layout_ci.bindingCount = 1;
12152 ds_layout_ci.pBindings = &layout_binding;
12153 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012154 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012155 ASSERT_VK_SUCCESS(err);
12156
12157 VkDescriptorSetAllocateInfo alloc_info = {};
12158 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12159 alloc_info.descriptorSetCount = 1;
12160 alloc_info.descriptorPool = ds_pool;
12161 alloc_info.pSetLayouts = &ds_layout;
12162 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012163 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012164 ASSERT_VK_SUCCESS(err);
12165
12166 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12167 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12168 pipeline_layout_ci.pNext = NULL;
12169 pipeline_layout_ci.setLayoutCount = 1;
12170 pipeline_layout_ci.pSetLayouts = &ds_layout;
12171
12172 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012173 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012174 ASSERT_VK_SUCCESS(err);
12175
12176 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012177 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 -060012178 ASSERT_TRUE(image.initialized());
12179
12180 VkImageView view;
12181 VkImageViewCreateInfo ivci = {};
12182 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12183 ivci.image = image.handle();
12184 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12185 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12186 ivci.subresourceRange.layerCount = 1;
12187 ivci.subresourceRange.baseMipLevel = 0;
12188 ivci.subresourceRange.levelCount = 1;
12189 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12190
12191 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12192 ASSERT_VK_SUCCESS(err);
12193
12194 VkDescriptorImageInfo image_info{};
12195 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12196 image_info.imageView = view;
12197 image_info.sampler = sampler;
12198
12199 VkWriteDescriptorSet descriptor_write = {};
12200 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12201 descriptor_write.dstSet = descriptor_set;
12202 descriptor_write.dstBinding = 0;
12203 descriptor_write.descriptorCount = 1;
12204 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12205 descriptor_write.pImageInfo = &image_info;
12206
12207 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12208
12209 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012210 char const *vsSource =
12211 "#version 450\n"
12212 "\n"
12213 "out gl_PerVertex { \n"
12214 " vec4 gl_Position;\n"
12215 "};\n"
12216 "void main(){\n"
12217 " gl_Position = vec4(1);\n"
12218 "}\n";
12219 char const *fsSource =
12220 "#version 450\n"
12221 "\n"
12222 "layout(set=0, binding=0) uniform sampler2D s;\n"
12223 "layout(location=0) out vec4 x;\n"
12224 "void main(){\n"
12225 " x = texture(s, vec2(1));\n"
12226 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012227 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12228 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12229 VkPipelineObj pipe(m_device);
12230 pipe.AddShader(&vs);
12231 pipe.AddShader(&fs);
12232 pipe.AddColorAttachment();
12233 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12234
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012236
Tony Barbour552f6c02016-12-21 14:34:07 -070012237 m_commandBuffer->BeginCommandBuffer();
12238 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012239 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012240 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12241 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12242 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012243
12244 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12245 VkRect2D scissor = {{0, 0}, {16, 16}};
12246 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12247 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12248
Tobin Ehlis209532e2016-09-07 13:52:18 -060012249 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012250 m_commandBuffer->EndRenderPass();
12251 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012252 // Submit cmd buffer then destroy sampler
12253 VkSubmitInfo submit_info = {};
12254 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12255 submit_info.commandBufferCount = 1;
12256 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12257 // Submit cmd buffer and then destroy sampler while in-flight
12258 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12259
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012260 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012261 m_errorMonitor->VerifyFound();
12262 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012263
Tobin Ehlis209532e2016-09-07 13:52:18 -060012264 // Now we can actually destroy sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012265 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012266 vkDestroyImageView(m_device->device(), view, NULL);
12267 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12268 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12269 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12270}
12271
Mark Mueller1cd9f412016-08-25 13:23:52 -060012272TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012273 TEST_DESCRIPTION(
12274 "Call VkQueueSubmit with a semaphore that is already "
12275 "signaled but not waited on by the queue. Wait on a "
12276 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012277
12278 ASSERT_NO_FATAL_FAILURE(InitState());
12279 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12280
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012281 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 -070012282 const char *invalid_fence_wait_message =
12283 " which has not been submitted on a Queue or during "
12284 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012285
Tony Barbour552f6c02016-12-21 14:34:07 -070012286 m_commandBuffer->BeginCommandBuffer();
12287 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012288
12289 VkSemaphoreCreateInfo semaphore_create_info = {};
12290 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12291 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012292 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012293 VkSubmitInfo submit_info = {};
12294 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12295 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012296 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012297 submit_info.signalSemaphoreCount = 1;
12298 submit_info.pSignalSemaphores = &semaphore;
12299 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012300 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012301 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012302 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012303 m_commandBuffer->BeginCommandBuffer();
12304 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012306 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12307 m_errorMonitor->VerifyFound();
12308
Mark Mueller1cd9f412016-08-25 13:23:52 -060012309 VkFenceCreateInfo fence_create_info = {};
12310 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12311 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012312 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012313
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012315 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12316 m_errorMonitor->VerifyFound();
12317
Mark Mueller4042b652016-09-05 22:52:21 -060012318 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012319 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012320 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12321}
12322
Tobin Ehlis4af23302016-07-19 10:50:30 -060012323TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012324 TEST_DESCRIPTION(
12325 "Bind a secondary command buffer with with a framebuffer "
12326 "that does not match the framebuffer for the active "
12327 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012328 ASSERT_NO_FATAL_FAILURE(InitState());
12329 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12330
12331 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012332 VkAttachmentDescription attachment = {0,
12333 VK_FORMAT_B8G8R8A8_UNORM,
12334 VK_SAMPLE_COUNT_1_BIT,
12335 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12336 VK_ATTACHMENT_STORE_OP_STORE,
12337 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12338 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12339 VK_IMAGE_LAYOUT_UNDEFINED,
12340 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012341
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012342 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012343
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012344 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012346 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012347
12348 VkRenderPass rp;
12349 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12350 ASSERT_VK_SUCCESS(err);
12351
12352 // A compatible framebuffer.
12353 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012354 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 -060012355 ASSERT_TRUE(image.initialized());
12356
12357 VkImageViewCreateInfo ivci = {
12358 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12359 nullptr,
12360 0,
12361 image.handle(),
12362 VK_IMAGE_VIEW_TYPE_2D,
12363 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012364 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12365 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012366 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12367 };
12368 VkImageView view;
12369 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12370 ASSERT_VK_SUCCESS(err);
12371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012372 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012373 VkFramebuffer fb;
12374 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12375 ASSERT_VK_SUCCESS(err);
12376
12377 VkCommandBufferAllocateInfo cbai = {};
12378 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12379 cbai.commandPool = m_commandPool;
12380 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12381 cbai.commandBufferCount = 1;
12382
12383 VkCommandBuffer sec_cb;
12384 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12385 ASSERT_VK_SUCCESS(err);
12386 VkCommandBufferBeginInfo cbbi = {};
12387 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130012388 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060012389 cbii.renderPass = renderPass();
12390 cbii.framebuffer = fb;
12391 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12392 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012393 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 -060012394 cbbi.pInheritanceInfo = &cbii;
12395 vkBeginCommandBuffer(sec_cb, &cbbi);
12396 vkEndCommandBuffer(sec_cb);
12397
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012398 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120012399 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12400 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012401
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012403 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012404 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12405 m_errorMonitor->VerifyFound();
12406 // Cleanup
12407 vkDestroyImageView(m_device->device(), view, NULL);
12408 vkDestroyRenderPass(m_device->device(), rp, NULL);
12409 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12410}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012411
12412TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012413 TEST_DESCRIPTION(
12414 "If logicOp is available on the device, set it to an "
12415 "invalid value. If logicOp is not available, attempt to "
12416 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012417 ASSERT_NO_FATAL_FAILURE(InitState());
12418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12419
12420 auto features = m_device->phy().features();
12421 // Set the expected error depending on whether or not logicOp available
12422 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12424 "If logic operations feature not "
12425 "enabled, logicOpEnable must be "
12426 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012427 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012429 }
12430 // Create a pipeline using logicOp
12431 VkResult err;
12432
12433 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12434 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12435
12436 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012437 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012438 ASSERT_VK_SUCCESS(err);
12439
12440 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12441 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12442 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012443 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012444 vp_state_ci.pViewports = &vp;
12445 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012446 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012447 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012448
12449 VkPipelineShaderStageCreateInfo shaderStages[2];
12450 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12451
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012452 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12453 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012454 shaderStages[0] = vs.GetStageCreateInfo();
12455 shaderStages[1] = fs.GetStageCreateInfo();
12456
12457 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12458 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12459
12460 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12461 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12462 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12463
12464 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12465 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012466 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012467
12468 VkPipelineColorBlendAttachmentState att = {};
12469 att.blendEnable = VK_FALSE;
12470 att.colorWriteMask = 0xf;
12471
12472 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12473 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12474 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12475 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012476 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012477 cb_ci.attachmentCount = 1;
12478 cb_ci.pAttachments = &att;
12479
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012480 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12481 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12482 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12483
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012484 VkGraphicsPipelineCreateInfo gp_ci = {};
12485 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12486 gp_ci.stageCount = 2;
12487 gp_ci.pStages = shaderStages;
12488 gp_ci.pVertexInputState = &vi_ci;
12489 gp_ci.pInputAssemblyState = &ia_ci;
12490 gp_ci.pViewportState = &vp_state_ci;
12491 gp_ci.pRasterizationState = &rs_ci;
12492 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012493 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012494 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12495 gp_ci.layout = pipeline_layout;
12496 gp_ci.renderPass = renderPass();
12497
12498 VkPipelineCacheCreateInfo pc_ci = {};
12499 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12500
12501 VkPipeline pipeline;
12502 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012503 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012504 ASSERT_VK_SUCCESS(err);
12505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012506 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012507 m_errorMonitor->VerifyFound();
12508 if (VK_SUCCESS == err) {
12509 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12510 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012511 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12512 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12513}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012514#endif // DRAW_STATE_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012515
Tobin Ehlis0788f522015-05-26 16:11:58 -060012516#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012517#if GTEST_IS_THREADSAFE
12518struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012519 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012520 VkEvent event;
12521 bool bailout;
12522};
12523
Karl Schultz6addd812016-02-02 17:17:23 -070012524extern "C" void *AddToCommandBuffer(void *arg) {
12525 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012526
Mike Stroyana6d14942016-07-13 15:10:05 -060012527 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012528 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012529 if (data->bailout) {
12530 break;
12531 }
12532 }
12533 return NULL;
12534}
12535
Karl Schultz6addd812016-02-02 17:17:23 -070012536TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012537 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012538
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012540
Mike Stroyanaccf7692015-05-12 16:00:45 -060012541 ASSERT_NO_FATAL_FAILURE(InitState());
12542 ASSERT_NO_FATAL_FAILURE(InitViewport());
12543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12544
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012545 // Calls AllocateCommandBuffers
12546 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012547
12548 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012549 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012550
12551 VkEventCreateInfo event_info;
12552 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012553 VkResult err;
12554
12555 memset(&event_info, 0, sizeof(event_info));
12556 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12557
Chia-I Wuf7458c52015-10-26 21:10:41 +080012558 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012559 ASSERT_VK_SUCCESS(err);
12560
Mike Stroyanaccf7692015-05-12 16:00:45 -060012561 err = vkResetEvent(device(), event);
12562 ASSERT_VK_SUCCESS(err);
12563
12564 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012565 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012566 data.event = event;
12567 data.bailout = false;
12568 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012569
12570 // First do some correct operations using multiple threads.
12571 // Add many entries to command buffer from another thread.
12572 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12573 // Make non-conflicting calls from this thread at the same time.
12574 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012575 uint32_t count;
12576 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012577 }
12578 test_platform_thread_join(thread, NULL);
12579
12580 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012581 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012582 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012583 // Add many entries to command buffer from this thread at the same time.
12584 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012585
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012586 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012587 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012588
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012589 m_errorMonitor->SetBailout(NULL);
12590
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012591 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012592
Chia-I Wuf7458c52015-10-26 21:10:41 +080012593 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012594}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012595#endif // GTEST_IS_THREADSAFE
12596#endif // THREADING_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012597
Chris Forbes9f7ff632015-05-25 11:13:08 +120012598#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012599TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012600 TEST_DESCRIPTION(
12601 "Test that an error is produced for a spirv module "
12602 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120012603
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012605
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012606 ASSERT_NO_FATAL_FAILURE(InitState());
12607 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12608
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012609 VkShaderModule module;
12610 VkShaderModuleCreateInfo moduleCreateInfo;
12611 struct icd_spv_header spv;
12612
12613 spv.magic = ICD_SPV_MAGIC;
12614 spv.version = ICD_SPV_VERSION;
12615 spv.gen_magic = 0;
12616
12617 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12618 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012619 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012620 moduleCreateInfo.codeSize = 4;
12621 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012622 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012623
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012624 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012625}
12626
Karl Schultz6addd812016-02-02 17:17:23 -070012627TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012628 TEST_DESCRIPTION(
12629 "Test that an error is produced for a spirv module "
12630 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120012631
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012633
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012634 ASSERT_NO_FATAL_FAILURE(InitState());
12635 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12636
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012637 VkShaderModule module;
12638 VkShaderModuleCreateInfo moduleCreateInfo;
12639 struct icd_spv_header spv;
12640
12641 spv.magic = ~ICD_SPV_MAGIC;
12642 spv.version = ICD_SPV_VERSION;
12643 spv.gen_magic = 0;
12644
12645 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12646 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012647 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012648 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12649 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012650 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012651
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012652 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012653}
12654
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012655#if 0
12656// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012657TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012659 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012660
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012661 ASSERT_NO_FATAL_FAILURE(InitState());
12662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12663
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012664 VkShaderModule module;
12665 VkShaderModuleCreateInfo moduleCreateInfo;
12666 struct icd_spv_header spv;
12667
12668 spv.magic = ICD_SPV_MAGIC;
12669 spv.version = ~ICD_SPV_VERSION;
12670 spv.gen_magic = 0;
12671
12672 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12673 moduleCreateInfo.pNext = NULL;
12674
Karl Schultz6addd812016-02-02 17:17:23 -070012675 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012676 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12677 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012678 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012679
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012680 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012681}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012682#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012683
Karl Schultz6addd812016-02-02 17:17:23 -070012684TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012685 TEST_DESCRIPTION(
12686 "Test that a warning is produced for a vertex output that "
12687 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012689
Chris Forbes9f7ff632015-05-25 11:13:08 +120012690 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012691 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012692
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012693 char const *vsSource =
12694 "#version 450\n"
12695 "\n"
12696 "layout(location=0) out float x;\n"
12697 "out gl_PerVertex {\n"
12698 " vec4 gl_Position;\n"
12699 "};\n"
12700 "void main(){\n"
12701 " gl_Position = vec4(1);\n"
12702 " x = 0;\n"
12703 "}\n";
12704 char const *fsSource =
12705 "#version 450\n"
12706 "\n"
12707 "layout(location=0) out vec4 color;\n"
12708 "void main(){\n"
12709 " color = vec4(1);\n"
12710 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012711
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012712 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12713 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012714
12715 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012716 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012717 pipe.AddShader(&vs);
12718 pipe.AddShader(&fs);
12719
Chris Forbes9f7ff632015-05-25 11:13:08 +120012720 VkDescriptorSetObj descriptorSet(m_device);
12721 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012722 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012723
Tony Barbour5781e8f2015-08-04 16:23:11 -060012724 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012725
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012726 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012727}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012728
Mark Mueller098c9cb2016-09-08 09:01:57 -060012729TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12730 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12731
12732 ASSERT_NO_FATAL_FAILURE(InitState());
12733 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12734
12735 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012736 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012737
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012738 char const *vsSource =
12739 "#version 450\n"
12740 "\n"
12741 "out gl_PerVertex {\n"
12742 " vec4 gl_Position;\n"
12743 "};\n"
12744 "void main(){\n"
12745 " gl_Position = vec4(1);\n"
12746 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012747
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012748 char const *fsSource =
12749 "#version 450\n"
12750 "\n"
12751 "layout (constant_id = 0) const float r = 0.0f;\n"
12752 "layout(location = 0) out vec4 uFragColor;\n"
12753 "void main(){\n"
12754 " uFragColor = vec4(r,1,0,1);\n"
12755 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012756
12757 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12758 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12759
12760 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12761 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12762
12763 VkPipelineLayout pipeline_layout;
12764 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12765
12766 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12767 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12768 vp_state_create_info.viewportCount = 1;
12769 VkViewport viewport = {};
12770 vp_state_create_info.pViewports = &viewport;
12771 vp_state_create_info.scissorCount = 1;
12772 VkRect2D scissors = {};
12773 vp_state_create_info.pScissors = &scissors;
12774
12775 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12776
12777 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12778 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12779 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12780 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12781
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012782 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060012783
12784 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12785 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12786
12787 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12788 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12789 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12790
12791 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12792 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12793 rasterization_state_create_info.pNext = nullptr;
12794 rasterization_state_create_info.lineWidth = 1.0f;
12795 rasterization_state_create_info.rasterizerDiscardEnable = true;
12796
12797 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12798 color_blend_attachment_state.blendEnable = VK_FALSE;
12799 color_blend_attachment_state.colorWriteMask = 0xf;
12800
12801 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12802 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12803 color_blend_state_create_info.attachmentCount = 1;
12804 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12805
12806 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12807 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12808 graphicspipe_create_info.stageCount = 2;
12809 graphicspipe_create_info.pStages = shader_stage_create_info;
12810 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12811 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12812 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12813 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12814 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12815 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12816 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12817 graphicspipe_create_info.layout = pipeline_layout;
12818 graphicspipe_create_info.renderPass = renderPass();
12819
12820 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12821 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12822
12823 VkPipelineCache pipelineCache;
12824 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12825
12826 // This structure maps constant ids to data locations.
12827 const VkSpecializationMapEntry entry =
12828 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012829 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060012830
12831 uint32_t data = 1;
12832
12833 // Set up the info describing spec map and data
12834 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012835 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060012836 };
12837 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12838
12839 VkPipeline pipeline;
12840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12841 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12842 m_errorMonitor->VerifyFound();
12843
12844 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12845 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12846}
12847
12848TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12849 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12850
12851 ASSERT_NO_FATAL_FAILURE(InitState());
12852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12853
12854 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12855
12856 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12857 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12858 descriptor_pool_type_count[0].descriptorCount = 1;
12859 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12860 descriptor_pool_type_count[1].descriptorCount = 1;
12861
12862 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12863 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12864 descriptor_pool_create_info.maxSets = 1;
12865 descriptor_pool_create_info.poolSizeCount = 2;
12866 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12867 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12868
12869 VkDescriptorPool descriptorset_pool;
12870 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12871
12872 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12873 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12874 descriptorset_layout_binding.descriptorCount = 1;
12875 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12876
12877 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12878 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12879 descriptorset_layout_create_info.bindingCount = 1;
12880 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12881
12882 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012883 ASSERT_VK_SUCCESS(
12884 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060012885
12886 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12887 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12888 descriptorset_allocate_info.descriptorSetCount = 1;
12889 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12890 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12891 VkDescriptorSet descriptorset;
12892 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12893
12894 // Challenge core_validation with a non uniform buffer type.
12895 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12896
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012897 char const *vsSource =
12898 "#version 450\n"
12899 "\n"
12900 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12901 " mat4 mvp;\n"
12902 "} ubuf;\n"
12903 "out gl_PerVertex {\n"
12904 " vec4 gl_Position;\n"
12905 "};\n"
12906 "void main(){\n"
12907 " gl_Position = ubuf.mvp * vec4(1);\n"
12908 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012909
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012910 char const *fsSource =
12911 "#version 450\n"
12912 "\n"
12913 "layout(location = 0) out vec4 uFragColor;\n"
12914 "void main(){\n"
12915 " uFragColor = vec4(0,1,0,1);\n"
12916 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012917
12918 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12919 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12920
12921 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12922 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12923 pipeline_layout_create_info.setLayoutCount = 1;
12924 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12925
12926 VkPipelineLayout pipeline_layout;
12927 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12928
12929 VkPipelineObj pipe(m_device);
12930 pipe.AddColorAttachment();
12931 pipe.AddShader(&vs);
12932 pipe.AddShader(&fs);
12933
12934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12935 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12936 m_errorMonitor->VerifyFound();
12937
12938 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12939 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12940 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12941}
12942
12943TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12944 TEST_DESCRIPTION(
12945 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12946
12947 ASSERT_NO_FATAL_FAILURE(InitState());
12948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12949
12950 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12951
12952 VkDescriptorPoolSize descriptor_pool_type_count = {};
12953 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12954 descriptor_pool_type_count.descriptorCount = 1;
12955
12956 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12957 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12958 descriptor_pool_create_info.maxSets = 1;
12959 descriptor_pool_create_info.poolSizeCount = 1;
12960 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12961 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12962
12963 VkDescriptorPool descriptorset_pool;
12964 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12965
12966 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12967 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12968 descriptorset_layout_binding.descriptorCount = 1;
12969 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12970 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12971
12972 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12973 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12974 descriptorset_layout_create_info.bindingCount = 1;
12975 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12976
12977 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012978 ASSERT_VK_SUCCESS(
12979 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060012980
12981 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12982 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12983 descriptorset_allocate_info.descriptorSetCount = 1;
12984 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12985 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12986 VkDescriptorSet descriptorset;
12987 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12988
12989 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12990
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012991 char const *vsSource =
12992 "#version 450\n"
12993 "\n"
12994 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12995 " mat4 mvp;\n"
12996 "} ubuf;\n"
12997 "out gl_PerVertex {\n"
12998 " vec4 gl_Position;\n"
12999 "};\n"
13000 "void main(){\n"
13001 " gl_Position = ubuf.mvp * vec4(1);\n"
13002 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013003
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013004 char const *fsSource =
13005 "#version 450\n"
13006 "\n"
13007 "layout(location = 0) out vec4 uFragColor;\n"
13008 "void main(){\n"
13009 " uFragColor = vec4(0,1,0,1);\n"
13010 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013011
13012 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13013 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13014
13015 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13016 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13017 pipeline_layout_create_info.setLayoutCount = 1;
13018 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13019
13020 VkPipelineLayout pipeline_layout;
13021 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13022
13023 VkPipelineObj pipe(m_device);
13024 pipe.AddColorAttachment();
13025 pipe.AddShader(&vs);
13026 pipe.AddShader(&fs);
13027
13028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13029 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13030 m_errorMonitor->VerifyFound();
13031
13032 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13033 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13034 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13035}
13036
13037TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013038 TEST_DESCRIPTION(
13039 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13040 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013041
13042 ASSERT_NO_FATAL_FAILURE(InitState());
13043 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13044
13045 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013046 "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 -060013047
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013048 char const *vsSource =
13049 "#version 450\n"
13050 "\n"
13051 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13052 "out gl_PerVertex {\n"
13053 " vec4 gl_Position;\n"
13054 "};\n"
13055 "void main(){\n"
13056 " gl_Position = vec4(consts.x);\n"
13057 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013058
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013059 char const *fsSource =
13060 "#version 450\n"
13061 "\n"
13062 "layout(location = 0) out vec4 uFragColor;\n"
13063 "void main(){\n"
13064 " uFragColor = vec4(0,1,0,1);\n"
13065 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013066
13067 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13068 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13069
13070 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13071 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13072
13073 // Set up a push constant range
13074 VkPushConstantRange push_constant_ranges = {};
13075 // Set to the wrong stage to challenge core_validation
13076 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13077 push_constant_ranges.size = 4;
13078
13079 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13080 pipeline_layout_create_info.pushConstantRangeCount = 1;
13081
13082 VkPipelineLayout pipeline_layout;
13083 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13084
13085 VkPipelineObj pipe(m_device);
13086 pipe.AddColorAttachment();
13087 pipe.AddShader(&vs);
13088 pipe.AddShader(&fs);
13089
13090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13091 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13092 m_errorMonitor->VerifyFound();
13093
13094 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13095}
13096
13097TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13098 TEST_DESCRIPTION(
13099 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13100
13101 ASSERT_NO_FATAL_FAILURE(InitState());
13102 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13103
13104 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013105 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013106
13107 // Some awkward steps are required to test with custom device features.
13108 std::vector<const char *> device_extension_names;
13109 auto features = m_device->phy().features();
13110 // Disable support for 64 bit floats
13111 features.shaderFloat64 = false;
13112 // The sacrificial device object
13113 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13114
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013115 char const *vsSource =
13116 "#version 450\n"
13117 "\n"
13118 "out gl_PerVertex {\n"
13119 " vec4 gl_Position;\n"
13120 "};\n"
13121 "void main(){\n"
13122 " gl_Position = vec4(1);\n"
13123 "}\n";
13124 char const *fsSource =
13125 "#version 450\n"
13126 "\n"
13127 "layout(location=0) out vec4 color;\n"
13128 "void main(){\n"
13129 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13130 " color = vec4(green);\n"
13131 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013132
13133 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13134 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13135
13136 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013137
13138 VkPipelineObj pipe(&test_device);
13139 pipe.AddColorAttachment();
13140 pipe.AddShader(&vs);
13141 pipe.AddShader(&fs);
13142
13143 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13144 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13145 VkPipelineLayout pipeline_layout;
13146 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13147
13148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13149 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13150 m_errorMonitor->VerifyFound();
13151
13152 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13153}
13154
13155TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13156 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13157
13158 ASSERT_NO_FATAL_FAILURE(InitState());
13159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13160
13161 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13162
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013163 char const *vsSource =
13164 "#version 450\n"
13165 "\n"
13166 "out gl_PerVertex {\n"
13167 " vec4 gl_Position;\n"
13168 "};\n"
13169 "layout(xfb_buffer = 1) out;"
13170 "void main(){\n"
13171 " gl_Position = vec4(1);\n"
13172 "}\n";
13173 char const *fsSource =
13174 "#version 450\n"
13175 "\n"
13176 "layout(location=0) out vec4 color;\n"
13177 "void main(){\n"
13178 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13179 " color = vec4(green);\n"
13180 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013181
13182 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13183 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13184
13185 VkPipelineObj pipe(m_device);
13186 pipe.AddColorAttachment();
13187 pipe.AddShader(&vs);
13188 pipe.AddShader(&fs);
13189
13190 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13191 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13192 VkPipelineLayout pipeline_layout;
13193 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13194
13195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13196 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13197 m_errorMonitor->VerifyFound();
13198
13199 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13200}
13201
Karl Schultz6addd812016-02-02 17:17:23 -070013202TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013203 TEST_DESCRIPTION(
13204 "Test that an error is produced for a fragment shader input "
13205 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013206
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013208
Chris Forbes59cb88d2015-05-25 11:13:13 +120013209 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013210 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013211
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013212 char const *vsSource =
13213 "#version 450\n"
13214 "\n"
13215 "out gl_PerVertex {\n"
13216 " vec4 gl_Position;\n"
13217 "};\n"
13218 "void main(){\n"
13219 " gl_Position = vec4(1);\n"
13220 "}\n";
13221 char const *fsSource =
13222 "#version 450\n"
13223 "\n"
13224 "layout(location=0) in float x;\n"
13225 "layout(location=0) out vec4 color;\n"
13226 "void main(){\n"
13227 " color = vec4(x);\n"
13228 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013229
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013230 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13231 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013232
13233 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013234 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013235 pipe.AddShader(&vs);
13236 pipe.AddShader(&fs);
13237
Chris Forbes59cb88d2015-05-25 11:13:13 +120013238 VkDescriptorSetObj descriptorSet(m_device);
13239 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013240 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013241
Tony Barbour5781e8f2015-08-04 16:23:11 -060013242 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013243
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013244 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013245}
13246
Karl Schultz6addd812016-02-02 17:17:23 -070013247TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013248 TEST_DESCRIPTION(
13249 "Test that an error is produced for a fragment shader input "
13250 "within an interace block, which is not present in the outputs "
13251 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013253
13254 ASSERT_NO_FATAL_FAILURE(InitState());
13255 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13256
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013257 char const *vsSource =
13258 "#version 450\n"
13259 "\n"
13260 "out gl_PerVertex {\n"
13261 " vec4 gl_Position;\n"
13262 "};\n"
13263 "void main(){\n"
13264 " gl_Position = vec4(1);\n"
13265 "}\n";
13266 char const *fsSource =
13267 "#version 450\n"
13268 "\n"
13269 "in block { layout(location=0) float x; } ins;\n"
13270 "layout(location=0) out vec4 color;\n"
13271 "void main(){\n"
13272 " color = vec4(ins.x);\n"
13273 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013274
13275 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13276 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13277
13278 VkPipelineObj pipe(m_device);
13279 pipe.AddColorAttachment();
13280 pipe.AddShader(&vs);
13281 pipe.AddShader(&fs);
13282
13283 VkDescriptorSetObj descriptorSet(m_device);
13284 descriptorSet.AppendDummy();
13285 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13286
13287 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13288
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013289 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013290}
13291
Karl Schultz6addd812016-02-02 17:17:23 -070013292TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013293 TEST_DESCRIPTION(
13294 "Test that an error is produced for mismatched array sizes "
13295 "across the vertex->fragment shader interface");
13296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13297 "Type mismatch on location 0.0: 'ptr to "
13298 "output arr[2] of float32' vs 'ptr to "
13299 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013300
13301 ASSERT_NO_FATAL_FAILURE(InitState());
13302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13303
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013304 char const *vsSource =
13305 "#version 450\n"
13306 "\n"
13307 "layout(location=0) out float x[2];\n"
13308 "out gl_PerVertex {\n"
13309 " vec4 gl_Position;\n"
13310 "};\n"
13311 "void main(){\n"
13312 " x[0] = 0; x[1] = 0;\n"
13313 " gl_Position = vec4(1);\n"
13314 "}\n";
13315 char const *fsSource =
13316 "#version 450\n"
13317 "\n"
13318 "layout(location=0) in float x[1];\n"
13319 "layout(location=0) out vec4 color;\n"
13320 "void main(){\n"
13321 " color = vec4(x[0]);\n"
13322 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013323
13324 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13325 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13326
13327 VkPipelineObj pipe(m_device);
13328 pipe.AddColorAttachment();
13329 pipe.AddShader(&vs);
13330 pipe.AddShader(&fs);
13331
13332 VkDescriptorSetObj descriptorSet(m_device);
13333 descriptorSet.AppendDummy();
13334 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13335
13336 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13337
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013338 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013339}
13340
Karl Schultz6addd812016-02-02 17:17:23 -070013341TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013342 TEST_DESCRIPTION(
13343 "Test that an error is produced for mismatched types across "
13344 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013346
Chris Forbesb56af562015-05-25 11:13:17 +120013347 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013348 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013349
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013350 char const *vsSource =
13351 "#version 450\n"
13352 "\n"
13353 "layout(location=0) out int x;\n"
13354 "out gl_PerVertex {\n"
13355 " vec4 gl_Position;\n"
13356 "};\n"
13357 "void main(){\n"
13358 " x = 0;\n"
13359 " gl_Position = vec4(1);\n"
13360 "}\n";
13361 char const *fsSource =
13362 "#version 450\n"
13363 "\n"
13364 "layout(location=0) in float x;\n" /* VS writes int */
13365 "layout(location=0) out vec4 color;\n"
13366 "void main(){\n"
13367 " color = vec4(x);\n"
13368 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013369
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013370 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13371 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013372
13373 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013374 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013375 pipe.AddShader(&vs);
13376 pipe.AddShader(&fs);
13377
Chris Forbesb56af562015-05-25 11:13:17 +120013378 VkDescriptorSetObj descriptorSet(m_device);
13379 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013380 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013381
Tony Barbour5781e8f2015-08-04 16:23:11 -060013382 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013383
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013384 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013385}
13386
Karl Schultz6addd812016-02-02 17:17:23 -070013387TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013388 TEST_DESCRIPTION(
13389 "Test that an error is produced for mismatched types across "
13390 "the vertex->fragment shader interface, when the variable is contained within "
13391 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013393
13394 ASSERT_NO_FATAL_FAILURE(InitState());
13395 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13396
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013397 char const *vsSource =
13398 "#version 450\n"
13399 "\n"
13400 "out block { layout(location=0) int x; } outs;\n"
13401 "out gl_PerVertex {\n"
13402 " vec4 gl_Position;\n"
13403 "};\n"
13404 "void main(){\n"
13405 " outs.x = 0;\n"
13406 " gl_Position = vec4(1);\n"
13407 "}\n";
13408 char const *fsSource =
13409 "#version 450\n"
13410 "\n"
13411 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13412 "layout(location=0) out vec4 color;\n"
13413 "void main(){\n"
13414 " color = vec4(ins.x);\n"
13415 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013416
13417 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13418 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13419
13420 VkPipelineObj pipe(m_device);
13421 pipe.AddColorAttachment();
13422 pipe.AddShader(&vs);
13423 pipe.AddShader(&fs);
13424
13425 VkDescriptorSetObj descriptorSet(m_device);
13426 descriptorSet.AppendDummy();
13427 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13428
13429 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13430
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013431 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013432}
13433
13434TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013435 TEST_DESCRIPTION(
13436 "Test that an error is produced for location mismatches across "
13437 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
13438 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013439 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 +130013440
13441 ASSERT_NO_FATAL_FAILURE(InitState());
13442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13443
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013444 char const *vsSource =
13445 "#version 450\n"
13446 "\n"
13447 "out block { layout(location=1) float x; } outs;\n"
13448 "out gl_PerVertex {\n"
13449 " vec4 gl_Position;\n"
13450 "};\n"
13451 "void main(){\n"
13452 " outs.x = 0;\n"
13453 " gl_Position = vec4(1);\n"
13454 "}\n";
13455 char const *fsSource =
13456 "#version 450\n"
13457 "\n"
13458 "in block { layout(location=0) float x; } ins;\n"
13459 "layout(location=0) out vec4 color;\n"
13460 "void main(){\n"
13461 " color = vec4(ins.x);\n"
13462 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013463
13464 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13465 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13466
13467 VkPipelineObj pipe(m_device);
13468 pipe.AddColorAttachment();
13469 pipe.AddShader(&vs);
13470 pipe.AddShader(&fs);
13471
13472 VkDescriptorSetObj descriptorSet(m_device);
13473 descriptorSet.AppendDummy();
13474 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13475
13476 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13477
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013478 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013479}
13480
13481TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013482 TEST_DESCRIPTION(
13483 "Test that an error is produced for component mismatches across the "
13484 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
13485 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013486 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 +130013487
13488 ASSERT_NO_FATAL_FAILURE(InitState());
13489 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13490
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013491 char const *vsSource =
13492 "#version 450\n"
13493 "\n"
13494 "out block { layout(location=0, component=0) float x; } outs;\n"
13495 "out gl_PerVertex {\n"
13496 " vec4 gl_Position;\n"
13497 "};\n"
13498 "void main(){\n"
13499 " outs.x = 0;\n"
13500 " gl_Position = vec4(1);\n"
13501 "}\n";
13502 char const *fsSource =
13503 "#version 450\n"
13504 "\n"
13505 "in block { layout(location=0, component=1) float x; } ins;\n"
13506 "layout(location=0) out vec4 color;\n"
13507 "void main(){\n"
13508 " color = vec4(ins.x);\n"
13509 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013510
13511 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13512 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13513
13514 VkPipelineObj pipe(m_device);
13515 pipe.AddColorAttachment();
13516 pipe.AddShader(&vs);
13517 pipe.AddShader(&fs);
13518
13519 VkDescriptorSetObj descriptorSet(m_device);
13520 descriptorSet.AppendDummy();
13521 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13522
13523 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13524
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013525 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013526}
13527
Chris Forbes1f3b0152016-11-30 12:48:40 +130013528TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13529 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13530
13531 ASSERT_NO_FATAL_FAILURE(InitState());
13532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13533
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013534 char const *vsSource =
13535 "#version 450\n"
13536 "layout(location=0) out mediump float x;\n"
13537 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13538 char const *fsSource =
13539 "#version 450\n"
13540 "layout(location=0) in highp float x;\n"
13541 "layout(location=0) out vec4 color;\n"
13542 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130013543
13544 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13545 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13546
13547 VkPipelineObj pipe(m_device);
13548 pipe.AddColorAttachment();
13549 pipe.AddShader(&vs);
13550 pipe.AddShader(&fs);
13551
13552 VkDescriptorSetObj descriptorSet(m_device);
13553 descriptorSet.AppendDummy();
13554 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13555
13556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13557
13558 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13559
13560 m_errorMonitor->VerifyFound();
13561}
13562
Chris Forbes870a39e2016-11-30 12:55:56 +130013563TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13564 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13565
13566 ASSERT_NO_FATAL_FAILURE(InitState());
13567 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13568
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013569 char const *vsSource =
13570 "#version 450\n"
13571 "out block { layout(location=0) mediump float x; };\n"
13572 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13573 char const *fsSource =
13574 "#version 450\n"
13575 "in block { layout(location=0) highp float x; };\n"
13576 "layout(location=0) out vec4 color;\n"
13577 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130013578
13579 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13580 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13581
13582 VkPipelineObj pipe(m_device);
13583 pipe.AddColorAttachment();
13584 pipe.AddShader(&vs);
13585 pipe.AddShader(&fs);
13586
13587 VkDescriptorSetObj descriptorSet(m_device);
13588 descriptorSet.AppendDummy();
13589 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13590
13591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13592
13593 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13594
13595 m_errorMonitor->VerifyFound();
13596}
13597
Karl Schultz6addd812016-02-02 17:17:23 -070013598TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013599 TEST_DESCRIPTION(
13600 "Test that a warning is produced for a vertex attribute which is "
13601 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013603
Chris Forbesde136e02015-05-25 11:13:28 +120013604 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013605 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013606
13607 VkVertexInputBindingDescription input_binding;
13608 memset(&input_binding, 0, sizeof(input_binding));
13609
13610 VkVertexInputAttributeDescription input_attrib;
13611 memset(&input_attrib, 0, sizeof(input_attrib));
13612 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13613
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013614 char const *vsSource =
13615 "#version 450\n"
13616 "\n"
13617 "out gl_PerVertex {\n"
13618 " vec4 gl_Position;\n"
13619 "};\n"
13620 "void main(){\n"
13621 " gl_Position = vec4(1);\n"
13622 "}\n";
13623 char const *fsSource =
13624 "#version 450\n"
13625 "\n"
13626 "layout(location=0) out vec4 color;\n"
13627 "void main(){\n"
13628 " color = vec4(1);\n"
13629 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013630
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013631 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13632 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013633
13634 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013635 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013636 pipe.AddShader(&vs);
13637 pipe.AddShader(&fs);
13638
13639 pipe.AddVertexInputBindings(&input_binding, 1);
13640 pipe.AddVertexInputAttribs(&input_attrib, 1);
13641
Chris Forbesde136e02015-05-25 11:13:28 +120013642 VkDescriptorSetObj descriptorSet(m_device);
13643 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013644 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013645
Tony Barbour5781e8f2015-08-04 16:23:11 -060013646 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013647
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013648 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013649}
13650
Karl Schultz6addd812016-02-02 17:17:23 -070013651TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013652 TEST_DESCRIPTION(
13653 "Test that a warning is produced for a location mismatch on "
13654 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013656
13657 ASSERT_NO_FATAL_FAILURE(InitState());
13658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13659
13660 VkVertexInputBindingDescription input_binding;
13661 memset(&input_binding, 0, sizeof(input_binding));
13662
13663 VkVertexInputAttributeDescription input_attrib;
13664 memset(&input_attrib, 0, sizeof(input_attrib));
13665 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13666
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013667 char const *vsSource =
13668 "#version 450\n"
13669 "\n"
13670 "layout(location=1) in float x;\n"
13671 "out gl_PerVertex {\n"
13672 " vec4 gl_Position;\n"
13673 "};\n"
13674 "void main(){\n"
13675 " gl_Position = vec4(x);\n"
13676 "}\n";
13677 char const *fsSource =
13678 "#version 450\n"
13679 "\n"
13680 "layout(location=0) out vec4 color;\n"
13681 "void main(){\n"
13682 " color = vec4(1);\n"
13683 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013684
13685 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13686 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13687
13688 VkPipelineObj pipe(m_device);
13689 pipe.AddColorAttachment();
13690 pipe.AddShader(&vs);
13691 pipe.AddShader(&fs);
13692
13693 pipe.AddVertexInputBindings(&input_binding, 1);
13694 pipe.AddVertexInputAttribs(&input_attrib, 1);
13695
13696 VkDescriptorSetObj descriptorSet(m_device);
13697 descriptorSet.AppendDummy();
13698 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13699
13700 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13701
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013702 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013703}
13704
Karl Schultz6addd812016-02-02 17:17:23 -070013705TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013706 TEST_DESCRIPTION(
13707 "Test that an error is produced for a vertex shader input which is not "
13708 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13710 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013711
Chris Forbes62e8e502015-05-25 11:13:29 +120013712 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013714
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013715 char const *vsSource =
13716 "#version 450\n"
13717 "\n"
13718 "layout(location=0) in vec4 x;\n" /* not provided */
13719 "out gl_PerVertex {\n"
13720 " vec4 gl_Position;\n"
13721 "};\n"
13722 "void main(){\n"
13723 " gl_Position = x;\n"
13724 "}\n";
13725 char const *fsSource =
13726 "#version 450\n"
13727 "\n"
13728 "layout(location=0) out vec4 color;\n"
13729 "void main(){\n"
13730 " color = vec4(1);\n"
13731 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013732
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013733 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13734 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013735
13736 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013737 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013738 pipe.AddShader(&vs);
13739 pipe.AddShader(&fs);
13740
Chris Forbes62e8e502015-05-25 11:13:29 +120013741 VkDescriptorSetObj descriptorSet(m_device);
13742 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013743 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013744
Tony Barbour5781e8f2015-08-04 16:23:11 -060013745 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013746
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013747 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013748}
13749
Karl Schultz6addd812016-02-02 17:17:23 -070013750TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013751 TEST_DESCRIPTION(
13752 "Test that an error is produced for a mismatch between the "
13753 "fundamental type (float/int/uint) of an attribute and the "
13754 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013755 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 -060013756
Chris Forbesc97d98e2015-05-25 11:13:31 +120013757 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013758 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013759
13760 VkVertexInputBindingDescription input_binding;
13761 memset(&input_binding, 0, sizeof(input_binding));
13762
13763 VkVertexInputAttributeDescription input_attrib;
13764 memset(&input_attrib, 0, sizeof(input_attrib));
13765 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13766
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013767 char const *vsSource =
13768 "#version 450\n"
13769 "\n"
13770 "layout(location=0) in int x;\n" /* attrib provided float */
13771 "out gl_PerVertex {\n"
13772 " vec4 gl_Position;\n"
13773 "};\n"
13774 "void main(){\n"
13775 " gl_Position = vec4(x);\n"
13776 "}\n";
13777 char const *fsSource =
13778 "#version 450\n"
13779 "\n"
13780 "layout(location=0) out vec4 color;\n"
13781 "void main(){\n"
13782 " color = vec4(1);\n"
13783 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013784
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013785 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13786 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013787
13788 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013789 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013790 pipe.AddShader(&vs);
13791 pipe.AddShader(&fs);
13792
13793 pipe.AddVertexInputBindings(&input_binding, 1);
13794 pipe.AddVertexInputAttribs(&input_attrib, 1);
13795
Chris Forbesc97d98e2015-05-25 11:13:31 +120013796 VkDescriptorSetObj descriptorSet(m_device);
13797 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013798 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013799
Tony Barbour5781e8f2015-08-04 16:23:11 -060013800 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013801
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013802 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013803}
13804
Chris Forbesc68b43c2016-04-06 11:18:47 +120013805TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013806 TEST_DESCRIPTION(
13807 "Test that an error is produced for a pipeline containing multiple "
13808 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13810 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013811
13812 ASSERT_NO_FATAL_FAILURE(InitState());
13813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13814
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013815 char const *vsSource =
13816 "#version 450\n"
13817 "\n"
13818 "out gl_PerVertex {\n"
13819 " vec4 gl_Position;\n"
13820 "};\n"
13821 "void main(){\n"
13822 " gl_Position = vec4(1);\n"
13823 "}\n";
13824 char const *fsSource =
13825 "#version 450\n"
13826 "\n"
13827 "layout(location=0) out vec4 color;\n"
13828 "void main(){\n"
13829 " color = vec4(1);\n"
13830 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013831
13832 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13833 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13834
13835 VkPipelineObj pipe(m_device);
13836 pipe.AddColorAttachment();
13837 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013838 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013839 pipe.AddShader(&fs);
13840
13841 VkDescriptorSetObj descriptorSet(m_device);
13842 descriptorSet.AppendDummy();
13843 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13844
13845 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13846
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013847 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013848}
13849
Chris Forbes82ff92a2016-09-09 10:50:24 +120013850TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120013852
13853 ASSERT_NO_FATAL_FAILURE(InitState());
13854 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13855
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013856 char const *vsSource =
13857 "#version 450\n"
13858 "out gl_PerVertex {\n"
13859 " vec4 gl_Position;\n"
13860 "};\n"
13861 "void main(){\n"
13862 " gl_Position = vec4(0);\n"
13863 "}\n";
13864 char const *fsSource =
13865 "#version 450\n"
13866 "\n"
13867 "layout(location=0) out vec4 color;\n"
13868 "void main(){\n"
13869 " color = vec4(1);\n"
13870 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120013871
13872 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13873 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13874
13875 VkPipelineObj pipe(m_device);
13876 pipe.AddColorAttachment();
13877 pipe.AddShader(&vs);
13878 pipe.AddShader(&fs);
13879
13880 VkDescriptorSetObj descriptorSet(m_device);
13881 descriptorSet.AppendDummy();
13882 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13883
13884 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13885
13886 m_errorMonitor->VerifyFound();
13887}
13888
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013889TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13891 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13892 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013893
13894 ASSERT_NO_FATAL_FAILURE(InitState());
13895 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13896
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013897 char const *vsSource =
13898 "#version 450\n"
13899 "void main(){ gl_Position = vec4(0); }\n";
13900 char const *fsSource =
13901 "#version 450\n"
13902 "\n"
13903 "layout(location=0) out vec4 color;\n"
13904 "void main(){\n"
13905 " color = vec4(1);\n"
13906 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013907
13908 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13909 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13910
13911 VkPipelineObj pipe(m_device);
13912 pipe.AddColorAttachment();
13913 pipe.AddShader(&vs);
13914 pipe.AddShader(&fs);
13915
13916 VkDescriptorSetObj descriptorSet(m_device);
13917 descriptorSet.AppendDummy();
13918 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13919
13920 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013921 {
13922 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13923 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
13924 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013925 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013926 {
13927 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13928 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
13929 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013930 },
13931 };
13932 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013933 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013934 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013935 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
13936 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013937 VkRenderPass rp;
13938 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13939 ASSERT_VK_SUCCESS(err);
13940
13941 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13942
13943 m_errorMonitor->VerifyFound();
13944
13945 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13946}
13947
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013948TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013949 TEST_DESCRIPTION(
13950 "Test that an error is produced for a variable output from "
13951 "the TCS without the patch decoration, but consumed in the TES "
13952 "with the decoration.");
13953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13954 "is per-vertex in tessellation control shader stage "
13955 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013956
13957 ASSERT_NO_FATAL_FAILURE(InitState());
13958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13959
Chris Forbesc1e852d2016-04-04 19:26:42 +120013960 if (!m_device->phy().features().tessellationShader) {
13961 printf("Device does not support tessellation shaders; skipped.\n");
13962 return;
13963 }
13964
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013965 char const *vsSource =
13966 "#version 450\n"
13967 "void main(){}\n";
13968 char const *tcsSource =
13969 "#version 450\n"
13970 "layout(location=0) out int x[];\n"
13971 "layout(vertices=3) out;\n"
13972 "void main(){\n"
13973 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13974 " gl_TessLevelInner[0] = 1;\n"
13975 " x[gl_InvocationID] = gl_InvocationID;\n"
13976 "}\n";
13977 char const *tesSource =
13978 "#version 450\n"
13979 "layout(triangles, equal_spacing, cw) in;\n"
13980 "layout(location=0) patch in int x;\n"
13981 "out gl_PerVertex { vec4 gl_Position; };\n"
13982 "void main(){\n"
13983 " gl_Position.xyz = gl_TessCoord;\n"
13984 " gl_Position.w = x;\n"
13985 "}\n";
13986 char const *fsSource =
13987 "#version 450\n"
13988 "layout(location=0) out vec4 color;\n"
13989 "void main(){\n"
13990 " color = vec4(1);\n"
13991 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013992
13993 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13994 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13995 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13996 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13997
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013998 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13999 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014001 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014002
14003 VkPipelineObj pipe(m_device);
14004 pipe.SetInputAssembly(&iasci);
14005 pipe.SetTessellation(&tsci);
14006 pipe.AddColorAttachment();
14007 pipe.AddShader(&vs);
14008 pipe.AddShader(&tcs);
14009 pipe.AddShader(&tes);
14010 pipe.AddShader(&fs);
14011
14012 VkDescriptorSetObj descriptorSet(m_device);
14013 descriptorSet.AppendDummy();
14014 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14015
14016 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14017
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014018 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014019}
14020
Karl Schultz6addd812016-02-02 17:17:23 -070014021TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014022 TEST_DESCRIPTION(
14023 "Test that an error is produced for a vertex attribute setup where multiple "
14024 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14026 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014027
Chris Forbes280ba2c2015-06-12 11:16:41 +120014028 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014030
14031 /* Two binding descriptions for binding 0 */
14032 VkVertexInputBindingDescription input_bindings[2];
14033 memset(input_bindings, 0, sizeof(input_bindings));
14034
14035 VkVertexInputAttributeDescription input_attrib;
14036 memset(&input_attrib, 0, sizeof(input_attrib));
14037 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14038
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014039 char const *vsSource =
14040 "#version 450\n"
14041 "\n"
14042 "layout(location=0) in float x;\n" /* attrib provided float */
14043 "out gl_PerVertex {\n"
14044 " vec4 gl_Position;\n"
14045 "};\n"
14046 "void main(){\n"
14047 " gl_Position = vec4(x);\n"
14048 "}\n";
14049 char const *fsSource =
14050 "#version 450\n"
14051 "\n"
14052 "layout(location=0) out vec4 color;\n"
14053 "void main(){\n"
14054 " color = vec4(1);\n"
14055 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014056
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014057 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14058 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014059
14060 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014061 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014062 pipe.AddShader(&vs);
14063 pipe.AddShader(&fs);
14064
14065 pipe.AddVertexInputBindings(input_bindings, 2);
14066 pipe.AddVertexInputAttribs(&input_attrib, 1);
14067
Chris Forbes280ba2c2015-06-12 11:16:41 +120014068 VkDescriptorSetObj descriptorSet(m_device);
14069 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014070 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014071
Tony Barbour5781e8f2015-08-04 16:23:11 -060014072 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014073
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014074 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014075}
Chris Forbes8f68b562015-05-25 11:13:32 +120014076
Karl Schultz6addd812016-02-02 17:17:23 -070014077TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014078 TEST_DESCRIPTION(
14079 "Test that an error is produced for a fragment shader which does not "
14080 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014082
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014083 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014084
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014085 char const *vsSource =
14086 "#version 450\n"
14087 "\n"
14088 "out gl_PerVertex {\n"
14089 " vec4 gl_Position;\n"
14090 "};\n"
14091 "void main(){\n"
14092 " gl_Position = vec4(1);\n"
14093 "}\n";
14094 char const *fsSource =
14095 "#version 450\n"
14096 "\n"
14097 "void main(){\n"
14098 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014099
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014100 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14101 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014102
14103 VkPipelineObj pipe(m_device);
14104 pipe.AddShader(&vs);
14105 pipe.AddShader(&fs);
14106
Chia-I Wu08accc62015-07-07 11:50:03 +080014107 /* set up CB 0, not written */
14108 pipe.AddColorAttachment();
14109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014110
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014111 VkDescriptorSetObj descriptorSet(m_device);
14112 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014113 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014114
Tony Barbour5781e8f2015-08-04 16:23:11 -060014115 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014116
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014117 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014118}
14119
Karl Schultz6addd812016-02-02 17:17:23 -070014120TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014121 TEST_DESCRIPTION(
14122 "Test that a warning is produced for a fragment shader which provides a spurious "
14123 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014125 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014126
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014127 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014128
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014129 char const *vsSource =
14130 "#version 450\n"
14131 "\n"
14132 "out gl_PerVertex {\n"
14133 " vec4 gl_Position;\n"
14134 "};\n"
14135 "void main(){\n"
14136 " gl_Position = vec4(1);\n"
14137 "}\n";
14138 char const *fsSource =
14139 "#version 450\n"
14140 "\n"
14141 "layout(location=0) out vec4 x;\n"
14142 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14143 "void main(){\n"
14144 " x = vec4(1);\n"
14145 " y = vec4(1);\n"
14146 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014147
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014148 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14149 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014150
14151 VkPipelineObj pipe(m_device);
14152 pipe.AddShader(&vs);
14153 pipe.AddShader(&fs);
14154
Chia-I Wu08accc62015-07-07 11:50:03 +080014155 /* set up CB 0, not written */
14156 pipe.AddColorAttachment();
14157 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014158 /* FS writes CB 1, but we don't configure it */
14159
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014160 VkDescriptorSetObj descriptorSet(m_device);
14161 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014162 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014163
Tony Barbour5781e8f2015-08-04 16:23:11 -060014164 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014165
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014166 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014167}
14168
Karl Schultz6addd812016-02-02 17:17:23 -070014169TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014170 TEST_DESCRIPTION(
14171 "Test that an error is produced for a mismatch between the fundamental "
14172 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014174
Chris Forbesa36d69e2015-05-25 11:13:44 +120014175 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014176
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014177 char const *vsSource =
14178 "#version 450\n"
14179 "\n"
14180 "out gl_PerVertex {\n"
14181 " vec4 gl_Position;\n"
14182 "};\n"
14183 "void main(){\n"
14184 " gl_Position = vec4(1);\n"
14185 "}\n";
14186 char const *fsSource =
14187 "#version 450\n"
14188 "\n"
14189 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14190 "void main(){\n"
14191 " x = ivec4(1);\n"
14192 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014193
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014194 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14195 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014196
14197 VkPipelineObj pipe(m_device);
14198 pipe.AddShader(&vs);
14199 pipe.AddShader(&fs);
14200
Chia-I Wu08accc62015-07-07 11:50:03 +080014201 /* set up CB 0; type is UNORM by default */
14202 pipe.AddColorAttachment();
14203 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014204
Chris Forbesa36d69e2015-05-25 11:13:44 +120014205 VkDescriptorSetObj descriptorSet(m_device);
14206 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014207 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014208
Tony Barbour5781e8f2015-08-04 16:23:11 -060014209 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014210
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014211 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014212}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014213
Karl Schultz6addd812016-02-02 17:17:23 -070014214TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014215 TEST_DESCRIPTION(
14216 "Test that an error is produced for a shader consuming a uniform "
14217 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014219
Chris Forbes556c76c2015-08-14 12:04:59 +120014220 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014221
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014222 char const *vsSource =
14223 "#version 450\n"
14224 "\n"
14225 "out gl_PerVertex {\n"
14226 " vec4 gl_Position;\n"
14227 "};\n"
14228 "void main(){\n"
14229 " gl_Position = vec4(1);\n"
14230 "}\n";
14231 char const *fsSource =
14232 "#version 450\n"
14233 "\n"
14234 "layout(location=0) out vec4 x;\n"
14235 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14236 "void main(){\n"
14237 " x = vec4(bar.y);\n"
14238 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014239
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014240 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14241 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014242
Chris Forbes556c76c2015-08-14 12:04:59 +120014243 VkPipelineObj pipe(m_device);
14244 pipe.AddShader(&vs);
14245 pipe.AddShader(&fs);
14246
14247 /* set up CB 0; type is UNORM by default */
14248 pipe.AddColorAttachment();
14249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14250
14251 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014252 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014253
14254 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14255
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014256 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014257}
14258
Chris Forbes5c59e902016-02-26 16:56:09 +130014259TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014260 TEST_DESCRIPTION(
14261 "Test that an error is produced for a shader consuming push constants "
14262 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014264
14265 ASSERT_NO_FATAL_FAILURE(InitState());
14266
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014267 char const *vsSource =
14268 "#version 450\n"
14269 "\n"
14270 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14271 "out gl_PerVertex {\n"
14272 " vec4 gl_Position;\n"
14273 "};\n"
14274 "void main(){\n"
14275 " gl_Position = vec4(consts.x);\n"
14276 "}\n";
14277 char const *fsSource =
14278 "#version 450\n"
14279 "\n"
14280 "layout(location=0) out vec4 x;\n"
14281 "void main(){\n"
14282 " x = vec4(1);\n"
14283 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014284
14285 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14286 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14287
14288 VkPipelineObj pipe(m_device);
14289 pipe.AddShader(&vs);
14290 pipe.AddShader(&fs);
14291
14292 /* set up CB 0; type is UNORM by default */
14293 pipe.AddColorAttachment();
14294 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14295
14296 VkDescriptorSetObj descriptorSet(m_device);
14297 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14298
14299 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14300
14301 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014302 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014303}
14304
Chris Forbes3fb17902016-08-22 14:57:55 +120014305TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014306 TEST_DESCRIPTION(
14307 "Test that an error is produced for a shader consuming an input attachment "
14308 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14310 "consumes input attachment index 0 but not provided in subpass");
14311
14312 ASSERT_NO_FATAL_FAILURE(InitState());
14313
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014314 char const *vsSource =
14315 "#version 450\n"
14316 "\n"
14317 "out gl_PerVertex {\n"
14318 " vec4 gl_Position;\n"
14319 "};\n"
14320 "void main(){\n"
14321 " gl_Position = vec4(1);\n"
14322 "}\n";
14323 char const *fsSource =
14324 "#version 450\n"
14325 "\n"
14326 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14327 "layout(location=0) out vec4 color;\n"
14328 "void main() {\n"
14329 " color = subpassLoad(x);\n"
14330 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014331
14332 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14333 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14334
14335 VkPipelineObj pipe(m_device);
14336 pipe.AddShader(&vs);
14337 pipe.AddShader(&fs);
14338 pipe.AddColorAttachment();
14339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014341 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14342 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014343 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014344 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014345 ASSERT_VK_SUCCESS(err);
14346
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014347 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014348 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014349 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014350 ASSERT_VK_SUCCESS(err);
14351
14352 // error here.
14353 pipe.CreateVKPipeline(pl, renderPass());
14354
14355 m_errorMonitor->VerifyFound();
14356
14357 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14358 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14359}
14360
Chris Forbes5a9a0472016-08-22 16:02:09 +120014361TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014362 TEST_DESCRIPTION(
14363 "Test that an error is produced for a shader consuming an input attachment "
14364 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120014365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14366 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14367
14368 ASSERT_NO_FATAL_FAILURE(InitState());
14369
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014370 char const *vsSource =
14371 "#version 450\n"
14372 "\n"
14373 "out gl_PerVertex {\n"
14374 " vec4 gl_Position;\n"
14375 "};\n"
14376 "void main(){\n"
14377 " gl_Position = vec4(1);\n"
14378 "}\n";
14379 char const *fsSource =
14380 "#version 450\n"
14381 "\n"
14382 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14383 "layout(location=0) out vec4 color;\n"
14384 "void main() {\n"
14385 " color = subpassLoad(x);\n"
14386 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014387
14388 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14389 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14390
14391 VkPipelineObj pipe(m_device);
14392 pipe.AddShader(&vs);
14393 pipe.AddShader(&fs);
14394 pipe.AddColorAttachment();
14395 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14396
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014397 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14398 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014399 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014400 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014401 ASSERT_VK_SUCCESS(err);
14402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014403 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014404 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014405 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014406 ASSERT_VK_SUCCESS(err);
14407
14408 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014409 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14410 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14411 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14412 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14413 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 +120014414 };
14415 VkAttachmentReference color = {
14416 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14417 };
14418 VkAttachmentReference input = {
14419 1, VK_IMAGE_LAYOUT_GENERAL,
14420 };
14421
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014422 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014423
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014424 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014425 VkRenderPass rp;
14426 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14427 ASSERT_VK_SUCCESS(err);
14428
14429 // error here.
14430 pipe.CreateVKPipeline(pl, rp);
14431
14432 m_errorMonitor->VerifyFound();
14433
14434 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14435 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14436 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14437}
14438
Chris Forbes541f7b02016-08-22 15:30:27 +120014439TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014440 TEST_DESCRIPTION(
14441 "Test that an error is produced for a shader consuming an input attachment "
14442 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120014443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070014444 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120014445
14446 ASSERT_NO_FATAL_FAILURE(InitState());
14447
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014448 char const *vsSource =
14449 "#version 450\n"
14450 "\n"
14451 "out gl_PerVertex {\n"
14452 " vec4 gl_Position;\n"
14453 "};\n"
14454 "void main(){\n"
14455 " gl_Position = vec4(1);\n"
14456 "}\n";
14457 char const *fsSource =
14458 "#version 450\n"
14459 "\n"
14460 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
14461 "layout(location=0) out vec4 color;\n"
14462 "void main() {\n"
14463 " color = subpassLoad(xs[0]);\n"
14464 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014465
14466 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14467 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14468
14469 VkPipelineObj pipe(m_device);
14470 pipe.AddShader(&vs);
14471 pipe.AddShader(&fs);
14472 pipe.AddColorAttachment();
14473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14474
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014475 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14476 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014477 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014478 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014479 ASSERT_VK_SUCCESS(err);
14480
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014481 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014482 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014483 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014484 ASSERT_VK_SUCCESS(err);
14485
14486 // error here.
14487 pipe.CreateVKPipeline(pl, renderPass());
14488
14489 m_errorMonitor->VerifyFound();
14490
14491 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14492 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14493}
14494
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014495TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014496 TEST_DESCRIPTION(
14497 "Test that an error is produced for a compute pipeline consuming a "
14498 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014500
14501 ASSERT_NO_FATAL_FAILURE(InitState());
14502
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014503 char const *csSource =
14504 "#version 450\n"
14505 "\n"
14506 "layout(local_size_x=1) in;\n"
14507 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14508 "void main(){\n"
14509 " x = vec4(1);\n"
14510 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014511
14512 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14513
14514 VkDescriptorSetObj descriptorSet(m_device);
14515 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014517 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14518 nullptr,
14519 0,
14520 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14521 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14522 descriptorSet.GetPipelineLayout(),
14523 VK_NULL_HANDLE,
14524 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014525
14526 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014527 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014528
14529 m_errorMonitor->VerifyFound();
14530
14531 if (err == VK_SUCCESS) {
14532 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14533 }
14534}
14535
Chris Forbes22a9b092016-07-19 14:34:05 +120014536TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014537 TEST_DESCRIPTION(
14538 "Test that an error is produced for a pipeline consuming a "
14539 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14541 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014542
14543 ASSERT_NO_FATAL_FAILURE(InitState());
14544
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014545 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14546 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014547 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014548 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014549 ASSERT_VK_SUCCESS(err);
14550
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014551 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014552 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014553 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014554 ASSERT_VK_SUCCESS(err);
14555
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014556 char const *csSource =
14557 "#version 450\n"
14558 "\n"
14559 "layout(local_size_x=1) in;\n"
14560 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14561 "void main() {\n"
14562 " x.x = 1.0f;\n"
14563 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014564 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14565
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014566 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14567 nullptr,
14568 0,
14569 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14570 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14571 pl,
14572 VK_NULL_HANDLE,
14573 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014574
14575 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014576 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014577
14578 m_errorMonitor->VerifyFound();
14579
14580 if (err == VK_SUCCESS) {
14581 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14582 }
14583
14584 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14585 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14586}
14587
Chris Forbes50020592016-07-27 13:52:41 +120014588TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014589 TEST_DESCRIPTION(
14590 "Test that an error is produced when an image view type "
14591 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120014592
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014593 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 +120014594
14595 ASSERT_NO_FATAL_FAILURE(InitState());
14596 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14597
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014598 char const *vsSource =
14599 "#version 450\n"
14600 "\n"
14601 "out gl_PerVertex { vec4 gl_Position; };\n"
14602 "void main() { gl_Position = vec4(0); }\n";
14603 char const *fsSource =
14604 "#version 450\n"
14605 "\n"
14606 "layout(set=0, binding=0) uniform sampler3D s;\n"
14607 "layout(location=0) out vec4 color;\n"
14608 "void main() {\n"
14609 " color = texture(s, vec3(0));\n"
14610 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014611 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14612 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14613
14614 VkPipelineObj pipe(m_device);
14615 pipe.AddShader(&vs);
14616 pipe.AddShader(&fs);
14617 pipe.AddColorAttachment();
14618
14619 VkTextureObj texture(m_device, nullptr);
14620 VkSamplerObj sampler(m_device);
14621
14622 VkDescriptorSetObj descriptorSet(m_device);
14623 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14624 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14625
14626 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14627 ASSERT_VK_SUCCESS(err);
14628
Tony Barbour552f6c02016-12-21 14:34:07 -070014629 m_commandBuffer->BeginCommandBuffer();
14630 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014631
14632 m_commandBuffer->BindPipeline(pipe);
14633 m_commandBuffer->BindDescriptorSet(descriptorSet);
14634
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014635 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014636 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014637 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014638 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14639
14640 // error produced here.
14641 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14642
14643 m_errorMonitor->VerifyFound();
14644
Tony Barbour552f6c02016-12-21 14:34:07 -070014645 m_commandBuffer->EndRenderPass();
14646 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014647}
14648
Chris Forbes5533bfc2016-07-27 14:12:34 +120014649TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014650 TEST_DESCRIPTION(
14651 "Test that an error is produced when a multisampled images "
14652 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014655
14656 ASSERT_NO_FATAL_FAILURE(InitState());
14657 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14658
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014659 char const *vsSource =
14660 "#version 450\n"
14661 "\n"
14662 "out gl_PerVertex { vec4 gl_Position; };\n"
14663 "void main() { gl_Position = vec4(0); }\n";
14664 char const *fsSource =
14665 "#version 450\n"
14666 "\n"
14667 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14668 "layout(location=0) out vec4 color;\n"
14669 "void main() {\n"
14670 " color = texelFetch(s, ivec2(0), 0);\n"
14671 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014672 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14673 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14674
14675 VkPipelineObj pipe(m_device);
14676 pipe.AddShader(&vs);
14677 pipe.AddShader(&fs);
14678 pipe.AddColorAttachment();
14679
14680 VkTextureObj texture(m_device, nullptr);
14681 VkSamplerObj sampler(m_device);
14682
14683 VkDescriptorSetObj descriptorSet(m_device);
14684 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14685 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14686
14687 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14688 ASSERT_VK_SUCCESS(err);
14689
Tony Barbour552f6c02016-12-21 14:34:07 -070014690 m_commandBuffer->BeginCommandBuffer();
14691 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014692
14693 m_commandBuffer->BindPipeline(pipe);
14694 m_commandBuffer->BindDescriptorSet(descriptorSet);
14695
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014696 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014697 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014698 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014699 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14700
14701 // error produced here.
14702 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14703
14704 m_errorMonitor->VerifyFound();
14705
Tony Barbour552f6c02016-12-21 14:34:07 -070014706 m_commandBuffer->EndRenderPass();
14707 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014708}
14709
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014710#endif // SHADER_CHECKER_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014711
14712#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014713TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014715
14716 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014717
14718 // Create an image
14719 VkImage image;
14720
Karl Schultz6addd812016-02-02 17:17:23 -070014721 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14722 const int32_t tex_width = 32;
14723 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014724
14725 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014726 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14727 image_create_info.pNext = NULL;
14728 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14729 image_create_info.format = tex_format;
14730 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014731 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014732 image_create_info.extent.depth = 1;
14733 image_create_info.mipLevels = 1;
14734 image_create_info.arrayLayers = 1;
14735 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14736 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14737 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14738 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014739
14740 // Introduce error by sending down a bogus width extent
14741 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014742 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014743
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014744 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014745}
14746
Mark Youngc48c4c12016-04-11 14:26:49 -060014747TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070014748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060014749
14750 ASSERT_NO_FATAL_FAILURE(InitState());
14751
14752 // Create an image
14753 VkImage image;
14754
14755 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14756 const int32_t tex_width = 32;
14757 const int32_t tex_height = 32;
14758
14759 VkImageCreateInfo image_create_info = {};
14760 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14761 image_create_info.pNext = NULL;
14762 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14763 image_create_info.format = tex_format;
14764 image_create_info.extent.width = tex_width;
14765 image_create_info.extent.height = tex_height;
14766 image_create_info.extent.depth = 1;
14767 image_create_info.mipLevels = 1;
14768 image_create_info.arrayLayers = 1;
14769 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14770 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14771 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14772 image_create_info.flags = 0;
14773
14774 // Introduce error by sending down a bogus width extent
14775 image_create_info.extent.width = 0;
14776 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14777
14778 m_errorMonitor->VerifyFound();
14779}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014780#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014781
Tobin Ehliscde08892015-09-22 10:11:37 -060014782#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014783
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014784TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014785 TEST_DESCRIPTION(
14786 "Create a render pass with an attachment description "
14787 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014788
14789 ASSERT_NO_FATAL_FAILURE(InitState());
14790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14791
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014793
14794 VkAttachmentReference color_attach = {};
14795 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14796 color_attach.attachment = 0;
14797 VkSubpassDescription subpass = {};
14798 subpass.colorAttachmentCount = 1;
14799 subpass.pColorAttachments = &color_attach;
14800
14801 VkRenderPassCreateInfo rpci = {};
14802 rpci.subpassCount = 1;
14803 rpci.pSubpasses = &subpass;
14804 rpci.attachmentCount = 1;
14805 VkAttachmentDescription attach_desc = {};
14806 attach_desc.format = VK_FORMAT_UNDEFINED;
14807 rpci.pAttachments = &attach_desc;
14808 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14809 VkRenderPass rp;
14810 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14811
14812 m_errorMonitor->VerifyFound();
14813
14814 if (result == VK_SUCCESS) {
14815 vkDestroyRenderPass(m_device->device(), rp, NULL);
14816 }
14817}
14818
Karl Schultz6addd812016-02-02 17:17:23 -070014819TEST_F(VkLayerTest, InvalidImageView) {
14820 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014821
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014823
Tobin Ehliscde08892015-09-22 10:11:37 -060014824 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014825
Mike Stroyana3082432015-09-25 13:39:21 -060014826 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014827 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014828
Karl Schultz6addd812016-02-02 17:17:23 -070014829 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14830 const int32_t tex_width = 32;
14831 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014832
14833 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014834 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14835 image_create_info.pNext = NULL;
14836 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14837 image_create_info.format = tex_format;
14838 image_create_info.extent.width = tex_width;
14839 image_create_info.extent.height = tex_height;
14840 image_create_info.extent.depth = 1;
14841 image_create_info.mipLevels = 1;
14842 image_create_info.arrayLayers = 1;
14843 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14844 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14845 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14846 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014847
Chia-I Wuf7458c52015-10-26 21:10:41 +080014848 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014849 ASSERT_VK_SUCCESS(err);
14850
14851 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014852 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014853 image_view_create_info.image = image;
14854 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14855 image_view_create_info.format = tex_format;
14856 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014857 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070014858 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014859 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014860
14861 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014862 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014863
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014864 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014865 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014866}
Mike Stroyana3082432015-09-25 13:39:21 -060014867
Mark Youngd339ba32016-05-30 13:28:35 -060014868TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14869 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014871 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014872
14873 ASSERT_NO_FATAL_FAILURE(InitState());
14874
14875 // Create an image and try to create a view with no memory backing the image
14876 VkImage image;
14877
14878 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14879 const int32_t tex_width = 32;
14880 const int32_t tex_height = 32;
14881
14882 VkImageCreateInfo image_create_info = {};
14883 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14884 image_create_info.pNext = NULL;
14885 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14886 image_create_info.format = tex_format;
14887 image_create_info.extent.width = tex_width;
14888 image_create_info.extent.height = tex_height;
14889 image_create_info.extent.depth = 1;
14890 image_create_info.mipLevels = 1;
14891 image_create_info.arrayLayers = 1;
14892 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14893 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14894 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14895 image_create_info.flags = 0;
14896
14897 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14898 ASSERT_VK_SUCCESS(err);
14899
14900 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014901 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014902 image_view_create_info.image = image;
14903 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14904 image_view_create_info.format = tex_format;
14905 image_view_create_info.subresourceRange.layerCount = 1;
14906 image_view_create_info.subresourceRange.baseMipLevel = 0;
14907 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014908 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014909
14910 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014911 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014912
14913 m_errorMonitor->VerifyFound();
14914 vkDestroyImage(m_device->device(), image, NULL);
14915 // If last error is success, it still created the view, so delete it.
14916 if (err == VK_SUCCESS) {
14917 vkDestroyImageView(m_device->device(), view, NULL);
14918 }
Mark Youngd339ba32016-05-30 13:28:35 -060014919}
14920
Karl Schultz6addd812016-02-02 17:17:23 -070014921TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014922 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014924
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014925 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014926
Karl Schultz6addd812016-02-02 17:17:23 -070014927 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014928 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014929 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014930 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014931
14932 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014933 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014934 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014935 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14936 image_view_create_info.format = tex_format;
14937 image_view_create_info.subresourceRange.baseMipLevel = 0;
14938 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014939 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014940 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014941 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014942
14943 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014944 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014945
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014946 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014947}
14948
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014949TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014950 VkResult err;
14951 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014952
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014954
Mike Stroyana3082432015-09-25 13:39:21 -060014955 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014956
14957 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014958 VkImage srcImage;
14959 VkImage dstImage;
14960 VkDeviceMemory srcMem;
14961 VkDeviceMemory destMem;
14962 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014963
14964 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014965 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14966 image_create_info.pNext = NULL;
14967 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14968 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14969 image_create_info.extent.width = 32;
14970 image_create_info.extent.height = 32;
14971 image_create_info.extent.depth = 1;
14972 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014973 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014974 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14975 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14976 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14977 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014978
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014979 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014980 ASSERT_VK_SUCCESS(err);
14981
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014982 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014983 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014984 ASSERT_VK_SUCCESS(err);
14985
14986 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014987 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014988 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14989 memAlloc.pNext = NULL;
14990 memAlloc.allocationSize = 0;
14991 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014992
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014993 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014994 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014995 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014996 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014997 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014998 ASSERT_VK_SUCCESS(err);
14999
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015000 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015001 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015002 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015003 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015004 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015005 ASSERT_VK_SUCCESS(err);
15006
15007 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15008 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015009 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015010 ASSERT_VK_SUCCESS(err);
15011
Tony Barbour552f6c02016-12-21 14:34:07 -070015012 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015013 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015014 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015015 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015016 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015017 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015018 copyRegion.srcOffset.x = 0;
15019 copyRegion.srcOffset.y = 0;
15020 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015021 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015022 copyRegion.dstSubresource.mipLevel = 0;
15023 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015024 // Introduce failure by forcing the dst layerCount to differ from src
15025 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015026 copyRegion.dstOffset.x = 0;
15027 copyRegion.dstOffset.y = 0;
15028 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015029 copyRegion.extent.width = 1;
15030 copyRegion.extent.height = 1;
15031 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015032 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015033 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015034
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015035 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015036
Chia-I Wuf7458c52015-10-26 21:10:41 +080015037 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015038 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015039 vkFreeMemory(m_device->device(), srcMem, NULL);
15040 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015041}
15042
Tony Barbourd6673642016-05-05 14:46:39 -060015043TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015044 TEST_DESCRIPTION("Creating images with unsuported formats ");
15045
15046 ASSERT_NO_FATAL_FAILURE(InitState());
15047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15048 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015049 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 -060015050 VK_IMAGE_TILING_OPTIMAL, 0);
15051 ASSERT_TRUE(image.initialized());
15052
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015053 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015054 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015055 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015056 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15057 image_create_info.format = VK_FORMAT_UNDEFINED;
15058 image_create_info.extent.width = 32;
15059 image_create_info.extent.height = 32;
15060 image_create_info.extent.depth = 1;
15061 image_create_info.mipLevels = 1;
15062 image_create_info.arrayLayers = 1;
15063 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15064 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15065 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15068 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015069
15070 VkImage localImage;
15071 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15072 m_errorMonitor->VerifyFound();
15073
Tony Barbourd6673642016-05-05 14:46:39 -060015074 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015075 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015076 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15077 VkFormat format = static_cast<VkFormat>(f);
15078 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015079 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015080 unsupported = format;
15081 break;
15082 }
15083 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015084
Tony Barbourd6673642016-05-05 14:46:39 -060015085 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015086 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015088
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015089 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015090 m_errorMonitor->VerifyFound();
15091 }
15092}
15093
15094TEST_F(VkLayerTest, ImageLayerViewTests) {
15095 VkResult ret;
15096 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15097
15098 ASSERT_NO_FATAL_FAILURE(InitState());
15099
15100 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015101 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 -060015102 VK_IMAGE_TILING_OPTIMAL, 0);
15103 ASSERT_TRUE(image.initialized());
15104
15105 VkImageView imgView;
15106 VkImageViewCreateInfo imgViewInfo = {};
15107 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15108 imgViewInfo.image = image.handle();
15109 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15110 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15111 imgViewInfo.subresourceRange.layerCount = 1;
15112 imgViewInfo.subresourceRange.baseMipLevel = 0;
15113 imgViewInfo.subresourceRange.levelCount = 1;
15114 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15115
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015117 // View can't have baseMipLevel >= image's mipLevels - Expect
15118 // VIEW_CREATE_ERROR
15119 imgViewInfo.subresourceRange.baseMipLevel = 1;
15120 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15121 m_errorMonitor->VerifyFound();
15122 imgViewInfo.subresourceRange.baseMipLevel = 0;
15123
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015125 // View can't have baseArrayLayer >= image's arraySize - Expect
15126 // VIEW_CREATE_ERROR
15127 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15128 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15129 m_errorMonitor->VerifyFound();
15130 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15131
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015132 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015133 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15134 imgViewInfo.subresourceRange.levelCount = 0;
15135 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15136 m_errorMonitor->VerifyFound();
15137 imgViewInfo.subresourceRange.levelCount = 1;
15138
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015139 m_errorMonitor->SetDesiredFailureMsg(
15140 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15141 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015142 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15143 imgViewInfo.subresourceRange.layerCount = 0;
15144 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15145 m_errorMonitor->VerifyFound();
15146 imgViewInfo.subresourceRange.layerCount = 1;
15147
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15149 "Formats MUST be IDENTICAL unless "
15150 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15151 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015152 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15153 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15154 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15155 m_errorMonitor->VerifyFound();
15156 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15157
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015159 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15160 // VIEW_CREATE_ERROR
15161 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15162 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15163 m_errorMonitor->VerifyFound();
15164 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15165
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015167 // TODO: Update framework to easily passing mutable flag into ImageObj init
15168 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015169 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15170 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15171 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015172 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15173 // VIEW_CREATE_ERROR
15174 VkImageCreateInfo mutImgInfo = image.create_info();
15175 VkImage mutImage;
15176 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015177 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015178 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15179 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15180 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15181 ASSERT_VK_SUCCESS(ret);
15182 imgViewInfo.image = mutImage;
15183 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15184 m_errorMonitor->VerifyFound();
15185 imgViewInfo.image = image.handle();
15186 vkDestroyImage(m_device->handle(), mutImage, NULL);
15187}
15188
15189TEST_F(VkLayerTest, MiscImageLayerTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060015190 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15191
15192 ASSERT_NO_FATAL_FAILURE(InitState());
15193
Rene Lindsay135204f2016-12-22 17:11:09 -070015194 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060015195 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070015196 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 -070015197 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060015198 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060015199 vk_testing::Buffer buffer;
15200 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070015201 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060015202 VkBufferImageCopy region = {};
15203 region.bufferRowLength = 128;
15204 region.bufferImageHeight = 128;
15205 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15206 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070015207 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015208 region.imageExtent.height = 4;
15209 region.imageExtent.width = 4;
15210 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070015211
15212 VkImageObj image2(m_device);
15213 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 -070015214 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070015215 ASSERT_TRUE(image2.initialized());
15216 vk_testing::Buffer buffer2;
15217 VkMemoryPropertyFlags reqs2 = 0;
15218 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
15219 VkBufferImageCopy region2 = {};
15220 region2.bufferRowLength = 128;
15221 region2.bufferImageHeight = 128;
15222 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15223 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15224 region2.imageSubresource.layerCount = 1;
15225 region2.imageExtent.height = 4;
15226 region2.imageExtent.width = 4;
15227 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015228 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060015229
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015230 // Image must have offset.z of 0 and extent.depth of 1
15231 // Introduce failure by setting imageExtent.depth to 0
15232 region.imageExtent.depth = 0;
15233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15234 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015235 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015236 m_errorMonitor->VerifyFound();
15237
15238 region.imageExtent.depth = 1;
15239
15240 // Image must have offset.z of 0 and extent.depth of 1
15241 // Introduce failure by setting imageOffset.z to 4
15242 region.imageOffset.z = 4;
15243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15244 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015245 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015246 m_errorMonitor->VerifyFound();
15247
15248 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015249 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15250 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070015251 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015253 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15254 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015255 m_errorMonitor->VerifyFound();
15256
15257 // BufferOffset must be a multiple of 4
15258 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070015259 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070015261 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
15262 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015263 m_errorMonitor->VerifyFound();
15264
15265 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15266 region.bufferOffset = 0;
15267 region.imageExtent.height = 128;
15268 region.imageExtent.width = 128;
15269 // Introduce failure by setting bufferRowLength > 0 but less than width
15270 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015272 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15273 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015274 m_errorMonitor->VerifyFound();
15275
15276 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15277 region.bufferRowLength = 128;
15278 // Introduce failure by setting bufferRowHeight > 0 but less than height
15279 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015281 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15282 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015283 m_errorMonitor->VerifyFound();
15284
15285 region.bufferImageHeight = 128;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15287 "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015288 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060015289 // Expect INVALID_FILTER
15290 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015291 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
15292 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015293 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015294 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15295 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015296 VkImageBlit blitRegion = {};
15297 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15298 blitRegion.srcSubresource.baseArrayLayer = 0;
15299 blitRegion.srcSubresource.layerCount = 1;
15300 blitRegion.srcSubresource.mipLevel = 0;
15301 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15302 blitRegion.dstSubresource.baseArrayLayer = 0;
15303 blitRegion.dstSubresource.layerCount = 1;
15304 blitRegion.dstSubresource.mipLevel = 0;
15305
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015306 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015307 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060015308 m_errorMonitor->VerifyFound();
15309
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015310 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
15312 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15313 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015314 m_errorMonitor->VerifyFound();
15315
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070015316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015317 VkImageMemoryBarrier img_barrier;
15318 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15319 img_barrier.pNext = NULL;
15320 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15321 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15322 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15323 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15324 img_barrier.image = image.handle();
15325 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15326 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15327 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15328 img_barrier.subresourceRange.baseArrayLayer = 0;
15329 img_barrier.subresourceRange.baseMipLevel = 0;
15330 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
15331 img_barrier.subresourceRange.layerCount = 0;
15332 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015333 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
15334 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060015335 m_errorMonitor->VerifyFound();
15336 img_barrier.subresourceRange.layerCount = 1;
15337}
15338
15339TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060015340 TEST_DESCRIPTION("Exceed the limits of image format ");
15341
Cody Northropc31a84f2016-08-22 10:41:47 -060015342 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060015344 VkImageCreateInfo image_create_info = {};
15345 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15346 image_create_info.pNext = NULL;
15347 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15348 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15349 image_create_info.extent.width = 32;
15350 image_create_info.extent.height = 32;
15351 image_create_info.extent.depth = 1;
15352 image_create_info.mipLevels = 1;
15353 image_create_info.arrayLayers = 1;
15354 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15355 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15356 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15357 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15358 image_create_info.flags = 0;
15359
15360 VkImage nullImg;
15361 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015362 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15363 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070015364 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015365 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15366 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15367 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070015368 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015371 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15372 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15373 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15374 m_errorMonitor->VerifyFound();
15375 image_create_info.mipLevels = 1;
15376
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015378 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15379 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15380 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15381 m_errorMonitor->VerifyFound();
15382 image_create_info.arrayLayers = 1;
15383
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060015385 int samples = imgFmtProps.sampleCounts >> 1;
15386 image_create_info.samples = (VkSampleCountFlagBits)samples;
15387 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15388 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15389 m_errorMonitor->VerifyFound();
15390 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15391
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15393 "pCreateInfo->initialLayout, must be "
15394 "VK_IMAGE_LAYOUT_UNDEFINED or "
15395 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060015396 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15397 // Expect INVALID_LAYOUT
15398 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15399 m_errorMonitor->VerifyFound();
15400 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15401}
15402
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015403TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015404 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015406
15407 ASSERT_NO_FATAL_FAILURE(InitState());
15408
15409 VkImageObj src_image(m_device);
15410 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15411 VkImageObj dst_image(m_device);
15412 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15413
Tony Barbour552f6c02016-12-21 14:34:07 -070015414 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015415 VkImageCopy copy_region;
15416 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15417 copy_region.srcSubresource.mipLevel = 0;
15418 copy_region.srcSubresource.baseArrayLayer = 0;
15419 copy_region.srcSubresource.layerCount = 0;
15420 copy_region.srcOffset.x = 0;
15421 copy_region.srcOffset.y = 0;
15422 copy_region.srcOffset.z = 0;
15423 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15424 copy_region.dstSubresource.mipLevel = 0;
15425 copy_region.dstSubresource.baseArrayLayer = 0;
15426 copy_region.dstSubresource.layerCount = 0;
15427 copy_region.dstOffset.x = 0;
15428 copy_region.dstOffset.y = 0;
15429 copy_region.dstOffset.z = 0;
15430 copy_region.extent.width = 64;
15431 copy_region.extent.height = 64;
15432 copy_region.extent.depth = 1;
15433 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15434 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015435 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015436
15437 m_errorMonitor->VerifyFound();
15438}
15439
15440TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015441 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015443
15444 ASSERT_NO_FATAL_FAILURE(InitState());
15445
15446 VkImageObj src_image(m_device);
15447 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15448 VkImageObj dst_image(m_device);
15449 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15450
Tony Barbour552f6c02016-12-21 14:34:07 -070015451 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015452 VkImageCopy copy_region;
15453 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15454 copy_region.srcSubresource.mipLevel = 0;
15455 copy_region.srcSubresource.baseArrayLayer = 0;
15456 copy_region.srcSubresource.layerCount = 0;
15457 copy_region.srcOffset.x = 0;
15458 copy_region.srcOffset.y = 0;
15459 copy_region.srcOffset.z = 0;
15460 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15461 copy_region.dstSubresource.mipLevel = 0;
15462 copy_region.dstSubresource.baseArrayLayer = 0;
15463 copy_region.dstSubresource.layerCount = 0;
15464 copy_region.dstOffset.x = 0;
15465 copy_region.dstOffset.y = 0;
15466 copy_region.dstOffset.z = 0;
15467 copy_region.extent.width = 64;
15468 copy_region.extent.height = 64;
15469 copy_region.extent.depth = 1;
15470 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15471 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015472 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015473
15474 m_errorMonitor->VerifyFound();
15475}
15476
Karl Schultz6addd812016-02-02 17:17:23 -070015477TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015478 VkResult err;
15479 bool pass;
15480
15481 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015482 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015483
15484 ASSERT_NO_FATAL_FAILURE(InitState());
15485
15486 // Create two images of different types and try to copy between them
15487 VkImage srcImage;
15488 VkImage dstImage;
15489 VkDeviceMemory srcMem;
15490 VkDeviceMemory destMem;
15491 VkMemoryRequirements memReqs;
15492
15493 VkImageCreateInfo image_create_info = {};
15494 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15495 image_create_info.pNext = NULL;
15496 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15497 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15498 image_create_info.extent.width = 32;
15499 image_create_info.extent.height = 32;
15500 image_create_info.extent.depth = 1;
15501 image_create_info.mipLevels = 1;
15502 image_create_info.arrayLayers = 1;
15503 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15504 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15505 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15506 image_create_info.flags = 0;
15507
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015508 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015509 ASSERT_VK_SUCCESS(err);
15510
15511 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15512 // Introduce failure by creating second image with a different-sized format.
15513 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15514
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015515 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015516 ASSERT_VK_SUCCESS(err);
15517
15518 // Allocate memory
15519 VkMemoryAllocateInfo memAlloc = {};
15520 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15521 memAlloc.pNext = NULL;
15522 memAlloc.allocationSize = 0;
15523 memAlloc.memoryTypeIndex = 0;
15524
15525 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15526 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015527 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015528 ASSERT_TRUE(pass);
15529 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15530 ASSERT_VK_SUCCESS(err);
15531
15532 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15533 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015534 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015535 ASSERT_TRUE(pass);
15536 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15537 ASSERT_VK_SUCCESS(err);
15538
15539 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15540 ASSERT_VK_SUCCESS(err);
15541 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15542 ASSERT_VK_SUCCESS(err);
15543
Tony Barbour552f6c02016-12-21 14:34:07 -070015544 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015545 VkImageCopy copyRegion;
15546 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15547 copyRegion.srcSubresource.mipLevel = 0;
15548 copyRegion.srcSubresource.baseArrayLayer = 0;
15549 copyRegion.srcSubresource.layerCount = 0;
15550 copyRegion.srcOffset.x = 0;
15551 copyRegion.srcOffset.y = 0;
15552 copyRegion.srcOffset.z = 0;
15553 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15554 copyRegion.dstSubresource.mipLevel = 0;
15555 copyRegion.dstSubresource.baseArrayLayer = 0;
15556 copyRegion.dstSubresource.layerCount = 0;
15557 copyRegion.dstOffset.x = 0;
15558 copyRegion.dstOffset.y = 0;
15559 copyRegion.dstOffset.z = 0;
15560 copyRegion.extent.width = 1;
15561 copyRegion.extent.height = 1;
15562 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015563 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015564 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015565
15566 m_errorMonitor->VerifyFound();
15567
15568 vkDestroyImage(m_device->device(), srcImage, NULL);
15569 vkDestroyImage(m_device->device(), dstImage, NULL);
15570 vkFreeMemory(m_device->device(), srcMem, NULL);
15571 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015572}
15573
Karl Schultz6addd812016-02-02 17:17:23 -070015574TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15575 VkResult err;
15576 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015577
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015578 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15580 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015581
Mike Stroyana3082432015-09-25 13:39:21 -060015582 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015583
15584 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015585 VkImage srcImage;
15586 VkImage dstImage;
15587 VkDeviceMemory srcMem;
15588 VkDeviceMemory destMem;
15589 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015590
15591 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015592 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15593 image_create_info.pNext = NULL;
15594 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15595 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15596 image_create_info.extent.width = 32;
15597 image_create_info.extent.height = 32;
15598 image_create_info.extent.depth = 1;
15599 image_create_info.mipLevels = 1;
15600 image_create_info.arrayLayers = 1;
15601 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15602 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15603 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15604 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015605
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015606 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015607 ASSERT_VK_SUCCESS(err);
15608
Karl Schultzbdb75952016-04-19 11:36:49 -060015609 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15610
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015611 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015612 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015613 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015614 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015615
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015616 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015617 ASSERT_VK_SUCCESS(err);
15618
15619 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015620 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015621 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15622 memAlloc.pNext = NULL;
15623 memAlloc.allocationSize = 0;
15624 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015625
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015626 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015627 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015628 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015629 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015630 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015631 ASSERT_VK_SUCCESS(err);
15632
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015633 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015634 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015635 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015636 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015637 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015638 ASSERT_VK_SUCCESS(err);
15639
15640 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15641 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015642 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015643 ASSERT_VK_SUCCESS(err);
15644
Tony Barbour552f6c02016-12-21 14:34:07 -070015645 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015646 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015647 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015648 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015649 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015650 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015651 copyRegion.srcOffset.x = 0;
15652 copyRegion.srcOffset.y = 0;
15653 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015654 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015655 copyRegion.dstSubresource.mipLevel = 0;
15656 copyRegion.dstSubresource.baseArrayLayer = 0;
15657 copyRegion.dstSubresource.layerCount = 0;
15658 copyRegion.dstOffset.x = 0;
15659 copyRegion.dstOffset.y = 0;
15660 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015661 copyRegion.extent.width = 1;
15662 copyRegion.extent.height = 1;
15663 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015664 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015665 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015666
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015667 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015668
Chia-I Wuf7458c52015-10-26 21:10:41 +080015669 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015670 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015671 vkFreeMemory(m_device->device(), srcMem, NULL);
15672 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015673}
15674
Karl Schultz6addd812016-02-02 17:17:23 -070015675TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15676 VkResult err;
15677 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015678
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15680 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015681
Mike Stroyana3082432015-09-25 13:39:21 -060015682 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015683
15684 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015685 VkImage srcImage;
15686 VkImage dstImage;
15687 VkDeviceMemory srcMem;
15688 VkDeviceMemory destMem;
15689 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015690
15691 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015692 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15693 image_create_info.pNext = NULL;
15694 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15695 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15696 image_create_info.extent.width = 32;
15697 image_create_info.extent.height = 1;
15698 image_create_info.extent.depth = 1;
15699 image_create_info.mipLevels = 1;
15700 image_create_info.arrayLayers = 1;
15701 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15702 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15703 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15704 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015705
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015706 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015707 ASSERT_VK_SUCCESS(err);
15708
Karl Schultz6addd812016-02-02 17:17:23 -070015709 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015710
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015711 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015712 ASSERT_VK_SUCCESS(err);
15713
15714 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015715 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015716 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15717 memAlloc.pNext = NULL;
15718 memAlloc.allocationSize = 0;
15719 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015720
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015721 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015722 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015723 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015724 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015725 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015726 ASSERT_VK_SUCCESS(err);
15727
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015728 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015729 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015730 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015731 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015732 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015733 ASSERT_VK_SUCCESS(err);
15734
15735 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15736 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015737 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015738 ASSERT_VK_SUCCESS(err);
15739
Tony Barbour552f6c02016-12-21 14:34:07 -070015740 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015741 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015742 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15743 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015744 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015745 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015746 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015747 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015748 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015749 resolveRegion.srcOffset.x = 0;
15750 resolveRegion.srcOffset.y = 0;
15751 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015752 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015753 resolveRegion.dstSubresource.mipLevel = 0;
15754 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015755 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015756 resolveRegion.dstOffset.x = 0;
15757 resolveRegion.dstOffset.y = 0;
15758 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015759 resolveRegion.extent.width = 1;
15760 resolveRegion.extent.height = 1;
15761 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015762 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015763 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015764
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015765 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015766
Chia-I Wuf7458c52015-10-26 21:10:41 +080015767 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015768 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015769 vkFreeMemory(m_device->device(), srcMem, NULL);
15770 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015771}
15772
Karl Schultz6addd812016-02-02 17:17:23 -070015773TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15774 VkResult err;
15775 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015776
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15778 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015779
Mike Stroyana3082432015-09-25 13:39:21 -060015780 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015781
Chris Forbesa7530692016-05-08 12:35:39 +120015782 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015783 VkImage srcImage;
15784 VkImage dstImage;
15785 VkDeviceMemory srcMem;
15786 VkDeviceMemory destMem;
15787 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015788
15789 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015790 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15791 image_create_info.pNext = NULL;
15792 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15793 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15794 image_create_info.extent.width = 32;
15795 image_create_info.extent.height = 1;
15796 image_create_info.extent.depth = 1;
15797 image_create_info.mipLevels = 1;
15798 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015799 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015800 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15801 // Note: Some implementations expect color attachment usage for any
15802 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015803 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015804 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015805
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015806 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015807 ASSERT_VK_SUCCESS(err);
15808
Karl Schultz6addd812016-02-02 17:17:23 -070015809 // Note: Some implementations expect color attachment usage for any
15810 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015811 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015813 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015814 ASSERT_VK_SUCCESS(err);
15815
15816 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015817 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015818 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15819 memAlloc.pNext = NULL;
15820 memAlloc.allocationSize = 0;
15821 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015822
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015823 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015824 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015825 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015826 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015827 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015828 ASSERT_VK_SUCCESS(err);
15829
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015830 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015831 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015832 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015833 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015834 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015835 ASSERT_VK_SUCCESS(err);
15836
15837 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15838 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015839 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015840 ASSERT_VK_SUCCESS(err);
15841
Tony Barbour552f6c02016-12-21 14:34:07 -070015842 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015843 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015844 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15845 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015846 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015847 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015848 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015849 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015850 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015851 resolveRegion.srcOffset.x = 0;
15852 resolveRegion.srcOffset.y = 0;
15853 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015854 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015855 resolveRegion.dstSubresource.mipLevel = 0;
15856 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015857 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015858 resolveRegion.dstOffset.x = 0;
15859 resolveRegion.dstOffset.y = 0;
15860 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015861 resolveRegion.extent.width = 1;
15862 resolveRegion.extent.height = 1;
15863 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015864 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015865 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015866
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015867 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015868
Chia-I Wuf7458c52015-10-26 21:10:41 +080015869 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015870 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015871 vkFreeMemory(m_device->device(), srcMem, NULL);
15872 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015873}
15874
Karl Schultz6addd812016-02-02 17:17:23 -070015875TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15876 VkResult err;
15877 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15880 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015881
Mike Stroyana3082432015-09-25 13:39:21 -060015882 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015883
15884 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015885 VkImage srcImage;
15886 VkImage dstImage;
15887 VkDeviceMemory srcMem;
15888 VkDeviceMemory destMem;
15889 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015890
15891 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015892 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15893 image_create_info.pNext = NULL;
15894 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15895 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15896 image_create_info.extent.width = 32;
15897 image_create_info.extent.height = 1;
15898 image_create_info.extent.depth = 1;
15899 image_create_info.mipLevels = 1;
15900 image_create_info.arrayLayers = 1;
15901 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15902 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15903 // Note: Some implementations expect color attachment usage for any
15904 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015905 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015906 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015907
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015908 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015909 ASSERT_VK_SUCCESS(err);
15910
Karl Schultz6addd812016-02-02 17:17:23 -070015911 // Set format to something other than source image
15912 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15913 // Note: Some implementations expect color attachment usage for any
15914 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015915 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015916 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015917
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015918 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015919 ASSERT_VK_SUCCESS(err);
15920
15921 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015922 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015923 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15924 memAlloc.pNext = NULL;
15925 memAlloc.allocationSize = 0;
15926 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015927
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015928 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015929 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015930 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015931 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015932 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015933 ASSERT_VK_SUCCESS(err);
15934
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015935 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015936 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015937 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015938 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015939 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015940 ASSERT_VK_SUCCESS(err);
15941
15942 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15943 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015944 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015945 ASSERT_VK_SUCCESS(err);
15946
Tony Barbour552f6c02016-12-21 14:34:07 -070015947 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015948 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015949 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15950 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015951 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015952 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015953 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015954 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015955 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015956 resolveRegion.srcOffset.x = 0;
15957 resolveRegion.srcOffset.y = 0;
15958 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015959 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015960 resolveRegion.dstSubresource.mipLevel = 0;
15961 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015962 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015963 resolveRegion.dstOffset.x = 0;
15964 resolveRegion.dstOffset.y = 0;
15965 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015966 resolveRegion.extent.width = 1;
15967 resolveRegion.extent.height = 1;
15968 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015969 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015970 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015971
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015972 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015973
Chia-I Wuf7458c52015-10-26 21:10:41 +080015974 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015975 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015976 vkFreeMemory(m_device->device(), srcMem, NULL);
15977 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015978}
15979
Karl Schultz6addd812016-02-02 17:17:23 -070015980TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15981 VkResult err;
15982 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015983
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15985 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015986
Mike Stroyana3082432015-09-25 13:39:21 -060015987 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015988
15989 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015990 VkImage srcImage;
15991 VkImage dstImage;
15992 VkDeviceMemory srcMem;
15993 VkDeviceMemory destMem;
15994 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015995
15996 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015997 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15998 image_create_info.pNext = NULL;
15999 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16000 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16001 image_create_info.extent.width = 32;
16002 image_create_info.extent.height = 1;
16003 image_create_info.extent.depth = 1;
16004 image_create_info.mipLevels = 1;
16005 image_create_info.arrayLayers = 1;
16006 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16007 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16008 // Note: Some implementations expect color attachment usage for any
16009 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016010 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016011 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016012
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016013 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016014 ASSERT_VK_SUCCESS(err);
16015
Karl Schultz6addd812016-02-02 17:17:23 -070016016 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16017 // Note: Some implementations expect color attachment usage for any
16018 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016019 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016020 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016021
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016022 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016023 ASSERT_VK_SUCCESS(err);
16024
16025 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016026 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016027 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16028 memAlloc.pNext = NULL;
16029 memAlloc.allocationSize = 0;
16030 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016031
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016032 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016033 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016034 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016035 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016036 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016037 ASSERT_VK_SUCCESS(err);
16038
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016039 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016040 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016041 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016042 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016043 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016044 ASSERT_VK_SUCCESS(err);
16045
16046 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16047 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016048 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016049 ASSERT_VK_SUCCESS(err);
16050
Tony Barbour552f6c02016-12-21 14:34:07 -070016051 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016052 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016053 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16054 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016055 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016056 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016057 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016058 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016059 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016060 resolveRegion.srcOffset.x = 0;
16061 resolveRegion.srcOffset.y = 0;
16062 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016063 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016064 resolveRegion.dstSubresource.mipLevel = 0;
16065 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016066 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016067 resolveRegion.dstOffset.x = 0;
16068 resolveRegion.dstOffset.y = 0;
16069 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016070 resolveRegion.extent.width = 1;
16071 resolveRegion.extent.height = 1;
16072 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016073 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016074 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016075
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016076 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016077
Chia-I Wuf7458c52015-10-26 21:10:41 +080016078 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016079 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016080 vkFreeMemory(m_device->device(), srcMem, NULL);
16081 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016082}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016083
Karl Schultz6addd812016-02-02 17:17:23 -070016084TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016085 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016086 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16087 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016088 // The image format check comes 2nd in validation so we trigger it first,
16089 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016090 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16093 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016094
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016095 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016096
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016097 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016098 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16099 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016100
16101 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016102 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16103 ds_pool_ci.pNext = NULL;
16104 ds_pool_ci.maxSets = 1;
16105 ds_pool_ci.poolSizeCount = 1;
16106 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016107
16108 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016109 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016110 ASSERT_VK_SUCCESS(err);
16111
16112 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016113 dsl_binding.binding = 0;
16114 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16115 dsl_binding.descriptorCount = 1;
16116 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16117 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016118
16119 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016120 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16121 ds_layout_ci.pNext = NULL;
16122 ds_layout_ci.bindingCount = 1;
16123 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016124 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016125 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016126 ASSERT_VK_SUCCESS(err);
16127
16128 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016129 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016130 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016131 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016132 alloc_info.descriptorPool = ds_pool;
16133 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016134 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016135 ASSERT_VK_SUCCESS(err);
16136
Karl Schultz6addd812016-02-02 17:17:23 -070016137 VkImage image_bad;
16138 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016139 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016140 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016141 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016142 const int32_t tex_width = 32;
16143 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016144
16145 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016146 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16147 image_create_info.pNext = NULL;
16148 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16149 image_create_info.format = tex_format_bad;
16150 image_create_info.extent.width = tex_width;
16151 image_create_info.extent.height = tex_height;
16152 image_create_info.extent.depth = 1;
16153 image_create_info.mipLevels = 1;
16154 image_create_info.arrayLayers = 1;
16155 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16156 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016157 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016158 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016159
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016160 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016161 ASSERT_VK_SUCCESS(err);
16162 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016163 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16164 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016165 ASSERT_VK_SUCCESS(err);
16166
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016167 // ---Bind image memory---
16168 VkMemoryRequirements img_mem_reqs;
16169 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
16170 VkMemoryAllocateInfo image_alloc_info = {};
16171 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16172 image_alloc_info.pNext = NULL;
16173 image_alloc_info.memoryTypeIndex = 0;
16174 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016175 bool pass =
16176 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 -070016177 ASSERT_TRUE(pass);
16178 VkDeviceMemory mem;
16179 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
16180 ASSERT_VK_SUCCESS(err);
16181 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
16182 ASSERT_VK_SUCCESS(err);
16183 // -----------------------
16184
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016185 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016186 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016187 image_view_create_info.image = image_bad;
16188 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16189 image_view_create_info.format = tex_format_bad;
16190 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16191 image_view_create_info.subresourceRange.baseMipLevel = 0;
16192 image_view_create_info.subresourceRange.layerCount = 1;
16193 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016194 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016195
16196 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016197 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016198
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016199 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016200
Chia-I Wuf7458c52015-10-26 21:10:41 +080016201 vkDestroyImage(m_device->device(), image_bad, NULL);
16202 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016203 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16204 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016205
16206 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016207}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016208
16209TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016210 TEST_DESCRIPTION(
16211 "Call ClearColorImage w/ a depth|stencil image and "
16212 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016213
16214 ASSERT_NO_FATAL_FAILURE(InitState());
16215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16216
Tony Barbour552f6c02016-12-21 14:34:07 -070016217 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016218
16219 // Color image
16220 VkClearColorValue clear_color;
16221 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16222 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16223 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16224 const int32_t img_width = 32;
16225 const int32_t img_height = 32;
16226 VkImageCreateInfo image_create_info = {};
16227 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16228 image_create_info.pNext = NULL;
16229 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16230 image_create_info.format = color_format;
16231 image_create_info.extent.width = img_width;
16232 image_create_info.extent.height = img_height;
16233 image_create_info.extent.depth = 1;
16234 image_create_info.mipLevels = 1;
16235 image_create_info.arrayLayers = 1;
16236 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16237 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16238 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16239
16240 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016241 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016243 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016244
16245 // Depth/Stencil image
16246 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016247 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016248 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16249 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16250 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16251 ds_image_create_info.extent.width = 64;
16252 ds_image_create_info.extent.height = 64;
16253 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016254 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 -060016255
16256 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016257 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016258
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016259 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 -060016260
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016262
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016263 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016264 &color_range);
16265
16266 m_errorMonitor->VerifyFound();
16267
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16269 "vkCmdClearColorImage called with "
16270 "image created without "
16271 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016272
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016273 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016274 &color_range);
16275
16276 m_errorMonitor->VerifyFound();
16277
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016278 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16280 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016281
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016282 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
16283 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016284
16285 m_errorMonitor->VerifyFound();
16286}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016287#endif // IMAGE_TESTS
Tobin Ehliscde08892015-09-22 10:11:37 -060016288
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016289// WSI Enabled Tests
16290//
Chris Forbes09368e42016-10-13 11:59:22 +130016291#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016292TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
16293
16294#if defined(VK_USE_PLATFORM_XCB_KHR)
16295 VkSurfaceKHR surface = VK_NULL_HANDLE;
16296
16297 VkResult err;
16298 bool pass;
16299 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
16300 VkSwapchainCreateInfoKHR swapchain_create_info = {};
16301 // uint32_t swapchain_image_count = 0;
16302 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
16303 // uint32_t image_index = 0;
16304 // VkPresentInfoKHR present_info = {};
16305
16306 ASSERT_NO_FATAL_FAILURE(InitState());
16307
16308 // Use the create function from one of the VK_KHR_*_surface extension in
16309 // order to create a surface, testing all known errors in the process,
16310 // before successfully creating a surface:
16311 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
16312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
16313 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
16314 pass = (err != VK_SUCCESS);
16315 ASSERT_TRUE(pass);
16316 m_errorMonitor->VerifyFound();
16317
16318 // Next, try to create a surface with the wrong
16319 // VkXcbSurfaceCreateInfoKHR::sType:
16320 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
16321 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16323 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16324 pass = (err != VK_SUCCESS);
16325 ASSERT_TRUE(pass);
16326 m_errorMonitor->VerifyFound();
16327
16328 // Create a native window, and then correctly create a surface:
16329 xcb_connection_t *connection;
16330 xcb_screen_t *screen;
16331 xcb_window_t xcb_window;
16332 xcb_intern_atom_reply_t *atom_wm_delete_window;
16333
16334 const xcb_setup_t *setup;
16335 xcb_screen_iterator_t iter;
16336 int scr;
16337 uint32_t value_mask, value_list[32];
16338 int width = 1;
16339 int height = 1;
16340
16341 connection = xcb_connect(NULL, &scr);
16342 ASSERT_TRUE(connection != NULL);
16343 setup = xcb_get_setup(connection);
16344 iter = xcb_setup_roots_iterator(setup);
16345 while (scr-- > 0)
16346 xcb_screen_next(&iter);
16347 screen = iter.data;
16348
16349 xcb_window = xcb_generate_id(connection);
16350
16351 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
16352 value_list[0] = screen->black_pixel;
16353 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
16354
16355 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
16356 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
16357
16358 /* Magic code that will send notification when window is destroyed */
16359 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
16360 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
16361
16362 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
16363 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
16364 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
16365 free(reply);
16366
16367 xcb_map_window(connection, xcb_window);
16368
16369 // Force the x/y coordinates to 100,100 results are identical in consecutive
16370 // runs
16371 const uint32_t coords[] = { 100, 100 };
16372 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
16373
16374 // Finally, try to correctly create a surface:
16375 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
16376 xcb_create_info.pNext = NULL;
16377 xcb_create_info.flags = 0;
16378 xcb_create_info.connection = connection;
16379 xcb_create_info.window = xcb_window;
16380 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16381 pass = (err == VK_SUCCESS);
16382 ASSERT_TRUE(pass);
16383
16384 // Check if surface supports presentation:
16385
16386 // 1st, do so without having queried the queue families:
16387 VkBool32 supported = false;
16388 // TODO: Get the following error to come out:
16389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16390 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
16391 "function");
16392 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16393 pass = (err != VK_SUCCESS);
16394 // ASSERT_TRUE(pass);
16395 // m_errorMonitor->VerifyFound();
16396
16397 // Next, query a queue family index that's too large:
16398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16399 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
16400 pass = (err != VK_SUCCESS);
16401 ASSERT_TRUE(pass);
16402 m_errorMonitor->VerifyFound();
16403
16404 // Finally, do so correctly:
16405 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16406 // SUPPORTED
16407 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16408 pass = (err == VK_SUCCESS);
16409 ASSERT_TRUE(pass);
16410
16411 // Before proceeding, try to create a swapchain without having called
16412 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
16413 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16414 swapchain_create_info.pNext = NULL;
16415 swapchain_create_info.flags = 0;
16416 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16417 swapchain_create_info.surface = surface;
16418 swapchain_create_info.imageArrayLayers = 1;
16419 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
16420 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
16421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16422 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
16423 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16424 pass = (err != VK_SUCCESS);
16425 ASSERT_TRUE(pass);
16426 m_errorMonitor->VerifyFound();
16427
16428 // Get the surface capabilities:
16429 VkSurfaceCapabilitiesKHR surface_capabilities;
16430
16431 // Do so correctly (only error logged by this entrypoint is if the
16432 // extension isn't enabled):
16433 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
16434 pass = (err == VK_SUCCESS);
16435 ASSERT_TRUE(pass);
16436
16437 // Get the surface formats:
16438 uint32_t surface_format_count;
16439
16440 // First, try without a pointer to surface_format_count:
16441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
16442 "specified as NULL");
16443 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
16444 pass = (err == VK_SUCCESS);
16445 ASSERT_TRUE(pass);
16446 m_errorMonitor->VerifyFound();
16447
16448 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
16449 // correctly done a 1st try (to get the count):
16450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16451 surface_format_count = 0;
16452 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
16453 pass = (err == VK_SUCCESS);
16454 ASSERT_TRUE(pass);
16455 m_errorMonitor->VerifyFound();
16456
16457 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16458 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16459 pass = (err == VK_SUCCESS);
16460 ASSERT_TRUE(pass);
16461
16462 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16463 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
16464
16465 // Next, do a 2nd try with surface_format_count being set too high:
16466 surface_format_count += 5;
16467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16468 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16469 pass = (err == VK_SUCCESS);
16470 ASSERT_TRUE(pass);
16471 m_errorMonitor->VerifyFound();
16472
16473 // Finally, do a correct 1st and 2nd try:
16474 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16475 pass = (err == VK_SUCCESS);
16476 ASSERT_TRUE(pass);
16477 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16478 pass = (err == VK_SUCCESS);
16479 ASSERT_TRUE(pass);
16480
16481 // Get the surface present modes:
16482 uint32_t surface_present_mode_count;
16483
16484 // First, try without a pointer to surface_format_count:
16485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16486 "specified as NULL");
16487
16488 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16489 pass = (err == VK_SUCCESS);
16490 ASSERT_TRUE(pass);
16491 m_errorMonitor->VerifyFound();
16492
16493 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16494 // correctly done a 1st try (to get the count):
16495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16496 surface_present_mode_count = 0;
16497 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16498 (VkPresentModeKHR *)&surface_present_mode_count);
16499 pass = (err == VK_SUCCESS);
16500 ASSERT_TRUE(pass);
16501 m_errorMonitor->VerifyFound();
16502
16503 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16504 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16505 pass = (err == VK_SUCCESS);
16506 ASSERT_TRUE(pass);
16507
16508 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16509 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16510
16511 // Next, do a 2nd try with surface_format_count being set too high:
16512 surface_present_mode_count += 5;
16513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16514 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16515 pass = (err == VK_SUCCESS);
16516 ASSERT_TRUE(pass);
16517 m_errorMonitor->VerifyFound();
16518
16519 // Finally, do a correct 1st and 2nd try:
16520 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16521 pass = (err == VK_SUCCESS);
16522 ASSERT_TRUE(pass);
16523 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16524 pass = (err == VK_SUCCESS);
16525 ASSERT_TRUE(pass);
16526
16527 // Create a swapchain:
16528
16529 // First, try without a pointer to swapchain_create_info:
16530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16531 "specified as NULL");
16532
16533 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16534 pass = (err != VK_SUCCESS);
16535 ASSERT_TRUE(pass);
16536 m_errorMonitor->VerifyFound();
16537
16538 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16539 // sType:
16540 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16542
16543 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16544 pass = (err != VK_SUCCESS);
16545 ASSERT_TRUE(pass);
16546 m_errorMonitor->VerifyFound();
16547
16548 // Next, call with a NULL swapchain pointer:
16549 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16550 swapchain_create_info.pNext = NULL;
16551 swapchain_create_info.flags = 0;
16552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16553 "specified as NULL");
16554
16555 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16556 pass = (err != VK_SUCCESS);
16557 ASSERT_TRUE(pass);
16558 m_errorMonitor->VerifyFound();
16559
16560 // TODO: Enhance swapchain layer so that
16561 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16562
16563 // Next, call with a queue family index that's too large:
16564 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16565 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16566 swapchain_create_info.queueFamilyIndexCount = 2;
16567 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16569 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16570 pass = (err != VK_SUCCESS);
16571 ASSERT_TRUE(pass);
16572 m_errorMonitor->VerifyFound();
16573
16574 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16575 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16576 swapchain_create_info.queueFamilyIndexCount = 1;
16577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16578 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16579 "pCreateInfo->pQueueFamilyIndices).");
16580 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16581 pass = (err != VK_SUCCESS);
16582 ASSERT_TRUE(pass);
16583 m_errorMonitor->VerifyFound();
16584
16585 // Next, call with an invalid imageSharingMode:
16586 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16587 swapchain_create_info.queueFamilyIndexCount = 1;
16588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16589 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16590 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16591 pass = (err != VK_SUCCESS);
16592 ASSERT_TRUE(pass);
16593 m_errorMonitor->VerifyFound();
16594 // Fix for the future:
16595 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16596 // SUPPORTED
16597 swapchain_create_info.queueFamilyIndexCount = 0;
16598 queueFamilyIndex[0] = 0;
16599 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16600
16601 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16602 // Get the images from a swapchain:
16603 // Acquire an image from a swapchain:
16604 // Present an image to a swapchain:
16605 // Destroy the swapchain:
16606
16607 // TODOs:
16608 //
16609 // - Try destroying the device without first destroying the swapchain
16610 //
16611 // - Try destroying the device without first destroying the surface
16612 //
16613 // - Try destroying the surface without first destroying the swapchain
16614
16615 // Destroy the surface:
16616 vkDestroySurfaceKHR(instance(), surface, NULL);
16617
16618 // Tear down the window:
16619 xcb_destroy_window(connection, xcb_window);
16620 xcb_disconnect(connection);
16621
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016622#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016623 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016624#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016625}
Chris Forbes09368e42016-10-13 11:59:22 +130016626#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016627
16628//
16629// POSITIVE VALIDATION TESTS
16630//
16631// These tests do not expect to encounter ANY validation errors pass only if this is true
16632
Tobin Ehlise0006882016-11-03 10:14:28 -060016633TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016634 TEST_DESCRIPTION(
16635 "Perform an image layout transition in a secondary command buffer followed "
16636 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060016637 VkResult err;
16638 m_errorMonitor->ExpectSuccess();
16639 ASSERT_NO_FATAL_FAILURE(InitState());
16640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16641 // Allocate a secondary and primary cmd buffer
16642 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16643 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16644 command_buffer_allocate_info.commandPool = m_commandPool;
16645 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16646 command_buffer_allocate_info.commandBufferCount = 1;
16647
16648 VkCommandBuffer secondary_command_buffer;
16649 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16650 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16651 VkCommandBuffer primary_command_buffer;
16652 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16653 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16654 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16655 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16656 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16657 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16658 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16659
16660 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16661 ASSERT_VK_SUCCESS(err);
16662 VkImageObj image(m_device);
16663 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16664 ASSERT_TRUE(image.initialized());
16665 VkImageMemoryBarrier img_barrier = {};
16666 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16667 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16668 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16669 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16670 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16671 img_barrier.image = image.handle();
16672 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16673 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16674 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16675 img_barrier.subresourceRange.baseArrayLayer = 0;
16676 img_barrier.subresourceRange.baseMipLevel = 0;
16677 img_barrier.subresourceRange.layerCount = 1;
16678 img_barrier.subresourceRange.levelCount = 1;
16679 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16680 0, nullptr, 1, &img_barrier);
16681 err = vkEndCommandBuffer(secondary_command_buffer);
16682 ASSERT_VK_SUCCESS(err);
16683
16684 // Now update primary cmd buffer to execute secondary and transitions image
16685 command_buffer_begin_info.pInheritanceInfo = nullptr;
16686 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16687 ASSERT_VK_SUCCESS(err);
16688 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16689 VkImageMemoryBarrier img_barrier2 = {};
16690 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16691 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16692 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16693 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16694 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16695 img_barrier2.image = image.handle();
16696 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16697 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16698 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16699 img_barrier2.subresourceRange.baseArrayLayer = 0;
16700 img_barrier2.subresourceRange.baseMipLevel = 0;
16701 img_barrier2.subresourceRange.layerCount = 1;
16702 img_barrier2.subresourceRange.levelCount = 1;
16703 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16704 nullptr, 1, &img_barrier2);
16705 err = vkEndCommandBuffer(primary_command_buffer);
16706 ASSERT_VK_SUCCESS(err);
16707 VkSubmitInfo submit_info = {};
16708 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16709 submit_info.commandBufferCount = 1;
16710 submit_info.pCommandBuffers = &primary_command_buffer;
16711 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16712 ASSERT_VK_SUCCESS(err);
16713 m_errorMonitor->VerifyNotFound();
16714 err = vkDeviceWaitIdle(m_device->device());
16715 ASSERT_VK_SUCCESS(err);
16716 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16717 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16718}
16719
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016720// This is a positive test. No failures are expected.
16721TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016722 TEST_DESCRIPTION(
16723 "Ensure that the vkUpdateDescriptorSets validation code "
16724 "is ignoring VkWriteDescriptorSet members that are not "
16725 "related to the descriptor type specified by "
16726 "VkWriteDescriptorSet::descriptorType. Correct "
16727 "validation behavior will result in the test running to "
16728 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016729
16730 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16731
16732 ASSERT_NO_FATAL_FAILURE(InitState());
16733
16734 // Image Case
16735 {
16736 m_errorMonitor->ExpectSuccess();
16737
16738 VkImage image;
16739 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16740 const int32_t tex_width = 32;
16741 const int32_t tex_height = 32;
16742 VkImageCreateInfo image_create_info = {};
16743 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16744 image_create_info.pNext = NULL;
16745 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16746 image_create_info.format = tex_format;
16747 image_create_info.extent.width = tex_width;
16748 image_create_info.extent.height = tex_height;
16749 image_create_info.extent.depth = 1;
16750 image_create_info.mipLevels = 1;
16751 image_create_info.arrayLayers = 1;
16752 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16753 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16754 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16755 image_create_info.flags = 0;
16756 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16757 ASSERT_VK_SUCCESS(err);
16758
16759 VkMemoryRequirements memory_reqs;
16760 VkDeviceMemory image_memory;
16761 bool pass;
16762 VkMemoryAllocateInfo memory_info = {};
16763 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16764 memory_info.pNext = NULL;
16765 memory_info.allocationSize = 0;
16766 memory_info.memoryTypeIndex = 0;
16767 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16768 memory_info.allocationSize = memory_reqs.size;
16769 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16770 ASSERT_TRUE(pass);
16771 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16772 ASSERT_VK_SUCCESS(err);
16773 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16774 ASSERT_VK_SUCCESS(err);
16775
16776 VkImageViewCreateInfo image_view_create_info = {};
16777 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16778 image_view_create_info.image = image;
16779 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16780 image_view_create_info.format = tex_format;
16781 image_view_create_info.subresourceRange.layerCount = 1;
16782 image_view_create_info.subresourceRange.baseMipLevel = 0;
16783 image_view_create_info.subresourceRange.levelCount = 1;
16784 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16785
16786 VkImageView view;
16787 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16788 ASSERT_VK_SUCCESS(err);
16789
16790 VkDescriptorPoolSize ds_type_count = {};
16791 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16792 ds_type_count.descriptorCount = 1;
16793
16794 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16795 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16796 ds_pool_ci.pNext = NULL;
16797 ds_pool_ci.maxSets = 1;
16798 ds_pool_ci.poolSizeCount = 1;
16799 ds_pool_ci.pPoolSizes = &ds_type_count;
16800
16801 VkDescriptorPool ds_pool;
16802 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16803 ASSERT_VK_SUCCESS(err);
16804
16805 VkDescriptorSetLayoutBinding dsl_binding = {};
16806 dsl_binding.binding = 0;
16807 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16808 dsl_binding.descriptorCount = 1;
16809 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16810 dsl_binding.pImmutableSamplers = NULL;
16811
16812 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16813 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16814 ds_layout_ci.pNext = NULL;
16815 ds_layout_ci.bindingCount = 1;
16816 ds_layout_ci.pBindings = &dsl_binding;
16817 VkDescriptorSetLayout ds_layout;
16818 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16819 ASSERT_VK_SUCCESS(err);
16820
16821 VkDescriptorSet descriptor_set;
16822 VkDescriptorSetAllocateInfo alloc_info = {};
16823 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16824 alloc_info.descriptorSetCount = 1;
16825 alloc_info.descriptorPool = ds_pool;
16826 alloc_info.pSetLayouts = &ds_layout;
16827 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16828 ASSERT_VK_SUCCESS(err);
16829
16830 VkDescriptorImageInfo image_info = {};
16831 image_info.imageView = view;
16832 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16833
16834 VkWriteDescriptorSet descriptor_write;
16835 memset(&descriptor_write, 0, sizeof(descriptor_write));
16836 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16837 descriptor_write.dstSet = descriptor_set;
16838 descriptor_write.dstBinding = 0;
16839 descriptor_write.descriptorCount = 1;
16840 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16841 descriptor_write.pImageInfo = &image_info;
16842
16843 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16844 // be
16845 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16846 // This will most likely produce a crash if the parameter_validation
16847 // layer
16848 // does not correctly ignore pBufferInfo.
16849 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16850 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16851
16852 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16853
16854 m_errorMonitor->VerifyNotFound();
16855
16856 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16857 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16858 vkDestroyImageView(m_device->device(), view, NULL);
16859 vkDestroyImage(m_device->device(), image, NULL);
16860 vkFreeMemory(m_device->device(), image_memory, NULL);
16861 }
16862
16863 // Buffer Case
16864 {
16865 m_errorMonitor->ExpectSuccess();
16866
16867 VkBuffer buffer;
16868 uint32_t queue_family_index = 0;
16869 VkBufferCreateInfo buffer_create_info = {};
16870 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16871 buffer_create_info.size = 1024;
16872 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16873 buffer_create_info.queueFamilyIndexCount = 1;
16874 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16875
16876 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16877 ASSERT_VK_SUCCESS(err);
16878
16879 VkMemoryRequirements memory_reqs;
16880 VkDeviceMemory buffer_memory;
16881 bool pass;
16882 VkMemoryAllocateInfo memory_info = {};
16883 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16884 memory_info.pNext = NULL;
16885 memory_info.allocationSize = 0;
16886 memory_info.memoryTypeIndex = 0;
16887
16888 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16889 memory_info.allocationSize = memory_reqs.size;
16890 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16891 ASSERT_TRUE(pass);
16892
16893 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16894 ASSERT_VK_SUCCESS(err);
16895 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16896 ASSERT_VK_SUCCESS(err);
16897
16898 VkDescriptorPoolSize ds_type_count = {};
16899 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16900 ds_type_count.descriptorCount = 1;
16901
16902 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16903 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16904 ds_pool_ci.pNext = NULL;
16905 ds_pool_ci.maxSets = 1;
16906 ds_pool_ci.poolSizeCount = 1;
16907 ds_pool_ci.pPoolSizes = &ds_type_count;
16908
16909 VkDescriptorPool ds_pool;
16910 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16911 ASSERT_VK_SUCCESS(err);
16912
16913 VkDescriptorSetLayoutBinding dsl_binding = {};
16914 dsl_binding.binding = 0;
16915 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16916 dsl_binding.descriptorCount = 1;
16917 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16918 dsl_binding.pImmutableSamplers = NULL;
16919
16920 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16921 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16922 ds_layout_ci.pNext = NULL;
16923 ds_layout_ci.bindingCount = 1;
16924 ds_layout_ci.pBindings = &dsl_binding;
16925 VkDescriptorSetLayout ds_layout;
16926 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16927 ASSERT_VK_SUCCESS(err);
16928
16929 VkDescriptorSet descriptor_set;
16930 VkDescriptorSetAllocateInfo alloc_info = {};
16931 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16932 alloc_info.descriptorSetCount = 1;
16933 alloc_info.descriptorPool = ds_pool;
16934 alloc_info.pSetLayouts = &ds_layout;
16935 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16936 ASSERT_VK_SUCCESS(err);
16937
16938 VkDescriptorBufferInfo buffer_info = {};
16939 buffer_info.buffer = buffer;
16940 buffer_info.offset = 0;
16941 buffer_info.range = 1024;
16942
16943 VkWriteDescriptorSet descriptor_write;
16944 memset(&descriptor_write, 0, sizeof(descriptor_write));
16945 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16946 descriptor_write.dstSet = descriptor_set;
16947 descriptor_write.dstBinding = 0;
16948 descriptor_write.descriptorCount = 1;
16949 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16950 descriptor_write.pBufferInfo = &buffer_info;
16951
16952 // Set pImageInfo and pTexelBufferView to invalid values, which should
16953 // be
16954 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16955 // This will most likely produce a crash if the parameter_validation
16956 // layer
16957 // does not correctly ignore pImageInfo.
16958 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16959 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16960
16961 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16962
16963 m_errorMonitor->VerifyNotFound();
16964
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16966 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16967 vkDestroyBuffer(m_device->device(), buffer, NULL);
16968 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16969 }
16970
16971 // Texel Buffer Case
16972 {
16973 m_errorMonitor->ExpectSuccess();
16974
16975 VkBuffer buffer;
16976 uint32_t queue_family_index = 0;
16977 VkBufferCreateInfo buffer_create_info = {};
16978 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16979 buffer_create_info.size = 1024;
16980 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16981 buffer_create_info.queueFamilyIndexCount = 1;
16982 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16983
16984 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16985 ASSERT_VK_SUCCESS(err);
16986
16987 VkMemoryRequirements memory_reqs;
16988 VkDeviceMemory buffer_memory;
16989 bool pass;
16990 VkMemoryAllocateInfo memory_info = {};
16991 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16992 memory_info.pNext = NULL;
16993 memory_info.allocationSize = 0;
16994 memory_info.memoryTypeIndex = 0;
16995
16996 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16997 memory_info.allocationSize = memory_reqs.size;
16998 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16999 ASSERT_TRUE(pass);
17000
17001 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17002 ASSERT_VK_SUCCESS(err);
17003 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17004 ASSERT_VK_SUCCESS(err);
17005
17006 VkBufferViewCreateInfo buff_view_ci = {};
17007 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
17008 buff_view_ci.buffer = buffer;
17009 buff_view_ci.format = VK_FORMAT_R8_UNORM;
17010 buff_view_ci.range = VK_WHOLE_SIZE;
17011 VkBufferView buffer_view;
17012 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
17013
17014 VkDescriptorPoolSize ds_type_count = {};
17015 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17016 ds_type_count.descriptorCount = 1;
17017
17018 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17019 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17020 ds_pool_ci.pNext = NULL;
17021 ds_pool_ci.maxSets = 1;
17022 ds_pool_ci.poolSizeCount = 1;
17023 ds_pool_ci.pPoolSizes = &ds_type_count;
17024
17025 VkDescriptorPool ds_pool;
17026 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17027 ASSERT_VK_SUCCESS(err);
17028
17029 VkDescriptorSetLayoutBinding dsl_binding = {};
17030 dsl_binding.binding = 0;
17031 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17032 dsl_binding.descriptorCount = 1;
17033 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17034 dsl_binding.pImmutableSamplers = NULL;
17035
17036 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17037 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17038 ds_layout_ci.pNext = NULL;
17039 ds_layout_ci.bindingCount = 1;
17040 ds_layout_ci.pBindings = &dsl_binding;
17041 VkDescriptorSetLayout ds_layout;
17042 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17043 ASSERT_VK_SUCCESS(err);
17044
17045 VkDescriptorSet descriptor_set;
17046 VkDescriptorSetAllocateInfo alloc_info = {};
17047 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17048 alloc_info.descriptorSetCount = 1;
17049 alloc_info.descriptorPool = ds_pool;
17050 alloc_info.pSetLayouts = &ds_layout;
17051 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17052 ASSERT_VK_SUCCESS(err);
17053
17054 VkWriteDescriptorSet descriptor_write;
17055 memset(&descriptor_write, 0, sizeof(descriptor_write));
17056 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17057 descriptor_write.dstSet = descriptor_set;
17058 descriptor_write.dstBinding = 0;
17059 descriptor_write.descriptorCount = 1;
17060 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17061 descriptor_write.pTexelBufferView = &buffer_view;
17062
17063 // Set pImageInfo and pBufferInfo to invalid values, which should be
17064 // ignored for descriptorType ==
17065 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
17066 // This will most likely produce a crash if the parameter_validation
17067 // layer
17068 // does not correctly ignore pImageInfo and pBufferInfo.
17069 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17070 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17071
17072 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17073
17074 m_errorMonitor->VerifyNotFound();
17075
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017076 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17077 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17078 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
17079 vkDestroyBuffer(m_device->device(), buffer, NULL);
17080 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17081 }
17082}
17083
Tobin Ehlisf7428442016-10-25 07:58:24 -060017084TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
17085 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
17086
17087 ASSERT_NO_FATAL_FAILURE(InitState());
17088 // Create layout where two binding #s are "1"
17089 static const uint32_t NUM_BINDINGS = 3;
17090 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17091 dsl_binding[0].binding = 1;
17092 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17093 dsl_binding[0].descriptorCount = 1;
17094 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17095 dsl_binding[0].pImmutableSamplers = NULL;
17096 dsl_binding[1].binding = 0;
17097 dsl_binding[1].descriptorCount = 1;
17098 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17099 dsl_binding[1].descriptorCount = 1;
17100 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17101 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017102 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060017103 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17104 dsl_binding[2].descriptorCount = 1;
17105 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17106 dsl_binding[2].pImmutableSamplers = NULL;
17107
17108 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17109 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17110 ds_layout_ci.pNext = NULL;
17111 ds_layout_ci.bindingCount = NUM_BINDINGS;
17112 ds_layout_ci.pBindings = dsl_binding;
17113 VkDescriptorSetLayout ds_layout;
17114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
17115 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17116 m_errorMonitor->VerifyFound();
17117}
17118
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017119TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017120 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
17121
17122 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017123
Tony Barbour552f6c02016-12-21 14:34:07 -070017124 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017125
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017126 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
17127
17128 {
17129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
17130 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
17131 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17132 m_errorMonitor->VerifyFound();
17133 }
17134
17135 {
17136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
17137 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
17138 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17139 m_errorMonitor->VerifyFound();
17140 }
17141
17142 {
17143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17144 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
17145 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17146 m_errorMonitor->VerifyFound();
17147 }
17148
17149 {
17150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17151 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
17152 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17153 m_errorMonitor->VerifyFound();
17154 }
17155
17156 {
17157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
17158 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
17159 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17160 m_errorMonitor->VerifyFound();
17161 }
17162
17163 {
17164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
17165 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
17166 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17167 m_errorMonitor->VerifyFound();
17168 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017169
17170 {
17171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17172 VkRect2D scissor = {{-1, 0}, {16, 16}};
17173 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17174 m_errorMonitor->VerifyFound();
17175 }
17176
17177 {
17178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17179 VkRect2D scissor = {{0, -2}, {16, 16}};
17180 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17181 m_errorMonitor->VerifyFound();
17182 }
17183
17184 {
17185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
17186 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
17187 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17188 m_errorMonitor->VerifyFound();
17189 }
17190
17191 {
17192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
17193 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
17194 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17195 m_errorMonitor->VerifyFound();
17196 }
17197
Tony Barbour552f6c02016-12-21 14:34:07 -070017198 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017199}
17200
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017201// This is a positive test. No failures are expected.
17202TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
17203 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
17204 VkResult err;
17205
17206 ASSERT_NO_FATAL_FAILURE(InitState());
17207 m_errorMonitor->ExpectSuccess();
17208 VkDescriptorPoolSize ds_type_count = {};
17209 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17210 ds_type_count.descriptorCount = 2;
17211
17212 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17213 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17214 ds_pool_ci.pNext = NULL;
17215 ds_pool_ci.maxSets = 1;
17216 ds_pool_ci.poolSizeCount = 1;
17217 ds_pool_ci.pPoolSizes = &ds_type_count;
17218
17219 VkDescriptorPool ds_pool;
17220 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17221 ASSERT_VK_SUCCESS(err);
17222
17223 // Create layout with two uniform buffer descriptors w/ empty binding between them
17224 static const uint32_t NUM_BINDINGS = 3;
17225 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17226 dsl_binding[0].binding = 0;
17227 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17228 dsl_binding[0].descriptorCount = 1;
17229 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
17230 dsl_binding[0].pImmutableSamplers = NULL;
17231 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017232 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017233 dsl_binding[2].binding = 2;
17234 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17235 dsl_binding[2].descriptorCount = 1;
17236 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
17237 dsl_binding[2].pImmutableSamplers = NULL;
17238
17239 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17240 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17241 ds_layout_ci.pNext = NULL;
17242 ds_layout_ci.bindingCount = NUM_BINDINGS;
17243 ds_layout_ci.pBindings = dsl_binding;
17244 VkDescriptorSetLayout ds_layout;
17245 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17246 ASSERT_VK_SUCCESS(err);
17247
17248 VkDescriptorSet descriptor_set = {};
17249 VkDescriptorSetAllocateInfo alloc_info = {};
17250 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17251 alloc_info.descriptorSetCount = 1;
17252 alloc_info.descriptorPool = ds_pool;
17253 alloc_info.pSetLayouts = &ds_layout;
17254 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17255 ASSERT_VK_SUCCESS(err);
17256
17257 // Create a buffer to be used for update
17258 VkBufferCreateInfo buff_ci = {};
17259 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17260 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17261 buff_ci.size = 256;
17262 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17263 VkBuffer buffer;
17264 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
17265 ASSERT_VK_SUCCESS(err);
17266 // Have to bind memory to buffer before descriptor update
17267 VkMemoryAllocateInfo mem_alloc = {};
17268 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17269 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017270 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017271 mem_alloc.memoryTypeIndex = 0;
17272
17273 VkMemoryRequirements mem_reqs;
17274 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17275 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
17276 if (!pass) {
17277 vkDestroyBuffer(m_device->device(), buffer, NULL);
17278 return;
17279 }
17280
17281 VkDeviceMemory mem;
17282 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17283 ASSERT_VK_SUCCESS(err);
17284 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17285 ASSERT_VK_SUCCESS(err);
17286
17287 // Only update the descriptor at binding 2
17288 VkDescriptorBufferInfo buff_info = {};
17289 buff_info.buffer = buffer;
17290 buff_info.offset = 0;
17291 buff_info.range = VK_WHOLE_SIZE;
17292 VkWriteDescriptorSet descriptor_write = {};
17293 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17294 descriptor_write.dstBinding = 2;
17295 descriptor_write.descriptorCount = 1;
17296 descriptor_write.pTexelBufferView = nullptr;
17297 descriptor_write.pBufferInfo = &buff_info;
17298 descriptor_write.pImageInfo = nullptr;
17299 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17300 descriptor_write.dstSet = descriptor_set;
17301
17302 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17303
17304 m_errorMonitor->VerifyNotFound();
17305 // Cleanup
17306 vkFreeMemory(m_device->device(), mem, NULL);
17307 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17308 vkDestroyBuffer(m_device->device(), buffer, NULL);
17309 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17310}
17311
17312// This is a positive test. No failures are expected.
17313TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
17314 VkResult err;
17315 bool pass;
17316
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017317 TEST_DESCRIPTION(
17318 "Create a buffer, allocate memory, bind memory, destroy "
17319 "the buffer, create an image, and bind the same memory to "
17320 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017321
17322 m_errorMonitor->ExpectSuccess();
17323
17324 ASSERT_NO_FATAL_FAILURE(InitState());
17325
17326 VkBuffer buffer;
17327 VkImage image;
17328 VkDeviceMemory mem;
17329 VkMemoryRequirements mem_reqs;
17330
17331 VkBufferCreateInfo buf_info = {};
17332 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17333 buf_info.pNext = NULL;
17334 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17335 buf_info.size = 256;
17336 buf_info.queueFamilyIndexCount = 0;
17337 buf_info.pQueueFamilyIndices = NULL;
17338 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17339 buf_info.flags = 0;
17340 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
17341 ASSERT_VK_SUCCESS(err);
17342
17343 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17344
17345 VkMemoryAllocateInfo alloc_info = {};
17346 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17347 alloc_info.pNext = NULL;
17348 alloc_info.memoryTypeIndex = 0;
17349
17350 // Ensure memory is big enough for both bindings
17351 alloc_info.allocationSize = 0x10000;
17352
17353 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17354 if (!pass) {
17355 vkDestroyBuffer(m_device->device(), buffer, NULL);
17356 return;
17357 }
17358
17359 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17360 ASSERT_VK_SUCCESS(err);
17361
17362 uint8_t *pData;
17363 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
17364 ASSERT_VK_SUCCESS(err);
17365
17366 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
17367
17368 vkUnmapMemory(m_device->device(), mem);
17369
17370 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17371 ASSERT_VK_SUCCESS(err);
17372
17373 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
17374 // memory. In fact, it was never used by the GPU.
17375 // Just be be sure, wait for idle.
17376 vkDestroyBuffer(m_device->device(), buffer, NULL);
17377 vkDeviceWaitIdle(m_device->device());
17378
Tobin Ehlis6a005702016-12-28 15:25:56 -070017379 // Use optimal as some platforms report linear support but then fail image creation
17380 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
17381 VkImageFormatProperties image_format_properties;
17382 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
17383 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
17384 if (image_format_properties.maxExtent.width == 0) {
17385 printf("Image format not supported; skipped.\n");
17386 vkFreeMemory(m_device->device(), mem, NULL);
17387 return;
17388 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017389 VkImageCreateInfo image_create_info = {};
17390 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17391 image_create_info.pNext = NULL;
17392 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17393 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
17394 image_create_info.extent.width = 64;
17395 image_create_info.extent.height = 64;
17396 image_create_info.extent.depth = 1;
17397 image_create_info.mipLevels = 1;
17398 image_create_info.arrayLayers = 1;
17399 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070017400 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017401 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
17402 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17403 image_create_info.queueFamilyIndexCount = 0;
17404 image_create_info.pQueueFamilyIndices = NULL;
17405 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17406 image_create_info.flags = 0;
17407
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017408 /* Create a mappable image. It will be the texture if linear images are ok
17409 * to be textures or it will be the staging image if they are not.
17410 */
17411 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17412 ASSERT_VK_SUCCESS(err);
17413
17414 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
17415
Tobin Ehlis6a005702016-12-28 15:25:56 -070017416 VkMemoryAllocateInfo mem_alloc = {};
17417 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17418 mem_alloc.pNext = NULL;
17419 mem_alloc.allocationSize = 0;
17420 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017421 mem_alloc.allocationSize = mem_reqs.size;
17422
17423 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17424 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070017425 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017426 vkDestroyImage(m_device->device(), image, NULL);
17427 return;
17428 }
17429
17430 // VALIDATION FAILURE:
17431 err = vkBindImageMemory(m_device->device(), image, mem, 0);
17432 ASSERT_VK_SUCCESS(err);
17433
17434 m_errorMonitor->VerifyNotFound();
17435
17436 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017437 vkDestroyImage(m_device->device(), image, NULL);
17438}
17439
Tony Barbourab713912017-02-02 14:17:35 -070017440// This is a positive test. No failures are expected.
17441TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
17442 VkResult err;
17443
17444 TEST_DESCRIPTION(
17445 "Call all applicable destroy and free routines with NULL"
17446 "handles, expecting no validation errors");
17447
17448 m_errorMonitor->ExpectSuccess();
17449
17450 ASSERT_NO_FATAL_FAILURE(InitState());
17451 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
17452 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
17453 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
17454 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
17455 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
17456 vkDestroyDevice(VK_NULL_HANDLE, NULL);
17457 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
17458 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
17459 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
17460 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
17461 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
17462 vkDestroyInstance(VK_NULL_HANDLE, NULL);
17463 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
17464 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
17465 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
17466 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
17467 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
17468 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
17469 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
17470 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
17471
17472 VkCommandPool command_pool;
17473 VkCommandPoolCreateInfo pool_create_info{};
17474 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17475 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17476 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17477 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17478 VkCommandBuffer command_buffers[3] = {};
17479 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17480 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17481 command_buffer_allocate_info.commandPool = command_pool;
17482 command_buffer_allocate_info.commandBufferCount = 1;
17483 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17484 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
17485 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
17486 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17487
17488 VkDescriptorPoolSize ds_type_count = {};
17489 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17490 ds_type_count.descriptorCount = 1;
17491
17492 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17493 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17494 ds_pool_ci.pNext = NULL;
17495 ds_pool_ci.maxSets = 1;
17496 ds_pool_ci.poolSizeCount = 1;
17497 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
17498 ds_pool_ci.pPoolSizes = &ds_type_count;
17499
17500 VkDescriptorPool ds_pool;
17501 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17502 ASSERT_VK_SUCCESS(err);
17503
17504 VkDescriptorSetLayoutBinding dsl_binding = {};
17505 dsl_binding.binding = 2;
17506 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17507 dsl_binding.descriptorCount = 1;
17508 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17509 dsl_binding.pImmutableSamplers = NULL;
17510 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17511 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17512 ds_layout_ci.pNext = NULL;
17513 ds_layout_ci.bindingCount = 1;
17514 ds_layout_ci.pBindings = &dsl_binding;
17515 VkDescriptorSetLayout ds_layout;
17516 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17517 ASSERT_VK_SUCCESS(err);
17518
17519 VkDescriptorSet descriptor_sets[3] = {};
17520 VkDescriptorSetAllocateInfo alloc_info = {};
17521 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17522 alloc_info.descriptorSetCount = 1;
17523 alloc_info.descriptorPool = ds_pool;
17524 alloc_info.pSetLayouts = &ds_layout;
17525 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
17526 ASSERT_VK_SUCCESS(err);
17527 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
17528 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17529 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17530
17531 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
17532
17533 m_errorMonitor->VerifyNotFound();
17534}
17535
Tobin Ehlis953e8392016-11-17 10:54:13 -070017536TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
17537 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
17538 // We previously had a bug where dynamic offset of inactive bindings was still being used
17539 VkResult err;
17540 m_errorMonitor->ExpectSuccess();
17541
17542 ASSERT_NO_FATAL_FAILURE(InitState());
17543 ASSERT_NO_FATAL_FAILURE(InitViewport());
17544 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17545
17546 VkDescriptorPoolSize ds_type_count = {};
17547 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17548 ds_type_count.descriptorCount = 3;
17549
17550 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17551 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17552 ds_pool_ci.pNext = NULL;
17553 ds_pool_ci.maxSets = 1;
17554 ds_pool_ci.poolSizeCount = 1;
17555 ds_pool_ci.pPoolSizes = &ds_type_count;
17556
17557 VkDescriptorPool ds_pool;
17558 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17559 ASSERT_VK_SUCCESS(err);
17560
17561 const uint32_t BINDING_COUNT = 3;
17562 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017563 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017564 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17565 dsl_binding[0].descriptorCount = 1;
17566 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17567 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017568 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017569 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17570 dsl_binding[1].descriptorCount = 1;
17571 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17572 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017573 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017574 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17575 dsl_binding[2].descriptorCount = 1;
17576 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17577 dsl_binding[2].pImmutableSamplers = NULL;
17578
17579 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17580 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17581 ds_layout_ci.pNext = NULL;
17582 ds_layout_ci.bindingCount = BINDING_COUNT;
17583 ds_layout_ci.pBindings = dsl_binding;
17584 VkDescriptorSetLayout ds_layout;
17585 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17586 ASSERT_VK_SUCCESS(err);
17587
17588 VkDescriptorSet descriptor_set;
17589 VkDescriptorSetAllocateInfo alloc_info = {};
17590 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17591 alloc_info.descriptorSetCount = 1;
17592 alloc_info.descriptorPool = ds_pool;
17593 alloc_info.pSetLayouts = &ds_layout;
17594 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17595 ASSERT_VK_SUCCESS(err);
17596
17597 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17598 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17599 pipeline_layout_ci.pNext = NULL;
17600 pipeline_layout_ci.setLayoutCount = 1;
17601 pipeline_layout_ci.pSetLayouts = &ds_layout;
17602
17603 VkPipelineLayout pipeline_layout;
17604 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17605 ASSERT_VK_SUCCESS(err);
17606
17607 // Create two buffers to update the descriptors with
17608 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17609 uint32_t qfi = 0;
17610 VkBufferCreateInfo buffCI = {};
17611 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17612 buffCI.size = 2048;
17613 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17614 buffCI.queueFamilyIndexCount = 1;
17615 buffCI.pQueueFamilyIndices = &qfi;
17616
17617 VkBuffer dyub1;
17618 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17619 ASSERT_VK_SUCCESS(err);
17620 // buffer2
17621 buffCI.size = 1024;
17622 VkBuffer dyub2;
17623 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17624 ASSERT_VK_SUCCESS(err);
17625 // Allocate memory and bind to buffers
17626 VkMemoryAllocateInfo mem_alloc[2] = {};
17627 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17628 mem_alloc[0].pNext = NULL;
17629 mem_alloc[0].memoryTypeIndex = 0;
17630 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17631 mem_alloc[1].pNext = NULL;
17632 mem_alloc[1].memoryTypeIndex = 0;
17633
17634 VkMemoryRequirements mem_reqs1;
17635 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17636 VkMemoryRequirements mem_reqs2;
17637 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17638 mem_alloc[0].allocationSize = mem_reqs1.size;
17639 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17640 mem_alloc[1].allocationSize = mem_reqs2.size;
17641 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17642 if (!pass) {
17643 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17644 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17645 return;
17646 }
17647
17648 VkDeviceMemory mem1;
17649 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17650 ASSERT_VK_SUCCESS(err);
17651 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17652 ASSERT_VK_SUCCESS(err);
17653 VkDeviceMemory mem2;
17654 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17655 ASSERT_VK_SUCCESS(err);
17656 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17657 ASSERT_VK_SUCCESS(err);
17658 // Update descriptors
17659 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17660 buff_info[0].buffer = dyub1;
17661 buff_info[0].offset = 0;
17662 buff_info[0].range = 256;
17663 buff_info[1].buffer = dyub1;
17664 buff_info[1].offset = 256;
17665 buff_info[1].range = 512;
17666 buff_info[2].buffer = dyub2;
17667 buff_info[2].offset = 0;
17668 buff_info[2].range = 512;
17669
17670 VkWriteDescriptorSet descriptor_write;
17671 memset(&descriptor_write, 0, sizeof(descriptor_write));
17672 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17673 descriptor_write.dstSet = descriptor_set;
17674 descriptor_write.dstBinding = 0;
17675 descriptor_write.descriptorCount = BINDING_COUNT;
17676 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17677 descriptor_write.pBufferInfo = buff_info;
17678
17679 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17680
Tony Barbour552f6c02016-12-21 14:34:07 -070017681 m_commandBuffer->BeginCommandBuffer();
17682 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017683
17684 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017685 char const *vsSource =
17686 "#version 450\n"
17687 "\n"
17688 "out gl_PerVertex { \n"
17689 " vec4 gl_Position;\n"
17690 "};\n"
17691 "void main(){\n"
17692 " gl_Position = vec4(1);\n"
17693 "}\n";
17694 char const *fsSource =
17695 "#version 450\n"
17696 "\n"
17697 "layout(location=0) out vec4 x;\n"
17698 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17699 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17700 "void main(){\n"
17701 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17702 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070017703 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17704 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17705 VkPipelineObj pipe(m_device);
17706 pipe.SetViewport(m_viewports);
17707 pipe.SetScissor(m_scissors);
17708 pipe.AddShader(&vs);
17709 pipe.AddShader(&fs);
17710 pipe.AddColorAttachment();
17711 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17712
17713 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17714 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17715 // we used to have a bug in this case.
17716 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17717 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17718 &descriptor_set, BINDING_COUNT, dyn_off);
17719 Draw(1, 0, 0, 0);
17720 m_errorMonitor->VerifyNotFound();
17721
17722 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17723 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17724 vkFreeMemory(m_device->device(), mem1, NULL);
17725 vkFreeMemory(m_device->device(), mem2, NULL);
17726
17727 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17728 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17729 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17730}
17731
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017732TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017733 TEST_DESCRIPTION(
17734 "Ensure that validations handling of non-coherent memory "
17735 "mapping while using VK_WHOLE_SIZE does not cause access "
17736 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017737 VkResult err;
17738 uint8_t *pData;
17739 ASSERT_NO_FATAL_FAILURE(InitState());
17740
17741 VkDeviceMemory mem;
17742 VkMemoryRequirements mem_reqs;
17743 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017744 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017745 VkMemoryAllocateInfo alloc_info = {};
17746 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17747 alloc_info.pNext = NULL;
17748 alloc_info.memoryTypeIndex = 0;
17749
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017750 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017751 alloc_info.allocationSize = allocation_size;
17752
17753 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17754 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 -070017755 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017756 if (!pass) {
17757 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017758 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17759 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017760 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017761 pass = m_device->phy().set_memory_type(
17762 mem_reqs.memoryTypeBits, &alloc_info,
17763 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17764 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017765 if (!pass) {
17766 return;
17767 }
17768 }
17769 }
17770
17771 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17772 ASSERT_VK_SUCCESS(err);
17773
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017774 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017775 m_errorMonitor->ExpectSuccess();
17776 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17777 ASSERT_VK_SUCCESS(err);
17778 VkMappedMemoryRange mmr = {};
17779 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17780 mmr.memory = mem;
17781 mmr.offset = 0;
17782 mmr.size = VK_WHOLE_SIZE;
17783 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17784 ASSERT_VK_SUCCESS(err);
17785 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17786 ASSERT_VK_SUCCESS(err);
17787 m_errorMonitor->VerifyNotFound();
17788 vkUnmapMemory(m_device->device(), mem);
17789
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017790 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017791 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017792 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017793 ASSERT_VK_SUCCESS(err);
17794 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17795 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017796 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017797 mmr.size = VK_WHOLE_SIZE;
17798 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17799 ASSERT_VK_SUCCESS(err);
17800 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17801 ASSERT_VK_SUCCESS(err);
17802 m_errorMonitor->VerifyNotFound();
17803 vkUnmapMemory(m_device->device(), mem);
17804
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017805 // Map with offset and size
17806 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017807 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017808 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017809 ASSERT_VK_SUCCESS(err);
17810 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17811 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017812 mmr.offset = 4 * atom_size;
17813 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017814 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17815 ASSERT_VK_SUCCESS(err);
17816 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17817 ASSERT_VK_SUCCESS(err);
17818 m_errorMonitor->VerifyNotFound();
17819 vkUnmapMemory(m_device->device(), mem);
17820
17821 // Map without offset and flush WHOLE_SIZE with two separate offsets
17822 m_errorMonitor->ExpectSuccess();
17823 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17824 ASSERT_VK_SUCCESS(err);
17825 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17826 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017827 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017828 mmr.size = VK_WHOLE_SIZE;
17829 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17830 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017831 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017832 mmr.size = VK_WHOLE_SIZE;
17833 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17834 ASSERT_VK_SUCCESS(err);
17835 m_errorMonitor->VerifyNotFound();
17836 vkUnmapMemory(m_device->device(), mem);
17837
17838 vkFreeMemory(m_device->device(), mem, NULL);
17839}
17840
17841// This is a positive test. We used to expect error in this case but spec now allows it
17842TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17843 m_errorMonitor->ExpectSuccess();
17844 vk_testing::Fence testFence;
17845 VkFenceCreateInfo fenceInfo = {};
17846 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17847 fenceInfo.pNext = NULL;
17848
17849 ASSERT_NO_FATAL_FAILURE(InitState());
17850 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017851 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017852 VkResult result = vkResetFences(m_device->device(), 1, fences);
17853 ASSERT_VK_SUCCESS(result);
17854
17855 m_errorMonitor->VerifyNotFound();
17856}
17857
17858TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17859 m_errorMonitor->ExpectSuccess();
17860
17861 ASSERT_NO_FATAL_FAILURE(InitState());
17862 VkResult err;
17863
17864 // Record (empty!) command buffer that can be submitted multiple times
17865 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017866 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17867 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017868 m_commandBuffer->BeginCommandBuffer(&cbbi);
17869 m_commandBuffer->EndCommandBuffer();
17870
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017871 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017872 VkFence fence;
17873 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17874 ASSERT_VK_SUCCESS(err);
17875
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017876 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017877 VkSemaphore s1, s2;
17878 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17879 ASSERT_VK_SUCCESS(err);
17880 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17881 ASSERT_VK_SUCCESS(err);
17882
17883 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017884 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017885 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17886 ASSERT_VK_SUCCESS(err);
17887
17888 // Submit CB again, signaling s2.
17889 si.pSignalSemaphores = &s2;
17890 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17891 ASSERT_VK_SUCCESS(err);
17892
17893 // Wait for fence.
17894 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17895 ASSERT_VK_SUCCESS(err);
17896
17897 // CB is still in flight from second submission, but semaphore s1 is no
17898 // longer in flight. delete it.
17899 vkDestroySemaphore(m_device->device(), s1, nullptr);
17900
17901 m_errorMonitor->VerifyNotFound();
17902
17903 // Force device idle and clean up remaining objects
17904 vkDeviceWaitIdle(m_device->device());
17905 vkDestroySemaphore(m_device->device(), s2, nullptr);
17906 vkDestroyFence(m_device->device(), fence, nullptr);
17907}
17908
17909TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17910 m_errorMonitor->ExpectSuccess();
17911
17912 ASSERT_NO_FATAL_FAILURE(InitState());
17913 VkResult err;
17914
17915 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017916 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017917 VkFence f1;
17918 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17919 ASSERT_VK_SUCCESS(err);
17920
17921 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017922 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017923 VkFence f2;
17924 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17925 ASSERT_VK_SUCCESS(err);
17926
17927 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017928 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017929 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17930
17931 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017932 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017933 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17934
17935 // Should have both retired!
17936 vkDestroyFence(m_device->device(), f1, nullptr);
17937 vkDestroyFence(m_device->device(), f2, nullptr);
17938
17939 m_errorMonitor->VerifyNotFound();
17940}
17941
17942TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017943 TEST_DESCRIPTION(
17944 "Verify that creating an image view from an image with valid usage "
17945 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017946
17947 ASSERT_NO_FATAL_FAILURE(InitState());
17948
17949 m_errorMonitor->ExpectSuccess();
17950 // Verify that we can create a view with usage INPUT_ATTACHMENT
17951 VkImageObj image(m_device);
17952 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17953 ASSERT_TRUE(image.initialized());
17954 VkImageView imageView;
17955 VkImageViewCreateInfo ivci = {};
17956 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17957 ivci.image = image.handle();
17958 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17959 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17960 ivci.subresourceRange.layerCount = 1;
17961 ivci.subresourceRange.baseMipLevel = 0;
17962 ivci.subresourceRange.levelCount = 1;
17963 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17964
17965 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17966 m_errorMonitor->VerifyNotFound();
17967 vkDestroyImageView(m_device->device(), imageView, NULL);
17968}
17969
17970// This is a positive test. No failures are expected.
17971TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017972 TEST_DESCRIPTION(
17973 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17974 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017975
17976 ASSERT_NO_FATAL_FAILURE(InitState());
17977
17978 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017979 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017980
17981 m_errorMonitor->ExpectSuccess();
17982
17983 VkImage image;
17984 VkImageCreateInfo image_create_info = {};
17985 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17986 image_create_info.pNext = NULL;
17987 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17988 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17989 image_create_info.extent.width = 64;
17990 image_create_info.extent.height = 64;
17991 image_create_info.extent.depth = 1;
17992 image_create_info.mipLevels = 1;
17993 image_create_info.arrayLayers = 1;
17994 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17995 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17996 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17997 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17998 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17999 ASSERT_VK_SUCCESS(err);
18000
18001 VkMemoryRequirements memory_reqs;
18002 VkDeviceMemory memory_one, memory_two;
18003 bool pass;
18004 VkMemoryAllocateInfo memory_info = {};
18005 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18006 memory_info.pNext = NULL;
18007 memory_info.allocationSize = 0;
18008 memory_info.memoryTypeIndex = 0;
18009 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18010 // Find an image big enough to allow sparse mapping of 2 memory regions
18011 // Increase the image size until it is at least twice the
18012 // size of the required alignment, to ensure we can bind both
18013 // allocated memory blocks to the image on aligned offsets.
18014 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
18015 vkDestroyImage(m_device->device(), image, nullptr);
18016 image_create_info.extent.width *= 2;
18017 image_create_info.extent.height *= 2;
18018 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
18019 ASSERT_VK_SUCCESS(err);
18020 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18021 }
18022 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
18023 // at the end of the first
18024 memory_info.allocationSize = memory_reqs.alignment;
18025 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18026 ASSERT_TRUE(pass);
18027 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
18028 ASSERT_VK_SUCCESS(err);
18029 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
18030 ASSERT_VK_SUCCESS(err);
18031 VkSparseMemoryBind binds[2];
18032 binds[0].flags = 0;
18033 binds[0].memory = memory_one;
18034 binds[0].memoryOffset = 0;
18035 binds[0].resourceOffset = 0;
18036 binds[0].size = memory_info.allocationSize;
18037 binds[1].flags = 0;
18038 binds[1].memory = memory_two;
18039 binds[1].memoryOffset = 0;
18040 binds[1].resourceOffset = memory_info.allocationSize;
18041 binds[1].size = memory_info.allocationSize;
18042
18043 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
18044 opaqueBindInfo.image = image;
18045 opaqueBindInfo.bindCount = 2;
18046 opaqueBindInfo.pBinds = binds;
18047
18048 VkFence fence = VK_NULL_HANDLE;
18049 VkBindSparseInfo bindSparseInfo = {};
18050 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
18051 bindSparseInfo.imageOpaqueBindCount = 1;
18052 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
18053
18054 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
18055 vkQueueWaitIdle(m_device->m_queue);
18056 vkDestroyImage(m_device->device(), image, NULL);
18057 vkFreeMemory(m_device->device(), memory_one, NULL);
18058 vkFreeMemory(m_device->device(), memory_two, NULL);
18059 m_errorMonitor->VerifyNotFound();
18060}
18061
18062TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018063 TEST_DESCRIPTION(
18064 "Ensure that CmdBeginRenderPass with an attachment's "
18065 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
18066 "the command buffer has prior knowledge of that "
18067 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018068
18069 m_errorMonitor->ExpectSuccess();
18070
18071 ASSERT_NO_FATAL_FAILURE(InitState());
18072
18073 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018074 VkAttachmentDescription attachment = {0,
18075 VK_FORMAT_R8G8B8A8_UNORM,
18076 VK_SAMPLE_COUNT_1_BIT,
18077 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18078 VK_ATTACHMENT_STORE_OP_STORE,
18079 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18080 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18081 VK_IMAGE_LAYOUT_UNDEFINED,
18082 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018083
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018084 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018085
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018086 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018087
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018088 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018089
18090 VkRenderPass rp;
18091 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18092 ASSERT_VK_SUCCESS(err);
18093
18094 // A compatible framebuffer.
18095 VkImageObj image(m_device);
18096 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18097 ASSERT_TRUE(image.initialized());
18098
18099 VkImageViewCreateInfo ivci = {
18100 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18101 nullptr,
18102 0,
18103 image.handle(),
18104 VK_IMAGE_VIEW_TYPE_2D,
18105 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018106 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18107 VK_COMPONENT_SWIZZLE_IDENTITY},
18108 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018109 };
18110 VkImageView view;
18111 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18112 ASSERT_VK_SUCCESS(err);
18113
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018114 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018115 VkFramebuffer fb;
18116 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18117 ASSERT_VK_SUCCESS(err);
18118
18119 // Record a single command buffer which uses this renderpass twice. The
18120 // bug is triggered at the beginning of the second renderpass, when the
18121 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018122 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 -070018123 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018124 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18125 vkCmdEndRenderPass(m_commandBuffer->handle());
18126 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18127
18128 m_errorMonitor->VerifyNotFound();
18129
18130 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018131 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018132
18133 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18134 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18135 vkDestroyImageView(m_device->device(), view, nullptr);
18136}
18137
18138TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018139 TEST_DESCRIPTION(
18140 "This test should pass. Create a Framebuffer and "
18141 "command buffer, bind them together, then destroy "
18142 "command pool and framebuffer and verify there are no "
18143 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018144
18145 m_errorMonitor->ExpectSuccess();
18146
18147 ASSERT_NO_FATAL_FAILURE(InitState());
18148
18149 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018150 VkAttachmentDescription attachment = {0,
18151 VK_FORMAT_R8G8B8A8_UNORM,
18152 VK_SAMPLE_COUNT_1_BIT,
18153 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18154 VK_ATTACHMENT_STORE_OP_STORE,
18155 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18156 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18157 VK_IMAGE_LAYOUT_UNDEFINED,
18158 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018159
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018160 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018161
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018162 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018163
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018164 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018165
18166 VkRenderPass rp;
18167 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18168 ASSERT_VK_SUCCESS(err);
18169
18170 // A compatible framebuffer.
18171 VkImageObj image(m_device);
18172 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18173 ASSERT_TRUE(image.initialized());
18174
18175 VkImageViewCreateInfo ivci = {
18176 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18177 nullptr,
18178 0,
18179 image.handle(),
18180 VK_IMAGE_VIEW_TYPE_2D,
18181 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018182 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18183 VK_COMPONENT_SWIZZLE_IDENTITY},
18184 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018185 };
18186 VkImageView view;
18187 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18188 ASSERT_VK_SUCCESS(err);
18189
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018190 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018191 VkFramebuffer fb;
18192 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18193 ASSERT_VK_SUCCESS(err);
18194
18195 // Explicitly create a command buffer to bind the FB to so that we can then
18196 // destroy the command pool in order to implicitly free command buffer
18197 VkCommandPool command_pool;
18198 VkCommandPoolCreateInfo pool_create_info{};
18199 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18200 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18201 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18202 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18203
18204 VkCommandBuffer command_buffer;
18205 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18206 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18207 command_buffer_allocate_info.commandPool = command_pool;
18208 command_buffer_allocate_info.commandBufferCount = 1;
18209 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18210 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18211
18212 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018213 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 -060018214 VkCommandBufferBeginInfo begin_info{};
18215 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18216 vkBeginCommandBuffer(command_buffer, &begin_info);
18217
18218 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18219 vkCmdEndRenderPass(command_buffer);
18220 vkEndCommandBuffer(command_buffer);
18221 vkDestroyImageView(m_device->device(), view, nullptr);
18222 // Destroy command pool to implicitly free command buffer
18223 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18224 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18225 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18226 m_errorMonitor->VerifyNotFound();
18227}
18228
18229TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018230 TEST_DESCRIPTION(
18231 "Ensure that CmdBeginRenderPass applies the layout "
18232 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018233
18234 m_errorMonitor->ExpectSuccess();
18235
18236 ASSERT_NO_FATAL_FAILURE(InitState());
18237
18238 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018239 VkAttachmentDescription attachment = {0,
18240 VK_FORMAT_R8G8B8A8_UNORM,
18241 VK_SAMPLE_COUNT_1_BIT,
18242 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18243 VK_ATTACHMENT_STORE_OP_STORE,
18244 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18245 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18246 VK_IMAGE_LAYOUT_UNDEFINED,
18247 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018248
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018249 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018250
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018251 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018252
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018253 VkSubpassDependency dep = {0,
18254 0,
18255 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18256 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18257 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18258 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18259 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018260
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018261 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018262
18263 VkResult err;
18264 VkRenderPass rp;
18265 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18266 ASSERT_VK_SUCCESS(err);
18267
18268 // A compatible framebuffer.
18269 VkImageObj image(m_device);
18270 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18271 ASSERT_TRUE(image.initialized());
18272
18273 VkImageViewCreateInfo ivci = {
18274 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18275 nullptr,
18276 0,
18277 image.handle(),
18278 VK_IMAGE_VIEW_TYPE_2D,
18279 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018280 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18281 VK_COMPONENT_SWIZZLE_IDENTITY},
18282 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018283 };
18284 VkImageView view;
18285 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18286 ASSERT_VK_SUCCESS(err);
18287
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018288 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018289 VkFramebuffer fb;
18290 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18291 ASSERT_VK_SUCCESS(err);
18292
18293 // Record a single command buffer which issues a pipeline barrier w/
18294 // image memory barrier for the attachment. This detects the previously
18295 // missing tracking of the subpass layout by throwing a validation error
18296 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018297 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 -070018298 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018299 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18300
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018301 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
18302 nullptr,
18303 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18304 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18305 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18306 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18307 VK_QUEUE_FAMILY_IGNORED,
18308 VK_QUEUE_FAMILY_IGNORED,
18309 image.handle(),
18310 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018311 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018312 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18313 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018314
18315 vkCmdEndRenderPass(m_commandBuffer->handle());
18316 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018317 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018318
18319 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18320 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18321 vkDestroyImageView(m_device->device(), view, nullptr);
18322}
18323
18324TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018325 TEST_DESCRIPTION(
18326 "Validate that when an imageView of a depth/stencil image "
18327 "is used as a depth/stencil framebuffer attachment, the "
18328 "aspectMask is ignored and both depth and stencil image "
18329 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018330
18331 VkFormatProperties format_properties;
18332 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
18333 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
18334 return;
18335 }
18336
18337 m_errorMonitor->ExpectSuccess();
18338
18339 ASSERT_NO_FATAL_FAILURE(InitState());
18340
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018341 VkAttachmentDescription attachment = {0,
18342 VK_FORMAT_D32_SFLOAT_S8_UINT,
18343 VK_SAMPLE_COUNT_1_BIT,
18344 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18345 VK_ATTACHMENT_STORE_OP_STORE,
18346 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18347 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18348 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
18349 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018350
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018351 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018352
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018353 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018354
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018355 VkSubpassDependency dep = {0,
18356 0,
18357 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18358 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18359 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18360 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18361 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018362
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018363 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018364
18365 VkResult err;
18366 VkRenderPass rp;
18367 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18368 ASSERT_VK_SUCCESS(err);
18369
18370 VkImageObj image(m_device);
18371 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018372 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018373 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018374 ASSERT_TRUE(image.initialized());
18375 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
18376
18377 VkImageViewCreateInfo ivci = {
18378 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18379 nullptr,
18380 0,
18381 image.handle(),
18382 VK_IMAGE_VIEW_TYPE_2D,
18383 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018384 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
18385 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018386 };
18387 VkImageView view;
18388 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18389 ASSERT_VK_SUCCESS(err);
18390
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018391 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018392 VkFramebuffer fb;
18393 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18394 ASSERT_VK_SUCCESS(err);
18395
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018396 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 -070018397 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018398 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18399
18400 VkImageMemoryBarrier imb = {};
18401 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18402 imb.pNext = nullptr;
18403 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18404 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18405 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18406 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18407 imb.srcQueueFamilyIndex = 0;
18408 imb.dstQueueFamilyIndex = 0;
18409 imb.image = image.handle();
18410 imb.subresourceRange.aspectMask = 0x6;
18411 imb.subresourceRange.baseMipLevel = 0;
18412 imb.subresourceRange.levelCount = 0x1;
18413 imb.subresourceRange.baseArrayLayer = 0;
18414 imb.subresourceRange.layerCount = 0x1;
18415
18416 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018417 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18418 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018419
18420 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018421 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018422 QueueCommandBuffer(false);
18423 m_errorMonitor->VerifyNotFound();
18424
18425 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18426 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18427 vkDestroyImageView(m_device->device(), view, nullptr);
18428}
18429
18430TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018431 TEST_DESCRIPTION(
18432 "Ensure that layout transitions work correctly without "
18433 "errors, when an attachment reference is "
18434 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018435
18436 m_errorMonitor->ExpectSuccess();
18437
18438 ASSERT_NO_FATAL_FAILURE(InitState());
18439
18440 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018441 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018442
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018443 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018444
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018445 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018446
18447 VkRenderPass rp;
18448 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18449 ASSERT_VK_SUCCESS(err);
18450
18451 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018452 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018453 VkFramebuffer fb;
18454 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18455 ASSERT_VK_SUCCESS(err);
18456
18457 // Record a command buffer which just begins and ends the renderpass. The
18458 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018459 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 -070018460 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018461 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18462 vkCmdEndRenderPass(m_commandBuffer->handle());
18463 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018464 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018465
18466 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18467 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18468}
18469
18470// This is a positive test. No errors are expected.
18471TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018472 TEST_DESCRIPTION(
18473 "Create a stencil-only attachment with a LOAD_OP set to "
18474 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018475 VkResult result = VK_SUCCESS;
18476 VkImageFormatProperties formatProps;
18477 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018478 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
18479 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018480 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
18481 return;
18482 }
18483
18484 ASSERT_NO_FATAL_FAILURE(InitState());
18485 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
18486 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018487 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018488 VkAttachmentDescription att = {};
18489 VkAttachmentReference ref = {};
18490 att.format = depth_stencil_fmt;
18491 att.samples = VK_SAMPLE_COUNT_1_BIT;
18492 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
18493 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18494 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18495 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
18496 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18497 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18498
18499 VkClearValue clear;
18500 clear.depthStencil.depth = 1.0;
18501 clear.depthStencil.stencil = 0;
18502 ref.attachment = 0;
18503 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18504
18505 VkSubpassDescription subpass = {};
18506 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
18507 subpass.flags = 0;
18508 subpass.inputAttachmentCount = 0;
18509 subpass.pInputAttachments = NULL;
18510 subpass.colorAttachmentCount = 0;
18511 subpass.pColorAttachments = NULL;
18512 subpass.pResolveAttachments = NULL;
18513 subpass.pDepthStencilAttachment = &ref;
18514 subpass.preserveAttachmentCount = 0;
18515 subpass.pPreserveAttachments = NULL;
18516
18517 VkRenderPass rp;
18518 VkRenderPassCreateInfo rp_info = {};
18519 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18520 rp_info.attachmentCount = 1;
18521 rp_info.pAttachments = &att;
18522 rp_info.subpassCount = 1;
18523 rp_info.pSubpasses = &subpass;
18524 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
18525 ASSERT_VK_SUCCESS(result);
18526
18527 VkImageView *depthView = m_depthStencil->BindInfo();
18528 VkFramebufferCreateInfo fb_info = {};
18529 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
18530 fb_info.pNext = NULL;
18531 fb_info.renderPass = rp;
18532 fb_info.attachmentCount = 1;
18533 fb_info.pAttachments = depthView;
18534 fb_info.width = 100;
18535 fb_info.height = 100;
18536 fb_info.layers = 1;
18537 VkFramebuffer fb;
18538 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
18539 ASSERT_VK_SUCCESS(result);
18540
18541 VkRenderPassBeginInfo rpbinfo = {};
18542 rpbinfo.clearValueCount = 1;
18543 rpbinfo.pClearValues = &clear;
18544 rpbinfo.pNext = NULL;
18545 rpbinfo.renderPass = rp;
18546 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
18547 rpbinfo.renderArea.extent.width = 100;
18548 rpbinfo.renderArea.extent.height = 100;
18549 rpbinfo.renderArea.offset.x = 0;
18550 rpbinfo.renderArea.offset.y = 0;
18551 rpbinfo.framebuffer = fb;
18552
18553 VkFence fence = {};
18554 VkFenceCreateInfo fence_ci = {};
18555 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18556 fence_ci.pNext = nullptr;
18557 fence_ci.flags = 0;
18558 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
18559 ASSERT_VK_SUCCESS(result);
18560
18561 m_commandBuffer->BeginCommandBuffer();
18562 m_commandBuffer->BeginRenderPass(rpbinfo);
18563 m_commandBuffer->EndRenderPass();
18564 m_commandBuffer->EndCommandBuffer();
18565 m_commandBuffer->QueueCommandBuffer(fence);
18566
18567 VkImageObj destImage(m_device);
18568 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 -070018569 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018570 VkImageMemoryBarrier barrier = {};
18571 VkImageSubresourceRange range;
18572 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18573 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18574 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
18575 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18576 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18577 barrier.image = m_depthStencil->handle();
18578 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18579 range.baseMipLevel = 0;
18580 range.levelCount = 1;
18581 range.baseArrayLayer = 0;
18582 range.layerCount = 1;
18583 barrier.subresourceRange = range;
18584 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18585 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18586 cmdbuf.BeginCommandBuffer();
18587 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 -070018588 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018589 barrier.srcAccessMask = 0;
18590 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18591 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18592 barrier.image = destImage.handle();
18593 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18594 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 -070018595 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018596 VkImageCopy cregion;
18597 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18598 cregion.srcSubresource.mipLevel = 0;
18599 cregion.srcSubresource.baseArrayLayer = 0;
18600 cregion.srcSubresource.layerCount = 1;
18601 cregion.srcOffset.x = 0;
18602 cregion.srcOffset.y = 0;
18603 cregion.srcOffset.z = 0;
18604 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18605 cregion.dstSubresource.mipLevel = 0;
18606 cregion.dstSubresource.baseArrayLayer = 0;
18607 cregion.dstSubresource.layerCount = 1;
18608 cregion.dstOffset.x = 0;
18609 cregion.dstOffset.y = 0;
18610 cregion.dstOffset.z = 0;
18611 cregion.extent.width = 100;
18612 cregion.extent.height = 100;
18613 cregion.extent.depth = 1;
18614 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018615 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018616 cmdbuf.EndCommandBuffer();
18617
18618 VkSubmitInfo submit_info;
18619 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18620 submit_info.pNext = NULL;
18621 submit_info.waitSemaphoreCount = 0;
18622 submit_info.pWaitSemaphores = NULL;
18623 submit_info.pWaitDstStageMask = NULL;
18624 submit_info.commandBufferCount = 1;
18625 submit_info.pCommandBuffers = &cmdbuf.handle();
18626 submit_info.signalSemaphoreCount = 0;
18627 submit_info.pSignalSemaphores = NULL;
18628
18629 m_errorMonitor->ExpectSuccess();
18630 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18631 m_errorMonitor->VerifyNotFound();
18632
18633 vkQueueWaitIdle(m_device->m_queue);
18634 vkDestroyFence(m_device->device(), fence, nullptr);
18635 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18636 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18637}
18638
18639// This is a positive test. No errors should be generated.
18640TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18641 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18642
18643 m_errorMonitor->ExpectSuccess();
18644 ASSERT_NO_FATAL_FAILURE(InitState());
18645
18646 VkEvent event;
18647 VkEventCreateInfo event_create_info{};
18648 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18649 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18650
18651 VkCommandPool command_pool;
18652 VkCommandPoolCreateInfo pool_create_info{};
18653 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18654 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18655 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18656 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18657
18658 VkCommandBuffer command_buffer;
18659 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18660 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18661 command_buffer_allocate_info.commandPool = command_pool;
18662 command_buffer_allocate_info.commandBufferCount = 1;
18663 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18664 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18665
18666 VkQueue queue = VK_NULL_HANDLE;
18667 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18668
18669 {
18670 VkCommandBufferBeginInfo begin_info{};
18671 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18672 vkBeginCommandBuffer(command_buffer, &begin_info);
18673
18674 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 -070018675 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018676 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18677 vkEndCommandBuffer(command_buffer);
18678 }
18679 {
18680 VkSubmitInfo submit_info{};
18681 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18682 submit_info.commandBufferCount = 1;
18683 submit_info.pCommandBuffers = &command_buffer;
18684 submit_info.signalSemaphoreCount = 0;
18685 submit_info.pSignalSemaphores = nullptr;
18686 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18687 }
18688 { vkSetEvent(m_device->device(), event); }
18689
18690 vkQueueWaitIdle(queue);
18691
18692 vkDestroyEvent(m_device->device(), event, nullptr);
18693 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18694 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18695
18696 m_errorMonitor->VerifyNotFound();
18697}
18698// This is a positive test. No errors should be generated.
18699TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18700 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18701
18702 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018703 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018704
18705 m_errorMonitor->ExpectSuccess();
18706
18707 VkQueryPool query_pool;
18708 VkQueryPoolCreateInfo query_pool_create_info{};
18709 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18710 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18711 query_pool_create_info.queryCount = 1;
18712 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18713
18714 VkCommandPool command_pool;
18715 VkCommandPoolCreateInfo pool_create_info{};
18716 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18717 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18718 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18719 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18720
18721 VkCommandBuffer command_buffer;
18722 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18723 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18724 command_buffer_allocate_info.commandPool = command_pool;
18725 command_buffer_allocate_info.commandBufferCount = 1;
18726 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18727 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18728
18729 VkCommandBuffer secondary_command_buffer;
18730 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18731 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18732
18733 VkQueue queue = VK_NULL_HANDLE;
18734 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18735
18736 uint32_t qfi = 0;
18737 VkBufferCreateInfo buff_create_info = {};
18738 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18739 buff_create_info.size = 1024;
18740 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18741 buff_create_info.queueFamilyIndexCount = 1;
18742 buff_create_info.pQueueFamilyIndices = &qfi;
18743
18744 VkResult err;
18745 VkBuffer buffer;
18746 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18747 ASSERT_VK_SUCCESS(err);
18748 VkMemoryAllocateInfo mem_alloc = {};
18749 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18750 mem_alloc.pNext = NULL;
18751 mem_alloc.allocationSize = 1024;
18752 mem_alloc.memoryTypeIndex = 0;
18753
18754 VkMemoryRequirements memReqs;
18755 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18756 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18757 if (!pass) {
18758 vkDestroyBuffer(m_device->device(), buffer, NULL);
18759 return;
18760 }
18761
18762 VkDeviceMemory mem;
18763 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18764 ASSERT_VK_SUCCESS(err);
18765 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18766 ASSERT_VK_SUCCESS(err);
18767
18768 VkCommandBufferInheritanceInfo hinfo = {};
18769 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18770 hinfo.renderPass = VK_NULL_HANDLE;
18771 hinfo.subpass = 0;
18772 hinfo.framebuffer = VK_NULL_HANDLE;
18773 hinfo.occlusionQueryEnable = VK_FALSE;
18774 hinfo.queryFlags = 0;
18775 hinfo.pipelineStatistics = 0;
18776
18777 {
18778 VkCommandBufferBeginInfo begin_info{};
18779 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18780 begin_info.pInheritanceInfo = &hinfo;
18781 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18782
18783 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18784 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18785
18786 vkEndCommandBuffer(secondary_command_buffer);
18787
18788 begin_info.pInheritanceInfo = nullptr;
18789 vkBeginCommandBuffer(command_buffer, &begin_info);
18790
18791 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18792 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18793
18794 vkEndCommandBuffer(command_buffer);
18795 }
18796 {
18797 VkSubmitInfo submit_info{};
18798 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18799 submit_info.commandBufferCount = 1;
18800 submit_info.pCommandBuffers = &command_buffer;
18801 submit_info.signalSemaphoreCount = 0;
18802 submit_info.pSignalSemaphores = nullptr;
18803 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18804 }
18805
18806 vkQueueWaitIdle(queue);
18807
18808 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18809 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18810 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18811 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18812 vkDestroyBuffer(m_device->device(), buffer, NULL);
18813 vkFreeMemory(m_device->device(), mem, NULL);
18814
18815 m_errorMonitor->VerifyNotFound();
18816}
18817
18818// This is a positive test. No errors should be generated.
18819TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18820 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18821
18822 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018823 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018824
18825 m_errorMonitor->ExpectSuccess();
18826
18827 VkQueryPool query_pool;
18828 VkQueryPoolCreateInfo query_pool_create_info{};
18829 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18830 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18831 query_pool_create_info.queryCount = 1;
18832 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18833
18834 VkCommandPool command_pool;
18835 VkCommandPoolCreateInfo pool_create_info{};
18836 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18837 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18838 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18839 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18840
18841 VkCommandBuffer command_buffer[2];
18842 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18843 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18844 command_buffer_allocate_info.commandPool = command_pool;
18845 command_buffer_allocate_info.commandBufferCount = 2;
18846 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18847 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18848
18849 VkQueue queue = VK_NULL_HANDLE;
18850 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18851
18852 uint32_t qfi = 0;
18853 VkBufferCreateInfo buff_create_info = {};
18854 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18855 buff_create_info.size = 1024;
18856 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18857 buff_create_info.queueFamilyIndexCount = 1;
18858 buff_create_info.pQueueFamilyIndices = &qfi;
18859
18860 VkResult err;
18861 VkBuffer buffer;
18862 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18863 ASSERT_VK_SUCCESS(err);
18864 VkMemoryAllocateInfo mem_alloc = {};
18865 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18866 mem_alloc.pNext = NULL;
18867 mem_alloc.allocationSize = 1024;
18868 mem_alloc.memoryTypeIndex = 0;
18869
18870 VkMemoryRequirements memReqs;
18871 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18872 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18873 if (!pass) {
18874 vkDestroyBuffer(m_device->device(), buffer, NULL);
18875 return;
18876 }
18877
18878 VkDeviceMemory mem;
18879 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18880 ASSERT_VK_SUCCESS(err);
18881 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18882 ASSERT_VK_SUCCESS(err);
18883
18884 {
18885 VkCommandBufferBeginInfo begin_info{};
18886 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18887 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18888
18889 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18890 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18891
18892 vkEndCommandBuffer(command_buffer[0]);
18893
18894 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18895
18896 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18897
18898 vkEndCommandBuffer(command_buffer[1]);
18899 }
18900 {
18901 VkSubmitInfo submit_info{};
18902 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18903 submit_info.commandBufferCount = 2;
18904 submit_info.pCommandBuffers = command_buffer;
18905 submit_info.signalSemaphoreCount = 0;
18906 submit_info.pSignalSemaphores = nullptr;
18907 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18908 }
18909
18910 vkQueueWaitIdle(queue);
18911
18912 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18913 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18914 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18915 vkDestroyBuffer(m_device->device(), buffer, NULL);
18916 vkFreeMemory(m_device->device(), mem, NULL);
18917
18918 m_errorMonitor->VerifyNotFound();
18919}
18920
Tony Barbourc46924f2016-11-04 11:49:52 -060018921TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018922 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18923
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018924 ASSERT_NO_FATAL_FAILURE(InitState());
18925 VkEvent event;
18926 VkEventCreateInfo event_create_info{};
18927 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18928 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18929
18930 VkCommandPool command_pool;
18931 VkCommandPoolCreateInfo pool_create_info{};
18932 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18933 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18934 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18935 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18936
18937 VkCommandBuffer command_buffer;
18938 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18939 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18940 command_buffer_allocate_info.commandPool = command_pool;
18941 command_buffer_allocate_info.commandBufferCount = 1;
18942 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18943 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18944
18945 VkQueue queue = VK_NULL_HANDLE;
18946 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18947
18948 {
18949 VkCommandBufferBeginInfo begin_info{};
18950 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18951 vkBeginCommandBuffer(command_buffer, &begin_info);
18952
18953 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018954 vkEndCommandBuffer(command_buffer);
18955 }
18956 {
18957 VkSubmitInfo submit_info{};
18958 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18959 submit_info.commandBufferCount = 1;
18960 submit_info.pCommandBuffers = &command_buffer;
18961 submit_info.signalSemaphoreCount = 0;
18962 submit_info.pSignalSemaphores = nullptr;
18963 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18964 }
18965 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18967 "that is already in use by a "
18968 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018969 vkSetEvent(m_device->device(), event);
18970 m_errorMonitor->VerifyFound();
18971 }
18972
18973 vkQueueWaitIdle(queue);
18974
18975 vkDestroyEvent(m_device->device(), event, nullptr);
18976 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18977 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18978}
18979
18980// This is a positive test. No errors should be generated.
18981TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018982 TEST_DESCRIPTION(
18983 "Two command buffers with two separate fences are each "
18984 "run through a Submit & WaitForFences cycle 3 times. This "
18985 "previously revealed a bug so running this positive test "
18986 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018987 m_errorMonitor->ExpectSuccess();
18988
18989 ASSERT_NO_FATAL_FAILURE(InitState());
18990 VkQueue queue = VK_NULL_HANDLE;
18991 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18992
18993 static const uint32_t NUM_OBJECTS = 2;
18994 static const uint32_t NUM_FRAMES = 3;
18995 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18996 VkFence fences[NUM_OBJECTS] = {};
18997
18998 VkCommandPool cmd_pool;
18999 VkCommandPoolCreateInfo cmd_pool_ci = {};
19000 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19001 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
19002 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19003 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
19004 ASSERT_VK_SUCCESS(err);
19005
19006 VkCommandBufferAllocateInfo cmd_buf_info = {};
19007 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19008 cmd_buf_info.commandPool = cmd_pool;
19009 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19010 cmd_buf_info.commandBufferCount = 1;
19011
19012 VkFenceCreateInfo fence_ci = {};
19013 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19014 fence_ci.pNext = nullptr;
19015 fence_ci.flags = 0;
19016
19017 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19018 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
19019 ASSERT_VK_SUCCESS(err);
19020 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
19021 ASSERT_VK_SUCCESS(err);
19022 }
19023
19024 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
19025 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
19026 // Create empty cmd buffer
19027 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
19028 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19029
19030 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
19031 ASSERT_VK_SUCCESS(err);
19032 err = vkEndCommandBuffer(cmd_buffers[obj]);
19033 ASSERT_VK_SUCCESS(err);
19034
19035 VkSubmitInfo submit_info = {};
19036 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19037 submit_info.commandBufferCount = 1;
19038 submit_info.pCommandBuffers = &cmd_buffers[obj];
19039 // Submit cmd buffer and wait for fence
19040 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
19041 ASSERT_VK_SUCCESS(err);
19042 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
19043 ASSERT_VK_SUCCESS(err);
19044 err = vkResetFences(m_device->device(), 1, &fences[obj]);
19045 ASSERT_VK_SUCCESS(err);
19046 }
19047 }
19048 m_errorMonitor->VerifyNotFound();
19049 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
19050 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19051 vkDestroyFence(m_device->device(), fences[i], nullptr);
19052 }
19053}
19054// This is a positive test. No errors should be generated.
19055TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019056 TEST_DESCRIPTION(
19057 "Two command buffers, each in a separate QueueSubmit call "
19058 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019059
19060 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019061 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019062
19063 m_errorMonitor->ExpectSuccess();
19064
19065 VkSemaphore semaphore;
19066 VkSemaphoreCreateInfo semaphore_create_info{};
19067 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19068 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19069
19070 VkCommandPool command_pool;
19071 VkCommandPoolCreateInfo pool_create_info{};
19072 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19073 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19074 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19075 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19076
19077 VkCommandBuffer command_buffer[2];
19078 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19079 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19080 command_buffer_allocate_info.commandPool = command_pool;
19081 command_buffer_allocate_info.commandBufferCount = 2;
19082 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19083 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19084
19085 VkQueue queue = VK_NULL_HANDLE;
19086 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19087
19088 {
19089 VkCommandBufferBeginInfo begin_info{};
19090 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19091 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19092
19093 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 -070019094 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019095
19096 VkViewport viewport{};
19097 viewport.maxDepth = 1.0f;
19098 viewport.minDepth = 0.0f;
19099 viewport.width = 512;
19100 viewport.height = 512;
19101 viewport.x = 0;
19102 viewport.y = 0;
19103 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19104 vkEndCommandBuffer(command_buffer[0]);
19105 }
19106 {
19107 VkCommandBufferBeginInfo begin_info{};
19108 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19109 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19110
19111 VkViewport viewport{};
19112 viewport.maxDepth = 1.0f;
19113 viewport.minDepth = 0.0f;
19114 viewport.width = 512;
19115 viewport.height = 512;
19116 viewport.x = 0;
19117 viewport.y = 0;
19118 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19119 vkEndCommandBuffer(command_buffer[1]);
19120 }
19121 {
19122 VkSubmitInfo submit_info{};
19123 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19124 submit_info.commandBufferCount = 1;
19125 submit_info.pCommandBuffers = &command_buffer[0];
19126 submit_info.signalSemaphoreCount = 1;
19127 submit_info.pSignalSemaphores = &semaphore;
19128 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19129 }
19130 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019131 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019132 VkSubmitInfo submit_info{};
19133 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19134 submit_info.commandBufferCount = 1;
19135 submit_info.pCommandBuffers = &command_buffer[1];
19136 submit_info.waitSemaphoreCount = 1;
19137 submit_info.pWaitSemaphores = &semaphore;
19138 submit_info.pWaitDstStageMask = flags;
19139 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19140 }
19141
19142 vkQueueWaitIdle(m_device->m_queue);
19143
19144 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19145 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19146 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19147
19148 m_errorMonitor->VerifyNotFound();
19149}
19150
19151// This is a positive test. No errors should be generated.
19152TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019153 TEST_DESCRIPTION(
19154 "Two command buffers, each in a separate QueueSubmit call "
19155 "submitted on separate queues, the second having a fence"
19156 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019157
19158 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019159 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019160
19161 m_errorMonitor->ExpectSuccess();
19162
19163 VkFence fence;
19164 VkFenceCreateInfo fence_create_info{};
19165 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19166 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19167
19168 VkSemaphore semaphore;
19169 VkSemaphoreCreateInfo semaphore_create_info{};
19170 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19171 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19172
19173 VkCommandPool command_pool;
19174 VkCommandPoolCreateInfo pool_create_info{};
19175 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19176 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19177 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19178 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19179
19180 VkCommandBuffer command_buffer[2];
19181 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19182 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19183 command_buffer_allocate_info.commandPool = command_pool;
19184 command_buffer_allocate_info.commandBufferCount = 2;
19185 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19186 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19187
19188 VkQueue queue = VK_NULL_HANDLE;
19189 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19190
19191 {
19192 VkCommandBufferBeginInfo begin_info{};
19193 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19194 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19195
19196 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 -070019197 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019198
19199 VkViewport viewport{};
19200 viewport.maxDepth = 1.0f;
19201 viewport.minDepth = 0.0f;
19202 viewport.width = 512;
19203 viewport.height = 512;
19204 viewport.x = 0;
19205 viewport.y = 0;
19206 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19207 vkEndCommandBuffer(command_buffer[0]);
19208 }
19209 {
19210 VkCommandBufferBeginInfo begin_info{};
19211 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19212 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19213
19214 VkViewport viewport{};
19215 viewport.maxDepth = 1.0f;
19216 viewport.minDepth = 0.0f;
19217 viewport.width = 512;
19218 viewport.height = 512;
19219 viewport.x = 0;
19220 viewport.y = 0;
19221 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19222 vkEndCommandBuffer(command_buffer[1]);
19223 }
19224 {
19225 VkSubmitInfo submit_info{};
19226 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19227 submit_info.commandBufferCount = 1;
19228 submit_info.pCommandBuffers = &command_buffer[0];
19229 submit_info.signalSemaphoreCount = 1;
19230 submit_info.pSignalSemaphores = &semaphore;
19231 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19232 }
19233 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019234 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019235 VkSubmitInfo submit_info{};
19236 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19237 submit_info.commandBufferCount = 1;
19238 submit_info.pCommandBuffers = &command_buffer[1];
19239 submit_info.waitSemaphoreCount = 1;
19240 submit_info.pWaitSemaphores = &semaphore;
19241 submit_info.pWaitDstStageMask = flags;
19242 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19243 }
19244
19245 vkQueueWaitIdle(m_device->m_queue);
19246
19247 vkDestroyFence(m_device->device(), fence, nullptr);
19248 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19249 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19250 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19251
19252 m_errorMonitor->VerifyNotFound();
19253}
19254
19255// This is a positive test. No errors should be generated.
19256TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019257 TEST_DESCRIPTION(
19258 "Two command buffers, each in a separate QueueSubmit call "
19259 "submitted on separate queues, the second having a fence"
19260 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019261
19262 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019263 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019264
19265 m_errorMonitor->ExpectSuccess();
19266
19267 VkFence fence;
19268 VkFenceCreateInfo fence_create_info{};
19269 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19270 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19271
19272 VkSemaphore semaphore;
19273 VkSemaphoreCreateInfo semaphore_create_info{};
19274 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19275 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19276
19277 VkCommandPool command_pool;
19278 VkCommandPoolCreateInfo pool_create_info{};
19279 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19280 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19281 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19282 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19283
19284 VkCommandBuffer command_buffer[2];
19285 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19286 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19287 command_buffer_allocate_info.commandPool = command_pool;
19288 command_buffer_allocate_info.commandBufferCount = 2;
19289 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19290 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19291
19292 VkQueue queue = VK_NULL_HANDLE;
19293 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19294
19295 {
19296 VkCommandBufferBeginInfo begin_info{};
19297 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19298 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19299
19300 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 -070019301 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019302
19303 VkViewport viewport{};
19304 viewport.maxDepth = 1.0f;
19305 viewport.minDepth = 0.0f;
19306 viewport.width = 512;
19307 viewport.height = 512;
19308 viewport.x = 0;
19309 viewport.y = 0;
19310 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19311 vkEndCommandBuffer(command_buffer[0]);
19312 }
19313 {
19314 VkCommandBufferBeginInfo begin_info{};
19315 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19316 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19317
19318 VkViewport viewport{};
19319 viewport.maxDepth = 1.0f;
19320 viewport.minDepth = 0.0f;
19321 viewport.width = 512;
19322 viewport.height = 512;
19323 viewport.x = 0;
19324 viewport.y = 0;
19325 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19326 vkEndCommandBuffer(command_buffer[1]);
19327 }
19328 {
19329 VkSubmitInfo submit_info{};
19330 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19331 submit_info.commandBufferCount = 1;
19332 submit_info.pCommandBuffers = &command_buffer[0];
19333 submit_info.signalSemaphoreCount = 1;
19334 submit_info.pSignalSemaphores = &semaphore;
19335 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19336 }
19337 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019338 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019339 VkSubmitInfo submit_info{};
19340 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19341 submit_info.commandBufferCount = 1;
19342 submit_info.pCommandBuffers = &command_buffer[1];
19343 submit_info.waitSemaphoreCount = 1;
19344 submit_info.pWaitSemaphores = &semaphore;
19345 submit_info.pWaitDstStageMask = flags;
19346 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19347 }
19348
19349 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19350 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19351
19352 vkDestroyFence(m_device->device(), fence, nullptr);
19353 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19354 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19355 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19356
19357 m_errorMonitor->VerifyNotFound();
19358}
19359
19360TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019361 ASSERT_NO_FATAL_FAILURE(InitState());
19362 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
19363 printf("Test requires two queues, skipping\n");
19364 return;
19365 }
19366
19367 VkResult err;
19368
19369 m_errorMonitor->ExpectSuccess();
19370
19371 VkQueue q0 = m_device->m_queue;
19372 VkQueue q1 = nullptr;
19373 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
19374 ASSERT_NE(q1, nullptr);
19375
19376 // An (empty) command buffer. We must have work in the first submission --
19377 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019378 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019379 VkCommandPool pool;
19380 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
19381 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019382 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
19383 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019384 VkCommandBuffer cb;
19385 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
19386 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019387 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019388 err = vkBeginCommandBuffer(cb, &cbbi);
19389 ASSERT_VK_SUCCESS(err);
19390 err = vkEndCommandBuffer(cb);
19391 ASSERT_VK_SUCCESS(err);
19392
19393 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019394 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019395 VkSemaphore s;
19396 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
19397 ASSERT_VK_SUCCESS(err);
19398
19399 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019400 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019401
19402 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
19403 ASSERT_VK_SUCCESS(err);
19404
19405 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019406 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019407 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019408
19409 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
19410 ASSERT_VK_SUCCESS(err);
19411
19412 // Wait for q0 idle
19413 err = vkQueueWaitIdle(q0);
19414 ASSERT_VK_SUCCESS(err);
19415
19416 // Command buffer should have been completed (it was on q0); reset the pool.
19417 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
19418
19419 m_errorMonitor->VerifyNotFound();
19420
19421 // Force device completely idle and clean up resources
19422 vkDeviceWaitIdle(m_device->device());
19423 vkDestroyCommandPool(m_device->device(), pool, nullptr);
19424 vkDestroySemaphore(m_device->device(), s, nullptr);
19425}
19426
19427// This is a positive test. No errors should be generated.
19428TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019429 TEST_DESCRIPTION(
19430 "Two command buffers, each in a separate QueueSubmit call "
19431 "submitted on separate queues, the second having a fence, "
19432 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019433
19434 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019435 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019436
19437 m_errorMonitor->ExpectSuccess();
19438
19439 ASSERT_NO_FATAL_FAILURE(InitState());
19440 VkFence fence;
19441 VkFenceCreateInfo fence_create_info{};
19442 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19443 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19444
19445 VkSemaphore semaphore;
19446 VkSemaphoreCreateInfo semaphore_create_info{};
19447 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19448 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19449
19450 VkCommandPool command_pool;
19451 VkCommandPoolCreateInfo pool_create_info{};
19452 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19453 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19454 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19455 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19456
19457 VkCommandBuffer command_buffer[2];
19458 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19459 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19460 command_buffer_allocate_info.commandPool = command_pool;
19461 command_buffer_allocate_info.commandBufferCount = 2;
19462 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19463 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19464
19465 VkQueue queue = VK_NULL_HANDLE;
19466 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19467
19468 {
19469 VkCommandBufferBeginInfo begin_info{};
19470 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19471 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19472
19473 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 -070019474 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019475
19476 VkViewport viewport{};
19477 viewport.maxDepth = 1.0f;
19478 viewport.minDepth = 0.0f;
19479 viewport.width = 512;
19480 viewport.height = 512;
19481 viewport.x = 0;
19482 viewport.y = 0;
19483 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19484 vkEndCommandBuffer(command_buffer[0]);
19485 }
19486 {
19487 VkCommandBufferBeginInfo begin_info{};
19488 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19489 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19490
19491 VkViewport viewport{};
19492 viewport.maxDepth = 1.0f;
19493 viewport.minDepth = 0.0f;
19494 viewport.width = 512;
19495 viewport.height = 512;
19496 viewport.x = 0;
19497 viewport.y = 0;
19498 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19499 vkEndCommandBuffer(command_buffer[1]);
19500 }
19501 {
19502 VkSubmitInfo submit_info{};
19503 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19504 submit_info.commandBufferCount = 1;
19505 submit_info.pCommandBuffers = &command_buffer[0];
19506 submit_info.signalSemaphoreCount = 1;
19507 submit_info.pSignalSemaphores = &semaphore;
19508 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19509 }
19510 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019511 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019512 VkSubmitInfo submit_info{};
19513 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19514 submit_info.commandBufferCount = 1;
19515 submit_info.pCommandBuffers = &command_buffer[1];
19516 submit_info.waitSemaphoreCount = 1;
19517 submit_info.pWaitSemaphores = &semaphore;
19518 submit_info.pWaitDstStageMask = flags;
19519 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19520 }
19521
19522 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19523
19524 vkDestroyFence(m_device->device(), fence, nullptr);
19525 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19526 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19527 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19528
19529 m_errorMonitor->VerifyNotFound();
19530}
19531
19532// This is a positive test. No errors should be generated.
19533TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019534 TEST_DESCRIPTION(
19535 "Two command buffers, each in a separate QueueSubmit call "
19536 "on the same queue, sharing a signal/wait semaphore, the "
19537 "second having a fence, "
19538 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019539
19540 m_errorMonitor->ExpectSuccess();
19541
19542 ASSERT_NO_FATAL_FAILURE(InitState());
19543 VkFence fence;
19544 VkFenceCreateInfo fence_create_info{};
19545 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19546 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19547
19548 VkSemaphore semaphore;
19549 VkSemaphoreCreateInfo semaphore_create_info{};
19550 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19551 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19552
19553 VkCommandPool command_pool;
19554 VkCommandPoolCreateInfo pool_create_info{};
19555 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19556 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19557 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19558 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19559
19560 VkCommandBuffer command_buffer[2];
19561 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19562 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19563 command_buffer_allocate_info.commandPool = command_pool;
19564 command_buffer_allocate_info.commandBufferCount = 2;
19565 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19566 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19567
19568 {
19569 VkCommandBufferBeginInfo begin_info{};
19570 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19571 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19572
19573 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 -070019574 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019575
19576 VkViewport viewport{};
19577 viewport.maxDepth = 1.0f;
19578 viewport.minDepth = 0.0f;
19579 viewport.width = 512;
19580 viewport.height = 512;
19581 viewport.x = 0;
19582 viewport.y = 0;
19583 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19584 vkEndCommandBuffer(command_buffer[0]);
19585 }
19586 {
19587 VkCommandBufferBeginInfo begin_info{};
19588 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19589 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19590
19591 VkViewport viewport{};
19592 viewport.maxDepth = 1.0f;
19593 viewport.minDepth = 0.0f;
19594 viewport.width = 512;
19595 viewport.height = 512;
19596 viewport.x = 0;
19597 viewport.y = 0;
19598 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19599 vkEndCommandBuffer(command_buffer[1]);
19600 }
19601 {
19602 VkSubmitInfo submit_info{};
19603 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19604 submit_info.commandBufferCount = 1;
19605 submit_info.pCommandBuffers = &command_buffer[0];
19606 submit_info.signalSemaphoreCount = 1;
19607 submit_info.pSignalSemaphores = &semaphore;
19608 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19609 }
19610 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019611 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019612 VkSubmitInfo submit_info{};
19613 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19614 submit_info.commandBufferCount = 1;
19615 submit_info.pCommandBuffers = &command_buffer[1];
19616 submit_info.waitSemaphoreCount = 1;
19617 submit_info.pWaitSemaphores = &semaphore;
19618 submit_info.pWaitDstStageMask = flags;
19619 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19620 }
19621
19622 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19623
19624 vkDestroyFence(m_device->device(), fence, nullptr);
19625 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19626 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19627 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19628
19629 m_errorMonitor->VerifyNotFound();
19630}
19631
19632// This is a positive test. No errors should be generated.
19633TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019634 TEST_DESCRIPTION(
19635 "Two command buffers, each in a separate QueueSubmit call "
19636 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19637 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019638
19639 m_errorMonitor->ExpectSuccess();
19640
19641 ASSERT_NO_FATAL_FAILURE(InitState());
19642 VkFence fence;
19643 VkFenceCreateInfo fence_create_info{};
19644 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19645 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19646
19647 VkCommandPool command_pool;
19648 VkCommandPoolCreateInfo pool_create_info{};
19649 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19650 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19651 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19652 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19653
19654 VkCommandBuffer command_buffer[2];
19655 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19656 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19657 command_buffer_allocate_info.commandPool = command_pool;
19658 command_buffer_allocate_info.commandBufferCount = 2;
19659 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19660 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19661
19662 {
19663 VkCommandBufferBeginInfo begin_info{};
19664 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19665 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19666
19667 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 -070019668 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019669
19670 VkViewport viewport{};
19671 viewport.maxDepth = 1.0f;
19672 viewport.minDepth = 0.0f;
19673 viewport.width = 512;
19674 viewport.height = 512;
19675 viewport.x = 0;
19676 viewport.y = 0;
19677 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19678 vkEndCommandBuffer(command_buffer[0]);
19679 }
19680 {
19681 VkCommandBufferBeginInfo begin_info{};
19682 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19683 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19684
19685 VkViewport viewport{};
19686 viewport.maxDepth = 1.0f;
19687 viewport.minDepth = 0.0f;
19688 viewport.width = 512;
19689 viewport.height = 512;
19690 viewport.x = 0;
19691 viewport.y = 0;
19692 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19693 vkEndCommandBuffer(command_buffer[1]);
19694 }
19695 {
19696 VkSubmitInfo submit_info{};
19697 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19698 submit_info.commandBufferCount = 1;
19699 submit_info.pCommandBuffers = &command_buffer[0];
19700 submit_info.signalSemaphoreCount = 0;
19701 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19702 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19703 }
19704 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019705 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019706 VkSubmitInfo submit_info{};
19707 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19708 submit_info.commandBufferCount = 1;
19709 submit_info.pCommandBuffers = &command_buffer[1];
19710 submit_info.waitSemaphoreCount = 0;
19711 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19712 submit_info.pWaitDstStageMask = flags;
19713 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19714 }
19715
19716 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19717
19718 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19719 ASSERT_VK_SUCCESS(err);
19720
19721 vkDestroyFence(m_device->device(), fence, nullptr);
19722 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19723 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19724
19725 m_errorMonitor->VerifyNotFound();
19726}
19727
19728// This is a positive test. No errors should be generated.
19729TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019730 TEST_DESCRIPTION(
19731 "Two command buffers, each in a separate QueueSubmit call "
19732 "on the same queue, the second having a fence, followed "
19733 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019734
19735 m_errorMonitor->ExpectSuccess();
19736
19737 ASSERT_NO_FATAL_FAILURE(InitState());
19738 VkFence fence;
19739 VkFenceCreateInfo fence_create_info{};
19740 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19741 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19742
19743 VkCommandPool command_pool;
19744 VkCommandPoolCreateInfo pool_create_info{};
19745 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19746 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19747 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19748 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19749
19750 VkCommandBuffer command_buffer[2];
19751 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19752 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19753 command_buffer_allocate_info.commandPool = command_pool;
19754 command_buffer_allocate_info.commandBufferCount = 2;
19755 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19756 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19757
19758 {
19759 VkCommandBufferBeginInfo begin_info{};
19760 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19761 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19762
19763 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 -070019764 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019765
19766 VkViewport viewport{};
19767 viewport.maxDepth = 1.0f;
19768 viewport.minDepth = 0.0f;
19769 viewport.width = 512;
19770 viewport.height = 512;
19771 viewport.x = 0;
19772 viewport.y = 0;
19773 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19774 vkEndCommandBuffer(command_buffer[0]);
19775 }
19776 {
19777 VkCommandBufferBeginInfo begin_info{};
19778 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19779 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19780
19781 VkViewport viewport{};
19782 viewport.maxDepth = 1.0f;
19783 viewport.minDepth = 0.0f;
19784 viewport.width = 512;
19785 viewport.height = 512;
19786 viewport.x = 0;
19787 viewport.y = 0;
19788 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19789 vkEndCommandBuffer(command_buffer[1]);
19790 }
19791 {
19792 VkSubmitInfo submit_info{};
19793 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19794 submit_info.commandBufferCount = 1;
19795 submit_info.pCommandBuffers = &command_buffer[0];
19796 submit_info.signalSemaphoreCount = 0;
19797 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19798 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19799 }
19800 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019801 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019802 VkSubmitInfo submit_info{};
19803 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19804 submit_info.commandBufferCount = 1;
19805 submit_info.pCommandBuffers = &command_buffer[1];
19806 submit_info.waitSemaphoreCount = 0;
19807 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19808 submit_info.pWaitDstStageMask = flags;
19809 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19810 }
19811
19812 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19813
19814 vkDestroyFence(m_device->device(), fence, nullptr);
19815 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19816 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19817
19818 m_errorMonitor->VerifyNotFound();
19819}
19820
19821// This is a positive test. No errors should be generated.
19822TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019823 TEST_DESCRIPTION(
19824 "Two command buffers each in a separate SubmitInfo sent in a single "
19825 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019826 ASSERT_NO_FATAL_FAILURE(InitState());
19827
19828 m_errorMonitor->ExpectSuccess();
19829
19830 VkFence fence;
19831 VkFenceCreateInfo fence_create_info{};
19832 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19833 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19834
19835 VkSemaphore semaphore;
19836 VkSemaphoreCreateInfo semaphore_create_info{};
19837 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19838 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19839
19840 VkCommandPool command_pool;
19841 VkCommandPoolCreateInfo pool_create_info{};
19842 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19843 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19844 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19845 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19846
19847 VkCommandBuffer command_buffer[2];
19848 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19849 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19850 command_buffer_allocate_info.commandPool = command_pool;
19851 command_buffer_allocate_info.commandBufferCount = 2;
19852 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19853 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19854
19855 {
19856 VkCommandBufferBeginInfo begin_info{};
19857 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19858 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19859
19860 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 -070019861 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019862
19863 VkViewport viewport{};
19864 viewport.maxDepth = 1.0f;
19865 viewport.minDepth = 0.0f;
19866 viewport.width = 512;
19867 viewport.height = 512;
19868 viewport.x = 0;
19869 viewport.y = 0;
19870 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19871 vkEndCommandBuffer(command_buffer[0]);
19872 }
19873 {
19874 VkCommandBufferBeginInfo begin_info{};
19875 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19876 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19877
19878 VkViewport viewport{};
19879 viewport.maxDepth = 1.0f;
19880 viewport.minDepth = 0.0f;
19881 viewport.width = 512;
19882 viewport.height = 512;
19883 viewport.x = 0;
19884 viewport.y = 0;
19885 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19886 vkEndCommandBuffer(command_buffer[1]);
19887 }
19888 {
19889 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019890 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019891
19892 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19893 submit_info[0].pNext = NULL;
19894 submit_info[0].commandBufferCount = 1;
19895 submit_info[0].pCommandBuffers = &command_buffer[0];
19896 submit_info[0].signalSemaphoreCount = 1;
19897 submit_info[0].pSignalSemaphores = &semaphore;
19898 submit_info[0].waitSemaphoreCount = 0;
19899 submit_info[0].pWaitSemaphores = NULL;
19900 submit_info[0].pWaitDstStageMask = 0;
19901
19902 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19903 submit_info[1].pNext = NULL;
19904 submit_info[1].commandBufferCount = 1;
19905 submit_info[1].pCommandBuffers = &command_buffer[1];
19906 submit_info[1].waitSemaphoreCount = 1;
19907 submit_info[1].pWaitSemaphores = &semaphore;
19908 submit_info[1].pWaitDstStageMask = flags;
19909 submit_info[1].signalSemaphoreCount = 0;
19910 submit_info[1].pSignalSemaphores = NULL;
19911 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19912 }
19913
19914 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19915
19916 vkDestroyFence(m_device->device(), fence, nullptr);
19917 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19918 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19919 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19920
19921 m_errorMonitor->VerifyNotFound();
19922}
19923
19924TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19925 m_errorMonitor->ExpectSuccess();
19926
19927 ASSERT_NO_FATAL_FAILURE(InitState());
19928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19929
Tony Barbour552f6c02016-12-21 14:34:07 -070019930 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019931
19932 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19933 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19934 m_errorMonitor->VerifyNotFound();
19935 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19936 m_errorMonitor->VerifyNotFound();
19937 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19938 m_errorMonitor->VerifyNotFound();
19939
19940 m_commandBuffer->EndCommandBuffer();
19941 m_errorMonitor->VerifyNotFound();
19942}
19943
19944TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019945 TEST_DESCRIPTION(
19946 "Positive test where we create a renderpass with an "
19947 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19948 "has a valid layout, and a second subpass then uses a "
19949 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019950 m_errorMonitor->ExpectSuccess();
19951 ASSERT_NO_FATAL_FAILURE(InitState());
19952
19953 VkAttachmentReference attach[2] = {};
19954 attach[0].attachment = 0;
19955 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19956 attach[1].attachment = 0;
19957 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19958 VkSubpassDescription subpasses[2] = {};
19959 // First subpass clears DS attach on load
19960 subpasses[0].pDepthStencilAttachment = &attach[0];
19961 // 2nd subpass reads in DS as input attachment
19962 subpasses[1].inputAttachmentCount = 1;
19963 subpasses[1].pInputAttachments = &attach[1];
19964 VkAttachmentDescription attach_desc = {};
19965 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19966 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19967 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19968 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19969 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19970 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19971 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19972 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19973 VkRenderPassCreateInfo rpci = {};
19974 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19975 rpci.attachmentCount = 1;
19976 rpci.pAttachments = &attach_desc;
19977 rpci.subpassCount = 2;
19978 rpci.pSubpasses = subpasses;
19979
19980 // Now create RenderPass and verify no errors
19981 VkRenderPass rp;
19982 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19983 m_errorMonitor->VerifyNotFound();
19984
19985 vkDestroyRenderPass(m_device->device(), rp, NULL);
19986}
19987
19988TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019989 TEST_DESCRIPTION(
19990 "Test that pipeline validation accepts matrices passed "
19991 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019992 m_errorMonitor->ExpectSuccess();
19993
19994 ASSERT_NO_FATAL_FAILURE(InitState());
19995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19996
19997 VkVertexInputBindingDescription input_binding;
19998 memset(&input_binding, 0, sizeof(input_binding));
19999
20000 VkVertexInputAttributeDescription input_attribs[2];
20001 memset(input_attribs, 0, sizeof(input_attribs));
20002
20003 for (int i = 0; i < 2; i++) {
20004 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20005 input_attribs[i].location = i;
20006 }
20007
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020008 char const *vsSource =
20009 "#version 450\n"
20010 "\n"
20011 "layout(location=0) in mat2x4 x;\n"
20012 "out gl_PerVertex {\n"
20013 " vec4 gl_Position;\n"
20014 "};\n"
20015 "void main(){\n"
20016 " gl_Position = x[0] + x[1];\n"
20017 "}\n";
20018 char const *fsSource =
20019 "#version 450\n"
20020 "\n"
20021 "layout(location=0) out vec4 color;\n"
20022 "void main(){\n"
20023 " color = vec4(1);\n"
20024 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020025
20026 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20027 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20028
20029 VkPipelineObj pipe(m_device);
20030 pipe.AddColorAttachment();
20031 pipe.AddShader(&vs);
20032 pipe.AddShader(&fs);
20033
20034 pipe.AddVertexInputBindings(&input_binding, 1);
20035 pipe.AddVertexInputAttribs(input_attribs, 2);
20036
20037 VkDescriptorSetObj descriptorSet(m_device);
20038 descriptorSet.AppendDummy();
20039 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20040
20041 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20042
20043 /* expect success */
20044 m_errorMonitor->VerifyNotFound();
20045}
20046
20047TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
20048 m_errorMonitor->ExpectSuccess();
20049
20050 ASSERT_NO_FATAL_FAILURE(InitState());
20051 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20052
20053 VkVertexInputBindingDescription input_binding;
20054 memset(&input_binding, 0, sizeof(input_binding));
20055
20056 VkVertexInputAttributeDescription input_attribs[2];
20057 memset(input_attribs, 0, sizeof(input_attribs));
20058
20059 for (int i = 0; i < 2; i++) {
20060 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20061 input_attribs[i].location = i;
20062 }
20063
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020064 char const *vsSource =
20065 "#version 450\n"
20066 "\n"
20067 "layout(location=0) in vec4 x[2];\n"
20068 "out gl_PerVertex {\n"
20069 " vec4 gl_Position;\n"
20070 "};\n"
20071 "void main(){\n"
20072 " gl_Position = x[0] + x[1];\n"
20073 "}\n";
20074 char const *fsSource =
20075 "#version 450\n"
20076 "\n"
20077 "layout(location=0) out vec4 color;\n"
20078 "void main(){\n"
20079 " color = vec4(1);\n"
20080 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020081
20082 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20083 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20084
20085 VkPipelineObj pipe(m_device);
20086 pipe.AddColorAttachment();
20087 pipe.AddShader(&vs);
20088 pipe.AddShader(&fs);
20089
20090 pipe.AddVertexInputBindings(&input_binding, 1);
20091 pipe.AddVertexInputAttribs(input_attribs, 2);
20092
20093 VkDescriptorSetObj descriptorSet(m_device);
20094 descriptorSet.AppendDummy();
20095 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20096
20097 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20098
20099 m_errorMonitor->VerifyNotFound();
20100}
20101
20102TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020103 TEST_DESCRIPTION(
20104 "Test that pipeline validation accepts consuming a vertex attribute "
20105 "through multiple vertex shader inputs, each consuming a different "
20106 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020107 m_errorMonitor->ExpectSuccess();
20108
20109 ASSERT_NO_FATAL_FAILURE(InitState());
20110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20111
20112 VkVertexInputBindingDescription input_binding;
20113 memset(&input_binding, 0, sizeof(input_binding));
20114
20115 VkVertexInputAttributeDescription input_attribs[3];
20116 memset(input_attribs, 0, sizeof(input_attribs));
20117
20118 for (int i = 0; i < 3; i++) {
20119 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20120 input_attribs[i].location = i;
20121 }
20122
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020123 char const *vsSource =
20124 "#version 450\n"
20125 "\n"
20126 "layout(location=0) in vec4 x;\n"
20127 "layout(location=1) in vec3 y1;\n"
20128 "layout(location=1, component=3) in float y2;\n"
20129 "layout(location=2) in vec4 z;\n"
20130 "out gl_PerVertex {\n"
20131 " vec4 gl_Position;\n"
20132 "};\n"
20133 "void main(){\n"
20134 " gl_Position = x + vec4(y1, y2) + z;\n"
20135 "}\n";
20136 char const *fsSource =
20137 "#version 450\n"
20138 "\n"
20139 "layout(location=0) out vec4 color;\n"
20140 "void main(){\n"
20141 " color = vec4(1);\n"
20142 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020143
20144 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20145 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20146
20147 VkPipelineObj pipe(m_device);
20148 pipe.AddColorAttachment();
20149 pipe.AddShader(&vs);
20150 pipe.AddShader(&fs);
20151
20152 pipe.AddVertexInputBindings(&input_binding, 1);
20153 pipe.AddVertexInputAttribs(input_attribs, 3);
20154
20155 VkDescriptorSetObj descriptorSet(m_device);
20156 descriptorSet.AppendDummy();
20157 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20158
20159 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20160
20161 m_errorMonitor->VerifyNotFound();
20162}
20163
20164TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
20165 m_errorMonitor->ExpectSuccess();
20166
20167 ASSERT_NO_FATAL_FAILURE(InitState());
20168 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20169
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020170 char const *vsSource =
20171 "#version 450\n"
20172 "out gl_PerVertex {\n"
20173 " vec4 gl_Position;\n"
20174 "};\n"
20175 "void main(){\n"
20176 " gl_Position = vec4(0);\n"
20177 "}\n";
20178 char const *fsSource =
20179 "#version 450\n"
20180 "\n"
20181 "layout(location=0) out vec4 color;\n"
20182 "void main(){\n"
20183 " color = vec4(1);\n"
20184 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020185
20186 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20187 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20188
20189 VkPipelineObj pipe(m_device);
20190 pipe.AddColorAttachment();
20191 pipe.AddShader(&vs);
20192 pipe.AddShader(&fs);
20193
20194 VkDescriptorSetObj descriptorSet(m_device);
20195 descriptorSet.AppendDummy();
20196 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20197
20198 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20199
20200 m_errorMonitor->VerifyNotFound();
20201}
20202
20203TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020204 TEST_DESCRIPTION(
20205 "Test that pipeline validation accepts the relaxed type matching rules "
20206 "set out in 14.1.3: fundamental type must match, and producer side must "
20207 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020208 m_errorMonitor->ExpectSuccess();
20209
20210 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
20211
20212 ASSERT_NO_FATAL_FAILURE(InitState());
20213 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20214
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020215 char const *vsSource =
20216 "#version 450\n"
20217 "out gl_PerVertex {\n"
20218 " vec4 gl_Position;\n"
20219 "};\n"
20220 "layout(location=0) out vec3 x;\n"
20221 "layout(location=1) out ivec3 y;\n"
20222 "layout(location=2) out vec3 z;\n"
20223 "void main(){\n"
20224 " gl_Position = vec4(0);\n"
20225 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
20226 "}\n";
20227 char const *fsSource =
20228 "#version 450\n"
20229 "\n"
20230 "layout(location=0) out vec4 color;\n"
20231 "layout(location=0) in float x;\n"
20232 "layout(location=1) flat in int y;\n"
20233 "layout(location=2) in vec2 z;\n"
20234 "void main(){\n"
20235 " color = vec4(1 + x + y + z.x);\n"
20236 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020237
20238 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20239 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20240
20241 VkPipelineObj pipe(m_device);
20242 pipe.AddColorAttachment();
20243 pipe.AddShader(&vs);
20244 pipe.AddShader(&fs);
20245
20246 VkDescriptorSetObj descriptorSet(m_device);
20247 descriptorSet.AppendDummy();
20248 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20249
20250 VkResult err = VK_SUCCESS;
20251 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20252 ASSERT_VK_SUCCESS(err);
20253
20254 m_errorMonitor->VerifyNotFound();
20255}
20256
20257TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020258 TEST_DESCRIPTION(
20259 "Test that pipeline validation accepts per-vertex variables "
20260 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020261 m_errorMonitor->ExpectSuccess();
20262
20263 ASSERT_NO_FATAL_FAILURE(InitState());
20264 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20265
20266 if (!m_device->phy().features().tessellationShader) {
20267 printf("Device does not support tessellation shaders; skipped.\n");
20268 return;
20269 }
20270
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020271 char const *vsSource =
20272 "#version 450\n"
20273 "void main(){}\n";
20274 char const *tcsSource =
20275 "#version 450\n"
20276 "layout(location=0) out int x[];\n"
20277 "layout(vertices=3) out;\n"
20278 "void main(){\n"
20279 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
20280 " gl_TessLevelInner[0] = 1;\n"
20281 " x[gl_InvocationID] = gl_InvocationID;\n"
20282 "}\n";
20283 char const *tesSource =
20284 "#version 450\n"
20285 "layout(triangles, equal_spacing, cw) in;\n"
20286 "layout(location=0) in int x[];\n"
20287 "out gl_PerVertex { vec4 gl_Position; };\n"
20288 "void main(){\n"
20289 " gl_Position.xyz = gl_TessCoord;\n"
20290 " gl_Position.w = x[0] + x[1] + x[2];\n"
20291 "}\n";
20292 char const *fsSource =
20293 "#version 450\n"
20294 "layout(location=0) out vec4 color;\n"
20295 "void main(){\n"
20296 " color = vec4(1);\n"
20297 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020298
20299 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20300 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
20301 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
20302 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20303
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020304 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
20305 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020306
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020307 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020308
20309 VkPipelineObj pipe(m_device);
20310 pipe.SetInputAssembly(&iasci);
20311 pipe.SetTessellation(&tsci);
20312 pipe.AddColorAttachment();
20313 pipe.AddShader(&vs);
20314 pipe.AddShader(&tcs);
20315 pipe.AddShader(&tes);
20316 pipe.AddShader(&fs);
20317
20318 VkDescriptorSetObj descriptorSet(m_device);
20319 descriptorSet.AppendDummy();
20320 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20321
20322 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20323
20324 m_errorMonitor->VerifyNotFound();
20325}
20326
20327TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020328 TEST_DESCRIPTION(
20329 "Test that pipeline validation accepts a user-defined "
20330 "interface block passed into the geometry shader. This "
20331 "is interesting because the 'extra' array level is not "
20332 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020333 m_errorMonitor->ExpectSuccess();
20334
20335 ASSERT_NO_FATAL_FAILURE(InitState());
20336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20337
20338 if (!m_device->phy().features().geometryShader) {
20339 printf("Device does not support geometry shaders; skipped.\n");
20340 return;
20341 }
20342
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020343 char const *vsSource =
20344 "#version 450\n"
20345 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
20346 "void main(){\n"
20347 " vs_out.x = vec4(1);\n"
20348 "}\n";
20349 char const *gsSource =
20350 "#version 450\n"
20351 "layout(triangles) in;\n"
20352 "layout(triangle_strip, max_vertices=3) out;\n"
20353 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
20354 "out gl_PerVertex { vec4 gl_Position; };\n"
20355 "void main() {\n"
20356 " gl_Position = gs_in[0].x;\n"
20357 " EmitVertex();\n"
20358 "}\n";
20359 char const *fsSource =
20360 "#version 450\n"
20361 "layout(location=0) out vec4 color;\n"
20362 "void main(){\n"
20363 " color = vec4(1);\n"
20364 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020365
20366 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20367 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
20368 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20369
20370 VkPipelineObj pipe(m_device);
20371 pipe.AddColorAttachment();
20372 pipe.AddShader(&vs);
20373 pipe.AddShader(&gs);
20374 pipe.AddShader(&fs);
20375
20376 VkDescriptorSetObj descriptorSet(m_device);
20377 descriptorSet.AppendDummy();
20378 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20379
20380 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20381
20382 m_errorMonitor->VerifyNotFound();
20383}
20384
20385TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020386 TEST_DESCRIPTION(
20387 "Test that pipeline validation accepts basic use of 64bit vertex "
20388 "attributes. This is interesting because they consume multiple "
20389 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020390 m_errorMonitor->ExpectSuccess();
20391
20392 ASSERT_NO_FATAL_FAILURE(InitState());
20393 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20394
20395 if (!m_device->phy().features().shaderFloat64) {
20396 printf("Device does not support 64bit vertex attributes; skipped.\n");
20397 return;
20398 }
20399
20400 VkVertexInputBindingDescription input_bindings[1];
20401 memset(input_bindings, 0, sizeof(input_bindings));
20402
20403 VkVertexInputAttributeDescription input_attribs[4];
20404 memset(input_attribs, 0, sizeof(input_attribs));
20405 input_attribs[0].location = 0;
20406 input_attribs[0].offset = 0;
20407 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20408 input_attribs[1].location = 2;
20409 input_attribs[1].offset = 32;
20410 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20411 input_attribs[2].location = 4;
20412 input_attribs[2].offset = 64;
20413 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20414 input_attribs[3].location = 6;
20415 input_attribs[3].offset = 96;
20416 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20417
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020418 char const *vsSource =
20419 "#version 450\n"
20420 "\n"
20421 "layout(location=0) in dmat4 x;\n"
20422 "out gl_PerVertex {\n"
20423 " vec4 gl_Position;\n"
20424 "};\n"
20425 "void main(){\n"
20426 " gl_Position = vec4(x[0][0]);\n"
20427 "}\n";
20428 char const *fsSource =
20429 "#version 450\n"
20430 "\n"
20431 "layout(location=0) out vec4 color;\n"
20432 "void main(){\n"
20433 " color = vec4(1);\n"
20434 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020435
20436 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20437 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20438
20439 VkPipelineObj pipe(m_device);
20440 pipe.AddColorAttachment();
20441 pipe.AddShader(&vs);
20442 pipe.AddShader(&fs);
20443
20444 pipe.AddVertexInputBindings(input_bindings, 1);
20445 pipe.AddVertexInputAttribs(input_attribs, 4);
20446
20447 VkDescriptorSetObj descriptorSet(m_device);
20448 descriptorSet.AppendDummy();
20449 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20450
20451 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20452
20453 m_errorMonitor->VerifyNotFound();
20454}
20455
20456TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
20457 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
20458 m_errorMonitor->ExpectSuccess();
20459
20460 ASSERT_NO_FATAL_FAILURE(InitState());
20461
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020462 char const *vsSource =
20463 "#version 450\n"
20464 "\n"
20465 "out gl_PerVertex {\n"
20466 " vec4 gl_Position;\n"
20467 "};\n"
20468 "void main(){\n"
20469 " gl_Position = vec4(1);\n"
20470 "}\n";
20471 char const *fsSource =
20472 "#version 450\n"
20473 "\n"
20474 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
20475 "layout(location=0) out vec4 color;\n"
20476 "void main() {\n"
20477 " color = subpassLoad(x);\n"
20478 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020479
20480 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20481 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20482
20483 VkPipelineObj pipe(m_device);
20484 pipe.AddShader(&vs);
20485 pipe.AddShader(&fs);
20486 pipe.AddColorAttachment();
20487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20488
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020489 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
20490 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020491 VkDescriptorSetLayout dsl;
20492 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20493 ASSERT_VK_SUCCESS(err);
20494
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020495 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020496 VkPipelineLayout pl;
20497 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20498 ASSERT_VK_SUCCESS(err);
20499
20500 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020501 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20502 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20503 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
20504 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20505 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 -060020506 };
20507 VkAttachmentReference color = {
20508 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20509 };
20510 VkAttachmentReference input = {
20511 1, VK_IMAGE_LAYOUT_GENERAL,
20512 };
20513
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020514 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020515
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020516 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020517 VkRenderPass rp;
20518 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20519 ASSERT_VK_SUCCESS(err);
20520
20521 // should be OK. would go wrong here if it's going to...
20522 pipe.CreateVKPipeline(pl, rp);
20523
20524 m_errorMonitor->VerifyNotFound();
20525
20526 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20527 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20528 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20529}
20530
20531TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020532 TEST_DESCRIPTION(
20533 "Test that pipeline validation accepts a compute pipeline which declares a "
20534 "descriptor-backed resource which is not provided, but the shader does not "
20535 "statically use it. This is interesting because it requires compute pipelines "
20536 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020537 m_errorMonitor->ExpectSuccess();
20538
20539 ASSERT_NO_FATAL_FAILURE(InitState());
20540
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020541 char const *csSource =
20542 "#version 450\n"
20543 "\n"
20544 "layout(local_size_x=1) in;\n"
20545 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
20546 "void main(){\n"
20547 " // x is not used.\n"
20548 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020549
20550 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20551
20552 VkDescriptorSetObj descriptorSet(m_device);
20553 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20554
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020555 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20556 nullptr,
20557 0,
20558 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20559 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20560 descriptorSet.GetPipelineLayout(),
20561 VK_NULL_HANDLE,
20562 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020563
20564 VkPipeline pipe;
20565 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20566
20567 m_errorMonitor->VerifyNotFound();
20568
20569 if (err == VK_SUCCESS) {
20570 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20571 }
20572}
20573
20574TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020575 TEST_DESCRIPTION(
20576 "Test that pipeline validation accepts a shader consuming only the "
20577 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020578 m_errorMonitor->ExpectSuccess();
20579
20580 ASSERT_NO_FATAL_FAILURE(InitState());
20581
20582 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020583 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20584 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20585 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020586 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020587 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020588 VkDescriptorSetLayout dsl;
20589 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20590 ASSERT_VK_SUCCESS(err);
20591
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020592 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020593 VkPipelineLayout pl;
20594 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20595 ASSERT_VK_SUCCESS(err);
20596
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020597 char const *csSource =
20598 "#version 450\n"
20599 "\n"
20600 "layout(local_size_x=1) in;\n"
20601 "layout(set=0, binding=0) uniform sampler s;\n"
20602 "layout(set=0, binding=1) uniform texture2D t;\n"
20603 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20604 "void main() {\n"
20605 " x = texture(sampler2D(t, s), vec2(0));\n"
20606 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020607 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20608
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020609 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20610 nullptr,
20611 0,
20612 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20613 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20614 pl,
20615 VK_NULL_HANDLE,
20616 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020617
20618 VkPipeline pipe;
20619 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20620
20621 m_errorMonitor->VerifyNotFound();
20622
20623 if (err == VK_SUCCESS) {
20624 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20625 }
20626
20627 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20628 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20629}
20630
20631TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020632 TEST_DESCRIPTION(
20633 "Test that pipeline validation accepts a shader consuming only the "
20634 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020635 m_errorMonitor->ExpectSuccess();
20636
20637 ASSERT_NO_FATAL_FAILURE(InitState());
20638
20639 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020640 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20641 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20642 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020643 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020644 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020645 VkDescriptorSetLayout dsl;
20646 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20647 ASSERT_VK_SUCCESS(err);
20648
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020649 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020650 VkPipelineLayout pl;
20651 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20652 ASSERT_VK_SUCCESS(err);
20653
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020654 char const *csSource =
20655 "#version 450\n"
20656 "\n"
20657 "layout(local_size_x=1) in;\n"
20658 "layout(set=0, binding=0) uniform texture2D t;\n"
20659 "layout(set=0, binding=1) uniform sampler s;\n"
20660 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20661 "void main() {\n"
20662 " x = texture(sampler2D(t, s), vec2(0));\n"
20663 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020664 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20665
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020666 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20667 nullptr,
20668 0,
20669 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20670 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20671 pl,
20672 VK_NULL_HANDLE,
20673 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020674
20675 VkPipeline pipe;
20676 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20677
20678 m_errorMonitor->VerifyNotFound();
20679
20680 if (err == VK_SUCCESS) {
20681 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20682 }
20683
20684 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20685 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20686}
20687
20688TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020689 TEST_DESCRIPTION(
20690 "Test that pipeline validation accepts a shader consuming "
20691 "both the sampler and the image of a combined image+sampler "
20692 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020693 m_errorMonitor->ExpectSuccess();
20694
20695 ASSERT_NO_FATAL_FAILURE(InitState());
20696
20697 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020698 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20699 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020700 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020701 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020702 VkDescriptorSetLayout dsl;
20703 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20704 ASSERT_VK_SUCCESS(err);
20705
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020706 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020707 VkPipelineLayout pl;
20708 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20709 ASSERT_VK_SUCCESS(err);
20710
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020711 char const *csSource =
20712 "#version 450\n"
20713 "\n"
20714 "layout(local_size_x=1) in;\n"
20715 "layout(set=0, binding=0) uniform texture2D t;\n"
20716 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20717 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20718 "void main() {\n"
20719 " x = texture(sampler2D(t, s), vec2(0));\n"
20720 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020721 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20722
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020723 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20724 nullptr,
20725 0,
20726 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20727 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20728 pl,
20729 VK_NULL_HANDLE,
20730 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020731
20732 VkPipeline pipe;
20733 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20734
20735 m_errorMonitor->VerifyNotFound();
20736
20737 if (err == VK_SUCCESS) {
20738 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20739 }
20740
20741 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20742 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20743}
20744
20745TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20746 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20747
20748 ASSERT_NO_FATAL_FAILURE(InitState());
20749
20750 // Positive test to check parameter_validation and unique_objects support
20751 // for NV_dedicated_allocation
20752 uint32_t extension_count = 0;
20753 bool supports_nv_dedicated_allocation = false;
20754 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20755 ASSERT_VK_SUCCESS(err);
20756
20757 if (extension_count > 0) {
20758 std::vector<VkExtensionProperties> available_extensions(extension_count);
20759
20760 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20761 ASSERT_VK_SUCCESS(err);
20762
20763 for (const auto &extension_props : available_extensions) {
20764 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20765 supports_nv_dedicated_allocation = true;
20766 }
20767 }
20768 }
20769
20770 if (supports_nv_dedicated_allocation) {
20771 m_errorMonitor->ExpectSuccess();
20772
20773 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20774 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20775 dedicated_buffer_create_info.pNext = nullptr;
20776 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20777
20778 uint32_t queue_family_index = 0;
20779 VkBufferCreateInfo buffer_create_info = {};
20780 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20781 buffer_create_info.pNext = &dedicated_buffer_create_info;
20782 buffer_create_info.size = 1024;
20783 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20784 buffer_create_info.queueFamilyIndexCount = 1;
20785 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20786
20787 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070020788 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020789 ASSERT_VK_SUCCESS(err);
20790
20791 VkMemoryRequirements memory_reqs;
20792 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20793
20794 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20795 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20796 dedicated_memory_info.pNext = nullptr;
20797 dedicated_memory_info.buffer = buffer;
20798 dedicated_memory_info.image = VK_NULL_HANDLE;
20799
20800 VkMemoryAllocateInfo memory_info = {};
20801 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20802 memory_info.pNext = &dedicated_memory_info;
20803 memory_info.allocationSize = memory_reqs.size;
20804
20805 bool pass;
20806 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20807 ASSERT_TRUE(pass);
20808
20809 VkDeviceMemory buffer_memory;
20810 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20811 ASSERT_VK_SUCCESS(err);
20812
20813 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20814 ASSERT_VK_SUCCESS(err);
20815
20816 vkDestroyBuffer(m_device->device(), buffer, NULL);
20817 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20818
20819 m_errorMonitor->VerifyNotFound();
20820 }
20821}
20822
20823TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20824 VkResult err;
20825
20826 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20827
20828 ASSERT_NO_FATAL_FAILURE(InitState());
20829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20830
20831 std::vector<const char *> device_extension_names;
20832 auto features = m_device->phy().features();
20833 // Artificially disable support for non-solid fill modes
20834 features.fillModeNonSolid = false;
20835 // The sacrificial device object
20836 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20837
20838 VkRenderpassObj render_pass(&test_device);
20839
20840 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20841 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20842 pipeline_layout_ci.setLayoutCount = 0;
20843 pipeline_layout_ci.pSetLayouts = NULL;
20844
20845 VkPipelineLayout pipeline_layout;
20846 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20847 ASSERT_VK_SUCCESS(err);
20848
20849 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20850 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20851 rs_ci.pNext = nullptr;
20852 rs_ci.lineWidth = 1.0f;
20853 rs_ci.rasterizerDiscardEnable = true;
20854
20855 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20856 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20857
20858 // Set polygonMode=FILL. No error is expected
20859 m_errorMonitor->ExpectSuccess();
20860 {
20861 VkPipelineObj pipe(&test_device);
20862 pipe.AddShader(&vs);
20863 pipe.AddShader(&fs);
20864 pipe.AddColorAttachment();
20865 // Set polygonMode to a good value
20866 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20867 pipe.SetRasterization(&rs_ci);
20868 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20869 }
20870 m_errorMonitor->VerifyNotFound();
20871
20872 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20873}
20874
20875TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20876 VkResult err;
20877 ASSERT_NO_FATAL_FAILURE(InitState());
20878 ASSERT_NO_FATAL_FAILURE(InitViewport());
20879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20880
20881 VkPipelineLayout pipeline_layout;
20882 VkPushConstantRange pc_range = {};
20883 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20884 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20885 pipeline_layout_ci.pushConstantRangeCount = 1;
20886 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20887
20888 //
20889 // Check for invalid push constant ranges in pipeline layouts.
20890 //
20891 struct PipelineLayoutTestCase {
20892 VkPushConstantRange const range;
20893 char const *msg;
20894 };
20895
20896 // Check for overlapping ranges
20897 const uint32_t ranges_per_test = 5;
20898 struct OverlappingRangeTestCase {
20899 VkPushConstantRange const ranges[ranges_per_test];
20900 char const *msg;
20901 };
20902
20903 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020904 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
20905 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
20906 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
20907 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
20908 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
20909 ""},
20910 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
20911 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
20912 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
20913 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
20914 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
20915 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020916 for (const auto &iter : overlapping_range_tests_pos) {
20917 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20918 m_errorMonitor->ExpectSuccess();
20919 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20920 m_errorMonitor->VerifyNotFound();
20921 if (VK_SUCCESS == err) {
20922 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20923 }
20924 }
20925
20926 //
20927 // CmdPushConstants tests
20928 //
20929 const uint8_t dummy_values[100] = {};
20930
Tony Barbour552f6c02016-12-21 14:34:07 -070020931 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020932
20933 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020934 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
20935 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
20936 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
20937 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
20938 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
20939 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020940
20941 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20942 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020943 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
20944 {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 -060020945 };
20946
20947 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20948 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20949 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20950 ASSERT_VK_SUCCESS(err);
20951 for (const auto &iter : cmd_overlap_tests_pos) {
20952 m_errorMonitor->ExpectSuccess();
20953 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020954 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020955 m_errorMonitor->VerifyNotFound();
20956 }
20957 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20958
Tony Barbour552f6c02016-12-21 14:34:07 -070020959 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020960}
20961
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020962#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020963TEST_F(VkPositiveLayerTest, LongFenceChain)
20964{
20965 m_errorMonitor->ExpectSuccess();
20966
20967 ASSERT_NO_FATAL_FAILURE(InitState());
20968 VkResult err;
20969
20970 std::vector<VkFence> fences;
20971
20972 const int chainLength = 32768;
20973
20974 for (int i = 0; i < chainLength; i++) {
20975 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20976 VkFence fence;
20977 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20978 ASSERT_VK_SUCCESS(err);
20979
20980 fences.push_back(fence);
20981
20982 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20983 0, nullptr, 0, nullptr };
20984 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20985 ASSERT_VK_SUCCESS(err);
20986
20987 }
20988
20989 // BOOM, stack overflow.
20990 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20991
20992 for (auto fence : fences)
20993 vkDestroyFence(m_device->device(), fence, nullptr);
20994
20995 m_errorMonitor->VerifyNotFound();
20996}
20997#endif
20998
Cody Northrop1242dfd2016-07-13 17:24:59 -060020999#if defined(ANDROID) && defined(VALIDATION_APK)
21000static bool initialized = false;
21001static bool active = false;
21002
21003// Convert Intents to argv
21004// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021005std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021006 std::vector<std::string> args;
21007 JavaVM &vm = *app.activity->vm;
21008 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021009 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021010
21011 JNIEnv &env = *p_env;
21012 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021013 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021014 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021015 jmethodID get_string_extra_method =
21016 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021017 jvalue get_string_extra_args;
21018 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021019 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060021020
21021 std::string args_str;
21022 if (extra_str) {
21023 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
21024 args_str = extra_utf;
21025 env.ReleaseStringUTFChars(extra_str, extra_utf);
21026 env.DeleteLocalRef(extra_str);
21027 }
21028
21029 env.DeleteLocalRef(get_string_extra_args.l);
21030 env.DeleteLocalRef(intent);
21031 vm.DetachCurrentThread();
21032
21033 // split args_str
21034 std::stringstream ss(args_str);
21035 std::string arg;
21036 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021037 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021038 }
21039
21040 return args;
21041}
21042
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021043static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021045static void processCommand(struct android_app *app, int32_t cmd) {
21046 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021047 case APP_CMD_INIT_WINDOW: {
21048 if (app->window) {
21049 initialized = true;
21050 }
21051 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021052 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021053 case APP_CMD_GAINED_FOCUS: {
21054 active = true;
21055 break;
21056 }
21057 case APP_CMD_LOST_FOCUS: {
21058 active = false;
21059 break;
21060 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021061 }
21062}
21063
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021064void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021065 app_dummy();
21066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021067 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060021068
21069 int vulkanSupport = InitVulkan();
21070 if (vulkanSupport == 0) {
21071 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
21072 return;
21073 }
21074
21075 app->onAppCmd = processCommand;
21076 app->onInputEvent = processInput;
21077
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021078 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021079 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021080 struct android_poll_source *source;
21081 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021082 if (source) {
21083 source->process(app, source);
21084 }
21085
21086 if (app->destroyRequested != 0) {
21087 VkTestFramework::Finish();
21088 return;
21089 }
21090 }
21091
21092 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021093 // Use the following key to send arguments to gtest, i.e.
21094 // --es args "--gtest_filter=-VkLayerTest.foo"
21095 const char key[] = "args";
21096 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021098 std::string filter = "";
21099 if (args.size() > 0) {
21100 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
21101 filter += args[0];
21102 } else {
21103 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
21104 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021106 int argc = 2;
21107 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
21108 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021110 // Route output to files until we can override the gtest output
21111 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
21112 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021113
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021114 ::testing::InitGoogleTest(&argc, argv);
21115 VkTestFramework::InitArgs(&argc, argv);
21116 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021118 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060021119
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021120 if (result != 0) {
21121 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
21122 } else {
21123 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
21124 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021126 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060021127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021128 fclose(stdout);
21129 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021131 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021132
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021133 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021134 }
21135 }
21136}
21137#endif
21138
Tony Barbour300a6082015-04-07 13:44:53 -060021139int main(int argc, char **argv) {
21140 int result;
21141
Cody Northrop8e54a402016-03-08 22:25:52 -070021142#ifdef ANDROID
21143 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021144 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070021145#endif
21146
Tony Barbour300a6082015-04-07 13:44:53 -060021147 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060021148 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060021149
21150 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
21151
21152 result = RUN_ALL_TESTS();
21153
Tony Barbour6918cd52015-04-09 12:58:51 -060021154 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060021155 return result;
21156}