blob: 300e314f0b390fa4c0f998b5b8df389bb36c3cb2 [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 Ehlis845887e2017-02-02 19:01:44 -07009310TEST_F(VkLayerTest, DSBufferLimitErrors) {
9311 TEST_DESCRIPTION(
9312 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9313 "Test cases include:\n"
9314 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9315 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9316 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9317 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9318 VkResult err;
9319
9320 ASSERT_NO_FATAL_FAILURE(InitState());
9321 VkDescriptorPoolSize ds_type_count[2] = {};
9322 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9323 ds_type_count[0].descriptorCount = 1;
9324 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9325 ds_type_count[1].descriptorCount = 1;
9326
9327 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9328 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9329 ds_pool_ci.pNext = NULL;
9330 ds_pool_ci.maxSets = 1;
9331 ds_pool_ci.poolSizeCount = 2;
9332 ds_pool_ci.pPoolSizes = ds_type_count;
9333
9334 VkDescriptorPool ds_pool;
9335 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9336 ASSERT_VK_SUCCESS(err);
9337
9338 // Create layout with single uniform buffer & single storage buffer descriptor
9339 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9340 dsl_binding[0].binding = 0;
9341 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9342 dsl_binding[0].descriptorCount = 1;
9343 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9344 dsl_binding[0].pImmutableSamplers = NULL;
9345 dsl_binding[1].binding = 1;
9346 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9347 dsl_binding[1].descriptorCount = 1;
9348 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9349 dsl_binding[1].pImmutableSamplers = NULL;
9350
9351 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9352 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9353 ds_layout_ci.pNext = NULL;
9354 ds_layout_ci.bindingCount = 2;
9355 ds_layout_ci.pBindings = dsl_binding;
9356 VkDescriptorSetLayout ds_layout;
9357 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9358 ASSERT_VK_SUCCESS(err);
9359
9360 VkDescriptorSet descriptor_set = {};
9361 VkDescriptorSetAllocateInfo alloc_info = {};
9362 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9363 alloc_info.descriptorSetCount = 1;
9364 alloc_info.descriptorPool = ds_pool;
9365 alloc_info.pSetLayouts = &ds_layout;
9366 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9367 ASSERT_VK_SUCCESS(err);
9368
9369 // Create a buffer to be used for invalid updates
9370 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9371 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9372 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9373 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9374 VkBufferCreateInfo ub_ci = {};
9375 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9376 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9377 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9378 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9379 VkBuffer uniform_buffer;
9380 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9381 ASSERT_VK_SUCCESS(err);
9382 VkBufferCreateInfo sb_ci = {};
9383 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9384 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9385 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9386 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9387 VkBuffer storage_buffer;
9388 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9389 ASSERT_VK_SUCCESS(err);
9390 // Have to bind memory to buffer before descriptor update
9391 VkMemoryAllocateInfo mem_alloc = {};
9392 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9393 mem_alloc.pNext = NULL;
9394 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9395 mem_alloc.memoryTypeIndex = 0;
9396
9397 VkMemoryRequirements mem_reqs;
9398 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &mem_reqs);
9399 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9400 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &mem_reqs);
9401 pass &= m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9402 if (!pass) {
9403 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9404 return;
9405 }
9406
9407 VkDeviceMemory mem;
9408 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9409 ASSERT_VK_SUCCESS(err);
9410 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9411 ASSERT_VK_SUCCESS(err);
9412 auto sb_offset = ub_ci.size + 1024;
9413 // Verify offset alignment, I know there's a bit trick to do this but it escapes me
9414 sb_offset = (sb_offset % mem_reqs.alignment) ? sb_offset - (sb_offset % mem_reqs.alignment) : sb_offset;
9415 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9416 ASSERT_VK_SUCCESS(err);
9417
9418 VkDescriptorBufferInfo buff_info = {};
9419 buff_info.buffer = uniform_buffer;
9420 buff_info.range = ub_ci.size; // This will exceed limit
9421 VkWriteDescriptorSet descriptor_write = {};
9422 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9423 descriptor_write.dstBinding = 0;
9424 descriptor_write.descriptorCount = 1;
9425 descriptor_write.pTexelBufferView = nullptr;
9426 descriptor_write.pBufferInfo = &buff_info;
9427 descriptor_write.pImageInfo = nullptr;
9428
9429 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9430 descriptor_write.dstSet = descriptor_set;
9431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9432 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9433 m_errorMonitor->VerifyFound();
9434
9435 // Reduce size of range to acceptable limit & cause offset error
9436 buff_info.range = max_ub_range;
9437 buff_info.offset = min_ub_align - 1;
9438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9439 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9440 m_errorMonitor->VerifyFound();
9441
9442 // Now break storage updates
9443 buff_info.buffer = storage_buffer;
9444 buff_info.range = sb_ci.size; // This will exceed limit
9445 buff_info.offset = 0; // Reset offset for this update
9446
9447 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9448 descriptor_write.dstBinding = 1;
9449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9450 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9451 m_errorMonitor->VerifyFound();
9452
9453 // Reduce size of range to acceptable limit & cause offset error
9454 buff_info.range = max_sb_range;
9455 buff_info.offset = min_sb_align - 1;
9456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9457 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9458 m_errorMonitor->VerifyFound();
9459
9460 vkFreeMemory(m_device->device(), mem, NULL);
9461 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9462 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9463 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9464 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9465}
9466
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009467TEST_F(VkLayerTest, DSAspectBitsErrors) {
9468 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9469 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009470 TEST_DESCRIPTION(
9471 "Attempt to update descriptor sets for images "
9472 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009473 VkResult err;
9474
9475 ASSERT_NO_FATAL_FAILURE(InitState());
9476 VkDescriptorPoolSize ds_type_count = {};
9477 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9478 ds_type_count.descriptorCount = 1;
9479
9480 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9481 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9482 ds_pool_ci.pNext = NULL;
9483 ds_pool_ci.maxSets = 5;
9484 ds_pool_ci.poolSizeCount = 1;
9485 ds_pool_ci.pPoolSizes = &ds_type_count;
9486
9487 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009488 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009489 ASSERT_VK_SUCCESS(err);
9490
9491 VkDescriptorSetLayoutBinding dsl_binding = {};
9492 dsl_binding.binding = 0;
9493 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9494 dsl_binding.descriptorCount = 1;
9495 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9496 dsl_binding.pImmutableSamplers = NULL;
9497
9498 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9499 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9500 ds_layout_ci.pNext = NULL;
9501 ds_layout_ci.bindingCount = 1;
9502 ds_layout_ci.pBindings = &dsl_binding;
9503 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009504 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009505 ASSERT_VK_SUCCESS(err);
9506
9507 VkDescriptorSet descriptor_set = {};
9508 VkDescriptorSetAllocateInfo alloc_info = {};
9509 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9510 alloc_info.descriptorSetCount = 1;
9511 alloc_info.descriptorPool = ds_pool;
9512 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009513 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009514 ASSERT_VK_SUCCESS(err);
9515
9516 // Create an image to be used for invalid updates
9517 VkImageCreateInfo image_ci = {};
9518 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9519 image_ci.imageType = VK_IMAGE_TYPE_2D;
9520 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9521 image_ci.extent.width = 64;
9522 image_ci.extent.height = 64;
9523 image_ci.extent.depth = 1;
9524 image_ci.mipLevels = 1;
9525 image_ci.arrayLayers = 1;
9526 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9527 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9528 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9529 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9530 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9531 VkImage image;
9532 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9533 ASSERT_VK_SUCCESS(err);
9534 // Bind memory to image
9535 VkMemoryRequirements mem_reqs;
9536 VkDeviceMemory image_mem;
9537 bool pass;
9538 VkMemoryAllocateInfo mem_alloc = {};
9539 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9540 mem_alloc.pNext = NULL;
9541 mem_alloc.allocationSize = 0;
9542 mem_alloc.memoryTypeIndex = 0;
9543 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9544 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009545 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009546 ASSERT_TRUE(pass);
9547 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9548 ASSERT_VK_SUCCESS(err);
9549 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9550 ASSERT_VK_SUCCESS(err);
9551 // Now create view for image
9552 VkImageViewCreateInfo image_view_ci = {};
9553 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9554 image_view_ci.image = image;
9555 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9556 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9557 image_view_ci.subresourceRange.layerCount = 1;
9558 image_view_ci.subresourceRange.baseArrayLayer = 0;
9559 image_view_ci.subresourceRange.levelCount = 1;
9560 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009561 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009562
9563 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009564 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009565 ASSERT_VK_SUCCESS(err);
9566
9567 VkDescriptorImageInfo img_info = {};
9568 img_info.imageView = image_view;
9569 VkWriteDescriptorSet descriptor_write = {};
9570 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9571 descriptor_write.dstBinding = 0;
9572 descriptor_write.descriptorCount = 1;
9573 descriptor_write.pTexelBufferView = NULL;
9574 descriptor_write.pBufferInfo = NULL;
9575 descriptor_write.pImageInfo = &img_info;
9576 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9577 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009578 const char *error_msg =
9579 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9580 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009582
9583 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9584
9585 m_errorMonitor->VerifyFound();
9586 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9587 vkDestroyImage(m_device->device(), image, NULL);
9588 vkFreeMemory(m_device->device(), image_mem, NULL);
9589 vkDestroyImageView(m_device->device(), image_view, NULL);
9590 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9591 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9592}
9593
Karl Schultz6addd812016-02-02 17:17:23 -07009594TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009595 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009596 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009597
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9599 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9600 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009601
Tobin Ehlis3b780662015-05-28 12:11:26 -06009602 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009603 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009604 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009605 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9606 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009607
9608 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009609 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9610 ds_pool_ci.pNext = NULL;
9611 ds_pool_ci.maxSets = 1;
9612 ds_pool_ci.poolSizeCount = 1;
9613 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009614
Tobin Ehlis3b780662015-05-28 12:11:26 -06009615 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009616 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009617 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009618 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009619 dsl_binding.binding = 0;
9620 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9621 dsl_binding.descriptorCount = 1;
9622 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9623 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009624
Tony Barboureb254902015-07-15 12:50:33 -06009625 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009626 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9627 ds_layout_ci.pNext = NULL;
9628 ds_layout_ci.bindingCount = 1;
9629 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009630
Tobin Ehlis3b780662015-05-28 12:11:26 -06009631 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009632 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009633 ASSERT_VK_SUCCESS(err);
9634
9635 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009636 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009637 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009638 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009639 alloc_info.descriptorPool = ds_pool;
9640 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009641 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009642 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009643
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009644 VkSamplerCreateInfo sampler_ci = {};
9645 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9646 sampler_ci.pNext = NULL;
9647 sampler_ci.magFilter = VK_FILTER_NEAREST;
9648 sampler_ci.minFilter = VK_FILTER_NEAREST;
9649 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9650 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9651 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9652 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9653 sampler_ci.mipLodBias = 1.0;
9654 sampler_ci.anisotropyEnable = VK_FALSE;
9655 sampler_ci.maxAnisotropy = 1;
9656 sampler_ci.compareEnable = VK_FALSE;
9657 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9658 sampler_ci.minLod = 1.0;
9659 sampler_ci.maxLod = 1.0;
9660 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9661 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9662 VkSampler sampler;
9663 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9664 ASSERT_VK_SUCCESS(err);
9665
9666 VkDescriptorImageInfo info = {};
9667 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009668
9669 VkWriteDescriptorSet descriptor_write;
9670 memset(&descriptor_write, 0, sizeof(descriptor_write));
9671 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009672 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009673 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009674 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009675 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009676 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009677
9678 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9679
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009680 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009681
Chia-I Wuf7458c52015-10-26 21:10:41 +08009682 vkDestroySampler(m_device->device(), sampler, NULL);
9683 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9684 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009685}
9686
Karl Schultz6addd812016-02-02 17:17:23 -07009687TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009688 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009689 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009690
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009692
Tobin Ehlis3b780662015-05-28 12:11:26 -06009693 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009694 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009695 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009696 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9697 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009698
9699 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009700 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9701 ds_pool_ci.pNext = NULL;
9702 ds_pool_ci.maxSets = 1;
9703 ds_pool_ci.poolSizeCount = 1;
9704 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009705
Tobin Ehlis3b780662015-05-28 12:11:26 -06009706 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009707 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009708 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009709
Tony Barboureb254902015-07-15 12:50:33 -06009710 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009711 dsl_binding.binding = 0;
9712 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9713 dsl_binding.descriptorCount = 1;
9714 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9715 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009716
9717 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009718 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9719 ds_layout_ci.pNext = NULL;
9720 ds_layout_ci.bindingCount = 1;
9721 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009722
Tobin Ehlis3b780662015-05-28 12:11:26 -06009723 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009724 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009725 ASSERT_VK_SUCCESS(err);
9726
9727 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009728 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009729 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009730 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009731 alloc_info.descriptorPool = ds_pool;
9732 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009733 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009734 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009735
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009736 // Correctly update descriptor to avoid "NOT_UPDATED" error
9737 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009738 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009739 buff_info.offset = 0;
9740 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009741
9742 VkWriteDescriptorSet descriptor_write;
9743 memset(&descriptor_write, 0, sizeof(descriptor_write));
9744 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009745 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009746 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009747 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009748 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9749 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009750
9751 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9752
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009753 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009754
Chia-I Wuf7458c52015-10-26 21:10:41 +08009755 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9756 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009757}
9758
Karl Schultz6addd812016-02-02 17:17:23 -07009759TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009760 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009761 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009762
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009764
Tobin Ehlis3b780662015-05-28 12:11:26 -06009765 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009766 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009767 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009768 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9769 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009770
9771 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009772 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9773 ds_pool_ci.pNext = NULL;
9774 ds_pool_ci.maxSets = 1;
9775 ds_pool_ci.poolSizeCount = 1;
9776 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009777
Tobin Ehlis3b780662015-05-28 12:11:26 -06009778 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009779 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009780 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009781
Tony Barboureb254902015-07-15 12:50:33 -06009782 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009783 dsl_binding.binding = 0;
9784 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9785 dsl_binding.descriptorCount = 1;
9786 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9787 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009788
9789 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009790 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9791 ds_layout_ci.pNext = NULL;
9792 ds_layout_ci.bindingCount = 1;
9793 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009794 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009795 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009796 ASSERT_VK_SUCCESS(err);
9797
9798 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009799 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009800 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009801 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009802 alloc_info.descriptorPool = ds_pool;
9803 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009804 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009805 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009806
Tony Barboureb254902015-07-15 12:50:33 -06009807 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009808 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9809 sampler_ci.pNext = NULL;
9810 sampler_ci.magFilter = VK_FILTER_NEAREST;
9811 sampler_ci.minFilter = VK_FILTER_NEAREST;
9812 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9813 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9814 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9815 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9816 sampler_ci.mipLodBias = 1.0;
9817 sampler_ci.anisotropyEnable = VK_FALSE;
9818 sampler_ci.maxAnisotropy = 1;
9819 sampler_ci.compareEnable = VK_FALSE;
9820 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9821 sampler_ci.minLod = 1.0;
9822 sampler_ci.maxLod = 1.0;
9823 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9824 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009825
Tobin Ehlis3b780662015-05-28 12:11:26 -06009826 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009827 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009828 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009829
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009830 VkDescriptorImageInfo info = {};
9831 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009832
9833 VkWriteDescriptorSet descriptor_write;
9834 memset(&descriptor_write, 0, sizeof(descriptor_write));
9835 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009836 descriptor_write.dstSet = descriptorSet;
9837 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009838 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009839 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009840 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009841 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009842
9843 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9844
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009845 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009846
Chia-I Wuf7458c52015-10-26 21:10:41 +08009847 vkDestroySampler(m_device->device(), sampler, NULL);
9848 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9849 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009850}
9851
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009852TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9853 // Create layout w/ empty binding and attempt to update it
9854 VkResult err;
9855
9856 ASSERT_NO_FATAL_FAILURE(InitState());
9857
9858 VkDescriptorPoolSize ds_type_count = {};
9859 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9860 ds_type_count.descriptorCount = 1;
9861
9862 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9863 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9864 ds_pool_ci.pNext = NULL;
9865 ds_pool_ci.maxSets = 1;
9866 ds_pool_ci.poolSizeCount = 1;
9867 ds_pool_ci.pPoolSizes = &ds_type_count;
9868
9869 VkDescriptorPool ds_pool;
9870 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9871 ASSERT_VK_SUCCESS(err);
9872
9873 VkDescriptorSetLayoutBinding dsl_binding = {};
9874 dsl_binding.binding = 0;
9875 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9876 dsl_binding.descriptorCount = 0;
9877 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9878 dsl_binding.pImmutableSamplers = NULL;
9879
9880 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9881 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9882 ds_layout_ci.pNext = NULL;
9883 ds_layout_ci.bindingCount = 1;
9884 ds_layout_ci.pBindings = &dsl_binding;
9885 VkDescriptorSetLayout ds_layout;
9886 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9887 ASSERT_VK_SUCCESS(err);
9888
9889 VkDescriptorSet descriptor_set;
9890 VkDescriptorSetAllocateInfo alloc_info = {};
9891 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9892 alloc_info.descriptorSetCount = 1;
9893 alloc_info.descriptorPool = ds_pool;
9894 alloc_info.pSetLayouts = &ds_layout;
9895 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9896 ASSERT_VK_SUCCESS(err);
9897
9898 VkSamplerCreateInfo sampler_ci = {};
9899 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9900 sampler_ci.magFilter = VK_FILTER_NEAREST;
9901 sampler_ci.minFilter = VK_FILTER_NEAREST;
9902 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9903 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9904 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9905 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9906 sampler_ci.mipLodBias = 1.0;
9907 sampler_ci.maxAnisotropy = 1;
9908 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9909 sampler_ci.minLod = 1.0;
9910 sampler_ci.maxLod = 1.0;
9911 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9912
9913 VkSampler sampler;
9914 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9915 ASSERT_VK_SUCCESS(err);
9916
9917 VkDescriptorImageInfo info = {};
9918 info.sampler = sampler;
9919
9920 VkWriteDescriptorSet descriptor_write;
9921 memset(&descriptor_write, 0, sizeof(descriptor_write));
9922 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9923 descriptor_write.dstSet = descriptor_set;
9924 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009925 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009926 // This is the wrong type, but empty binding error will be flagged first
9927 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9928 descriptor_write.pImageInfo = &info;
9929
9930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9931 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9932 m_errorMonitor->VerifyFound();
9933
9934 vkDestroySampler(m_device->device(), sampler, NULL);
9935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9936 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9937}
9938
Karl Schultz6addd812016-02-02 17:17:23 -07009939TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9940 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9941 // types
9942 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009944 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 -06009945
Tobin Ehlis3b780662015-05-28 12:11:26 -06009946 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009947
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009948 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009949 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9950 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009951
9952 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009953 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9954 ds_pool_ci.pNext = NULL;
9955 ds_pool_ci.maxSets = 1;
9956 ds_pool_ci.poolSizeCount = 1;
9957 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009958
Tobin Ehlis3b780662015-05-28 12:11:26 -06009959 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009960 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009961 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009962 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009963 dsl_binding.binding = 0;
9964 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9965 dsl_binding.descriptorCount = 1;
9966 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9967 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009968
Tony Barboureb254902015-07-15 12:50:33 -06009969 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009970 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9971 ds_layout_ci.pNext = NULL;
9972 ds_layout_ci.bindingCount = 1;
9973 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009974
Tobin Ehlis3b780662015-05-28 12:11:26 -06009975 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009977 ASSERT_VK_SUCCESS(err);
9978
9979 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009980 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009981 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009982 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009983 alloc_info.descriptorPool = ds_pool;
9984 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009985 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009986 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009987
Tony Barboureb254902015-07-15 12:50:33 -06009988 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009989 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9990 sampler_ci.pNext = NULL;
9991 sampler_ci.magFilter = VK_FILTER_NEAREST;
9992 sampler_ci.minFilter = VK_FILTER_NEAREST;
9993 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9994 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9995 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9996 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9997 sampler_ci.mipLodBias = 1.0;
9998 sampler_ci.anisotropyEnable = VK_FALSE;
9999 sampler_ci.maxAnisotropy = 1;
10000 sampler_ci.compareEnable = VK_FALSE;
10001 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10002 sampler_ci.minLod = 1.0;
10003 sampler_ci.maxLod = 1.0;
10004 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10005 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010006 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010007 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010008 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010009
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010010 VkDescriptorImageInfo info = {};
10011 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010012
10013 VkWriteDescriptorSet descriptor_write;
10014 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010015 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010016 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010017 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010018 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010019 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010020 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010021
10022 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10023
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010024 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010025
Chia-I Wuf7458c52015-10-26 21:10:41 +080010026 vkDestroySampler(m_device->device(), sampler, NULL);
10027 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10028 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010029}
10030
Karl Schultz6addd812016-02-02 17:17:23 -070010031TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010032 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010033 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010034
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010036
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010037 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010038 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10039 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010040 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010041 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10042 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010043
10044 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010045 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10046 ds_pool_ci.pNext = NULL;
10047 ds_pool_ci.maxSets = 1;
10048 ds_pool_ci.poolSizeCount = 1;
10049 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010050
10051 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010052 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010053 ASSERT_VK_SUCCESS(err);
10054
10055 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010056 dsl_binding.binding = 0;
10057 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10058 dsl_binding.descriptorCount = 1;
10059 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10060 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010061
10062 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010063 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10064 ds_layout_ci.pNext = NULL;
10065 ds_layout_ci.bindingCount = 1;
10066 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010067 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010068 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010069 ASSERT_VK_SUCCESS(err);
10070
10071 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010072 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010073 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010074 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010075 alloc_info.descriptorPool = ds_pool;
10076 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010077 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010078 ASSERT_VK_SUCCESS(err);
10079
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010080 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010081
10082 VkDescriptorImageInfo descriptor_info;
10083 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10084 descriptor_info.sampler = sampler;
10085
10086 VkWriteDescriptorSet descriptor_write;
10087 memset(&descriptor_write, 0, sizeof(descriptor_write));
10088 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010089 descriptor_write.dstSet = descriptorSet;
10090 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010091 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010092 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10093 descriptor_write.pImageInfo = &descriptor_info;
10094
10095 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10096
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010097 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010098
Chia-I Wuf7458c52015-10-26 21:10:41 +080010099 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10100 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010101}
10102
Karl Schultz6addd812016-02-02 17:17:23 -070010103TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10104 // Create a single combined Image/Sampler descriptor and send it an invalid
10105 // imageView
10106 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010107
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010109
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010110 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010111 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010112 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10113 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010114
10115 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010116 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10117 ds_pool_ci.pNext = NULL;
10118 ds_pool_ci.maxSets = 1;
10119 ds_pool_ci.poolSizeCount = 1;
10120 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010121
10122 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010123 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010124 ASSERT_VK_SUCCESS(err);
10125
10126 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010127 dsl_binding.binding = 0;
10128 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10129 dsl_binding.descriptorCount = 1;
10130 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10131 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010132
10133 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010134 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10135 ds_layout_ci.pNext = NULL;
10136 ds_layout_ci.bindingCount = 1;
10137 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010138 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010139 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010140 ASSERT_VK_SUCCESS(err);
10141
10142 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010143 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010144 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010145 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010146 alloc_info.descriptorPool = ds_pool;
10147 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010148 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010149 ASSERT_VK_SUCCESS(err);
10150
10151 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010152 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10153 sampler_ci.pNext = NULL;
10154 sampler_ci.magFilter = VK_FILTER_NEAREST;
10155 sampler_ci.minFilter = VK_FILTER_NEAREST;
10156 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10157 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10158 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10159 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10160 sampler_ci.mipLodBias = 1.0;
10161 sampler_ci.anisotropyEnable = VK_FALSE;
10162 sampler_ci.maxAnisotropy = 1;
10163 sampler_ci.compareEnable = VK_FALSE;
10164 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10165 sampler_ci.minLod = 1.0;
10166 sampler_ci.maxLod = 1.0;
10167 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10168 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010169
10170 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010171 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010172 ASSERT_VK_SUCCESS(err);
10173
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010174 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010175
10176 VkDescriptorImageInfo descriptor_info;
10177 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10178 descriptor_info.sampler = sampler;
10179 descriptor_info.imageView = view;
10180
10181 VkWriteDescriptorSet descriptor_write;
10182 memset(&descriptor_write, 0, sizeof(descriptor_write));
10183 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010184 descriptor_write.dstSet = descriptorSet;
10185 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010186 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010187 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10188 descriptor_write.pImageInfo = &descriptor_info;
10189
10190 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10191
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010192 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010193
Chia-I Wuf7458c52015-10-26 21:10:41 +080010194 vkDestroySampler(m_device->device(), sampler, NULL);
10195 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10196 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010197}
10198
Karl Schultz6addd812016-02-02 17:17:23 -070010199TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10200 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10201 // into the other
10202 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010203
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10205 " binding #1 with type "
10206 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10207 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010208
Tobin Ehlis04356f92015-10-27 16:35:27 -060010209 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010210 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010211 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010212 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10213 ds_type_count[0].descriptorCount = 1;
10214 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10215 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010216
10217 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010218 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10219 ds_pool_ci.pNext = NULL;
10220 ds_pool_ci.maxSets = 1;
10221 ds_pool_ci.poolSizeCount = 2;
10222 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010223
10224 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010225 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010226 ASSERT_VK_SUCCESS(err);
10227 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010228 dsl_binding[0].binding = 0;
10229 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10230 dsl_binding[0].descriptorCount = 1;
10231 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10232 dsl_binding[0].pImmutableSamplers = NULL;
10233 dsl_binding[1].binding = 1;
10234 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10235 dsl_binding[1].descriptorCount = 1;
10236 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10237 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010238
10239 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010240 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10241 ds_layout_ci.pNext = NULL;
10242 ds_layout_ci.bindingCount = 2;
10243 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010244
10245 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010246 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010247 ASSERT_VK_SUCCESS(err);
10248
10249 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010250 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010251 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010252 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010253 alloc_info.descriptorPool = ds_pool;
10254 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010255 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010256 ASSERT_VK_SUCCESS(err);
10257
10258 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010259 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10260 sampler_ci.pNext = NULL;
10261 sampler_ci.magFilter = VK_FILTER_NEAREST;
10262 sampler_ci.minFilter = VK_FILTER_NEAREST;
10263 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10264 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10265 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10266 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10267 sampler_ci.mipLodBias = 1.0;
10268 sampler_ci.anisotropyEnable = VK_FALSE;
10269 sampler_ci.maxAnisotropy = 1;
10270 sampler_ci.compareEnable = VK_FALSE;
10271 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10272 sampler_ci.minLod = 1.0;
10273 sampler_ci.maxLod = 1.0;
10274 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10275 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010276
10277 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010278 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010279 ASSERT_VK_SUCCESS(err);
10280
10281 VkDescriptorImageInfo info = {};
10282 info.sampler = sampler;
10283
10284 VkWriteDescriptorSet descriptor_write;
10285 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10286 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010287 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010288 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010289 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010290 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10291 descriptor_write.pImageInfo = &info;
10292 // This write update should succeed
10293 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10294 // Now perform a copy update that fails due to type mismatch
10295 VkCopyDescriptorSet copy_ds_update;
10296 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10297 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10298 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010299 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010300 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010301 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10302 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010303 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10304
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010305 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010306 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010307 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 -060010308 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10309 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10310 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010311 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010312 copy_ds_update.dstSet = descriptorSet;
10313 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010314 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010315 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10316
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010317 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010318
Tobin Ehlis04356f92015-10-27 16:35:27 -060010319 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10321 " binding#1 with offset index of 1 plus "
10322 "update array offset of 0 and update of "
10323 "5 descriptors oversteps total number "
10324 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010325
Tobin Ehlis04356f92015-10-27 16:35:27 -060010326 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10327 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10328 copy_ds_update.srcSet = descriptorSet;
10329 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010330 copy_ds_update.dstSet = descriptorSet;
10331 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010332 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010333 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10334
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010335 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010336
Chia-I Wuf7458c52015-10-26 21:10:41 +080010337 vkDestroySampler(m_device->device(), sampler, NULL);
10338 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10339 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010340}
10341
Karl Schultz6addd812016-02-02 17:17:23 -070010342TEST_F(VkLayerTest, NumSamplesMismatch) {
10343 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10344 // sampleCount
10345 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010346
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010348
Tobin Ehlis3b780662015-05-28 12:11:26 -060010349 ASSERT_NO_FATAL_FAILURE(InitState());
10350 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010351 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010352 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010353 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010354
10355 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010356 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10357 ds_pool_ci.pNext = NULL;
10358 ds_pool_ci.maxSets = 1;
10359 ds_pool_ci.poolSizeCount = 1;
10360 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010361
Tobin Ehlis3b780662015-05-28 12:11:26 -060010362 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010363 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010364 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010365
Tony Barboureb254902015-07-15 12:50:33 -060010366 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010367 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010368 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010369 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010370 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10371 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010372
Tony Barboureb254902015-07-15 12:50:33 -060010373 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10374 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10375 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010376 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010377 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010378
Tobin Ehlis3b780662015-05-28 12:11:26 -060010379 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010380 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010381 ASSERT_VK_SUCCESS(err);
10382
10383 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010384 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010385 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010386 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010387 alloc_info.descriptorPool = ds_pool;
10388 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010389 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010390 ASSERT_VK_SUCCESS(err);
10391
Tony Barboureb254902015-07-15 12:50:33 -060010392 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010393 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010394 pipe_ms_state_ci.pNext = NULL;
10395 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10396 pipe_ms_state_ci.sampleShadingEnable = 0;
10397 pipe_ms_state_ci.minSampleShading = 1.0;
10398 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010399
Tony Barboureb254902015-07-15 12:50:33 -060010400 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010401 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10402 pipeline_layout_ci.pNext = NULL;
10403 pipeline_layout_ci.setLayoutCount = 1;
10404 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010405
10406 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010407 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010408 ASSERT_VK_SUCCESS(err);
10409
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010410 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010411 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 -060010412 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010413 VkPipelineObj pipe(m_device);
10414 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010415 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010416 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010417 pipe.SetMSAA(&pipe_ms_state_ci);
10418 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010419
Tony Barbour552f6c02016-12-21 14:34:07 -070010420 m_commandBuffer->BeginCommandBuffer();
10421 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010422 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010423
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010424 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10425 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10426 VkRect2D scissor = {{0, 0}, {16, 16}};
10427 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10428
Mark Young29927482016-05-04 14:38:51 -060010429 // Render triangle (the error should trigger on the attempt to draw).
10430 Draw(3, 1, 0, 0);
10431
10432 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010433 m_commandBuffer->EndRenderPass();
10434 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010435
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010436 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010437
Chia-I Wuf7458c52015-10-26 21:10:41 +080010438 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10439 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10440 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010441}
Mark Young29927482016-05-04 14:38:51 -060010442
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010443TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010444 TEST_DESCRIPTION(
10445 "Hit RenderPass incompatible cases. "
10446 "Initial case is drawing with an active renderpass that's "
10447 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010448 VkResult err;
10449
10450 ASSERT_NO_FATAL_FAILURE(InitState());
10451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10452
10453 VkDescriptorSetLayoutBinding dsl_binding = {};
10454 dsl_binding.binding = 0;
10455 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10456 dsl_binding.descriptorCount = 1;
10457 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10458 dsl_binding.pImmutableSamplers = NULL;
10459
10460 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10461 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10462 ds_layout_ci.pNext = NULL;
10463 ds_layout_ci.bindingCount = 1;
10464 ds_layout_ci.pBindings = &dsl_binding;
10465
10466 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010467 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010468 ASSERT_VK_SUCCESS(err);
10469
10470 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10471 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10472 pipeline_layout_ci.pNext = NULL;
10473 pipeline_layout_ci.setLayoutCount = 1;
10474 pipeline_layout_ci.pSetLayouts = &ds_layout;
10475
10476 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010477 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010478 ASSERT_VK_SUCCESS(err);
10479
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010480 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010481 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 -060010482 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010483 // Create a renderpass that will be incompatible with default renderpass
10484 VkAttachmentReference attach = {};
10485 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10486 VkAttachmentReference color_att = {};
10487 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10488 VkSubpassDescription subpass = {};
10489 subpass.inputAttachmentCount = 1;
10490 subpass.pInputAttachments = &attach;
10491 subpass.colorAttachmentCount = 1;
10492 subpass.pColorAttachments = &color_att;
10493 VkRenderPassCreateInfo rpci = {};
10494 rpci.subpassCount = 1;
10495 rpci.pSubpasses = &subpass;
10496 rpci.attachmentCount = 1;
10497 VkAttachmentDescription attach_desc = {};
10498 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010499 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10500 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010501 rpci.pAttachments = &attach_desc;
10502 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10503 VkRenderPass rp;
10504 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10505 VkPipelineObj pipe(m_device);
10506 pipe.AddShader(&vs);
10507 pipe.AddShader(&fs);
10508 pipe.AddColorAttachment();
10509 VkViewport view_port = {};
10510 m_viewports.push_back(view_port);
10511 pipe.SetViewport(m_viewports);
10512 VkRect2D rect = {};
10513 m_scissors.push_back(rect);
10514 pipe.SetScissor(m_scissors);
10515 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10516
10517 VkCommandBufferInheritanceInfo cbii = {};
10518 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10519 cbii.renderPass = rp;
10520 cbii.subpass = 0;
10521 VkCommandBufferBeginInfo cbbi = {};
10522 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10523 cbbi.pInheritanceInfo = &cbii;
10524 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10525 VkRenderPassBeginInfo rpbi = {};
10526 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10527 rpbi.framebuffer = m_framebuffer;
10528 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010529 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10530 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010531
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010533 // Render triangle (the error should trigger on the attempt to draw).
10534 Draw(3, 1, 0, 0);
10535
10536 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010537 m_commandBuffer->EndRenderPass();
10538 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010539
10540 m_errorMonitor->VerifyFound();
10541
10542 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10543 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10544 vkDestroyRenderPass(m_device->device(), rp, NULL);
10545}
10546
Mark Youngc89c6312016-03-31 16:03:20 -060010547TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10548 // Create Pipeline where the number of blend attachments doesn't match the
10549 // number of color attachments. In this case, we don't add any color
10550 // blend attachments even though we have a color attachment.
10551 VkResult err;
10552
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010554
10555 ASSERT_NO_FATAL_FAILURE(InitState());
10556 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10557 VkDescriptorPoolSize ds_type_count = {};
10558 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10559 ds_type_count.descriptorCount = 1;
10560
10561 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10562 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10563 ds_pool_ci.pNext = NULL;
10564 ds_pool_ci.maxSets = 1;
10565 ds_pool_ci.poolSizeCount = 1;
10566 ds_pool_ci.pPoolSizes = &ds_type_count;
10567
10568 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010569 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010570 ASSERT_VK_SUCCESS(err);
10571
10572 VkDescriptorSetLayoutBinding dsl_binding = {};
10573 dsl_binding.binding = 0;
10574 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10575 dsl_binding.descriptorCount = 1;
10576 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10577 dsl_binding.pImmutableSamplers = NULL;
10578
10579 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10580 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10581 ds_layout_ci.pNext = NULL;
10582 ds_layout_ci.bindingCount = 1;
10583 ds_layout_ci.pBindings = &dsl_binding;
10584
10585 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010586 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010587 ASSERT_VK_SUCCESS(err);
10588
10589 VkDescriptorSet descriptorSet;
10590 VkDescriptorSetAllocateInfo alloc_info = {};
10591 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10592 alloc_info.descriptorSetCount = 1;
10593 alloc_info.descriptorPool = ds_pool;
10594 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010595 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010596 ASSERT_VK_SUCCESS(err);
10597
10598 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010599 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010600 pipe_ms_state_ci.pNext = NULL;
10601 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10602 pipe_ms_state_ci.sampleShadingEnable = 0;
10603 pipe_ms_state_ci.minSampleShading = 1.0;
10604 pipe_ms_state_ci.pSampleMask = NULL;
10605
10606 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10607 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10608 pipeline_layout_ci.pNext = NULL;
10609 pipeline_layout_ci.setLayoutCount = 1;
10610 pipeline_layout_ci.pSetLayouts = &ds_layout;
10611
10612 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010613 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010614 ASSERT_VK_SUCCESS(err);
10615
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010616 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010617 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 -060010618 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010619 VkPipelineObj pipe(m_device);
10620 pipe.AddShader(&vs);
10621 pipe.AddShader(&fs);
10622 pipe.SetMSAA(&pipe_ms_state_ci);
10623 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010624 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010625
10626 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10627 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10628 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10629}
Mark Young29927482016-05-04 14:38:51 -060010630
Mark Muellerd4914412016-06-13 17:52:06 -060010631TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010632 TEST_DESCRIPTION(
10633 "Points to a wrong colorAttachment index in a VkClearAttachment "
10634 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010635 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010637
10638 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10639 m_errorMonitor->VerifyFound();
10640}
10641
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010642TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010643 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10644 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010645
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010646 ASSERT_NO_FATAL_FAILURE(InitState());
10647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010648
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010649 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010650 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10651 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010652
10653 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010654 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10655 ds_pool_ci.pNext = NULL;
10656 ds_pool_ci.maxSets = 1;
10657 ds_pool_ci.poolSizeCount = 1;
10658 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010659
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010660 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010661 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010662 ASSERT_VK_SUCCESS(err);
10663
Tony Barboureb254902015-07-15 12:50:33 -060010664 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010665 dsl_binding.binding = 0;
10666 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10667 dsl_binding.descriptorCount = 1;
10668 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10669 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010670
Tony Barboureb254902015-07-15 12:50:33 -060010671 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010672 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10673 ds_layout_ci.pNext = NULL;
10674 ds_layout_ci.bindingCount = 1;
10675 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010676
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010677 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010678 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010679 ASSERT_VK_SUCCESS(err);
10680
10681 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010682 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010683 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010684 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010685 alloc_info.descriptorPool = ds_pool;
10686 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010687 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010688 ASSERT_VK_SUCCESS(err);
10689
Tony Barboureb254902015-07-15 12:50:33 -060010690 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010691 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010692 pipe_ms_state_ci.pNext = NULL;
10693 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10694 pipe_ms_state_ci.sampleShadingEnable = 0;
10695 pipe_ms_state_ci.minSampleShading = 1.0;
10696 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010697
Tony Barboureb254902015-07-15 12:50:33 -060010698 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010699 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10700 pipeline_layout_ci.pNext = NULL;
10701 pipeline_layout_ci.setLayoutCount = 1;
10702 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010703
10704 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010705 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010706 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010707
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010708 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010709 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010710 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010711 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010712
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010713 VkPipelineObj pipe(m_device);
10714 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010715 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010716 pipe.SetMSAA(&pipe_ms_state_ci);
10717 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010718
Tony Barbour552f6c02016-12-21 14:34:07 -070010719 m_commandBuffer->BeginCommandBuffer();
10720 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010721
Karl Schultz6addd812016-02-02 17:17:23 -070010722 // Main thing we care about for this test is that the VkImage obj we're
10723 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010724 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010725 VkClearAttachment color_attachment;
10726 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10727 color_attachment.clearValue.color.float32[0] = 1.0;
10728 color_attachment.clearValue.color.float32[1] = 1.0;
10729 color_attachment.clearValue.color.float32[2] = 1.0;
10730 color_attachment.clearValue.color.float32[3] = 1.0;
10731 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010732 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010733
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010734 // Call for full-sized FB Color attachment prior to issuing a Draw
10735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070010736 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010737 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010738 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010739
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010740 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
10741 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
10742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
10743 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
10744 m_errorMonitor->VerifyFound();
10745
10746 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
10747 clear_rect.layerCount = 2;
10748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
10749 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010750 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010751
Chia-I Wuf7458c52015-10-26 21:10:41 +080010752 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10753 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10754 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010755}
10756
Karl Schultz6addd812016-02-02 17:17:23 -070010757TEST_F(VkLayerTest, VtxBufferBadIndex) {
10758 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010759
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10761 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010762
Tobin Ehlis502480b2015-06-24 15:53:07 -060010763 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010764 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010765 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010766
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010767 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010768 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10769 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010770
10771 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010772 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10773 ds_pool_ci.pNext = NULL;
10774 ds_pool_ci.maxSets = 1;
10775 ds_pool_ci.poolSizeCount = 1;
10776 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010777
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010778 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010779 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010780 ASSERT_VK_SUCCESS(err);
10781
Tony Barboureb254902015-07-15 12:50:33 -060010782 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010783 dsl_binding.binding = 0;
10784 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10785 dsl_binding.descriptorCount = 1;
10786 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10787 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010788
Tony Barboureb254902015-07-15 12:50:33 -060010789 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010790 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10791 ds_layout_ci.pNext = NULL;
10792 ds_layout_ci.bindingCount = 1;
10793 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010794
Tobin Ehlis502480b2015-06-24 15:53:07 -060010795 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010796 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010797 ASSERT_VK_SUCCESS(err);
10798
10799 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010800 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010801 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010802 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010803 alloc_info.descriptorPool = ds_pool;
10804 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010805 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010806 ASSERT_VK_SUCCESS(err);
10807
Tony Barboureb254902015-07-15 12:50:33 -060010808 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010809 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010810 pipe_ms_state_ci.pNext = NULL;
10811 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10812 pipe_ms_state_ci.sampleShadingEnable = 0;
10813 pipe_ms_state_ci.minSampleShading = 1.0;
10814 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010815
Tony Barboureb254902015-07-15 12:50:33 -060010816 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010817 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10818 pipeline_layout_ci.pNext = NULL;
10819 pipeline_layout_ci.setLayoutCount = 1;
10820 pipeline_layout_ci.pSetLayouts = &ds_layout;
10821 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010822
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010823 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010824 ASSERT_VK_SUCCESS(err);
10825
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010826 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010827 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 -060010828 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010829 VkPipelineObj pipe(m_device);
10830 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010831 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010832 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010833 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010834 pipe.SetViewport(m_viewports);
10835 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010836 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010837
Tony Barbour552f6c02016-12-21 14:34:07 -070010838 m_commandBuffer->BeginCommandBuffer();
10839 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010840 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010841 // Don't care about actual data, just need to get to draw to flag error
10842 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010843 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010844 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010845 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010846
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010847 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010848
Chia-I Wuf7458c52015-10-26 21:10:41 +080010849 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10850 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10851 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010852}
Mark Muellerdfe37552016-07-07 14:47:42 -060010853
Mark Mueller2ee294f2016-08-04 12:59:48 -060010854TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010855 TEST_DESCRIPTION(
10856 "Use an invalid count in a vkEnumeratePhysicalDevices call."
10857 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010858 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010859
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010860 const char *invalid_queueFamilyIndex_message =
10861 "Invalid queue create request in vkCreateDevice(). Invalid "
10862 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010863
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010864 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010865
Mark Mueller880fce52016-08-17 15:23:23 -060010866 // The following test fails with recent NVidia drivers.
10867 // By the time core_validation is reached, the NVidia
10868 // driver has sanitized the invalid condition and core_validation
10869 // is not introduced to the failure condition. This is not the case
10870 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010871 // uint32_t count = static_cast<uint32_t>(~0);
10872 // VkPhysicalDevice physical_device;
10873 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10874 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010875
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010877 float queue_priority = 0.0;
10878
10879 VkDeviceQueueCreateInfo queue_create_info = {};
10880 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10881 queue_create_info.queueCount = 1;
10882 queue_create_info.pQueuePriorities = &queue_priority;
10883 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10884
10885 VkPhysicalDeviceFeatures features = m_device->phy().features();
10886 VkDevice testDevice;
10887 VkDeviceCreateInfo device_create_info = {};
10888 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10889 device_create_info.queueCreateInfoCount = 1;
10890 device_create_info.pQueueCreateInfos = &queue_create_info;
10891 device_create_info.pEnabledFeatures = &features;
10892 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10893 m_errorMonitor->VerifyFound();
10894
10895 queue_create_info.queueFamilyIndex = 1;
10896
10897 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10898 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10899 for (unsigned i = 0; i < feature_count; i++) {
10900 if (VK_FALSE == feature_array[i]) {
10901 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010903 device_create_info.pEnabledFeatures = &features;
10904 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10905 m_errorMonitor->VerifyFound();
10906 break;
10907 }
10908 }
10909}
10910
Tobin Ehlis16edf082016-11-21 12:33:49 -070010911TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10912 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10913
10914 ASSERT_NO_FATAL_FAILURE(InitState());
10915
10916 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10917 std::vector<VkDeviceQueueCreateInfo> queue_info;
10918 queue_info.reserve(queue_props.size());
10919 std::vector<std::vector<float>> queue_priorities;
10920 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10921 VkDeviceQueueCreateInfo qi{};
10922 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10923 qi.queueFamilyIndex = i;
10924 qi.queueCount = queue_props[i].queueCount;
10925 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10926 qi.pQueuePriorities = queue_priorities[i].data();
10927 queue_info.push_back(qi);
10928 }
10929
10930 std::vector<const char *> device_extension_names;
10931
10932 VkDevice local_device;
10933 VkDeviceCreateInfo device_create_info = {};
10934 auto features = m_device->phy().features();
10935 // Intentionally disable pipeline stats
10936 features.pipelineStatisticsQuery = VK_FALSE;
10937 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10938 device_create_info.pNext = NULL;
10939 device_create_info.queueCreateInfoCount = queue_info.size();
10940 device_create_info.pQueueCreateInfos = queue_info.data();
10941 device_create_info.enabledLayerCount = 0;
10942 device_create_info.ppEnabledLayerNames = NULL;
10943 device_create_info.pEnabledFeatures = &features;
10944 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10945 ASSERT_VK_SUCCESS(err);
10946
10947 VkQueryPoolCreateInfo qpci{};
10948 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10949 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10950 qpci.queryCount = 1;
10951 VkQueryPool query_pool;
10952
10953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10954 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10955 m_errorMonitor->VerifyFound();
10956
10957 vkDestroyDevice(local_device, nullptr);
10958}
10959
Mark Mueller2ee294f2016-08-04 12:59:48 -060010960TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010961 TEST_DESCRIPTION(
10962 "Use an invalid queue index in a vkCmdWaitEvents call."
10963 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060010964
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010965 const char *invalid_queue_index =
10966 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10967 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10968 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010969
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010970 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010971
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010973
10974 ASSERT_NO_FATAL_FAILURE(InitState());
10975
10976 VkEvent event;
10977 VkEventCreateInfo event_create_info{};
10978 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10979 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10980
Mark Mueller2ee294f2016-08-04 12:59:48 -060010981 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010982 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010983
Tony Barbour552f6c02016-12-21 14:34:07 -070010984 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010985
10986 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010987 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 -060010988 ASSERT_TRUE(image.initialized());
10989 VkImageMemoryBarrier img_barrier = {};
10990 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10991 img_barrier.pNext = NULL;
10992 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10993 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10994 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10995 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10996 img_barrier.image = image.handle();
10997 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010998
10999 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11000 // that layer validation catches the case when it is not.
11001 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011002 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11003 img_barrier.subresourceRange.baseArrayLayer = 0;
11004 img_barrier.subresourceRange.baseMipLevel = 0;
11005 img_barrier.subresourceRange.layerCount = 1;
11006 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011007 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11008 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011009 m_errorMonitor->VerifyFound();
11010
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011012
11013 VkQueryPool query_pool;
11014 VkQueryPoolCreateInfo query_pool_create_info = {};
11015 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11016 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11017 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011018 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011019
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011020 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011021 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11022
11023 vkEndCommandBuffer(m_commandBuffer->handle());
11024 m_errorMonitor->VerifyFound();
11025
11026 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11027 vkDestroyEvent(m_device->device(), event, nullptr);
11028}
11029
Mark Muellerdfe37552016-07-07 14:47:42 -060011030TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011031 TEST_DESCRIPTION(
11032 "Submit a command buffer using deleted vertex buffer, "
11033 "delete a buffer twice, use an invalid offset for each "
11034 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011035
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011036 const char *deleted_buffer_in_command_buffer =
11037 "Cannot submit cmd buffer "
11038 "using deleted buffer ";
11039 const char *invalid_offset_message =
11040 "vkBindBufferMemory(): "
11041 "memoryOffset is 0x";
11042 const char *invalid_storage_buffer_offset_message =
11043 "vkBindBufferMemory(): "
11044 "storage memoryOffset "
11045 "is 0x";
11046 const char *invalid_texel_buffer_offset_message =
11047 "vkBindBufferMemory(): "
11048 "texel memoryOffset "
11049 "is 0x";
11050 const char *invalid_uniform_buffer_offset_message =
11051 "vkBindBufferMemory(): "
11052 "uniform memoryOffset "
11053 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011054
11055 ASSERT_NO_FATAL_FAILURE(InitState());
11056 ASSERT_NO_FATAL_FAILURE(InitViewport());
11057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11058
11059 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011060 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011061 pipe_ms_state_ci.pNext = NULL;
11062 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11063 pipe_ms_state_ci.sampleShadingEnable = 0;
11064 pipe_ms_state_ci.minSampleShading = 1.0;
11065 pipe_ms_state_ci.pSampleMask = nullptr;
11066
11067 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11068 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11069 VkPipelineLayout pipeline_layout;
11070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011071 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011072 ASSERT_VK_SUCCESS(err);
11073
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011074 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11075 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011076 VkPipelineObj pipe(m_device);
11077 pipe.AddShader(&vs);
11078 pipe.AddShader(&fs);
11079 pipe.AddColorAttachment();
11080 pipe.SetMSAA(&pipe_ms_state_ci);
11081 pipe.SetViewport(m_viewports);
11082 pipe.SetScissor(m_scissors);
11083 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11084
Tony Barbour552f6c02016-12-21 14:34:07 -070011085 m_commandBuffer->BeginCommandBuffer();
11086 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011087 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011088
11089 {
11090 // Create and bind a vertex buffer in a reduced scope, which will cause
11091 // it to be deleted upon leaving this scope
11092 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011093 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011094 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11095 draw_verticies.AddVertexInputToPipe(pipe);
11096 }
11097
11098 Draw(1, 0, 0, 0);
11099
Tony Barbour552f6c02016-12-21 14:34:07 -070011100 m_commandBuffer->EndRenderPass();
11101 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011104 QueueCommandBuffer(false);
11105 m_errorMonitor->VerifyFound();
11106
11107 {
11108 // Create and bind a vertex buffer in a reduced scope, and delete it
11109 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011110 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011112 buffer_test.TestDoubleDestroy();
11113 }
11114 m_errorMonitor->VerifyFound();
11115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011116 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011117 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
11119 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11120 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011121 m_errorMonitor->VerifyFound();
11122 }
11123
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011124 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11125 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011126 // Create and bind a memory buffer with an invalid offset again,
11127 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
11129 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11130 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011131 m_errorMonitor->VerifyFound();
11132 }
11133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011134 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011135 // Create and bind a memory buffer with an invalid offset again, but
11136 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
11138 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11139 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011140 m_errorMonitor->VerifyFound();
11141 }
11142
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011143 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011144 // Create and bind a memory buffer with an invalid offset again, but
11145 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
11147 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11148 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011149 m_errorMonitor->VerifyFound();
11150 }
11151
11152 {
11153 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011155 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11156 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011157 m_errorMonitor->VerifyFound();
11158 }
11159
11160 {
11161 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011163 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11164 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011165 }
11166 m_errorMonitor->VerifyFound();
11167
11168 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11169}
11170
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011171// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11172TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011173 TEST_DESCRIPTION(
11174 "Hit all possible validation checks associated with the "
11175 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11176 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011177 // 3 in ValidateCmdBufImageLayouts
11178 // * -1 Attempt to submit cmd buf w/ deleted image
11179 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11180 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011181
11182 ASSERT_NO_FATAL_FAILURE(InitState());
11183 // Create src & dst images to use for copy operations
11184 VkImage src_image;
11185 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011186 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011187
11188 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11189 const int32_t tex_width = 32;
11190 const int32_t tex_height = 32;
11191
11192 VkImageCreateInfo image_create_info = {};
11193 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11194 image_create_info.pNext = NULL;
11195 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11196 image_create_info.format = tex_format;
11197 image_create_info.extent.width = tex_width;
11198 image_create_info.extent.height = tex_height;
11199 image_create_info.extent.depth = 1;
11200 image_create_info.mipLevels = 1;
11201 image_create_info.arrayLayers = 4;
11202 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11203 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11204 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011205 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011206 image_create_info.flags = 0;
11207
11208 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11209 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011210 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011211 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11212 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011213 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11214 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11215 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11216 ASSERT_VK_SUCCESS(err);
11217
11218 // Allocate memory
11219 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011220 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011221 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011222 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11223 mem_alloc.pNext = NULL;
11224 mem_alloc.allocationSize = 0;
11225 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011226
11227 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011228 mem_alloc.allocationSize = img_mem_reqs.size;
11229 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011230 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011231 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011232 ASSERT_VK_SUCCESS(err);
11233
11234 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011235 mem_alloc.allocationSize = img_mem_reqs.size;
11236 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011237 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011238 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011239 ASSERT_VK_SUCCESS(err);
11240
11241 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011242 mem_alloc.allocationSize = img_mem_reqs.size;
11243 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011244 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011245 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011246 ASSERT_VK_SUCCESS(err);
11247
11248 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11249 ASSERT_VK_SUCCESS(err);
11250 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11251 ASSERT_VK_SUCCESS(err);
11252 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11253 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011254
Tony Barbour552f6c02016-12-21 14:34:07 -070011255 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011256 VkImageCopy copy_region;
11257 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11258 copy_region.srcSubresource.mipLevel = 0;
11259 copy_region.srcSubresource.baseArrayLayer = 0;
11260 copy_region.srcSubresource.layerCount = 1;
11261 copy_region.srcOffset.x = 0;
11262 copy_region.srcOffset.y = 0;
11263 copy_region.srcOffset.z = 0;
11264 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11265 copy_region.dstSubresource.mipLevel = 0;
11266 copy_region.dstSubresource.baseArrayLayer = 0;
11267 copy_region.dstSubresource.layerCount = 1;
11268 copy_region.dstOffset.x = 0;
11269 copy_region.dstOffset.y = 0;
11270 copy_region.dstOffset.z = 0;
11271 copy_region.extent.width = 1;
11272 copy_region.extent.height = 1;
11273 copy_region.extent.depth = 1;
11274
11275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11276 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
11277 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 -060011278 m_errorMonitor->VerifyFound();
11279 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11281 "Cannot copy from an image whose source layout is "
11282 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11283 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011284 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 -060011285 m_errorMonitor->VerifyFound();
11286 // Final src error is due to bad layout type
11287 m_errorMonitor->SetDesiredFailureMsg(
11288 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11289 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011290 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 -060011291 m_errorMonitor->VerifyFound();
11292 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11294 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011295 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 -060011296 m_errorMonitor->VerifyFound();
11297 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11299 "Cannot copy from an image whose dest layout is "
11300 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11301 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011302 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 -060011303 m_errorMonitor->VerifyFound();
11304 m_errorMonitor->SetDesiredFailureMsg(
11305 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11306 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011307 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 -060011308 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011309
Cort3b021012016-12-07 12:00:57 -080011310 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11311 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11312 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11313 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11314 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11315 transfer_dst_image_barrier[0].srcAccessMask = 0;
11316 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11317 transfer_dst_image_barrier[0].image = dst_image;
11318 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11319 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11320 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11321 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11322 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11323 transfer_dst_image_barrier[0].image = depth_image;
11324 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11325 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11326 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11327
11328 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011329 VkClearColorValue color_clear_value = {};
11330 VkImageSubresourceRange clear_range;
11331 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11332 clear_range.baseMipLevel = 0;
11333 clear_range.baseArrayLayer = 0;
11334 clear_range.layerCount = 1;
11335 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011336
Cort3b021012016-12-07 12:00:57 -080011337 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11338 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011341 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011342 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011343 // Fail due to provided layout not matching actual current layout for color clear.
11344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011345 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011346 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011347
Cort530cf382016-12-08 09:59:47 -080011348 VkClearDepthStencilValue depth_clear_value = {};
11349 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011350
11351 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11352 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011355 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011356 m_errorMonitor->VerifyFound();
11357 // Fail due to provided layout not matching actual current layout for depth clear.
11358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011359 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011360 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011361
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011362 // Now cause error due to bad image layout transition in PipelineBarrier
11363 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011364 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011365 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011366 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011367 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011368 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11369 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011370 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11372 "You cannot transition the layout of aspect 1 from "
11373 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11374 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011375 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11376 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011377 m_errorMonitor->VerifyFound();
11378
11379 // Finally some layout errors at RenderPass create time
11380 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11381 VkAttachmentReference attach = {};
11382 // perf warning for GENERAL layout w/ non-DS input attachment
11383 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11384 VkSubpassDescription subpass = {};
11385 subpass.inputAttachmentCount = 1;
11386 subpass.pInputAttachments = &attach;
11387 VkRenderPassCreateInfo rpci = {};
11388 rpci.subpassCount = 1;
11389 rpci.pSubpasses = &subpass;
11390 rpci.attachmentCount = 1;
11391 VkAttachmentDescription attach_desc = {};
11392 attach_desc.format = VK_FORMAT_UNDEFINED;
11393 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011394 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011395 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11397 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011398 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11399 m_errorMonitor->VerifyFound();
11400 // error w/ non-general layout
11401 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11402
11403 m_errorMonitor->SetDesiredFailureMsg(
11404 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11405 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11406 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11407 m_errorMonitor->VerifyFound();
11408 subpass.inputAttachmentCount = 0;
11409 subpass.colorAttachmentCount = 1;
11410 subpass.pColorAttachments = &attach;
11411 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11412 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11414 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011415 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11416 m_errorMonitor->VerifyFound();
11417 // error w/ non-color opt or GENERAL layout for color attachment
11418 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11419 m_errorMonitor->SetDesiredFailureMsg(
11420 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11421 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11422 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11423 m_errorMonitor->VerifyFound();
11424 subpass.colorAttachmentCount = 0;
11425 subpass.pDepthStencilAttachment = &attach;
11426 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11427 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11429 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011430 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11431 m_errorMonitor->VerifyFound();
11432 // error w/ non-ds opt or GENERAL layout for color attachment
11433 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11435 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11436 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011437 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11438 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011439 // For this error we need a valid renderpass so create default one
11440 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11441 attach.attachment = 0;
11442 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11443 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11444 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11445 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11446 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11447 // Can't do a CLEAR load on READ_ONLY initialLayout
11448 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11449 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11450 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11452 " with invalid first layout "
11453 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11454 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011455 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11456 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011457
Cort3b021012016-12-07 12:00:57 -080011458 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11459 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11460 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011461 vkDestroyImage(m_device->device(), src_image, NULL);
11462 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011463 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011464}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011465
Tobin Ehlise0936662016-10-11 08:10:51 -060011466TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11467 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11468 VkResult err;
11469
11470 ASSERT_NO_FATAL_FAILURE(InitState());
11471
11472 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11473 VkImageTiling tiling;
11474 VkFormatProperties format_properties;
11475 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11476 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11477 tiling = VK_IMAGE_TILING_LINEAR;
11478 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11479 tiling = VK_IMAGE_TILING_OPTIMAL;
11480 } else {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011481 printf(
11482 "Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11483 "skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011484 return;
11485 }
11486
11487 VkDescriptorPoolSize ds_type = {};
11488 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11489 ds_type.descriptorCount = 1;
11490
11491 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11492 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11493 ds_pool_ci.maxSets = 1;
11494 ds_pool_ci.poolSizeCount = 1;
11495 ds_pool_ci.pPoolSizes = &ds_type;
11496 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11497
11498 VkDescriptorPool ds_pool;
11499 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11500 ASSERT_VK_SUCCESS(err);
11501
11502 VkDescriptorSetLayoutBinding dsl_binding = {};
11503 dsl_binding.binding = 0;
11504 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11505 dsl_binding.descriptorCount = 1;
11506 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11507 dsl_binding.pImmutableSamplers = NULL;
11508
11509 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11510 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11511 ds_layout_ci.pNext = NULL;
11512 ds_layout_ci.bindingCount = 1;
11513 ds_layout_ci.pBindings = &dsl_binding;
11514
11515 VkDescriptorSetLayout ds_layout;
11516 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11517 ASSERT_VK_SUCCESS(err);
11518
11519 VkDescriptorSetAllocateInfo alloc_info = {};
11520 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11521 alloc_info.descriptorSetCount = 1;
11522 alloc_info.descriptorPool = ds_pool;
11523 alloc_info.pSetLayouts = &ds_layout;
11524 VkDescriptorSet descriptor_set;
11525 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11526 ASSERT_VK_SUCCESS(err);
11527
11528 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11529 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11530 pipeline_layout_ci.pNext = NULL;
11531 pipeline_layout_ci.setLayoutCount = 1;
11532 pipeline_layout_ci.pSetLayouts = &ds_layout;
11533 VkPipelineLayout pipeline_layout;
11534 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11535 ASSERT_VK_SUCCESS(err);
11536
11537 VkImageObj image(m_device);
11538 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11539 ASSERT_TRUE(image.initialized());
11540 VkImageView view = image.targetView(tex_format);
11541
11542 VkDescriptorImageInfo image_info = {};
11543 image_info.imageView = view;
11544 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11545
11546 VkWriteDescriptorSet descriptor_write = {};
11547 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11548 descriptor_write.dstSet = descriptor_set;
11549 descriptor_write.dstBinding = 0;
11550 descriptor_write.descriptorCount = 1;
11551 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11552 descriptor_write.pImageInfo = &image_info;
11553
11554 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11555 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11556 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11557 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11558 m_errorMonitor->VerifyFound();
11559
11560 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11561 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11562 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11563 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11564}
11565
Mark Mueller93b938f2016-08-18 10:27:40 -060011566TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011567 TEST_DESCRIPTION(
11568 "Use vkCmdExecuteCommands with invalid state "
11569 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011570
11571 ASSERT_NO_FATAL_FAILURE(InitState());
11572 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11573
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011574 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011575 const char *simultaneous_use_message2 =
11576 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11577 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011578
11579 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011580 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011581 command_buffer_allocate_info.commandPool = m_commandPool;
11582 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11583 command_buffer_allocate_info.commandBufferCount = 1;
11584
11585 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011586 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011587 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11588 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011589 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011590 command_buffer_inheritance_info.renderPass = m_renderPass;
11591 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011592
Mark Mueller93b938f2016-08-18 10:27:40 -060011593 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011594 command_buffer_begin_info.flags =
11595 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011596 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11597
11598 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11599 vkEndCommandBuffer(secondary_command_buffer);
11600
Mark Mueller93b938f2016-08-18 10:27:40 -060011601 VkSubmitInfo submit_info = {};
11602 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11603 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011604 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011605
Mark Mueller4042b652016-09-05 22:52:21 -060011606 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011607 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11609 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011610 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011611 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011612 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11613 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011614
Dave Houltonfbf52152017-01-06 12:55:29 -070011615 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060011616 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070011617 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060011618
Mark Mueller4042b652016-09-05 22:52:21 -060011619 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011620 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011621 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11624 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011625 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011626 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11627 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011628
11629 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011630}
11631
Tobin Ehlisb093da82017-01-19 12:05:27 -070011632TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011633 TEST_DESCRIPTION(
11634 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
11635 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070011636
11637 ASSERT_NO_FATAL_FAILURE(InitState());
11638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11639
11640 std::vector<const char *> device_extension_names;
11641 auto features = m_device->phy().features();
11642 // Make sure gs & ts are disabled
11643 features.geometryShader = false;
11644 features.tessellationShader = false;
11645 // The sacrificial device object
11646 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11647
11648 VkCommandPoolCreateInfo pool_create_info{};
11649 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
11650 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
11651
11652 VkCommandPool command_pool;
11653 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
11654
11655 VkCommandBufferAllocateInfo cmd = {};
11656 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11657 cmd.pNext = NULL;
11658 cmd.commandPool = command_pool;
11659 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
11660 cmd.commandBufferCount = 1;
11661
11662 VkCommandBuffer cmd_buffer;
11663 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
11664 ASSERT_VK_SUCCESS(err);
11665
11666 VkEvent event;
11667 VkEventCreateInfo evci = {};
11668 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11669 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
11670 ASSERT_VK_SUCCESS(result);
11671
11672 VkCommandBufferBeginInfo cbbi = {};
11673 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11674 vkBeginCommandBuffer(cmd_buffer, &cbbi);
11675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
11676 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
11677 m_errorMonitor->VerifyFound();
11678
11679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
11680 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
11681 m_errorMonitor->VerifyFound();
11682
11683 vkDestroyEvent(test_device.handle(), event, NULL);
11684 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
11685}
11686
Mark Mueller917f6bc2016-08-30 10:57:19 -060011687TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011688 TEST_DESCRIPTION(
11689 "Use vkCmdExecuteCommands with invalid state "
11690 "in primary and secondary command buffers. "
11691 "Delete objects that are inuse. Call VkQueueSubmit "
11692 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011693
11694 ASSERT_NO_FATAL_FAILURE(InitState());
11695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11696
Tony Barbour552f6c02016-12-21 14:34:07 -070011697 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011698
11699 VkEvent event;
11700 VkEventCreateInfo event_create_info = {};
11701 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11702 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011703 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011704
Tony Barbour552f6c02016-12-21 14:34:07 -070011705 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011706 vkDestroyEvent(m_device->device(), event, nullptr);
11707
11708 VkSubmitInfo submit_info = {};
11709 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11710 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011711 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b082d72017-01-27 11:34:28 -070011712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted event 0x");
11713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You are submitting command buffer 0x");
Mark Muellerc8d441e2016-08-23 17:36:00 -060011714 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11715 m_errorMonitor->VerifyFound();
11716
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011717 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060011718 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11719
11720 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11721
Mark Mueller917f6bc2016-08-30 10:57:19 -060011722 VkSemaphoreCreateInfo semaphore_create_info = {};
11723 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11724 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011725 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011726 VkFenceCreateInfo fence_create_info = {};
11727 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11728 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011729 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011730
11731 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011732 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011733 descriptor_pool_type_count.descriptorCount = 1;
11734
11735 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11736 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11737 descriptor_pool_create_info.maxSets = 1;
11738 descriptor_pool_create_info.poolSizeCount = 1;
11739 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011740 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011741
11742 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011743 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011744
11745 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011746 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011747 descriptorset_layout_binding.descriptorCount = 1;
11748 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11749
11750 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011751 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011752 descriptorset_layout_create_info.bindingCount = 1;
11753 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11754
11755 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011756 ASSERT_VK_SUCCESS(
11757 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011758
11759 VkDescriptorSet descriptorset;
11760 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011761 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011762 descriptorset_allocate_info.descriptorSetCount = 1;
11763 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11764 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011765 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011766
Mark Mueller4042b652016-09-05 22:52:21 -060011767 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11768
11769 VkDescriptorBufferInfo buffer_info = {};
11770 buffer_info.buffer = buffer_test.GetBuffer();
11771 buffer_info.offset = 0;
11772 buffer_info.range = 1024;
11773
11774 VkWriteDescriptorSet write_descriptor_set = {};
11775 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11776 write_descriptor_set.dstSet = descriptorset;
11777 write_descriptor_set.descriptorCount = 1;
11778 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11779 write_descriptor_set.pBufferInfo = &buffer_info;
11780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011781 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011782
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011783 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11784 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011785
11786 VkPipelineObj pipe(m_device);
11787 pipe.AddColorAttachment();
11788 pipe.AddShader(&vs);
11789 pipe.AddShader(&fs);
11790
11791 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011792 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011793 pipeline_layout_create_info.setLayoutCount = 1;
11794 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11795
11796 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011797 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011798
11799 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11800
Tony Barbour552f6c02016-12-21 14:34:07 -070011801 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011802 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011803
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011804 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11805 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11806 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011807
Tony Barbour552f6c02016-12-21 14:34:07 -070011808 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011809
Mark Mueller917f6bc2016-08-30 10:57:19 -060011810 submit_info.signalSemaphoreCount = 1;
11811 submit_info.pSignalSemaphores = &semaphore;
11812 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011813 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060011814
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011816 vkDestroyEvent(m_device->device(), event, nullptr);
11817 m_errorMonitor->VerifyFound();
11818
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011820 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11821 m_errorMonitor->VerifyFound();
11822
Jeremy Hayes08369882017-02-02 10:31:06 -070011823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011824 vkDestroyFence(m_device->device(), fence, nullptr);
11825 m_errorMonitor->VerifyFound();
11826
Tobin Ehlis122207b2016-09-01 08:50:06 -070011827 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011828 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11829 vkDestroyFence(m_device->device(), fence, nullptr);
11830 vkDestroyEvent(m_device->device(), event, nullptr);
11831 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011832 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011833 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11834}
11835
Tobin Ehlis2adda372016-09-01 08:51:06 -070011836TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11837 TEST_DESCRIPTION("Delete in-use query pool.");
11838
11839 ASSERT_NO_FATAL_FAILURE(InitState());
11840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11841
11842 VkQueryPool query_pool;
11843 VkQueryPoolCreateInfo query_pool_ci{};
11844 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11845 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11846 query_pool_ci.queryCount = 1;
11847 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011848 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011849 // Reset query pool to create binding with cmd buffer
11850 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11851
Tony Barbour552f6c02016-12-21 14:34:07 -070011852 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011853
11854 VkSubmitInfo submit_info = {};
11855 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11856 submit_info.commandBufferCount = 1;
11857 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11858 // Submit cmd buffer and then destroy query pool while in-flight
11859 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11860
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011862 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11863 m_errorMonitor->VerifyFound();
11864
11865 vkQueueWaitIdle(m_device->m_queue);
11866 // Now that cmd buffer done we can safely destroy query_pool
11867 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11868}
11869
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011870TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11871 TEST_DESCRIPTION("Delete in-use pipeline.");
11872
11873 ASSERT_NO_FATAL_FAILURE(InitState());
11874 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11875
11876 // Empty pipeline layout used for binding PSO
11877 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11878 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11879 pipeline_layout_ci.setLayoutCount = 0;
11880 pipeline_layout_ci.pSetLayouts = NULL;
11881
11882 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011883 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011884 ASSERT_VK_SUCCESS(err);
11885
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011887 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011888 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11889 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011890 // Store pipeline handle so we can actually delete it before test finishes
11891 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011892 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011893 VkPipelineObj pipe(m_device);
11894 pipe.AddShader(&vs);
11895 pipe.AddShader(&fs);
11896 pipe.AddColorAttachment();
11897 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11898 delete_this_pipeline = pipe.handle();
11899
Tony Barbour552f6c02016-12-21 14:34:07 -070011900 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011901 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011902 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011903
Tony Barbour552f6c02016-12-21 14:34:07 -070011904 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011905
11906 VkSubmitInfo submit_info = {};
11907 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11908 submit_info.commandBufferCount = 1;
11909 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11910 // Submit cmd buffer and then pipeline destroyed while in-flight
11911 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011912 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011913 m_errorMonitor->VerifyFound();
11914 // Make sure queue finished and then actually delete pipeline
11915 vkQueueWaitIdle(m_device->m_queue);
11916 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11917 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11918}
11919
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011920TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11921 TEST_DESCRIPTION("Delete in-use imageView.");
11922
11923 ASSERT_NO_FATAL_FAILURE(InitState());
11924 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11925
11926 VkDescriptorPoolSize ds_type_count;
11927 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11928 ds_type_count.descriptorCount = 1;
11929
11930 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11931 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11932 ds_pool_ci.maxSets = 1;
11933 ds_pool_ci.poolSizeCount = 1;
11934 ds_pool_ci.pPoolSizes = &ds_type_count;
11935
11936 VkDescriptorPool ds_pool;
11937 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11938 ASSERT_VK_SUCCESS(err);
11939
11940 VkSamplerCreateInfo sampler_ci = {};
11941 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11942 sampler_ci.pNext = NULL;
11943 sampler_ci.magFilter = VK_FILTER_NEAREST;
11944 sampler_ci.minFilter = VK_FILTER_NEAREST;
11945 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11946 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11947 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11948 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11949 sampler_ci.mipLodBias = 1.0;
11950 sampler_ci.anisotropyEnable = VK_FALSE;
11951 sampler_ci.maxAnisotropy = 1;
11952 sampler_ci.compareEnable = VK_FALSE;
11953 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11954 sampler_ci.minLod = 1.0;
11955 sampler_ci.maxLod = 1.0;
11956 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11957 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11958 VkSampler sampler;
11959
11960 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11961 ASSERT_VK_SUCCESS(err);
11962
11963 VkDescriptorSetLayoutBinding layout_binding;
11964 layout_binding.binding = 0;
11965 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11966 layout_binding.descriptorCount = 1;
11967 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11968 layout_binding.pImmutableSamplers = NULL;
11969
11970 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11971 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11972 ds_layout_ci.bindingCount = 1;
11973 ds_layout_ci.pBindings = &layout_binding;
11974 VkDescriptorSetLayout ds_layout;
11975 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11976 ASSERT_VK_SUCCESS(err);
11977
11978 VkDescriptorSetAllocateInfo alloc_info = {};
11979 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11980 alloc_info.descriptorSetCount = 1;
11981 alloc_info.descriptorPool = ds_pool;
11982 alloc_info.pSetLayouts = &ds_layout;
11983 VkDescriptorSet descriptor_set;
11984 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11985 ASSERT_VK_SUCCESS(err);
11986
11987 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11988 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11989 pipeline_layout_ci.pNext = NULL;
11990 pipeline_layout_ci.setLayoutCount = 1;
11991 pipeline_layout_ci.pSetLayouts = &ds_layout;
11992
11993 VkPipelineLayout pipeline_layout;
11994 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11995 ASSERT_VK_SUCCESS(err);
11996
11997 VkImageObj image(m_device);
11998 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11999 ASSERT_TRUE(image.initialized());
12000
12001 VkImageView view;
12002 VkImageViewCreateInfo ivci = {};
12003 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12004 ivci.image = image.handle();
12005 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12006 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12007 ivci.subresourceRange.layerCount = 1;
12008 ivci.subresourceRange.baseMipLevel = 0;
12009 ivci.subresourceRange.levelCount = 1;
12010 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12011
12012 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12013 ASSERT_VK_SUCCESS(err);
12014
12015 VkDescriptorImageInfo image_info{};
12016 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12017 image_info.imageView = view;
12018 image_info.sampler = sampler;
12019
12020 VkWriteDescriptorSet descriptor_write = {};
12021 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12022 descriptor_write.dstSet = descriptor_set;
12023 descriptor_write.dstBinding = 0;
12024 descriptor_write.descriptorCount = 1;
12025 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12026 descriptor_write.pImageInfo = &image_info;
12027
12028 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12029
12030 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012031 char const *vsSource =
12032 "#version 450\n"
12033 "\n"
12034 "out gl_PerVertex { \n"
12035 " vec4 gl_Position;\n"
12036 "};\n"
12037 "void main(){\n"
12038 " gl_Position = vec4(1);\n"
12039 "}\n";
12040 char const *fsSource =
12041 "#version 450\n"
12042 "\n"
12043 "layout(set=0, binding=0) uniform sampler2D s;\n"
12044 "layout(location=0) out vec4 x;\n"
12045 "void main(){\n"
12046 " x = texture(s, vec2(1));\n"
12047 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012048 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12049 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12050 VkPipelineObj pipe(m_device);
12051 pipe.AddShader(&vs);
12052 pipe.AddShader(&fs);
12053 pipe.AddColorAttachment();
12054 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12055
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012057
Tony Barbour552f6c02016-12-21 14:34:07 -070012058 m_commandBuffer->BeginCommandBuffer();
12059 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012060 // Bind pipeline to cmd buffer
12061 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12062 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12063 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012064
12065 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12066 VkRect2D scissor = {{0, 0}, {16, 16}};
12067 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12068 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12069
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012070 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012071 m_commandBuffer->EndRenderPass();
12072 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012073 // Submit cmd buffer then destroy sampler
12074 VkSubmitInfo submit_info = {};
12075 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12076 submit_info.commandBufferCount = 1;
12077 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12078 // Submit cmd buffer and then destroy imageView while in-flight
12079 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12080
12081 vkDestroyImageView(m_device->device(), view, nullptr);
12082 m_errorMonitor->VerifyFound();
12083 vkQueueWaitIdle(m_device->m_queue);
12084 // Now we can actually destroy imageView
12085 vkDestroyImageView(m_device->device(), view, NULL);
12086 vkDestroySampler(m_device->device(), sampler, nullptr);
12087 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12088 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12089 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12090}
12091
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012092TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12093 TEST_DESCRIPTION("Delete in-use bufferView.");
12094
12095 ASSERT_NO_FATAL_FAILURE(InitState());
12096 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12097
12098 VkDescriptorPoolSize ds_type_count;
12099 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12100 ds_type_count.descriptorCount = 1;
12101
12102 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12103 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12104 ds_pool_ci.maxSets = 1;
12105 ds_pool_ci.poolSizeCount = 1;
12106 ds_pool_ci.pPoolSizes = &ds_type_count;
12107
12108 VkDescriptorPool ds_pool;
12109 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12110 ASSERT_VK_SUCCESS(err);
12111
12112 VkDescriptorSetLayoutBinding layout_binding;
12113 layout_binding.binding = 0;
12114 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12115 layout_binding.descriptorCount = 1;
12116 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12117 layout_binding.pImmutableSamplers = NULL;
12118
12119 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12120 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12121 ds_layout_ci.bindingCount = 1;
12122 ds_layout_ci.pBindings = &layout_binding;
12123 VkDescriptorSetLayout ds_layout;
12124 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12125 ASSERT_VK_SUCCESS(err);
12126
12127 VkDescriptorSetAllocateInfo alloc_info = {};
12128 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12129 alloc_info.descriptorSetCount = 1;
12130 alloc_info.descriptorPool = ds_pool;
12131 alloc_info.pSetLayouts = &ds_layout;
12132 VkDescriptorSet descriptor_set;
12133 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12134 ASSERT_VK_SUCCESS(err);
12135
12136 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12137 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12138 pipeline_layout_ci.pNext = NULL;
12139 pipeline_layout_ci.setLayoutCount = 1;
12140 pipeline_layout_ci.pSetLayouts = &ds_layout;
12141
12142 VkPipelineLayout pipeline_layout;
12143 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12144 ASSERT_VK_SUCCESS(err);
12145
12146 VkBuffer buffer;
12147 uint32_t queue_family_index = 0;
12148 VkBufferCreateInfo buffer_create_info = {};
12149 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12150 buffer_create_info.size = 1024;
12151 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12152 buffer_create_info.queueFamilyIndexCount = 1;
12153 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12154
12155 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12156 ASSERT_VK_SUCCESS(err);
12157
12158 VkMemoryRequirements memory_reqs;
12159 VkDeviceMemory buffer_memory;
12160
12161 VkMemoryAllocateInfo memory_info = {};
12162 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12163 memory_info.allocationSize = 0;
12164 memory_info.memoryTypeIndex = 0;
12165
12166 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12167 memory_info.allocationSize = memory_reqs.size;
12168 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12169 ASSERT_TRUE(pass);
12170
12171 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12172 ASSERT_VK_SUCCESS(err);
12173 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12174 ASSERT_VK_SUCCESS(err);
12175
12176 VkBufferView view;
12177 VkBufferViewCreateInfo bvci = {};
12178 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12179 bvci.buffer = buffer;
12180 bvci.format = VK_FORMAT_R8_UNORM;
12181 bvci.range = VK_WHOLE_SIZE;
12182
12183 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12184 ASSERT_VK_SUCCESS(err);
12185
12186 VkWriteDescriptorSet descriptor_write = {};
12187 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12188 descriptor_write.dstSet = descriptor_set;
12189 descriptor_write.dstBinding = 0;
12190 descriptor_write.descriptorCount = 1;
12191 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12192 descriptor_write.pTexelBufferView = &view;
12193
12194 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12195
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012196 char const *vsSource =
12197 "#version 450\n"
12198 "\n"
12199 "out gl_PerVertex { \n"
12200 " vec4 gl_Position;\n"
12201 "};\n"
12202 "void main(){\n"
12203 " gl_Position = vec4(1);\n"
12204 "}\n";
12205 char const *fsSource =
12206 "#version 450\n"
12207 "\n"
12208 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12209 "layout(location=0) out vec4 x;\n"
12210 "void main(){\n"
12211 " x = imageLoad(s, 0);\n"
12212 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012213 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12214 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12215 VkPipelineObj pipe(m_device);
12216 pipe.AddShader(&vs);
12217 pipe.AddShader(&fs);
12218 pipe.AddColorAttachment();
12219 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12220
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012222
Tony Barbour552f6c02016-12-21 14:34:07 -070012223 m_commandBuffer->BeginCommandBuffer();
12224 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012225 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12226 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12227 VkRect2D scissor = {{0, 0}, {16, 16}};
12228 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12229 // Bind pipeline to cmd buffer
12230 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12231 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12232 &descriptor_set, 0, nullptr);
12233 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012234 m_commandBuffer->EndRenderPass();
12235 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012236
12237 VkSubmitInfo submit_info = {};
12238 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12239 submit_info.commandBufferCount = 1;
12240 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12241 // Submit cmd buffer and then destroy bufferView while in-flight
12242 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12243
12244 vkDestroyBufferView(m_device->device(), view, nullptr);
12245 m_errorMonitor->VerifyFound();
12246 vkQueueWaitIdle(m_device->m_queue);
12247 // Now we can actually destroy bufferView
12248 vkDestroyBufferView(m_device->device(), view, NULL);
12249 vkDestroyBuffer(m_device->device(), buffer, NULL);
12250 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12251 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12252 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12253 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12254}
12255
Tobin Ehlis209532e2016-09-07 13:52:18 -060012256TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12257 TEST_DESCRIPTION("Delete in-use sampler.");
12258
12259 ASSERT_NO_FATAL_FAILURE(InitState());
12260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12261
12262 VkDescriptorPoolSize ds_type_count;
12263 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12264 ds_type_count.descriptorCount = 1;
12265
12266 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12267 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12268 ds_pool_ci.maxSets = 1;
12269 ds_pool_ci.poolSizeCount = 1;
12270 ds_pool_ci.pPoolSizes = &ds_type_count;
12271
12272 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012273 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012274 ASSERT_VK_SUCCESS(err);
12275
12276 VkSamplerCreateInfo sampler_ci = {};
12277 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12278 sampler_ci.pNext = NULL;
12279 sampler_ci.magFilter = VK_FILTER_NEAREST;
12280 sampler_ci.minFilter = VK_FILTER_NEAREST;
12281 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12282 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12283 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12284 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12285 sampler_ci.mipLodBias = 1.0;
12286 sampler_ci.anisotropyEnable = VK_FALSE;
12287 sampler_ci.maxAnisotropy = 1;
12288 sampler_ci.compareEnable = VK_FALSE;
12289 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12290 sampler_ci.minLod = 1.0;
12291 sampler_ci.maxLod = 1.0;
12292 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12293 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12294 VkSampler sampler;
12295
12296 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12297 ASSERT_VK_SUCCESS(err);
12298
12299 VkDescriptorSetLayoutBinding layout_binding;
12300 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012301 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012302 layout_binding.descriptorCount = 1;
12303 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12304 layout_binding.pImmutableSamplers = NULL;
12305
12306 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12307 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12308 ds_layout_ci.bindingCount = 1;
12309 ds_layout_ci.pBindings = &layout_binding;
12310 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012311 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012312 ASSERT_VK_SUCCESS(err);
12313
12314 VkDescriptorSetAllocateInfo alloc_info = {};
12315 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12316 alloc_info.descriptorSetCount = 1;
12317 alloc_info.descriptorPool = ds_pool;
12318 alloc_info.pSetLayouts = &ds_layout;
12319 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012320 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012321 ASSERT_VK_SUCCESS(err);
12322
12323 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12324 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12325 pipeline_layout_ci.pNext = NULL;
12326 pipeline_layout_ci.setLayoutCount = 1;
12327 pipeline_layout_ci.pSetLayouts = &ds_layout;
12328
12329 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012330 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012331 ASSERT_VK_SUCCESS(err);
12332
12333 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012334 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 -060012335 ASSERT_TRUE(image.initialized());
12336
12337 VkImageView view;
12338 VkImageViewCreateInfo ivci = {};
12339 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12340 ivci.image = image.handle();
12341 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12342 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12343 ivci.subresourceRange.layerCount = 1;
12344 ivci.subresourceRange.baseMipLevel = 0;
12345 ivci.subresourceRange.levelCount = 1;
12346 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12347
12348 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12349 ASSERT_VK_SUCCESS(err);
12350
12351 VkDescriptorImageInfo image_info{};
12352 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12353 image_info.imageView = view;
12354 image_info.sampler = sampler;
12355
12356 VkWriteDescriptorSet descriptor_write = {};
12357 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12358 descriptor_write.dstSet = descriptor_set;
12359 descriptor_write.dstBinding = 0;
12360 descriptor_write.descriptorCount = 1;
12361 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12362 descriptor_write.pImageInfo = &image_info;
12363
12364 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12365
12366 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012367 char const *vsSource =
12368 "#version 450\n"
12369 "\n"
12370 "out gl_PerVertex { \n"
12371 " vec4 gl_Position;\n"
12372 "};\n"
12373 "void main(){\n"
12374 " gl_Position = vec4(1);\n"
12375 "}\n";
12376 char const *fsSource =
12377 "#version 450\n"
12378 "\n"
12379 "layout(set=0, binding=0) uniform sampler2D s;\n"
12380 "layout(location=0) out vec4 x;\n"
12381 "void main(){\n"
12382 " x = texture(s, vec2(1));\n"
12383 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012384 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12385 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12386 VkPipelineObj pipe(m_device);
12387 pipe.AddShader(&vs);
12388 pipe.AddShader(&fs);
12389 pipe.AddColorAttachment();
12390 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12391
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012393
Tony Barbour552f6c02016-12-21 14:34:07 -070012394 m_commandBuffer->BeginCommandBuffer();
12395 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012396 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012397 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12398 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12399 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012400
12401 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12402 VkRect2D scissor = {{0, 0}, {16, 16}};
12403 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12404 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12405
Tobin Ehlis209532e2016-09-07 13:52:18 -060012406 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012407 m_commandBuffer->EndRenderPass();
12408 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012409 // Submit cmd buffer then destroy sampler
12410 VkSubmitInfo submit_info = {};
12411 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12412 submit_info.commandBufferCount = 1;
12413 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12414 // Submit cmd buffer and then destroy sampler while in-flight
12415 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12416
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012417 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012418 m_errorMonitor->VerifyFound();
12419 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012420
Tobin Ehlis209532e2016-09-07 13:52:18 -060012421 // Now we can actually destroy sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012422 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012423 vkDestroyImageView(m_device->device(), view, NULL);
12424 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12425 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12426 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12427}
12428
Mark Mueller1cd9f412016-08-25 13:23:52 -060012429TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012430 TEST_DESCRIPTION(
12431 "Call VkQueueSubmit with a semaphore that is already "
12432 "signaled but not waited on by the queue. Wait on a "
12433 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012434
12435 ASSERT_NO_FATAL_FAILURE(InitState());
12436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012438 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 -070012439 const char *invalid_fence_wait_message =
12440 " which has not been submitted on a Queue or during "
12441 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012442
Tony Barbour552f6c02016-12-21 14:34:07 -070012443 m_commandBuffer->BeginCommandBuffer();
12444 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012445
12446 VkSemaphoreCreateInfo semaphore_create_info = {};
12447 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12448 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012449 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012450 VkSubmitInfo submit_info = {};
12451 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12452 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012453 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012454 submit_info.signalSemaphoreCount = 1;
12455 submit_info.pSignalSemaphores = &semaphore;
12456 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012457 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012458 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012459 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012460 m_commandBuffer->BeginCommandBuffer();
12461 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012463 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12464 m_errorMonitor->VerifyFound();
12465
Mark Mueller1cd9f412016-08-25 13:23:52 -060012466 VkFenceCreateInfo fence_create_info = {};
12467 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12468 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012469 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012470
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012472 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12473 m_errorMonitor->VerifyFound();
12474
Mark Mueller4042b652016-09-05 22:52:21 -060012475 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012476 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012477 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12478}
12479
Tobin Ehlis4af23302016-07-19 10:50:30 -060012480TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012481 TEST_DESCRIPTION(
12482 "Bind a secondary command buffer with with a framebuffer "
12483 "that does not match the framebuffer for the active "
12484 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012485 ASSERT_NO_FATAL_FAILURE(InitState());
12486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12487
12488 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012489 VkAttachmentDescription attachment = {0,
12490 VK_FORMAT_B8G8R8A8_UNORM,
12491 VK_SAMPLE_COUNT_1_BIT,
12492 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12493 VK_ATTACHMENT_STORE_OP_STORE,
12494 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12495 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12496 VK_IMAGE_LAYOUT_UNDEFINED,
12497 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012498
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012499 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012500
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012501 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012502
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012503 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012504
12505 VkRenderPass rp;
12506 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12507 ASSERT_VK_SUCCESS(err);
12508
12509 // A compatible framebuffer.
12510 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012511 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 -060012512 ASSERT_TRUE(image.initialized());
12513
12514 VkImageViewCreateInfo ivci = {
12515 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12516 nullptr,
12517 0,
12518 image.handle(),
12519 VK_IMAGE_VIEW_TYPE_2D,
12520 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012521 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12522 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012523 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12524 };
12525 VkImageView view;
12526 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12527 ASSERT_VK_SUCCESS(err);
12528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012529 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012530 VkFramebuffer fb;
12531 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12532 ASSERT_VK_SUCCESS(err);
12533
12534 VkCommandBufferAllocateInfo cbai = {};
12535 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12536 cbai.commandPool = m_commandPool;
12537 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12538 cbai.commandBufferCount = 1;
12539
12540 VkCommandBuffer sec_cb;
12541 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12542 ASSERT_VK_SUCCESS(err);
12543 VkCommandBufferBeginInfo cbbi = {};
12544 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130012545 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060012546 cbii.renderPass = renderPass();
12547 cbii.framebuffer = fb;
12548 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12549 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012550 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 -060012551 cbbi.pInheritanceInfo = &cbii;
12552 vkBeginCommandBuffer(sec_cb, &cbbi);
12553 vkEndCommandBuffer(sec_cb);
12554
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012555 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120012556 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12557 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012558
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012560 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012561 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12562 m_errorMonitor->VerifyFound();
12563 // Cleanup
12564 vkDestroyImageView(m_device->device(), view, NULL);
12565 vkDestroyRenderPass(m_device->device(), rp, NULL);
12566 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12567}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012568
12569TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012570 TEST_DESCRIPTION(
12571 "If logicOp is available on the device, set it to an "
12572 "invalid value. If logicOp is not available, attempt to "
12573 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012574 ASSERT_NO_FATAL_FAILURE(InitState());
12575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12576
12577 auto features = m_device->phy().features();
12578 // Set the expected error depending on whether or not logicOp available
12579 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12581 "If logic operations feature not "
12582 "enabled, logicOpEnable must be "
12583 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012584 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012586 }
12587 // Create a pipeline using logicOp
12588 VkResult err;
12589
12590 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12591 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12592
12593 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012594 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012595 ASSERT_VK_SUCCESS(err);
12596
12597 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12598 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12599 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012600 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012601 vp_state_ci.pViewports = &vp;
12602 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012603 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012604 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012605
12606 VkPipelineShaderStageCreateInfo shaderStages[2];
12607 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012609 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12610 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012611 shaderStages[0] = vs.GetStageCreateInfo();
12612 shaderStages[1] = fs.GetStageCreateInfo();
12613
12614 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12615 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12616
12617 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12618 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12619 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12620
12621 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12622 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012623 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012624
12625 VkPipelineColorBlendAttachmentState att = {};
12626 att.blendEnable = VK_FALSE;
12627 att.colorWriteMask = 0xf;
12628
12629 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12630 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12631 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12632 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012633 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012634 cb_ci.attachmentCount = 1;
12635 cb_ci.pAttachments = &att;
12636
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012637 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12638 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12639 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12640
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012641 VkGraphicsPipelineCreateInfo gp_ci = {};
12642 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12643 gp_ci.stageCount = 2;
12644 gp_ci.pStages = shaderStages;
12645 gp_ci.pVertexInputState = &vi_ci;
12646 gp_ci.pInputAssemblyState = &ia_ci;
12647 gp_ci.pViewportState = &vp_state_ci;
12648 gp_ci.pRasterizationState = &rs_ci;
12649 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012650 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012651 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12652 gp_ci.layout = pipeline_layout;
12653 gp_ci.renderPass = renderPass();
12654
12655 VkPipelineCacheCreateInfo pc_ci = {};
12656 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12657
12658 VkPipeline pipeline;
12659 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012660 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012661 ASSERT_VK_SUCCESS(err);
12662
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012663 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012664 m_errorMonitor->VerifyFound();
12665 if (VK_SUCCESS == err) {
12666 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12667 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012668 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12669 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12670}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012671#endif // DRAW_STATE_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012672
Tobin Ehlis0788f522015-05-26 16:11:58 -060012673#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012674#if GTEST_IS_THREADSAFE
12675struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012676 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012677 VkEvent event;
12678 bool bailout;
12679};
12680
Karl Schultz6addd812016-02-02 17:17:23 -070012681extern "C" void *AddToCommandBuffer(void *arg) {
12682 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012683
Mike Stroyana6d14942016-07-13 15:10:05 -060012684 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012685 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012686 if (data->bailout) {
12687 break;
12688 }
12689 }
12690 return NULL;
12691}
12692
Karl Schultz6addd812016-02-02 17:17:23 -070012693TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012694 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012695
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012697
Mike Stroyanaccf7692015-05-12 16:00:45 -060012698 ASSERT_NO_FATAL_FAILURE(InitState());
12699 ASSERT_NO_FATAL_FAILURE(InitViewport());
12700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12701
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012702 // Calls AllocateCommandBuffers
12703 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012704
12705 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012706 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012707
12708 VkEventCreateInfo event_info;
12709 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012710 VkResult err;
12711
12712 memset(&event_info, 0, sizeof(event_info));
12713 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12714
Chia-I Wuf7458c52015-10-26 21:10:41 +080012715 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012716 ASSERT_VK_SUCCESS(err);
12717
Mike Stroyanaccf7692015-05-12 16:00:45 -060012718 err = vkResetEvent(device(), event);
12719 ASSERT_VK_SUCCESS(err);
12720
12721 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012722 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012723 data.event = event;
12724 data.bailout = false;
12725 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012726
12727 // First do some correct operations using multiple threads.
12728 // Add many entries to command buffer from another thread.
12729 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12730 // Make non-conflicting calls from this thread at the same time.
12731 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012732 uint32_t count;
12733 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012734 }
12735 test_platform_thread_join(thread, NULL);
12736
12737 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012738 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012739 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012740 // Add many entries to command buffer from this thread at the same time.
12741 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012742
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012743 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012744 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012745
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012746 m_errorMonitor->SetBailout(NULL);
12747
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012748 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012749
Chia-I Wuf7458c52015-10-26 21:10:41 +080012750 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012751}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012752#endif // GTEST_IS_THREADSAFE
12753#endif // THREADING_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012754
Chris Forbes9f7ff632015-05-25 11:13:08 +120012755#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012756TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012757 TEST_DESCRIPTION(
12758 "Test that an error is produced for a spirv module "
12759 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120012760
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012762
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012763 ASSERT_NO_FATAL_FAILURE(InitState());
12764 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12765
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012766 VkShaderModule module;
12767 VkShaderModuleCreateInfo moduleCreateInfo;
12768 struct icd_spv_header spv;
12769
12770 spv.magic = ICD_SPV_MAGIC;
12771 spv.version = ICD_SPV_VERSION;
12772 spv.gen_magic = 0;
12773
12774 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12775 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012776 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012777 moduleCreateInfo.codeSize = 4;
12778 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012779 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012780
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012781 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012782}
12783
Karl Schultz6addd812016-02-02 17:17:23 -070012784TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012785 TEST_DESCRIPTION(
12786 "Test that an error is produced for a spirv module "
12787 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120012788
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012790
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012791 ASSERT_NO_FATAL_FAILURE(InitState());
12792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12793
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012794 VkShaderModule module;
12795 VkShaderModuleCreateInfo moduleCreateInfo;
12796 struct icd_spv_header spv;
12797
12798 spv.magic = ~ICD_SPV_MAGIC;
12799 spv.version = ICD_SPV_VERSION;
12800 spv.gen_magic = 0;
12801
12802 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12803 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012804 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012805 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12806 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012807 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012808
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012809 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012810}
12811
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012812#if 0
12813// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012814TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012816 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012817
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012818 ASSERT_NO_FATAL_FAILURE(InitState());
12819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12820
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012821 VkShaderModule module;
12822 VkShaderModuleCreateInfo moduleCreateInfo;
12823 struct icd_spv_header spv;
12824
12825 spv.magic = ICD_SPV_MAGIC;
12826 spv.version = ~ICD_SPV_VERSION;
12827 spv.gen_magic = 0;
12828
12829 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12830 moduleCreateInfo.pNext = NULL;
12831
Karl Schultz6addd812016-02-02 17:17:23 -070012832 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012833 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12834 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012835 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012836
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012837 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012838}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012839#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012840
Karl Schultz6addd812016-02-02 17:17:23 -070012841TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012842 TEST_DESCRIPTION(
12843 "Test that a warning is produced for a vertex output that "
12844 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012846
Chris Forbes9f7ff632015-05-25 11:13:08 +120012847 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012848 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012849
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012850 char const *vsSource =
12851 "#version 450\n"
12852 "\n"
12853 "layout(location=0) out float x;\n"
12854 "out gl_PerVertex {\n"
12855 " vec4 gl_Position;\n"
12856 "};\n"
12857 "void main(){\n"
12858 " gl_Position = vec4(1);\n"
12859 " x = 0;\n"
12860 "}\n";
12861 char const *fsSource =
12862 "#version 450\n"
12863 "\n"
12864 "layout(location=0) out vec4 color;\n"
12865 "void main(){\n"
12866 " color = vec4(1);\n"
12867 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012868
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012869 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12870 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012871
12872 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012873 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012874 pipe.AddShader(&vs);
12875 pipe.AddShader(&fs);
12876
Chris Forbes9f7ff632015-05-25 11:13:08 +120012877 VkDescriptorSetObj descriptorSet(m_device);
12878 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012879 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012880
Tony Barbour5781e8f2015-08-04 16:23:11 -060012881 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012882
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012883 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012884}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012885
Mark Mueller098c9cb2016-09-08 09:01:57 -060012886TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12887 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12888
12889 ASSERT_NO_FATAL_FAILURE(InitState());
12890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12891
12892 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012893 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012894
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012895 char const *vsSource =
12896 "#version 450\n"
12897 "\n"
12898 "out gl_PerVertex {\n"
12899 " vec4 gl_Position;\n"
12900 "};\n"
12901 "void main(){\n"
12902 " gl_Position = vec4(1);\n"
12903 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012904
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012905 char const *fsSource =
12906 "#version 450\n"
12907 "\n"
12908 "layout (constant_id = 0) const float r = 0.0f;\n"
12909 "layout(location = 0) out vec4 uFragColor;\n"
12910 "void main(){\n"
12911 " uFragColor = vec4(r,1,0,1);\n"
12912 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012913
12914 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12915 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12916
12917 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12918 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12919
12920 VkPipelineLayout pipeline_layout;
12921 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12922
12923 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12924 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12925 vp_state_create_info.viewportCount = 1;
12926 VkViewport viewport = {};
12927 vp_state_create_info.pViewports = &viewport;
12928 vp_state_create_info.scissorCount = 1;
12929 VkRect2D scissors = {};
12930 vp_state_create_info.pScissors = &scissors;
12931
12932 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12933
12934 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12935 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12936 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12937 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12938
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012939 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060012940
12941 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12942 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12943
12944 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12945 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12946 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12947
12948 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12949 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12950 rasterization_state_create_info.pNext = nullptr;
12951 rasterization_state_create_info.lineWidth = 1.0f;
12952 rasterization_state_create_info.rasterizerDiscardEnable = true;
12953
12954 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12955 color_blend_attachment_state.blendEnable = VK_FALSE;
12956 color_blend_attachment_state.colorWriteMask = 0xf;
12957
12958 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12959 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12960 color_blend_state_create_info.attachmentCount = 1;
12961 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12962
12963 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12964 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12965 graphicspipe_create_info.stageCount = 2;
12966 graphicspipe_create_info.pStages = shader_stage_create_info;
12967 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12968 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12969 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12970 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12971 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12972 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12973 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12974 graphicspipe_create_info.layout = pipeline_layout;
12975 graphicspipe_create_info.renderPass = renderPass();
12976
12977 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12978 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12979
12980 VkPipelineCache pipelineCache;
12981 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12982
12983 // This structure maps constant ids to data locations.
12984 const VkSpecializationMapEntry entry =
12985 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012986 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060012987
12988 uint32_t data = 1;
12989
12990 // Set up the info describing spec map and data
12991 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012992 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060012993 };
12994 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12995
12996 VkPipeline pipeline;
12997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12998 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12999 m_errorMonitor->VerifyFound();
13000
13001 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13002 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13003}
13004
13005TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13006 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13007
13008 ASSERT_NO_FATAL_FAILURE(InitState());
13009 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13010
13011 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13012
13013 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13014 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13015 descriptor_pool_type_count[0].descriptorCount = 1;
13016 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13017 descriptor_pool_type_count[1].descriptorCount = 1;
13018
13019 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13020 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13021 descriptor_pool_create_info.maxSets = 1;
13022 descriptor_pool_create_info.poolSizeCount = 2;
13023 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13024 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13025
13026 VkDescriptorPool descriptorset_pool;
13027 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13028
13029 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13030 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13031 descriptorset_layout_binding.descriptorCount = 1;
13032 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13033
13034 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13035 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13036 descriptorset_layout_create_info.bindingCount = 1;
13037 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13038
13039 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013040 ASSERT_VK_SUCCESS(
13041 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013042
13043 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13044 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13045 descriptorset_allocate_info.descriptorSetCount = 1;
13046 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13047 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13048 VkDescriptorSet descriptorset;
13049 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13050
13051 // Challenge core_validation with a non uniform buffer type.
13052 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13053
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013054 char const *vsSource =
13055 "#version 450\n"
13056 "\n"
13057 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13058 " mat4 mvp;\n"
13059 "} ubuf;\n"
13060 "out gl_PerVertex {\n"
13061 " vec4 gl_Position;\n"
13062 "};\n"
13063 "void main(){\n"
13064 " gl_Position = ubuf.mvp * vec4(1);\n"
13065 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013066
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013067 char const *fsSource =
13068 "#version 450\n"
13069 "\n"
13070 "layout(location = 0) out vec4 uFragColor;\n"
13071 "void main(){\n"
13072 " uFragColor = vec4(0,1,0,1);\n"
13073 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013074
13075 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13076 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13077
13078 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13079 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13080 pipeline_layout_create_info.setLayoutCount = 1;
13081 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13082
13083 VkPipelineLayout pipeline_layout;
13084 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13085
13086 VkPipelineObj pipe(m_device);
13087 pipe.AddColorAttachment();
13088 pipe.AddShader(&vs);
13089 pipe.AddShader(&fs);
13090
13091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13092 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13093 m_errorMonitor->VerifyFound();
13094
13095 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13096 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13097 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13098}
13099
13100TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13101 TEST_DESCRIPTION(
13102 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13103
13104 ASSERT_NO_FATAL_FAILURE(InitState());
13105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13106
13107 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13108
13109 VkDescriptorPoolSize descriptor_pool_type_count = {};
13110 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13111 descriptor_pool_type_count.descriptorCount = 1;
13112
13113 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13114 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13115 descriptor_pool_create_info.maxSets = 1;
13116 descriptor_pool_create_info.poolSizeCount = 1;
13117 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13118 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13119
13120 VkDescriptorPool descriptorset_pool;
13121 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13122
13123 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13124 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13125 descriptorset_layout_binding.descriptorCount = 1;
13126 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13127 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13128
13129 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13130 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13131 descriptorset_layout_create_info.bindingCount = 1;
13132 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13133
13134 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013135 ASSERT_VK_SUCCESS(
13136 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013137
13138 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13139 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13140 descriptorset_allocate_info.descriptorSetCount = 1;
13141 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13142 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13143 VkDescriptorSet descriptorset;
13144 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13145
13146 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13147
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013148 char const *vsSource =
13149 "#version 450\n"
13150 "\n"
13151 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13152 " mat4 mvp;\n"
13153 "} ubuf;\n"
13154 "out gl_PerVertex {\n"
13155 " vec4 gl_Position;\n"
13156 "};\n"
13157 "void main(){\n"
13158 " gl_Position = ubuf.mvp * vec4(1);\n"
13159 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013160
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013161 char const *fsSource =
13162 "#version 450\n"
13163 "\n"
13164 "layout(location = 0) out vec4 uFragColor;\n"
13165 "void main(){\n"
13166 " uFragColor = vec4(0,1,0,1);\n"
13167 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013168
13169 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13170 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13171
13172 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13173 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13174 pipeline_layout_create_info.setLayoutCount = 1;
13175 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13176
13177 VkPipelineLayout pipeline_layout;
13178 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13179
13180 VkPipelineObj pipe(m_device);
13181 pipe.AddColorAttachment();
13182 pipe.AddShader(&vs);
13183 pipe.AddShader(&fs);
13184
13185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13186 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13187 m_errorMonitor->VerifyFound();
13188
13189 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13190 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13191 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13192}
13193
13194TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013195 TEST_DESCRIPTION(
13196 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13197 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013198
13199 ASSERT_NO_FATAL_FAILURE(InitState());
13200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13201
13202 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013203 "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 -060013204
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013205 char const *vsSource =
13206 "#version 450\n"
13207 "\n"
13208 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13209 "out gl_PerVertex {\n"
13210 " vec4 gl_Position;\n"
13211 "};\n"
13212 "void main(){\n"
13213 " gl_Position = vec4(consts.x);\n"
13214 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013215
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013216 char const *fsSource =
13217 "#version 450\n"
13218 "\n"
13219 "layout(location = 0) out vec4 uFragColor;\n"
13220 "void main(){\n"
13221 " uFragColor = vec4(0,1,0,1);\n"
13222 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013223
13224 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13225 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13226
13227 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13228 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13229
13230 // Set up a push constant range
13231 VkPushConstantRange push_constant_ranges = {};
13232 // Set to the wrong stage to challenge core_validation
13233 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13234 push_constant_ranges.size = 4;
13235
13236 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13237 pipeline_layout_create_info.pushConstantRangeCount = 1;
13238
13239 VkPipelineLayout pipeline_layout;
13240 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13241
13242 VkPipelineObj pipe(m_device);
13243 pipe.AddColorAttachment();
13244 pipe.AddShader(&vs);
13245 pipe.AddShader(&fs);
13246
13247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13248 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13249 m_errorMonitor->VerifyFound();
13250
13251 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13252}
13253
13254TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13255 TEST_DESCRIPTION(
13256 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13257
13258 ASSERT_NO_FATAL_FAILURE(InitState());
13259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13260
13261 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013262 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013263
13264 // Some awkward steps are required to test with custom device features.
13265 std::vector<const char *> device_extension_names;
13266 auto features = m_device->phy().features();
13267 // Disable support for 64 bit floats
13268 features.shaderFloat64 = false;
13269 // The sacrificial device object
13270 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13271
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013272 char const *vsSource =
13273 "#version 450\n"
13274 "\n"
13275 "out gl_PerVertex {\n"
13276 " vec4 gl_Position;\n"
13277 "};\n"
13278 "void main(){\n"
13279 " gl_Position = vec4(1);\n"
13280 "}\n";
13281 char const *fsSource =
13282 "#version 450\n"
13283 "\n"
13284 "layout(location=0) out vec4 color;\n"
13285 "void main(){\n"
13286 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13287 " color = vec4(green);\n"
13288 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013289
13290 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13291 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13292
13293 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013294
13295 VkPipelineObj pipe(&test_device);
13296 pipe.AddColorAttachment();
13297 pipe.AddShader(&vs);
13298 pipe.AddShader(&fs);
13299
13300 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13301 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13302 VkPipelineLayout pipeline_layout;
13303 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13304
13305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13306 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13307 m_errorMonitor->VerifyFound();
13308
13309 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13310}
13311
13312TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13313 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13314
13315 ASSERT_NO_FATAL_FAILURE(InitState());
13316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13317
13318 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13319
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013320 char const *vsSource =
13321 "#version 450\n"
13322 "\n"
13323 "out gl_PerVertex {\n"
13324 " vec4 gl_Position;\n"
13325 "};\n"
13326 "layout(xfb_buffer = 1) out;"
13327 "void main(){\n"
13328 " gl_Position = vec4(1);\n"
13329 "}\n";
13330 char const *fsSource =
13331 "#version 450\n"
13332 "\n"
13333 "layout(location=0) out vec4 color;\n"
13334 "void main(){\n"
13335 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13336 " color = vec4(green);\n"
13337 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013338
13339 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13340 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13341
13342 VkPipelineObj pipe(m_device);
13343 pipe.AddColorAttachment();
13344 pipe.AddShader(&vs);
13345 pipe.AddShader(&fs);
13346
13347 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13348 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13349 VkPipelineLayout pipeline_layout;
13350 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13351
13352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13353 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13354 m_errorMonitor->VerifyFound();
13355
13356 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13357}
13358
Karl Schultz6addd812016-02-02 17:17:23 -070013359TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013360 TEST_DESCRIPTION(
13361 "Test that an error is produced for a fragment shader input "
13362 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013365
Chris Forbes59cb88d2015-05-25 11:13:13 +120013366 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013367 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013368
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013369 char const *vsSource =
13370 "#version 450\n"
13371 "\n"
13372 "out gl_PerVertex {\n"
13373 " vec4 gl_Position;\n"
13374 "};\n"
13375 "void main(){\n"
13376 " gl_Position = vec4(1);\n"
13377 "}\n";
13378 char const *fsSource =
13379 "#version 450\n"
13380 "\n"
13381 "layout(location=0) in float x;\n"
13382 "layout(location=0) out vec4 color;\n"
13383 "void main(){\n"
13384 " color = vec4(x);\n"
13385 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013386
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013387 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13388 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013389
13390 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013391 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013392 pipe.AddShader(&vs);
13393 pipe.AddShader(&fs);
13394
Chris Forbes59cb88d2015-05-25 11:13:13 +120013395 VkDescriptorSetObj descriptorSet(m_device);
13396 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013397 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013398
Tony Barbour5781e8f2015-08-04 16:23:11 -060013399 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013400
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013401 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013402}
13403
Karl Schultz6addd812016-02-02 17:17:23 -070013404TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013405 TEST_DESCRIPTION(
13406 "Test that an error is produced for a fragment shader input "
13407 "within an interace block, which is not present in the outputs "
13408 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013410
13411 ASSERT_NO_FATAL_FAILURE(InitState());
13412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13413
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013414 char const *vsSource =
13415 "#version 450\n"
13416 "\n"
13417 "out gl_PerVertex {\n"
13418 " vec4 gl_Position;\n"
13419 "};\n"
13420 "void main(){\n"
13421 " gl_Position = vec4(1);\n"
13422 "}\n";
13423 char const *fsSource =
13424 "#version 450\n"
13425 "\n"
13426 "in block { layout(location=0) float x; } ins;\n"
13427 "layout(location=0) out vec4 color;\n"
13428 "void main(){\n"
13429 " color = vec4(ins.x);\n"
13430 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013431
13432 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13433 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13434
13435 VkPipelineObj pipe(m_device);
13436 pipe.AddColorAttachment();
13437 pipe.AddShader(&vs);
13438 pipe.AddShader(&fs);
13439
13440 VkDescriptorSetObj descriptorSet(m_device);
13441 descriptorSet.AppendDummy();
13442 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13443
13444 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13445
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013446 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013447}
13448
Karl Schultz6addd812016-02-02 17:17:23 -070013449TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013450 TEST_DESCRIPTION(
13451 "Test that an error is produced for mismatched array sizes "
13452 "across the vertex->fragment shader interface");
13453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13454 "Type mismatch on location 0.0: 'ptr to "
13455 "output arr[2] of float32' vs 'ptr to "
13456 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013457
13458 ASSERT_NO_FATAL_FAILURE(InitState());
13459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13460
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013461 char const *vsSource =
13462 "#version 450\n"
13463 "\n"
13464 "layout(location=0) out float x[2];\n"
13465 "out gl_PerVertex {\n"
13466 " vec4 gl_Position;\n"
13467 "};\n"
13468 "void main(){\n"
13469 " x[0] = 0; x[1] = 0;\n"
13470 " gl_Position = vec4(1);\n"
13471 "}\n";
13472 char const *fsSource =
13473 "#version 450\n"
13474 "\n"
13475 "layout(location=0) in float x[1];\n"
13476 "layout(location=0) out vec4 color;\n"
13477 "void main(){\n"
13478 " color = vec4(x[0]);\n"
13479 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013480
13481 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13482 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13483
13484 VkPipelineObj pipe(m_device);
13485 pipe.AddColorAttachment();
13486 pipe.AddShader(&vs);
13487 pipe.AddShader(&fs);
13488
13489 VkDescriptorSetObj descriptorSet(m_device);
13490 descriptorSet.AppendDummy();
13491 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13492
13493 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13494
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013495 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013496}
13497
Karl Schultz6addd812016-02-02 17:17:23 -070013498TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013499 TEST_DESCRIPTION(
13500 "Test that an error is produced for mismatched types across "
13501 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013503
Chris Forbesb56af562015-05-25 11:13:17 +120013504 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013505 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013506
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013507 char const *vsSource =
13508 "#version 450\n"
13509 "\n"
13510 "layout(location=0) out int x;\n"
13511 "out gl_PerVertex {\n"
13512 " vec4 gl_Position;\n"
13513 "};\n"
13514 "void main(){\n"
13515 " x = 0;\n"
13516 " gl_Position = vec4(1);\n"
13517 "}\n";
13518 char const *fsSource =
13519 "#version 450\n"
13520 "\n"
13521 "layout(location=0) in float x;\n" /* VS writes int */
13522 "layout(location=0) out vec4 color;\n"
13523 "void main(){\n"
13524 " color = vec4(x);\n"
13525 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013526
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013527 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13528 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013529
13530 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013531 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013532 pipe.AddShader(&vs);
13533 pipe.AddShader(&fs);
13534
Chris Forbesb56af562015-05-25 11:13:17 +120013535 VkDescriptorSetObj descriptorSet(m_device);
13536 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013537 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013538
Tony Barbour5781e8f2015-08-04 16:23:11 -060013539 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013540
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013541 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013542}
13543
Karl Schultz6addd812016-02-02 17:17:23 -070013544TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013545 TEST_DESCRIPTION(
13546 "Test that an error is produced for mismatched types across "
13547 "the vertex->fragment shader interface, when the variable is contained within "
13548 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013550
13551 ASSERT_NO_FATAL_FAILURE(InitState());
13552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13553
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013554 char const *vsSource =
13555 "#version 450\n"
13556 "\n"
13557 "out block { layout(location=0) int x; } outs;\n"
13558 "out gl_PerVertex {\n"
13559 " vec4 gl_Position;\n"
13560 "};\n"
13561 "void main(){\n"
13562 " outs.x = 0;\n"
13563 " gl_Position = vec4(1);\n"
13564 "}\n";
13565 char const *fsSource =
13566 "#version 450\n"
13567 "\n"
13568 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13569 "layout(location=0) out vec4 color;\n"
13570 "void main(){\n"
13571 " color = vec4(ins.x);\n"
13572 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013573
13574 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13575 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13576
13577 VkPipelineObj pipe(m_device);
13578 pipe.AddColorAttachment();
13579 pipe.AddShader(&vs);
13580 pipe.AddShader(&fs);
13581
13582 VkDescriptorSetObj descriptorSet(m_device);
13583 descriptorSet.AppendDummy();
13584 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13585
13586 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13587
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013588 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013589}
13590
13591TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013592 TEST_DESCRIPTION(
13593 "Test that an error is produced for location mismatches across "
13594 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
13595 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013596 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 +130013597
13598 ASSERT_NO_FATAL_FAILURE(InitState());
13599 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13600
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013601 char const *vsSource =
13602 "#version 450\n"
13603 "\n"
13604 "out block { layout(location=1) float x; } outs;\n"
13605 "out gl_PerVertex {\n"
13606 " vec4 gl_Position;\n"
13607 "};\n"
13608 "void main(){\n"
13609 " outs.x = 0;\n"
13610 " gl_Position = vec4(1);\n"
13611 "}\n";
13612 char const *fsSource =
13613 "#version 450\n"
13614 "\n"
13615 "in block { layout(location=0) float x; } ins;\n"
13616 "layout(location=0) out vec4 color;\n"
13617 "void main(){\n"
13618 " color = vec4(ins.x);\n"
13619 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013620
13621 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13622 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13623
13624 VkPipelineObj pipe(m_device);
13625 pipe.AddColorAttachment();
13626 pipe.AddShader(&vs);
13627 pipe.AddShader(&fs);
13628
13629 VkDescriptorSetObj descriptorSet(m_device);
13630 descriptorSet.AppendDummy();
13631 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13632
13633 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13634
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013635 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013636}
13637
13638TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013639 TEST_DESCRIPTION(
13640 "Test that an error is produced for component mismatches across the "
13641 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
13642 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013643 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 +130013644
13645 ASSERT_NO_FATAL_FAILURE(InitState());
13646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13647
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013648 char const *vsSource =
13649 "#version 450\n"
13650 "\n"
13651 "out block { layout(location=0, component=0) float x; } outs;\n"
13652 "out gl_PerVertex {\n"
13653 " vec4 gl_Position;\n"
13654 "};\n"
13655 "void main(){\n"
13656 " outs.x = 0;\n"
13657 " gl_Position = vec4(1);\n"
13658 "}\n";
13659 char const *fsSource =
13660 "#version 450\n"
13661 "\n"
13662 "in block { layout(location=0, component=1) float x; } ins;\n"
13663 "layout(location=0) out vec4 color;\n"
13664 "void main(){\n"
13665 " color = vec4(ins.x);\n"
13666 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013667
13668 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13669 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13670
13671 VkPipelineObj pipe(m_device);
13672 pipe.AddColorAttachment();
13673 pipe.AddShader(&vs);
13674 pipe.AddShader(&fs);
13675
13676 VkDescriptorSetObj descriptorSet(m_device);
13677 descriptorSet.AppendDummy();
13678 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13679
13680 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13681
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013682 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013683}
13684
Chris Forbes1f3b0152016-11-30 12:48:40 +130013685TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13686 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13687
13688 ASSERT_NO_FATAL_FAILURE(InitState());
13689 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13690
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013691 char const *vsSource =
13692 "#version 450\n"
13693 "layout(location=0) out mediump float x;\n"
13694 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13695 char const *fsSource =
13696 "#version 450\n"
13697 "layout(location=0) in highp float x;\n"
13698 "layout(location=0) out vec4 color;\n"
13699 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130013700
13701 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13702 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13703
13704 VkPipelineObj pipe(m_device);
13705 pipe.AddColorAttachment();
13706 pipe.AddShader(&vs);
13707 pipe.AddShader(&fs);
13708
13709 VkDescriptorSetObj descriptorSet(m_device);
13710 descriptorSet.AppendDummy();
13711 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13712
13713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13714
13715 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13716
13717 m_errorMonitor->VerifyFound();
13718}
13719
Chris Forbes870a39e2016-11-30 12:55:56 +130013720TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13721 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13722
13723 ASSERT_NO_FATAL_FAILURE(InitState());
13724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13725
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013726 char const *vsSource =
13727 "#version 450\n"
13728 "out block { layout(location=0) mediump float x; };\n"
13729 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13730 char const *fsSource =
13731 "#version 450\n"
13732 "in block { layout(location=0) highp float x; };\n"
13733 "layout(location=0) out vec4 color;\n"
13734 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130013735
13736 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13737 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13738
13739 VkPipelineObj pipe(m_device);
13740 pipe.AddColorAttachment();
13741 pipe.AddShader(&vs);
13742 pipe.AddShader(&fs);
13743
13744 VkDescriptorSetObj descriptorSet(m_device);
13745 descriptorSet.AppendDummy();
13746 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13747
13748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13749
13750 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13751
13752 m_errorMonitor->VerifyFound();
13753}
13754
Karl Schultz6addd812016-02-02 17:17:23 -070013755TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013756 TEST_DESCRIPTION(
13757 "Test that a warning is produced for a vertex attribute which is "
13758 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013760
Chris Forbesde136e02015-05-25 11:13:28 +120013761 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013763
13764 VkVertexInputBindingDescription input_binding;
13765 memset(&input_binding, 0, sizeof(input_binding));
13766
13767 VkVertexInputAttributeDescription input_attrib;
13768 memset(&input_attrib, 0, sizeof(input_attrib));
13769 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13770
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013771 char const *vsSource =
13772 "#version 450\n"
13773 "\n"
13774 "out gl_PerVertex {\n"
13775 " vec4 gl_Position;\n"
13776 "};\n"
13777 "void main(){\n"
13778 " gl_Position = vec4(1);\n"
13779 "}\n";
13780 char const *fsSource =
13781 "#version 450\n"
13782 "\n"
13783 "layout(location=0) out vec4 color;\n"
13784 "void main(){\n"
13785 " color = vec4(1);\n"
13786 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013787
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013788 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13789 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013790
13791 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013792 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013793 pipe.AddShader(&vs);
13794 pipe.AddShader(&fs);
13795
13796 pipe.AddVertexInputBindings(&input_binding, 1);
13797 pipe.AddVertexInputAttribs(&input_attrib, 1);
13798
Chris Forbesde136e02015-05-25 11:13:28 +120013799 VkDescriptorSetObj descriptorSet(m_device);
13800 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013801 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013802
Tony Barbour5781e8f2015-08-04 16:23:11 -060013803 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013804
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013805 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013806}
13807
Karl Schultz6addd812016-02-02 17:17:23 -070013808TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013809 TEST_DESCRIPTION(
13810 "Test that a warning is produced for a location mismatch on "
13811 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013813
13814 ASSERT_NO_FATAL_FAILURE(InitState());
13815 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13816
13817 VkVertexInputBindingDescription input_binding;
13818 memset(&input_binding, 0, sizeof(input_binding));
13819
13820 VkVertexInputAttributeDescription input_attrib;
13821 memset(&input_attrib, 0, sizeof(input_attrib));
13822 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13823
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013824 char const *vsSource =
13825 "#version 450\n"
13826 "\n"
13827 "layout(location=1) in float x;\n"
13828 "out gl_PerVertex {\n"
13829 " vec4 gl_Position;\n"
13830 "};\n"
13831 "void main(){\n"
13832 " gl_Position = vec4(x);\n"
13833 "}\n";
13834 char const *fsSource =
13835 "#version 450\n"
13836 "\n"
13837 "layout(location=0) out vec4 color;\n"
13838 "void main(){\n"
13839 " color = vec4(1);\n"
13840 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013841
13842 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13843 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13844
13845 VkPipelineObj pipe(m_device);
13846 pipe.AddColorAttachment();
13847 pipe.AddShader(&vs);
13848 pipe.AddShader(&fs);
13849
13850 pipe.AddVertexInputBindings(&input_binding, 1);
13851 pipe.AddVertexInputAttribs(&input_attrib, 1);
13852
13853 VkDescriptorSetObj descriptorSet(m_device);
13854 descriptorSet.AppendDummy();
13855 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13856
13857 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13858
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013859 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013860}
13861
Karl Schultz6addd812016-02-02 17:17:23 -070013862TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013863 TEST_DESCRIPTION(
13864 "Test that an error is produced for a vertex shader input which is not "
13865 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13867 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013868
Chris Forbes62e8e502015-05-25 11:13:29 +120013869 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013870 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013871
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013872 char const *vsSource =
13873 "#version 450\n"
13874 "\n"
13875 "layout(location=0) in vec4 x;\n" /* not provided */
13876 "out gl_PerVertex {\n"
13877 " vec4 gl_Position;\n"
13878 "};\n"
13879 "void main(){\n"
13880 " gl_Position = x;\n"
13881 "}\n";
13882 char const *fsSource =
13883 "#version 450\n"
13884 "\n"
13885 "layout(location=0) out vec4 color;\n"
13886 "void main(){\n"
13887 " color = vec4(1);\n"
13888 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013889
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013890 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13891 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013892
13893 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013894 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013895 pipe.AddShader(&vs);
13896 pipe.AddShader(&fs);
13897
Chris Forbes62e8e502015-05-25 11:13:29 +120013898 VkDescriptorSetObj descriptorSet(m_device);
13899 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013900 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013901
Tony Barbour5781e8f2015-08-04 16:23:11 -060013902 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013903
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013904 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013905}
13906
Karl Schultz6addd812016-02-02 17:17:23 -070013907TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013908 TEST_DESCRIPTION(
13909 "Test that an error is produced for a mismatch between the "
13910 "fundamental type (float/int/uint) of an attribute and the "
13911 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013912 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 -060013913
Chris Forbesc97d98e2015-05-25 11:13:31 +120013914 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013916
13917 VkVertexInputBindingDescription input_binding;
13918 memset(&input_binding, 0, sizeof(input_binding));
13919
13920 VkVertexInputAttributeDescription input_attrib;
13921 memset(&input_attrib, 0, sizeof(input_attrib));
13922 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13923
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013924 char const *vsSource =
13925 "#version 450\n"
13926 "\n"
13927 "layout(location=0) in int x;\n" /* attrib provided float */
13928 "out gl_PerVertex {\n"
13929 " vec4 gl_Position;\n"
13930 "};\n"
13931 "void main(){\n"
13932 " gl_Position = vec4(x);\n"
13933 "}\n";
13934 char const *fsSource =
13935 "#version 450\n"
13936 "\n"
13937 "layout(location=0) out vec4 color;\n"
13938 "void main(){\n"
13939 " color = vec4(1);\n"
13940 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013941
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013944
13945 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013946 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013947 pipe.AddShader(&vs);
13948 pipe.AddShader(&fs);
13949
13950 pipe.AddVertexInputBindings(&input_binding, 1);
13951 pipe.AddVertexInputAttribs(&input_attrib, 1);
13952
Chris Forbesc97d98e2015-05-25 11:13:31 +120013953 VkDescriptorSetObj descriptorSet(m_device);
13954 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013955 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013956
Tony Barbour5781e8f2015-08-04 16:23:11 -060013957 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013958
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013959 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013960}
13961
Chris Forbesc68b43c2016-04-06 11:18:47 +120013962TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013963 TEST_DESCRIPTION(
13964 "Test that an error is produced for a pipeline containing multiple "
13965 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13967 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013968
13969 ASSERT_NO_FATAL_FAILURE(InitState());
13970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13971
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013972 char const *vsSource =
13973 "#version 450\n"
13974 "\n"
13975 "out gl_PerVertex {\n"
13976 " vec4 gl_Position;\n"
13977 "};\n"
13978 "void main(){\n"
13979 " gl_Position = vec4(1);\n"
13980 "}\n";
13981 char const *fsSource =
13982 "#version 450\n"
13983 "\n"
13984 "layout(location=0) out vec4 color;\n"
13985 "void main(){\n"
13986 " color = vec4(1);\n"
13987 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013988
13989 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13990 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13991
13992 VkPipelineObj pipe(m_device);
13993 pipe.AddColorAttachment();
13994 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013995 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013996 pipe.AddShader(&fs);
13997
13998 VkDescriptorSetObj descriptorSet(m_device);
13999 descriptorSet.AppendDummy();
14000 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14001
14002 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14003
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014004 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014005}
14006
Chris Forbes82ff92a2016-09-09 10:50:24 +120014007TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014009
14010 ASSERT_NO_FATAL_FAILURE(InitState());
14011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14012
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014013 char const *vsSource =
14014 "#version 450\n"
14015 "out gl_PerVertex {\n"
14016 " vec4 gl_Position;\n"
14017 "};\n"
14018 "void main(){\n"
14019 " gl_Position = vec4(0);\n"
14020 "}\n";
14021 char const *fsSource =
14022 "#version 450\n"
14023 "\n"
14024 "layout(location=0) out vec4 color;\n"
14025 "void main(){\n"
14026 " color = vec4(1);\n"
14027 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014028
14029 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14030 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14031
14032 VkPipelineObj pipe(m_device);
14033 pipe.AddColorAttachment();
14034 pipe.AddShader(&vs);
14035 pipe.AddShader(&fs);
14036
14037 VkDescriptorSetObj descriptorSet(m_device);
14038 descriptorSet.AppendDummy();
14039 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14040
14041 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14042
14043 m_errorMonitor->VerifyFound();
14044}
14045
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014046TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14048 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14049 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014050
14051 ASSERT_NO_FATAL_FAILURE(InitState());
14052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14053
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014054 char const *vsSource =
14055 "#version 450\n"
14056 "void main(){ gl_Position = vec4(0); }\n";
14057 char const *fsSource =
14058 "#version 450\n"
14059 "\n"
14060 "layout(location=0) out vec4 color;\n"
14061 "void main(){\n"
14062 " color = vec4(1);\n"
14063 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014064
14065 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14066 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14067
14068 VkPipelineObj pipe(m_device);
14069 pipe.AddColorAttachment();
14070 pipe.AddShader(&vs);
14071 pipe.AddShader(&fs);
14072
14073 VkDescriptorSetObj descriptorSet(m_device);
14074 descriptorSet.AppendDummy();
14075 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14076
14077 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014078 {
14079 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14080 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14081 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014082 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014083 {
14084 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14085 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14086 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014087 },
14088 };
14089 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014090 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014091 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014092 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14093 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014094 VkRenderPass rp;
14095 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14096 ASSERT_VK_SUCCESS(err);
14097
14098 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14099
14100 m_errorMonitor->VerifyFound();
14101
14102 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14103}
14104
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014105TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014106 TEST_DESCRIPTION(
14107 "Test that an error is produced for a variable output from "
14108 "the TCS without the patch decoration, but consumed in the TES "
14109 "with the decoration.");
14110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14111 "is per-vertex in tessellation control shader stage "
14112 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014113
14114 ASSERT_NO_FATAL_FAILURE(InitState());
14115 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14116
Chris Forbesc1e852d2016-04-04 19:26:42 +120014117 if (!m_device->phy().features().tessellationShader) {
14118 printf("Device does not support tessellation shaders; skipped.\n");
14119 return;
14120 }
14121
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014122 char const *vsSource =
14123 "#version 450\n"
14124 "void main(){}\n";
14125 char const *tcsSource =
14126 "#version 450\n"
14127 "layout(location=0) out int x[];\n"
14128 "layout(vertices=3) out;\n"
14129 "void main(){\n"
14130 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14131 " gl_TessLevelInner[0] = 1;\n"
14132 " x[gl_InvocationID] = gl_InvocationID;\n"
14133 "}\n";
14134 char const *tesSource =
14135 "#version 450\n"
14136 "layout(triangles, equal_spacing, cw) in;\n"
14137 "layout(location=0) patch in int x;\n"
14138 "out gl_PerVertex { vec4 gl_Position; };\n"
14139 "void main(){\n"
14140 " gl_Position.xyz = gl_TessCoord;\n"
14141 " gl_Position.w = x;\n"
14142 "}\n";
14143 char const *fsSource =
14144 "#version 450\n"
14145 "layout(location=0) out vec4 color;\n"
14146 "void main(){\n"
14147 " color = vec4(1);\n"
14148 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014149
14150 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14151 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14152 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14153 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14154
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014155 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14156 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014158 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014159
14160 VkPipelineObj pipe(m_device);
14161 pipe.SetInputAssembly(&iasci);
14162 pipe.SetTessellation(&tsci);
14163 pipe.AddColorAttachment();
14164 pipe.AddShader(&vs);
14165 pipe.AddShader(&tcs);
14166 pipe.AddShader(&tes);
14167 pipe.AddShader(&fs);
14168
14169 VkDescriptorSetObj descriptorSet(m_device);
14170 descriptorSet.AppendDummy();
14171 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14172
14173 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14174
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014175 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014176}
14177
Karl Schultz6addd812016-02-02 17:17:23 -070014178TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014179 TEST_DESCRIPTION(
14180 "Test that an error is produced for a vertex attribute setup where multiple "
14181 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14183 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014184
Chris Forbes280ba2c2015-06-12 11:16:41 +120014185 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014186 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014187
14188 /* Two binding descriptions for binding 0 */
14189 VkVertexInputBindingDescription input_bindings[2];
14190 memset(input_bindings, 0, sizeof(input_bindings));
14191
14192 VkVertexInputAttributeDescription input_attrib;
14193 memset(&input_attrib, 0, sizeof(input_attrib));
14194 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14195
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014196 char const *vsSource =
14197 "#version 450\n"
14198 "\n"
14199 "layout(location=0) in float x;\n" /* attrib provided float */
14200 "out gl_PerVertex {\n"
14201 " vec4 gl_Position;\n"
14202 "};\n"
14203 "void main(){\n"
14204 " gl_Position = vec4(x);\n"
14205 "}\n";
14206 char const *fsSource =
14207 "#version 450\n"
14208 "\n"
14209 "layout(location=0) out vec4 color;\n"
14210 "void main(){\n"
14211 " color = vec4(1);\n"
14212 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014213
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014214 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14215 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014216
14217 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014218 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014219 pipe.AddShader(&vs);
14220 pipe.AddShader(&fs);
14221
14222 pipe.AddVertexInputBindings(input_bindings, 2);
14223 pipe.AddVertexInputAttribs(&input_attrib, 1);
14224
Chris Forbes280ba2c2015-06-12 11:16:41 +120014225 VkDescriptorSetObj descriptorSet(m_device);
14226 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014227 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014228
Tony Barbour5781e8f2015-08-04 16:23:11 -060014229 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014230
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014231 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014232}
Chris Forbes8f68b562015-05-25 11:13:32 +120014233
Karl Schultz6addd812016-02-02 17:17:23 -070014234TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014235 TEST_DESCRIPTION(
14236 "Test that an error is produced for a fragment shader which does not "
14237 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014238 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014239
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014240 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014241
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014242 char const *vsSource =
14243 "#version 450\n"
14244 "\n"
14245 "out gl_PerVertex {\n"
14246 " vec4 gl_Position;\n"
14247 "};\n"
14248 "void main(){\n"
14249 " gl_Position = vec4(1);\n"
14250 "}\n";
14251 char const *fsSource =
14252 "#version 450\n"
14253 "\n"
14254 "void main(){\n"
14255 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014256
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014257 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14258 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014259
14260 VkPipelineObj pipe(m_device);
14261 pipe.AddShader(&vs);
14262 pipe.AddShader(&fs);
14263
Chia-I Wu08accc62015-07-07 11:50:03 +080014264 /* set up CB 0, not written */
14265 pipe.AddColorAttachment();
14266 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014267
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014268 VkDescriptorSetObj descriptorSet(m_device);
14269 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014270 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014271
Tony Barbour5781e8f2015-08-04 16:23:11 -060014272 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014273
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014274 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014275}
14276
Karl Schultz6addd812016-02-02 17:17:23 -070014277TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014278 TEST_DESCRIPTION(
14279 "Test that a warning is produced for a fragment shader which provides a spurious "
14280 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014282 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014283
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014284 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014285
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014286 char const *vsSource =
14287 "#version 450\n"
14288 "\n"
14289 "out gl_PerVertex {\n"
14290 " vec4 gl_Position;\n"
14291 "};\n"
14292 "void main(){\n"
14293 " gl_Position = vec4(1);\n"
14294 "}\n";
14295 char const *fsSource =
14296 "#version 450\n"
14297 "\n"
14298 "layout(location=0) out vec4 x;\n"
14299 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14300 "void main(){\n"
14301 " x = vec4(1);\n"
14302 " y = vec4(1);\n"
14303 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014304
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014305 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14306 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014307
14308 VkPipelineObj pipe(m_device);
14309 pipe.AddShader(&vs);
14310 pipe.AddShader(&fs);
14311
Chia-I Wu08accc62015-07-07 11:50:03 +080014312 /* set up CB 0, not written */
14313 pipe.AddColorAttachment();
14314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014315 /* FS writes CB 1, but we don't configure it */
14316
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014317 VkDescriptorSetObj descriptorSet(m_device);
14318 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014319 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014320
Tony Barbour5781e8f2015-08-04 16:23:11 -060014321 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014322
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014323 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014324}
14325
Karl Schultz6addd812016-02-02 17:17:23 -070014326TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014327 TEST_DESCRIPTION(
14328 "Test that an error is produced for a mismatch between the fundamental "
14329 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014331
Chris Forbesa36d69e2015-05-25 11:13:44 +120014332 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014333
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014334 char const *vsSource =
14335 "#version 450\n"
14336 "\n"
14337 "out gl_PerVertex {\n"
14338 " vec4 gl_Position;\n"
14339 "};\n"
14340 "void main(){\n"
14341 " gl_Position = vec4(1);\n"
14342 "}\n";
14343 char const *fsSource =
14344 "#version 450\n"
14345 "\n"
14346 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14347 "void main(){\n"
14348 " x = ivec4(1);\n"
14349 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014350
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014351 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14352 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014353
14354 VkPipelineObj pipe(m_device);
14355 pipe.AddShader(&vs);
14356 pipe.AddShader(&fs);
14357
Chia-I Wu08accc62015-07-07 11:50:03 +080014358 /* set up CB 0; type is UNORM by default */
14359 pipe.AddColorAttachment();
14360 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014361
Chris Forbesa36d69e2015-05-25 11:13:44 +120014362 VkDescriptorSetObj descriptorSet(m_device);
14363 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014364 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014365
Tony Barbour5781e8f2015-08-04 16:23:11 -060014366 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014367
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014368 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014369}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014370
Karl Schultz6addd812016-02-02 17:17:23 -070014371TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014372 TEST_DESCRIPTION(
14373 "Test that an error is produced for a shader consuming a uniform "
14374 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014376
Chris Forbes556c76c2015-08-14 12:04:59 +120014377 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014378
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014379 char const *vsSource =
14380 "#version 450\n"
14381 "\n"
14382 "out gl_PerVertex {\n"
14383 " vec4 gl_Position;\n"
14384 "};\n"
14385 "void main(){\n"
14386 " gl_Position = vec4(1);\n"
14387 "}\n";
14388 char const *fsSource =
14389 "#version 450\n"
14390 "\n"
14391 "layout(location=0) out vec4 x;\n"
14392 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14393 "void main(){\n"
14394 " x = vec4(bar.y);\n"
14395 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014396
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014397 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14398 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014399
Chris Forbes556c76c2015-08-14 12:04:59 +120014400 VkPipelineObj pipe(m_device);
14401 pipe.AddShader(&vs);
14402 pipe.AddShader(&fs);
14403
14404 /* set up CB 0; type is UNORM by default */
14405 pipe.AddColorAttachment();
14406 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14407
14408 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014409 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014410
14411 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14412
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014413 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014414}
14415
Chris Forbes5c59e902016-02-26 16:56:09 +130014416TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014417 TEST_DESCRIPTION(
14418 "Test that an error is produced for a shader consuming push constants "
14419 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014421
14422 ASSERT_NO_FATAL_FAILURE(InitState());
14423
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014424 char const *vsSource =
14425 "#version 450\n"
14426 "\n"
14427 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14428 "out gl_PerVertex {\n"
14429 " vec4 gl_Position;\n"
14430 "};\n"
14431 "void main(){\n"
14432 " gl_Position = vec4(consts.x);\n"
14433 "}\n";
14434 char const *fsSource =
14435 "#version 450\n"
14436 "\n"
14437 "layout(location=0) out vec4 x;\n"
14438 "void main(){\n"
14439 " x = vec4(1);\n"
14440 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014441
14442 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14443 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14444
14445 VkPipelineObj pipe(m_device);
14446 pipe.AddShader(&vs);
14447 pipe.AddShader(&fs);
14448
14449 /* set up CB 0; type is UNORM by default */
14450 pipe.AddColorAttachment();
14451 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14452
14453 VkDescriptorSetObj descriptorSet(m_device);
14454 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14455
14456 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14457
14458 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014459 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014460}
14461
Chris Forbes3fb17902016-08-22 14:57:55 +120014462TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014463 TEST_DESCRIPTION(
14464 "Test that an error is produced for a shader consuming an input attachment "
14465 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14467 "consumes input attachment index 0 but not provided in subpass");
14468
14469 ASSERT_NO_FATAL_FAILURE(InitState());
14470
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014471 char const *vsSource =
14472 "#version 450\n"
14473 "\n"
14474 "out gl_PerVertex {\n"
14475 " vec4 gl_Position;\n"
14476 "};\n"
14477 "void main(){\n"
14478 " gl_Position = vec4(1);\n"
14479 "}\n";
14480 char const *fsSource =
14481 "#version 450\n"
14482 "\n"
14483 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14484 "layout(location=0) out vec4 color;\n"
14485 "void main() {\n"
14486 " color = subpassLoad(x);\n"
14487 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014488
14489 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14490 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14491
14492 VkPipelineObj pipe(m_device);
14493 pipe.AddShader(&vs);
14494 pipe.AddShader(&fs);
14495 pipe.AddColorAttachment();
14496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14497
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014498 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14499 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014500 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014501 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014502 ASSERT_VK_SUCCESS(err);
14503
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014504 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014505 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014506 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014507 ASSERT_VK_SUCCESS(err);
14508
14509 // error here.
14510 pipe.CreateVKPipeline(pl, renderPass());
14511
14512 m_errorMonitor->VerifyFound();
14513
14514 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14515 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14516}
14517
Chris Forbes5a9a0472016-08-22 16:02:09 +120014518TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014519 TEST_DESCRIPTION(
14520 "Test that an error is produced for a shader consuming an input attachment "
14521 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120014522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14523 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14524
14525 ASSERT_NO_FATAL_FAILURE(InitState());
14526
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014527 char const *vsSource =
14528 "#version 450\n"
14529 "\n"
14530 "out gl_PerVertex {\n"
14531 " vec4 gl_Position;\n"
14532 "};\n"
14533 "void main(){\n"
14534 " gl_Position = vec4(1);\n"
14535 "}\n";
14536 char const *fsSource =
14537 "#version 450\n"
14538 "\n"
14539 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14540 "layout(location=0) out vec4 color;\n"
14541 "void main() {\n"
14542 " color = subpassLoad(x);\n"
14543 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014544
14545 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14546 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14547
14548 VkPipelineObj pipe(m_device);
14549 pipe.AddShader(&vs);
14550 pipe.AddShader(&fs);
14551 pipe.AddColorAttachment();
14552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14553
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014554 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14555 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014556 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014557 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014558 ASSERT_VK_SUCCESS(err);
14559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014560 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014561 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014562 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014563 ASSERT_VK_SUCCESS(err);
14564
14565 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014566 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14567 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14568 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14569 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14570 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 +120014571 };
14572 VkAttachmentReference color = {
14573 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14574 };
14575 VkAttachmentReference input = {
14576 1, VK_IMAGE_LAYOUT_GENERAL,
14577 };
14578
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014579 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014581 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014582 VkRenderPass rp;
14583 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14584 ASSERT_VK_SUCCESS(err);
14585
14586 // error here.
14587 pipe.CreateVKPipeline(pl, rp);
14588
14589 m_errorMonitor->VerifyFound();
14590
14591 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14592 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14593 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14594}
14595
Chris Forbes541f7b02016-08-22 15:30:27 +120014596TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014597 TEST_DESCRIPTION(
14598 "Test that an error is produced for a shader consuming an input attachment "
14599 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120014600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070014601 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120014602
14603 ASSERT_NO_FATAL_FAILURE(InitState());
14604
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014605 char const *vsSource =
14606 "#version 450\n"
14607 "\n"
14608 "out gl_PerVertex {\n"
14609 " vec4 gl_Position;\n"
14610 "};\n"
14611 "void main(){\n"
14612 " gl_Position = vec4(1);\n"
14613 "}\n";
14614 char const *fsSource =
14615 "#version 450\n"
14616 "\n"
14617 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
14618 "layout(location=0) out vec4 color;\n"
14619 "void main() {\n"
14620 " color = subpassLoad(xs[0]);\n"
14621 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014622
14623 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14624 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14625
14626 VkPipelineObj pipe(m_device);
14627 pipe.AddShader(&vs);
14628 pipe.AddShader(&fs);
14629 pipe.AddColorAttachment();
14630 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14631
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014632 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14633 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014634 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014635 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014636 ASSERT_VK_SUCCESS(err);
14637
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014638 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014639 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014640 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014641 ASSERT_VK_SUCCESS(err);
14642
14643 // error here.
14644 pipe.CreateVKPipeline(pl, renderPass());
14645
14646 m_errorMonitor->VerifyFound();
14647
14648 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14649 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14650}
14651
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014652TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014653 TEST_DESCRIPTION(
14654 "Test that an error is produced for a compute pipeline consuming a "
14655 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014657
14658 ASSERT_NO_FATAL_FAILURE(InitState());
14659
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014660 char const *csSource =
14661 "#version 450\n"
14662 "\n"
14663 "layout(local_size_x=1) in;\n"
14664 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14665 "void main(){\n"
14666 " x = vec4(1);\n"
14667 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014668
14669 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14670
14671 VkDescriptorSetObj descriptorSet(m_device);
14672 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14673
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014674 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14675 nullptr,
14676 0,
14677 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14678 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14679 descriptorSet.GetPipelineLayout(),
14680 VK_NULL_HANDLE,
14681 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014682
14683 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014684 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014685
14686 m_errorMonitor->VerifyFound();
14687
14688 if (err == VK_SUCCESS) {
14689 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14690 }
14691}
14692
Chris Forbes22a9b092016-07-19 14:34:05 +120014693TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014694 TEST_DESCRIPTION(
14695 "Test that an error is produced for a pipeline consuming a "
14696 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14698 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014699
14700 ASSERT_NO_FATAL_FAILURE(InitState());
14701
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014702 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14703 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014704 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014705 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014706 ASSERT_VK_SUCCESS(err);
14707
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014708 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014709 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014710 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014711 ASSERT_VK_SUCCESS(err);
14712
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014713 char const *csSource =
14714 "#version 450\n"
14715 "\n"
14716 "layout(local_size_x=1) in;\n"
14717 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14718 "void main() {\n"
14719 " x.x = 1.0f;\n"
14720 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014721 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14722
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014723 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14724 nullptr,
14725 0,
14726 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14727 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14728 pl,
14729 VK_NULL_HANDLE,
14730 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014731
14732 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014733 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014734
14735 m_errorMonitor->VerifyFound();
14736
14737 if (err == VK_SUCCESS) {
14738 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14739 }
14740
14741 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14742 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14743}
14744
Chris Forbes50020592016-07-27 13:52:41 +120014745TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014746 TEST_DESCRIPTION(
14747 "Test that an error is produced when an image view type "
14748 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120014749
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014750 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 +120014751
14752 ASSERT_NO_FATAL_FAILURE(InitState());
14753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14754
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014755 char const *vsSource =
14756 "#version 450\n"
14757 "\n"
14758 "out gl_PerVertex { vec4 gl_Position; };\n"
14759 "void main() { gl_Position = vec4(0); }\n";
14760 char const *fsSource =
14761 "#version 450\n"
14762 "\n"
14763 "layout(set=0, binding=0) uniform sampler3D s;\n"
14764 "layout(location=0) out vec4 color;\n"
14765 "void main() {\n"
14766 " color = texture(s, vec3(0));\n"
14767 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014768 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14769 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14770
14771 VkPipelineObj pipe(m_device);
14772 pipe.AddShader(&vs);
14773 pipe.AddShader(&fs);
14774 pipe.AddColorAttachment();
14775
14776 VkTextureObj texture(m_device, nullptr);
14777 VkSamplerObj sampler(m_device);
14778
14779 VkDescriptorSetObj descriptorSet(m_device);
14780 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14781 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14782
14783 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14784 ASSERT_VK_SUCCESS(err);
14785
Tony Barbour552f6c02016-12-21 14:34:07 -070014786 m_commandBuffer->BeginCommandBuffer();
14787 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014788
14789 m_commandBuffer->BindPipeline(pipe);
14790 m_commandBuffer->BindDescriptorSet(descriptorSet);
14791
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014792 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014793 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014794 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014795 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14796
14797 // error produced here.
14798 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14799
14800 m_errorMonitor->VerifyFound();
14801
Tony Barbour552f6c02016-12-21 14:34:07 -070014802 m_commandBuffer->EndRenderPass();
14803 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014804}
14805
Chris Forbes5533bfc2016-07-27 14:12:34 +120014806TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014807 TEST_DESCRIPTION(
14808 "Test that an error is produced when a multisampled images "
14809 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014810
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014812
14813 ASSERT_NO_FATAL_FAILURE(InitState());
14814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14815
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014816 char const *vsSource =
14817 "#version 450\n"
14818 "\n"
14819 "out gl_PerVertex { vec4 gl_Position; };\n"
14820 "void main() { gl_Position = vec4(0); }\n";
14821 char const *fsSource =
14822 "#version 450\n"
14823 "\n"
14824 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14825 "layout(location=0) out vec4 color;\n"
14826 "void main() {\n"
14827 " color = texelFetch(s, ivec2(0), 0);\n"
14828 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014829 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14830 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14831
14832 VkPipelineObj pipe(m_device);
14833 pipe.AddShader(&vs);
14834 pipe.AddShader(&fs);
14835 pipe.AddColorAttachment();
14836
14837 VkTextureObj texture(m_device, nullptr);
14838 VkSamplerObj sampler(m_device);
14839
14840 VkDescriptorSetObj descriptorSet(m_device);
14841 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14842 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14843
14844 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14845 ASSERT_VK_SUCCESS(err);
14846
Tony Barbour552f6c02016-12-21 14:34:07 -070014847 m_commandBuffer->BeginCommandBuffer();
14848 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014849
14850 m_commandBuffer->BindPipeline(pipe);
14851 m_commandBuffer->BindDescriptorSet(descriptorSet);
14852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014853 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014854 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014855 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014856 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14857
14858 // error produced here.
14859 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14860
14861 m_errorMonitor->VerifyFound();
14862
Tony Barbour552f6c02016-12-21 14:34:07 -070014863 m_commandBuffer->EndRenderPass();
14864 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014865}
14866
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014867#endif // SHADER_CHECKER_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014868
14869#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014870TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014872
14873 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014874
14875 // Create an image
14876 VkImage image;
14877
Karl Schultz6addd812016-02-02 17:17:23 -070014878 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14879 const int32_t tex_width = 32;
14880 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014881
14882 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014883 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;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014888 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014889 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;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014896
14897 // Introduce error by sending down a bogus width extent
14898 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014899 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014900
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014901 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014902}
14903
Mark Youngc48c4c12016-04-11 14:26:49 -060014904TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070014905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060014906
14907 ASSERT_NO_FATAL_FAILURE(InitState());
14908
14909 // Create an image
14910 VkImage image;
14911
14912 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14913 const int32_t tex_width = 32;
14914 const int32_t tex_height = 32;
14915
14916 VkImageCreateInfo image_create_info = {};
14917 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14918 image_create_info.pNext = NULL;
14919 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14920 image_create_info.format = tex_format;
14921 image_create_info.extent.width = tex_width;
14922 image_create_info.extent.height = tex_height;
14923 image_create_info.extent.depth = 1;
14924 image_create_info.mipLevels = 1;
14925 image_create_info.arrayLayers = 1;
14926 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14927 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14928 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14929 image_create_info.flags = 0;
14930
14931 // Introduce error by sending down a bogus width extent
14932 image_create_info.extent.width = 0;
14933 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14934
14935 m_errorMonitor->VerifyFound();
14936}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014937#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014938
Tobin Ehliscde08892015-09-22 10:11:37 -060014939#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014940
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014941TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014942 TEST_DESCRIPTION(
14943 "Create a render pass with an attachment description "
14944 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014945
14946 ASSERT_NO_FATAL_FAILURE(InitState());
14947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14948
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014950
14951 VkAttachmentReference color_attach = {};
14952 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14953 color_attach.attachment = 0;
14954 VkSubpassDescription subpass = {};
14955 subpass.colorAttachmentCount = 1;
14956 subpass.pColorAttachments = &color_attach;
14957
14958 VkRenderPassCreateInfo rpci = {};
14959 rpci.subpassCount = 1;
14960 rpci.pSubpasses = &subpass;
14961 rpci.attachmentCount = 1;
14962 VkAttachmentDescription attach_desc = {};
14963 attach_desc.format = VK_FORMAT_UNDEFINED;
14964 rpci.pAttachments = &attach_desc;
14965 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14966 VkRenderPass rp;
14967 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14968
14969 m_errorMonitor->VerifyFound();
14970
14971 if (result == VK_SUCCESS) {
14972 vkDestroyRenderPass(m_device->device(), rp, NULL);
14973 }
14974}
14975
Karl Schultz6addd812016-02-02 17:17:23 -070014976TEST_F(VkLayerTest, InvalidImageView) {
14977 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014978
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014980
Tobin Ehliscde08892015-09-22 10:11:37 -060014981 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014982
Mike Stroyana3082432015-09-25 13:39:21 -060014983 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014984 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014985
Karl Schultz6addd812016-02-02 17:17:23 -070014986 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14987 const int32_t tex_width = 32;
14988 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014989
14990 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014991 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14992 image_create_info.pNext = NULL;
14993 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14994 image_create_info.format = tex_format;
14995 image_create_info.extent.width = tex_width;
14996 image_create_info.extent.height = tex_height;
14997 image_create_info.extent.depth = 1;
14998 image_create_info.mipLevels = 1;
14999 image_create_info.arrayLayers = 1;
15000 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15001 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15002 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15003 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015004
Chia-I Wuf7458c52015-10-26 21:10:41 +080015005 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015006 ASSERT_VK_SUCCESS(err);
15007
15008 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015009 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015010 image_view_create_info.image = image;
15011 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15012 image_view_create_info.format = tex_format;
15013 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015014 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015015 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015016 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015017
15018 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015019 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015020
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015021 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015022 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015023}
Mike Stroyana3082432015-09-25 13:39:21 -060015024
Mark Youngd339ba32016-05-30 13:28:35 -060015025TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15026 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015028 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015029
15030 ASSERT_NO_FATAL_FAILURE(InitState());
15031
15032 // Create an image and try to create a view with no memory backing the image
15033 VkImage image;
15034
15035 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15036 const int32_t tex_width = 32;
15037 const int32_t tex_height = 32;
15038
15039 VkImageCreateInfo image_create_info = {};
15040 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15041 image_create_info.pNext = NULL;
15042 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15043 image_create_info.format = tex_format;
15044 image_create_info.extent.width = tex_width;
15045 image_create_info.extent.height = tex_height;
15046 image_create_info.extent.depth = 1;
15047 image_create_info.mipLevels = 1;
15048 image_create_info.arrayLayers = 1;
15049 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15050 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15051 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15052 image_create_info.flags = 0;
15053
15054 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15055 ASSERT_VK_SUCCESS(err);
15056
15057 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015058 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015059 image_view_create_info.image = image;
15060 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15061 image_view_create_info.format = tex_format;
15062 image_view_create_info.subresourceRange.layerCount = 1;
15063 image_view_create_info.subresourceRange.baseMipLevel = 0;
15064 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015065 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015066
15067 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015068 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015069
15070 m_errorMonitor->VerifyFound();
15071 vkDestroyImage(m_device->device(), image, NULL);
15072 // If last error is success, it still created the view, so delete it.
15073 if (err == VK_SUCCESS) {
15074 vkDestroyImageView(m_device->device(), view, NULL);
15075 }
Mark Youngd339ba32016-05-30 13:28:35 -060015076}
15077
Karl Schultz6addd812016-02-02 17:17:23 -070015078TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015079 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015081
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015082 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015083
Karl Schultz6addd812016-02-02 17:17:23 -070015084 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015085 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015086 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015087 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015088
15089 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015090 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015091 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015092 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15093 image_view_create_info.format = tex_format;
15094 image_view_create_info.subresourceRange.baseMipLevel = 0;
15095 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015096 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015097 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015098 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015099
15100 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015101 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015102
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015103 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015104}
15105
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015106TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015107 VkResult err;
15108 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015109
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015111
Mike Stroyana3082432015-09-25 13:39:21 -060015112 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015113
15114 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015115 VkImage srcImage;
15116 VkImage dstImage;
15117 VkDeviceMemory srcMem;
15118 VkDeviceMemory destMem;
15119 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015120
15121 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015122 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15123 image_create_info.pNext = NULL;
15124 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15125 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15126 image_create_info.extent.width = 32;
15127 image_create_info.extent.height = 32;
15128 image_create_info.extent.depth = 1;
15129 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015130 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015131 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15132 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15133 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15134 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015136 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015137 ASSERT_VK_SUCCESS(err);
15138
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015139 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015140 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015141 ASSERT_VK_SUCCESS(err);
15142
15143 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015144 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015145 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15146 memAlloc.pNext = NULL;
15147 memAlloc.allocationSize = 0;
15148 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015149
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015150 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015151 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015152 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015153 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015154 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015155 ASSERT_VK_SUCCESS(err);
15156
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015157 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015158 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015159 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015160 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015161 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015162 ASSERT_VK_SUCCESS(err);
15163
15164 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15165 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015166 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015167 ASSERT_VK_SUCCESS(err);
15168
Tony Barbour552f6c02016-12-21 14:34:07 -070015169 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015170 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015171 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015172 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015173 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015174 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015175 copyRegion.srcOffset.x = 0;
15176 copyRegion.srcOffset.y = 0;
15177 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015178 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015179 copyRegion.dstSubresource.mipLevel = 0;
15180 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015181 // Introduce failure by forcing the dst layerCount to differ from src
15182 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015183 copyRegion.dstOffset.x = 0;
15184 copyRegion.dstOffset.y = 0;
15185 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015186 copyRegion.extent.width = 1;
15187 copyRegion.extent.height = 1;
15188 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015189 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015190 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015191
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015192 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015193
Chia-I Wuf7458c52015-10-26 21:10:41 +080015194 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015195 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015196 vkFreeMemory(m_device->device(), srcMem, NULL);
15197 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015198}
15199
Tony Barbourd6673642016-05-05 14:46:39 -060015200TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015201 TEST_DESCRIPTION("Creating images with unsuported formats ");
15202
15203 ASSERT_NO_FATAL_FAILURE(InitState());
15204 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15205 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015206 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 -060015207 VK_IMAGE_TILING_OPTIMAL, 0);
15208 ASSERT_TRUE(image.initialized());
15209
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015210 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015211 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015212 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015213 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15214 image_create_info.format = VK_FORMAT_UNDEFINED;
15215 image_create_info.extent.width = 32;
15216 image_create_info.extent.height = 32;
15217 image_create_info.extent.depth = 1;
15218 image_create_info.mipLevels = 1;
15219 image_create_info.arrayLayers = 1;
15220 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15221 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15222 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015223
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15225 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015226
15227 VkImage localImage;
15228 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15229 m_errorMonitor->VerifyFound();
15230
Tony Barbourd6673642016-05-05 14:46:39 -060015231 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015232 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015233 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15234 VkFormat format = static_cast<VkFormat>(f);
15235 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015236 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015237 unsupported = format;
15238 break;
15239 }
15240 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015241
Tony Barbourd6673642016-05-05 14:46:39 -060015242 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015243 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015245
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015246 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015247 m_errorMonitor->VerifyFound();
15248 }
15249}
15250
15251TEST_F(VkLayerTest, ImageLayerViewTests) {
15252 VkResult ret;
15253 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15254
15255 ASSERT_NO_FATAL_FAILURE(InitState());
15256
15257 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015258 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 -060015259 VK_IMAGE_TILING_OPTIMAL, 0);
15260 ASSERT_TRUE(image.initialized());
15261
15262 VkImageView imgView;
15263 VkImageViewCreateInfo imgViewInfo = {};
15264 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15265 imgViewInfo.image = image.handle();
15266 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15267 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15268 imgViewInfo.subresourceRange.layerCount = 1;
15269 imgViewInfo.subresourceRange.baseMipLevel = 0;
15270 imgViewInfo.subresourceRange.levelCount = 1;
15271 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15272
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015274 // View can't have baseMipLevel >= image's mipLevels - Expect
15275 // VIEW_CREATE_ERROR
15276 imgViewInfo.subresourceRange.baseMipLevel = 1;
15277 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15278 m_errorMonitor->VerifyFound();
15279 imgViewInfo.subresourceRange.baseMipLevel = 0;
15280
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015282 // View can't have baseArrayLayer >= image's arraySize - Expect
15283 // VIEW_CREATE_ERROR
15284 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15285 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15286 m_errorMonitor->VerifyFound();
15287 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15288
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015290 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15291 imgViewInfo.subresourceRange.levelCount = 0;
15292 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15293 m_errorMonitor->VerifyFound();
15294 imgViewInfo.subresourceRange.levelCount = 1;
15295
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015296 m_errorMonitor->SetDesiredFailureMsg(
15297 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15298 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015299 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15300 imgViewInfo.subresourceRange.layerCount = 0;
15301 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15302 m_errorMonitor->VerifyFound();
15303 imgViewInfo.subresourceRange.layerCount = 1;
15304
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15306 "Formats MUST be IDENTICAL unless "
15307 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15308 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015309 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15310 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15311 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15312 m_errorMonitor->VerifyFound();
15313 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15314
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015316 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15317 // VIEW_CREATE_ERROR
15318 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15319 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15320 m_errorMonitor->VerifyFound();
15321 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15322
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015324 // TODO: Update framework to easily passing mutable flag into ImageObj init
15325 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015326 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15327 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15328 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015329 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15330 // VIEW_CREATE_ERROR
15331 VkImageCreateInfo mutImgInfo = image.create_info();
15332 VkImage mutImage;
15333 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015334 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015335 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15336 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15337 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15338 ASSERT_VK_SUCCESS(ret);
15339 imgViewInfo.image = mutImage;
15340 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15341 m_errorMonitor->VerifyFound();
15342 imgViewInfo.image = image.handle();
15343 vkDestroyImage(m_device->handle(), mutImage, NULL);
15344}
15345
15346TEST_F(VkLayerTest, MiscImageLayerTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060015347 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15348
15349 ASSERT_NO_FATAL_FAILURE(InitState());
15350
Rene Lindsay135204f2016-12-22 17:11:09 -070015351 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060015352 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070015353 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 -070015354 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060015355 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060015356 vk_testing::Buffer buffer;
15357 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070015358 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060015359 VkBufferImageCopy region = {};
15360 region.bufferRowLength = 128;
15361 region.bufferImageHeight = 128;
15362 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15363 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070015364 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015365 region.imageExtent.height = 4;
15366 region.imageExtent.width = 4;
15367 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070015368
15369 VkImageObj image2(m_device);
15370 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 -070015371 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070015372 ASSERT_TRUE(image2.initialized());
15373 vk_testing::Buffer buffer2;
15374 VkMemoryPropertyFlags reqs2 = 0;
15375 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
15376 VkBufferImageCopy region2 = {};
15377 region2.bufferRowLength = 128;
15378 region2.bufferImageHeight = 128;
15379 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15380 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15381 region2.imageSubresource.layerCount = 1;
15382 region2.imageExtent.height = 4;
15383 region2.imageExtent.width = 4;
15384 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015385 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060015386
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015387 // Image must have offset.z of 0 and extent.depth of 1
15388 // Introduce failure by setting imageExtent.depth to 0
15389 region.imageExtent.depth = 0;
15390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15391 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015392 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015393 m_errorMonitor->VerifyFound();
15394
15395 region.imageExtent.depth = 1;
15396
15397 // Image must have offset.z of 0 and extent.depth of 1
15398 // Introduce failure by setting imageOffset.z to 4
15399 region.imageOffset.z = 4;
15400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15401 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015402 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015403 m_errorMonitor->VerifyFound();
15404
15405 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015406 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15407 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070015408 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015410 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15411 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015412 m_errorMonitor->VerifyFound();
15413
15414 // BufferOffset must be a multiple of 4
15415 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070015416 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070015418 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
15419 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015420 m_errorMonitor->VerifyFound();
15421
15422 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15423 region.bufferOffset = 0;
15424 region.imageExtent.height = 128;
15425 region.imageExtent.width = 128;
15426 // Introduce failure by setting bufferRowLength > 0 but less than width
15427 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015429 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15430 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015431 m_errorMonitor->VerifyFound();
15432
15433 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15434 region.bufferRowLength = 128;
15435 // Introduce failure by setting bufferRowHeight > 0 but less than height
15436 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015438 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15439 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015440 m_errorMonitor->VerifyFound();
15441
15442 region.bufferImageHeight = 128;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15444 "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015445 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060015446 // Expect INVALID_FILTER
15447 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015448 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
15449 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015450 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015451 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15452 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015453 VkImageBlit blitRegion = {};
15454 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15455 blitRegion.srcSubresource.baseArrayLayer = 0;
15456 blitRegion.srcSubresource.layerCount = 1;
15457 blitRegion.srcSubresource.mipLevel = 0;
15458 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15459 blitRegion.dstSubresource.baseArrayLayer = 0;
15460 blitRegion.dstSubresource.layerCount = 1;
15461 blitRegion.dstSubresource.mipLevel = 0;
15462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015463 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015464 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060015465 m_errorMonitor->VerifyFound();
15466
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015467 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015468 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
15469 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15470 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015471 m_errorMonitor->VerifyFound();
15472
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070015473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015474 VkImageMemoryBarrier img_barrier;
15475 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15476 img_barrier.pNext = NULL;
15477 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15478 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15479 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15480 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15481 img_barrier.image = image.handle();
15482 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15483 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15484 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15485 img_barrier.subresourceRange.baseArrayLayer = 0;
15486 img_barrier.subresourceRange.baseMipLevel = 0;
15487 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
15488 img_barrier.subresourceRange.layerCount = 0;
15489 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015490 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
15491 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060015492 m_errorMonitor->VerifyFound();
15493 img_barrier.subresourceRange.layerCount = 1;
15494}
15495
15496TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060015497 TEST_DESCRIPTION("Exceed the limits of image format ");
15498
Cody Northropc31a84f2016-08-22 10:41:47 -060015499 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060015501 VkImageCreateInfo image_create_info = {};
15502 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15503 image_create_info.pNext = NULL;
15504 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15505 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15506 image_create_info.extent.width = 32;
15507 image_create_info.extent.height = 32;
15508 image_create_info.extent.depth = 1;
15509 image_create_info.mipLevels = 1;
15510 image_create_info.arrayLayers = 1;
15511 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15512 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15513 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15514 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15515 image_create_info.flags = 0;
15516
15517 VkImage nullImg;
15518 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015519 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15520 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070015521 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015522 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15523 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15524 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070015525 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015528 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15529 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15530 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15531 m_errorMonitor->VerifyFound();
15532 image_create_info.mipLevels = 1;
15533
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015535 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15536 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15537 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15538 m_errorMonitor->VerifyFound();
15539 image_create_info.arrayLayers = 1;
15540
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060015542 int samples = imgFmtProps.sampleCounts >> 1;
15543 image_create_info.samples = (VkSampleCountFlagBits)samples;
15544 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15545 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15546 m_errorMonitor->VerifyFound();
15547 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15548
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15550 "pCreateInfo->initialLayout, must be "
15551 "VK_IMAGE_LAYOUT_UNDEFINED or "
15552 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060015553 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15554 // Expect INVALID_LAYOUT
15555 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15556 m_errorMonitor->VerifyFound();
15557 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15558}
15559
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015560TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015561 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015563
15564 ASSERT_NO_FATAL_FAILURE(InitState());
15565
15566 VkImageObj src_image(m_device);
15567 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15568 VkImageObj dst_image(m_device);
15569 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15570
Tony Barbour552f6c02016-12-21 14:34:07 -070015571 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015572 VkImageCopy copy_region;
15573 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15574 copy_region.srcSubresource.mipLevel = 0;
15575 copy_region.srcSubresource.baseArrayLayer = 0;
15576 copy_region.srcSubresource.layerCount = 0;
15577 copy_region.srcOffset.x = 0;
15578 copy_region.srcOffset.y = 0;
15579 copy_region.srcOffset.z = 0;
15580 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15581 copy_region.dstSubresource.mipLevel = 0;
15582 copy_region.dstSubresource.baseArrayLayer = 0;
15583 copy_region.dstSubresource.layerCount = 0;
15584 copy_region.dstOffset.x = 0;
15585 copy_region.dstOffset.y = 0;
15586 copy_region.dstOffset.z = 0;
15587 copy_region.extent.width = 64;
15588 copy_region.extent.height = 64;
15589 copy_region.extent.depth = 1;
15590 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15591 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015592 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015593
15594 m_errorMonitor->VerifyFound();
15595}
15596
15597TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015598 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015600
15601 ASSERT_NO_FATAL_FAILURE(InitState());
15602
15603 VkImageObj src_image(m_device);
15604 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15605 VkImageObj dst_image(m_device);
15606 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15607
Tony Barbour552f6c02016-12-21 14:34:07 -070015608 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015609 VkImageCopy copy_region;
15610 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15611 copy_region.srcSubresource.mipLevel = 0;
15612 copy_region.srcSubresource.baseArrayLayer = 0;
15613 copy_region.srcSubresource.layerCount = 0;
15614 copy_region.srcOffset.x = 0;
15615 copy_region.srcOffset.y = 0;
15616 copy_region.srcOffset.z = 0;
15617 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15618 copy_region.dstSubresource.mipLevel = 0;
15619 copy_region.dstSubresource.baseArrayLayer = 0;
15620 copy_region.dstSubresource.layerCount = 0;
15621 copy_region.dstOffset.x = 0;
15622 copy_region.dstOffset.y = 0;
15623 copy_region.dstOffset.z = 0;
15624 copy_region.extent.width = 64;
15625 copy_region.extent.height = 64;
15626 copy_region.extent.depth = 1;
15627 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15628 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015629 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015630
15631 m_errorMonitor->VerifyFound();
15632}
15633
Karl Schultz6addd812016-02-02 17:17:23 -070015634TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015635 VkResult err;
15636 bool pass;
15637
15638 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015640
15641 ASSERT_NO_FATAL_FAILURE(InitState());
15642
15643 // Create two images of different types and try to copy between them
15644 VkImage srcImage;
15645 VkImage dstImage;
15646 VkDeviceMemory srcMem;
15647 VkDeviceMemory destMem;
15648 VkMemoryRequirements memReqs;
15649
15650 VkImageCreateInfo image_create_info = {};
15651 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15652 image_create_info.pNext = NULL;
15653 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15654 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15655 image_create_info.extent.width = 32;
15656 image_create_info.extent.height = 32;
15657 image_create_info.extent.depth = 1;
15658 image_create_info.mipLevels = 1;
15659 image_create_info.arrayLayers = 1;
15660 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15661 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15662 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15663 image_create_info.flags = 0;
15664
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015665 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015666 ASSERT_VK_SUCCESS(err);
15667
15668 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15669 // Introduce failure by creating second image with a different-sized format.
15670 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15671
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015672 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015673 ASSERT_VK_SUCCESS(err);
15674
15675 // Allocate memory
15676 VkMemoryAllocateInfo memAlloc = {};
15677 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15678 memAlloc.pNext = NULL;
15679 memAlloc.allocationSize = 0;
15680 memAlloc.memoryTypeIndex = 0;
15681
15682 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15683 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015684 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015685 ASSERT_TRUE(pass);
15686 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15687 ASSERT_VK_SUCCESS(err);
15688
15689 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15690 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015691 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015692 ASSERT_TRUE(pass);
15693 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15694 ASSERT_VK_SUCCESS(err);
15695
15696 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15697 ASSERT_VK_SUCCESS(err);
15698 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15699 ASSERT_VK_SUCCESS(err);
15700
Tony Barbour552f6c02016-12-21 14:34:07 -070015701 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015702 VkImageCopy copyRegion;
15703 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15704 copyRegion.srcSubresource.mipLevel = 0;
15705 copyRegion.srcSubresource.baseArrayLayer = 0;
15706 copyRegion.srcSubresource.layerCount = 0;
15707 copyRegion.srcOffset.x = 0;
15708 copyRegion.srcOffset.y = 0;
15709 copyRegion.srcOffset.z = 0;
15710 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15711 copyRegion.dstSubresource.mipLevel = 0;
15712 copyRegion.dstSubresource.baseArrayLayer = 0;
15713 copyRegion.dstSubresource.layerCount = 0;
15714 copyRegion.dstOffset.x = 0;
15715 copyRegion.dstOffset.y = 0;
15716 copyRegion.dstOffset.z = 0;
15717 copyRegion.extent.width = 1;
15718 copyRegion.extent.height = 1;
15719 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015720 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015721 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015722
15723 m_errorMonitor->VerifyFound();
15724
15725 vkDestroyImage(m_device->device(), srcImage, NULL);
15726 vkDestroyImage(m_device->device(), dstImage, NULL);
15727 vkFreeMemory(m_device->device(), srcMem, NULL);
15728 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015729}
15730
Karl Schultz6addd812016-02-02 17:17:23 -070015731TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15732 VkResult err;
15733 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015734
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015735 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15737 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015738
Mike Stroyana3082432015-09-25 13:39:21 -060015739 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015740
15741 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015742 VkImage srcImage;
15743 VkImage dstImage;
15744 VkDeviceMemory srcMem;
15745 VkDeviceMemory destMem;
15746 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015747
15748 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015749 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15750 image_create_info.pNext = NULL;
15751 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15752 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15753 image_create_info.extent.width = 32;
15754 image_create_info.extent.height = 32;
15755 image_create_info.extent.depth = 1;
15756 image_create_info.mipLevels = 1;
15757 image_create_info.arrayLayers = 1;
15758 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15759 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15760 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15761 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015762
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015763 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015764 ASSERT_VK_SUCCESS(err);
15765
Karl Schultzbdb75952016-04-19 11:36:49 -060015766 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15767
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015768 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015769 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015770 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015771 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015772
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015773 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015774 ASSERT_VK_SUCCESS(err);
15775
15776 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015777 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015778 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15779 memAlloc.pNext = NULL;
15780 memAlloc.allocationSize = 0;
15781 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015782
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015783 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015784 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015785 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015786 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015787 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015788 ASSERT_VK_SUCCESS(err);
15789
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015790 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015791 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015792 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015793 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015794 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015795 ASSERT_VK_SUCCESS(err);
15796
15797 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15798 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015799 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015800 ASSERT_VK_SUCCESS(err);
15801
Tony Barbour552f6c02016-12-21 14:34:07 -070015802 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015803 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015804 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015805 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015806 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015807 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015808 copyRegion.srcOffset.x = 0;
15809 copyRegion.srcOffset.y = 0;
15810 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015811 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015812 copyRegion.dstSubresource.mipLevel = 0;
15813 copyRegion.dstSubresource.baseArrayLayer = 0;
15814 copyRegion.dstSubresource.layerCount = 0;
15815 copyRegion.dstOffset.x = 0;
15816 copyRegion.dstOffset.y = 0;
15817 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015818 copyRegion.extent.width = 1;
15819 copyRegion.extent.height = 1;
15820 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015821 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015822 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015823
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015824 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015825
Chia-I Wuf7458c52015-10-26 21:10:41 +080015826 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015827 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015828 vkFreeMemory(m_device->device(), srcMem, NULL);
15829 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015830}
15831
Karl Schultz6addd812016-02-02 17:17:23 -070015832TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15833 VkResult err;
15834 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15837 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015838
Mike Stroyana3082432015-09-25 13:39:21 -060015839 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015840
15841 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015842 VkImage srcImage;
15843 VkImage dstImage;
15844 VkDeviceMemory srcMem;
15845 VkDeviceMemory destMem;
15846 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015847
15848 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015849 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15850 image_create_info.pNext = NULL;
15851 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15852 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15853 image_create_info.extent.width = 32;
15854 image_create_info.extent.height = 1;
15855 image_create_info.extent.depth = 1;
15856 image_create_info.mipLevels = 1;
15857 image_create_info.arrayLayers = 1;
15858 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15859 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15860 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15861 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015862
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015863 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015864 ASSERT_VK_SUCCESS(err);
15865
Karl Schultz6addd812016-02-02 17:17:23 -070015866 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015867
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015868 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015869 ASSERT_VK_SUCCESS(err);
15870
15871 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015872 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015873 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15874 memAlloc.pNext = NULL;
15875 memAlloc.allocationSize = 0;
15876 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015877
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015878 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015879 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015880 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015881 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015882 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015883 ASSERT_VK_SUCCESS(err);
15884
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015885 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015886 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015887 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015888 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015889 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015890 ASSERT_VK_SUCCESS(err);
15891
15892 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15893 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015894 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015895 ASSERT_VK_SUCCESS(err);
15896
Tony Barbour552f6c02016-12-21 14:34:07 -070015897 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015898 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015899 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15900 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015901 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015902 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015903 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015904 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015905 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015906 resolveRegion.srcOffset.x = 0;
15907 resolveRegion.srcOffset.y = 0;
15908 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015909 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015910 resolveRegion.dstSubresource.mipLevel = 0;
15911 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015912 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015913 resolveRegion.dstOffset.x = 0;
15914 resolveRegion.dstOffset.y = 0;
15915 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015916 resolveRegion.extent.width = 1;
15917 resolveRegion.extent.height = 1;
15918 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015919 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015920 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015921
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015922 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015923
Chia-I Wuf7458c52015-10-26 21:10:41 +080015924 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015925 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015926 vkFreeMemory(m_device->device(), srcMem, NULL);
15927 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015928}
15929
Karl Schultz6addd812016-02-02 17:17:23 -070015930TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15931 VkResult err;
15932 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15935 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015936
Mike Stroyana3082432015-09-25 13:39:21 -060015937 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015938
Chris Forbesa7530692016-05-08 12:35:39 +120015939 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015940 VkImage srcImage;
15941 VkImage dstImage;
15942 VkDeviceMemory srcMem;
15943 VkDeviceMemory destMem;
15944 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015945
15946 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015947 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15948 image_create_info.pNext = NULL;
15949 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15950 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15951 image_create_info.extent.width = 32;
15952 image_create_info.extent.height = 1;
15953 image_create_info.extent.depth = 1;
15954 image_create_info.mipLevels = 1;
15955 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015956 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015957 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15958 // Note: Some implementations expect color attachment usage for any
15959 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015960 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015961 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015963 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015964 ASSERT_VK_SUCCESS(err);
15965
Karl Schultz6addd812016-02-02 17:17:23 -070015966 // Note: Some implementations expect color attachment usage for any
15967 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015968 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015969
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015970 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015971 ASSERT_VK_SUCCESS(err);
15972
15973 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015974 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015975 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15976 memAlloc.pNext = NULL;
15977 memAlloc.allocationSize = 0;
15978 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015979
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015980 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015981 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015982 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015983 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015984 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015985 ASSERT_VK_SUCCESS(err);
15986
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015987 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015988 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015989 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015990 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015991 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015992 ASSERT_VK_SUCCESS(err);
15993
15994 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15995 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015996 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015997 ASSERT_VK_SUCCESS(err);
15998
Tony Barbour552f6c02016-12-21 14:34:07 -070015999 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016000 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016001 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16002 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016003 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016004 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016005 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016006 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016007 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016008 resolveRegion.srcOffset.x = 0;
16009 resolveRegion.srcOffset.y = 0;
16010 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016011 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016012 resolveRegion.dstSubresource.mipLevel = 0;
16013 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016014 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016015 resolveRegion.dstOffset.x = 0;
16016 resolveRegion.dstOffset.y = 0;
16017 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016018 resolveRegion.extent.width = 1;
16019 resolveRegion.extent.height = 1;
16020 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016021 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016022 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016023
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016024 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016025
Chia-I Wuf7458c52015-10-26 21:10:41 +080016026 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016027 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016028 vkFreeMemory(m_device->device(), srcMem, NULL);
16029 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016030}
16031
Karl Schultz6addd812016-02-02 17:17:23 -070016032TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16033 VkResult err;
16034 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16037 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016038
Mike Stroyana3082432015-09-25 13:39:21 -060016039 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016040
16041 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016042 VkImage srcImage;
16043 VkImage dstImage;
16044 VkDeviceMemory srcMem;
16045 VkDeviceMemory destMem;
16046 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016047
16048 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016049 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16050 image_create_info.pNext = NULL;
16051 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16052 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16053 image_create_info.extent.width = 32;
16054 image_create_info.extent.height = 1;
16055 image_create_info.extent.depth = 1;
16056 image_create_info.mipLevels = 1;
16057 image_create_info.arrayLayers = 1;
16058 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16059 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16060 // Note: Some implementations expect color attachment usage for any
16061 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016062 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016063 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016064
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016065 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016066 ASSERT_VK_SUCCESS(err);
16067
Karl Schultz6addd812016-02-02 17:17:23 -070016068 // Set format to something other than source image
16069 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16070 // Note: Some implementations expect color attachment usage for any
16071 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016072 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016073 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016074
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016075 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016076 ASSERT_VK_SUCCESS(err);
16077
16078 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016079 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016080 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16081 memAlloc.pNext = NULL;
16082 memAlloc.allocationSize = 0;
16083 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016084
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016085 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016086 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016087 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016088 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016089 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016090 ASSERT_VK_SUCCESS(err);
16091
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016092 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016093 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016094 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016095 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016096 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016097 ASSERT_VK_SUCCESS(err);
16098
16099 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16100 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016101 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016102 ASSERT_VK_SUCCESS(err);
16103
Tony Barbour552f6c02016-12-21 14:34:07 -070016104 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016105 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016106 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16107 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016108 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016109 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016110 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016111 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016112 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016113 resolveRegion.srcOffset.x = 0;
16114 resolveRegion.srcOffset.y = 0;
16115 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016116 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016117 resolveRegion.dstSubresource.mipLevel = 0;
16118 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016119 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016120 resolveRegion.dstOffset.x = 0;
16121 resolveRegion.dstOffset.y = 0;
16122 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016123 resolveRegion.extent.width = 1;
16124 resolveRegion.extent.height = 1;
16125 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016126 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016127 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016128
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016129 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016130
Chia-I Wuf7458c52015-10-26 21:10:41 +080016131 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016132 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016133 vkFreeMemory(m_device->device(), srcMem, NULL);
16134 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016135}
16136
Karl Schultz6addd812016-02-02 17:17:23 -070016137TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16138 VkResult err;
16139 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016140
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16142 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016143
Mike Stroyana3082432015-09-25 13:39:21 -060016144 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016145
16146 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016147 VkImage srcImage;
16148 VkImage dstImage;
16149 VkDeviceMemory srcMem;
16150 VkDeviceMemory destMem;
16151 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016152
16153 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016154 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16155 image_create_info.pNext = NULL;
16156 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16157 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16158 image_create_info.extent.width = 32;
16159 image_create_info.extent.height = 1;
16160 image_create_info.extent.depth = 1;
16161 image_create_info.mipLevels = 1;
16162 image_create_info.arrayLayers = 1;
16163 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16164 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16165 // Note: Some implementations expect color attachment usage for any
16166 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016167 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016168 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016169
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016170 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016171 ASSERT_VK_SUCCESS(err);
16172
Karl Schultz6addd812016-02-02 17:17:23 -070016173 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16174 // Note: Some implementations expect color attachment usage for any
16175 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016176 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016177 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016179 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016180 ASSERT_VK_SUCCESS(err);
16181
16182 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016183 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016184 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16185 memAlloc.pNext = NULL;
16186 memAlloc.allocationSize = 0;
16187 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016188
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016189 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016190 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016191 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016192 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016193 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016194 ASSERT_VK_SUCCESS(err);
16195
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016196 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016197 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016198 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016199 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016200 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016201 ASSERT_VK_SUCCESS(err);
16202
16203 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16204 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016205 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016206 ASSERT_VK_SUCCESS(err);
16207
Tony Barbour552f6c02016-12-21 14:34:07 -070016208 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016209 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016210 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16211 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016212 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016213 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016214 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016215 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016216 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016217 resolveRegion.srcOffset.x = 0;
16218 resolveRegion.srcOffset.y = 0;
16219 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016220 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016221 resolveRegion.dstSubresource.mipLevel = 0;
16222 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016223 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016224 resolveRegion.dstOffset.x = 0;
16225 resolveRegion.dstOffset.y = 0;
16226 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016227 resolveRegion.extent.width = 1;
16228 resolveRegion.extent.height = 1;
16229 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016230 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016231 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016232
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016233 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016234
Chia-I Wuf7458c52015-10-26 21:10:41 +080016235 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016236 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016237 vkFreeMemory(m_device->device(), srcMem, NULL);
16238 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016239}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016240
Karl Schultz6addd812016-02-02 17:17:23 -070016241TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016242 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016243 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16244 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016245 // The image format check comes 2nd in validation so we trigger it first,
16246 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016247 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016248
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16250 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016251
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016252 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016253
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016254 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016255 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16256 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016257
16258 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016259 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16260 ds_pool_ci.pNext = NULL;
16261 ds_pool_ci.maxSets = 1;
16262 ds_pool_ci.poolSizeCount = 1;
16263 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016264
16265 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016266 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016267 ASSERT_VK_SUCCESS(err);
16268
16269 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016270 dsl_binding.binding = 0;
16271 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16272 dsl_binding.descriptorCount = 1;
16273 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16274 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016275
16276 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016277 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16278 ds_layout_ci.pNext = NULL;
16279 ds_layout_ci.bindingCount = 1;
16280 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016281 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016282 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016283 ASSERT_VK_SUCCESS(err);
16284
16285 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016286 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016287 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016288 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016289 alloc_info.descriptorPool = ds_pool;
16290 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016291 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016292 ASSERT_VK_SUCCESS(err);
16293
Karl Schultz6addd812016-02-02 17:17:23 -070016294 VkImage image_bad;
16295 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016296 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016297 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016298 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016299 const int32_t tex_width = 32;
16300 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016301
16302 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016303 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16304 image_create_info.pNext = NULL;
16305 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16306 image_create_info.format = tex_format_bad;
16307 image_create_info.extent.width = tex_width;
16308 image_create_info.extent.height = tex_height;
16309 image_create_info.extent.depth = 1;
16310 image_create_info.mipLevels = 1;
16311 image_create_info.arrayLayers = 1;
16312 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16313 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016314 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016315 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016316
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016317 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016318 ASSERT_VK_SUCCESS(err);
16319 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016320 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16321 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016322 ASSERT_VK_SUCCESS(err);
16323
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016324 // ---Bind image memory---
16325 VkMemoryRequirements img_mem_reqs;
16326 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
16327 VkMemoryAllocateInfo image_alloc_info = {};
16328 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16329 image_alloc_info.pNext = NULL;
16330 image_alloc_info.memoryTypeIndex = 0;
16331 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016332 bool pass =
16333 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 -070016334 ASSERT_TRUE(pass);
16335 VkDeviceMemory mem;
16336 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
16337 ASSERT_VK_SUCCESS(err);
16338 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
16339 ASSERT_VK_SUCCESS(err);
16340 // -----------------------
16341
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016342 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016343 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016344 image_view_create_info.image = image_bad;
16345 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16346 image_view_create_info.format = tex_format_bad;
16347 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16348 image_view_create_info.subresourceRange.baseMipLevel = 0;
16349 image_view_create_info.subresourceRange.layerCount = 1;
16350 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016351 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016352
16353 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016354 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016355
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016356 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016357
Chia-I Wuf7458c52015-10-26 21:10:41 +080016358 vkDestroyImage(m_device->device(), image_bad, NULL);
16359 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016360 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16361 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016362
16363 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016364}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016365
16366TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016367 TEST_DESCRIPTION(
16368 "Call ClearColorImage w/ a depth|stencil image and "
16369 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016370
16371 ASSERT_NO_FATAL_FAILURE(InitState());
16372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16373
Tony Barbour552f6c02016-12-21 14:34:07 -070016374 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016375
16376 // Color image
16377 VkClearColorValue clear_color;
16378 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16379 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16380 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16381 const int32_t img_width = 32;
16382 const int32_t img_height = 32;
16383 VkImageCreateInfo image_create_info = {};
16384 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16385 image_create_info.pNext = NULL;
16386 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16387 image_create_info.format = color_format;
16388 image_create_info.extent.width = img_width;
16389 image_create_info.extent.height = img_height;
16390 image_create_info.extent.depth = 1;
16391 image_create_info.mipLevels = 1;
16392 image_create_info.arrayLayers = 1;
16393 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16394 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16395 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16396
16397 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016398 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016399
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016400 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016401
16402 // Depth/Stencil image
16403 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016404 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016405 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16406 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16407 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16408 ds_image_create_info.extent.width = 64;
16409 ds_image_create_info.extent.height = 64;
16410 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016411 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 -060016412
16413 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016414 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016415
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016416 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 -060016417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016419
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016420 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016421 &color_range);
16422
16423 m_errorMonitor->VerifyFound();
16424
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16426 "vkCmdClearColorImage called with "
16427 "image created without "
16428 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016429
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016430 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016431 &color_range);
16432
16433 m_errorMonitor->VerifyFound();
16434
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016435 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16437 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016438
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016439 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
16440 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016441
16442 m_errorMonitor->VerifyFound();
16443}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016444#endif // IMAGE_TESTS
Tobin Ehliscde08892015-09-22 10:11:37 -060016445
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016446// WSI Enabled Tests
16447//
Chris Forbes09368e42016-10-13 11:59:22 +130016448#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016449TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
16450
16451#if defined(VK_USE_PLATFORM_XCB_KHR)
16452 VkSurfaceKHR surface = VK_NULL_HANDLE;
16453
16454 VkResult err;
16455 bool pass;
16456 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
16457 VkSwapchainCreateInfoKHR swapchain_create_info = {};
16458 // uint32_t swapchain_image_count = 0;
16459 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
16460 // uint32_t image_index = 0;
16461 // VkPresentInfoKHR present_info = {};
16462
16463 ASSERT_NO_FATAL_FAILURE(InitState());
16464
16465 // Use the create function from one of the VK_KHR_*_surface extension in
16466 // order to create a surface, testing all known errors in the process,
16467 // before successfully creating a surface:
16468 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
16469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
16470 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
16471 pass = (err != VK_SUCCESS);
16472 ASSERT_TRUE(pass);
16473 m_errorMonitor->VerifyFound();
16474
16475 // Next, try to create a surface with the wrong
16476 // VkXcbSurfaceCreateInfoKHR::sType:
16477 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
16478 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16480 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16481 pass = (err != VK_SUCCESS);
16482 ASSERT_TRUE(pass);
16483 m_errorMonitor->VerifyFound();
16484
16485 // Create a native window, and then correctly create a surface:
16486 xcb_connection_t *connection;
16487 xcb_screen_t *screen;
16488 xcb_window_t xcb_window;
16489 xcb_intern_atom_reply_t *atom_wm_delete_window;
16490
16491 const xcb_setup_t *setup;
16492 xcb_screen_iterator_t iter;
16493 int scr;
16494 uint32_t value_mask, value_list[32];
16495 int width = 1;
16496 int height = 1;
16497
16498 connection = xcb_connect(NULL, &scr);
16499 ASSERT_TRUE(connection != NULL);
16500 setup = xcb_get_setup(connection);
16501 iter = xcb_setup_roots_iterator(setup);
16502 while (scr-- > 0)
16503 xcb_screen_next(&iter);
16504 screen = iter.data;
16505
16506 xcb_window = xcb_generate_id(connection);
16507
16508 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
16509 value_list[0] = screen->black_pixel;
16510 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
16511
16512 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
16513 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
16514
16515 /* Magic code that will send notification when window is destroyed */
16516 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
16517 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
16518
16519 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
16520 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
16521 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
16522 free(reply);
16523
16524 xcb_map_window(connection, xcb_window);
16525
16526 // Force the x/y coordinates to 100,100 results are identical in consecutive
16527 // runs
16528 const uint32_t coords[] = { 100, 100 };
16529 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
16530
16531 // Finally, try to correctly create a surface:
16532 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
16533 xcb_create_info.pNext = NULL;
16534 xcb_create_info.flags = 0;
16535 xcb_create_info.connection = connection;
16536 xcb_create_info.window = xcb_window;
16537 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16538 pass = (err == VK_SUCCESS);
16539 ASSERT_TRUE(pass);
16540
16541 // Check if surface supports presentation:
16542
16543 // 1st, do so without having queried the queue families:
16544 VkBool32 supported = false;
16545 // TODO: Get the following error to come out:
16546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16547 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
16548 "function");
16549 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16550 pass = (err != VK_SUCCESS);
16551 // ASSERT_TRUE(pass);
16552 // m_errorMonitor->VerifyFound();
16553
16554 // Next, query a queue family index that's too large:
16555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16556 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
16557 pass = (err != VK_SUCCESS);
16558 ASSERT_TRUE(pass);
16559 m_errorMonitor->VerifyFound();
16560
16561 // Finally, do so correctly:
16562 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16563 // SUPPORTED
16564 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16565 pass = (err == VK_SUCCESS);
16566 ASSERT_TRUE(pass);
16567
16568 // Before proceeding, try to create a swapchain without having called
16569 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
16570 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16571 swapchain_create_info.pNext = NULL;
16572 swapchain_create_info.flags = 0;
16573 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16574 swapchain_create_info.surface = surface;
16575 swapchain_create_info.imageArrayLayers = 1;
16576 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
16577 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
16578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16579 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
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 // Get the surface capabilities:
16586 VkSurfaceCapabilitiesKHR surface_capabilities;
16587
16588 // Do so correctly (only error logged by this entrypoint is if the
16589 // extension isn't enabled):
16590 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
16591 pass = (err == VK_SUCCESS);
16592 ASSERT_TRUE(pass);
16593
16594 // Get the surface formats:
16595 uint32_t surface_format_count;
16596
16597 // First, try without a pointer to surface_format_count:
16598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
16599 "specified as NULL");
16600 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
16601 pass = (err == VK_SUCCESS);
16602 ASSERT_TRUE(pass);
16603 m_errorMonitor->VerifyFound();
16604
16605 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
16606 // correctly done a 1st try (to get the count):
16607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16608 surface_format_count = 0;
16609 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
16610 pass = (err == VK_SUCCESS);
16611 ASSERT_TRUE(pass);
16612 m_errorMonitor->VerifyFound();
16613
16614 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16615 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16616 pass = (err == VK_SUCCESS);
16617 ASSERT_TRUE(pass);
16618
16619 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16620 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
16621
16622 // Next, do a 2nd try with surface_format_count being set too high:
16623 surface_format_count += 5;
16624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16625 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16626 pass = (err == VK_SUCCESS);
16627 ASSERT_TRUE(pass);
16628 m_errorMonitor->VerifyFound();
16629
16630 // Finally, do a correct 1st and 2nd try:
16631 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16632 pass = (err == VK_SUCCESS);
16633 ASSERT_TRUE(pass);
16634 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16635 pass = (err == VK_SUCCESS);
16636 ASSERT_TRUE(pass);
16637
16638 // Get the surface present modes:
16639 uint32_t surface_present_mode_count;
16640
16641 // First, try without a pointer to surface_format_count:
16642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16643 "specified as NULL");
16644
16645 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16646 pass = (err == VK_SUCCESS);
16647 ASSERT_TRUE(pass);
16648 m_errorMonitor->VerifyFound();
16649
16650 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16651 // correctly done a 1st try (to get the count):
16652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16653 surface_present_mode_count = 0;
16654 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16655 (VkPresentModeKHR *)&surface_present_mode_count);
16656 pass = (err == VK_SUCCESS);
16657 ASSERT_TRUE(pass);
16658 m_errorMonitor->VerifyFound();
16659
16660 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16661 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16662 pass = (err == VK_SUCCESS);
16663 ASSERT_TRUE(pass);
16664
16665 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16666 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16667
16668 // Next, do a 2nd try with surface_format_count being set too high:
16669 surface_present_mode_count += 5;
16670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16671 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16672 pass = (err == VK_SUCCESS);
16673 ASSERT_TRUE(pass);
16674 m_errorMonitor->VerifyFound();
16675
16676 // Finally, do a correct 1st and 2nd try:
16677 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16678 pass = (err == VK_SUCCESS);
16679 ASSERT_TRUE(pass);
16680 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16681 pass = (err == VK_SUCCESS);
16682 ASSERT_TRUE(pass);
16683
16684 // Create a swapchain:
16685
16686 // First, try without a pointer to swapchain_create_info:
16687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16688 "specified as NULL");
16689
16690 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16691 pass = (err != VK_SUCCESS);
16692 ASSERT_TRUE(pass);
16693 m_errorMonitor->VerifyFound();
16694
16695 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16696 // sType:
16697 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16699
16700 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16701 pass = (err != VK_SUCCESS);
16702 ASSERT_TRUE(pass);
16703 m_errorMonitor->VerifyFound();
16704
16705 // Next, call with a NULL swapchain pointer:
16706 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16707 swapchain_create_info.pNext = NULL;
16708 swapchain_create_info.flags = 0;
16709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16710 "specified as NULL");
16711
16712 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16713 pass = (err != VK_SUCCESS);
16714 ASSERT_TRUE(pass);
16715 m_errorMonitor->VerifyFound();
16716
16717 // TODO: Enhance swapchain layer so that
16718 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16719
16720 // Next, call with a queue family index that's too large:
16721 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16722 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16723 swapchain_create_info.queueFamilyIndexCount = 2;
16724 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16726 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16727 pass = (err != VK_SUCCESS);
16728 ASSERT_TRUE(pass);
16729 m_errorMonitor->VerifyFound();
16730
16731 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16732 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16733 swapchain_create_info.queueFamilyIndexCount = 1;
16734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16735 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16736 "pCreateInfo->pQueueFamilyIndices).");
16737 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16738 pass = (err != VK_SUCCESS);
16739 ASSERT_TRUE(pass);
16740 m_errorMonitor->VerifyFound();
16741
16742 // Next, call with an invalid imageSharingMode:
16743 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16744 swapchain_create_info.queueFamilyIndexCount = 1;
16745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16746 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16747 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16748 pass = (err != VK_SUCCESS);
16749 ASSERT_TRUE(pass);
16750 m_errorMonitor->VerifyFound();
16751 // Fix for the future:
16752 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16753 // SUPPORTED
16754 swapchain_create_info.queueFamilyIndexCount = 0;
16755 queueFamilyIndex[0] = 0;
16756 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16757
16758 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16759 // Get the images from a swapchain:
16760 // Acquire an image from a swapchain:
16761 // Present an image to a swapchain:
16762 // Destroy the swapchain:
16763
16764 // TODOs:
16765 //
16766 // - Try destroying the device without first destroying the swapchain
16767 //
16768 // - Try destroying the device without first destroying the surface
16769 //
16770 // - Try destroying the surface without first destroying the swapchain
16771
16772 // Destroy the surface:
16773 vkDestroySurfaceKHR(instance(), surface, NULL);
16774
16775 // Tear down the window:
16776 xcb_destroy_window(connection, xcb_window);
16777 xcb_disconnect(connection);
16778
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016779#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016780 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016781#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016782}
Chris Forbes09368e42016-10-13 11:59:22 +130016783#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016784
16785//
16786// POSITIVE VALIDATION TESTS
16787//
16788// These tests do not expect to encounter ANY validation errors pass only if this is true
16789
Tobin Ehlise0006882016-11-03 10:14:28 -060016790TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016791 TEST_DESCRIPTION(
16792 "Perform an image layout transition in a secondary command buffer followed "
16793 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060016794 VkResult err;
16795 m_errorMonitor->ExpectSuccess();
16796 ASSERT_NO_FATAL_FAILURE(InitState());
16797 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16798 // Allocate a secondary and primary cmd buffer
16799 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16800 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16801 command_buffer_allocate_info.commandPool = m_commandPool;
16802 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16803 command_buffer_allocate_info.commandBufferCount = 1;
16804
16805 VkCommandBuffer secondary_command_buffer;
16806 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16807 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16808 VkCommandBuffer primary_command_buffer;
16809 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16810 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16811 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16812 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16813 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16814 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16815 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16816
16817 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16818 ASSERT_VK_SUCCESS(err);
16819 VkImageObj image(m_device);
16820 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16821 ASSERT_TRUE(image.initialized());
16822 VkImageMemoryBarrier img_barrier = {};
16823 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16824 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16825 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16826 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16827 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16828 img_barrier.image = image.handle();
16829 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16830 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16831 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16832 img_barrier.subresourceRange.baseArrayLayer = 0;
16833 img_barrier.subresourceRange.baseMipLevel = 0;
16834 img_barrier.subresourceRange.layerCount = 1;
16835 img_barrier.subresourceRange.levelCount = 1;
16836 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16837 0, nullptr, 1, &img_barrier);
16838 err = vkEndCommandBuffer(secondary_command_buffer);
16839 ASSERT_VK_SUCCESS(err);
16840
16841 // Now update primary cmd buffer to execute secondary and transitions image
16842 command_buffer_begin_info.pInheritanceInfo = nullptr;
16843 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16844 ASSERT_VK_SUCCESS(err);
16845 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16846 VkImageMemoryBarrier img_barrier2 = {};
16847 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16848 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16849 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16850 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16851 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16852 img_barrier2.image = image.handle();
16853 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16854 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16855 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16856 img_barrier2.subresourceRange.baseArrayLayer = 0;
16857 img_barrier2.subresourceRange.baseMipLevel = 0;
16858 img_barrier2.subresourceRange.layerCount = 1;
16859 img_barrier2.subresourceRange.levelCount = 1;
16860 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16861 nullptr, 1, &img_barrier2);
16862 err = vkEndCommandBuffer(primary_command_buffer);
16863 ASSERT_VK_SUCCESS(err);
16864 VkSubmitInfo submit_info = {};
16865 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16866 submit_info.commandBufferCount = 1;
16867 submit_info.pCommandBuffers = &primary_command_buffer;
16868 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16869 ASSERT_VK_SUCCESS(err);
16870 m_errorMonitor->VerifyNotFound();
16871 err = vkDeviceWaitIdle(m_device->device());
16872 ASSERT_VK_SUCCESS(err);
16873 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16874 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16875}
16876
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016877// This is a positive test. No failures are expected.
16878TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016879 TEST_DESCRIPTION(
16880 "Ensure that the vkUpdateDescriptorSets validation code "
16881 "is ignoring VkWriteDescriptorSet members that are not "
16882 "related to the descriptor type specified by "
16883 "VkWriteDescriptorSet::descriptorType. Correct "
16884 "validation behavior will result in the test running to "
16885 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016886
16887 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16888
16889 ASSERT_NO_FATAL_FAILURE(InitState());
16890
16891 // Image Case
16892 {
16893 m_errorMonitor->ExpectSuccess();
16894
16895 VkImage image;
16896 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16897 const int32_t tex_width = 32;
16898 const int32_t tex_height = 32;
16899 VkImageCreateInfo image_create_info = {};
16900 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16901 image_create_info.pNext = NULL;
16902 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16903 image_create_info.format = tex_format;
16904 image_create_info.extent.width = tex_width;
16905 image_create_info.extent.height = tex_height;
16906 image_create_info.extent.depth = 1;
16907 image_create_info.mipLevels = 1;
16908 image_create_info.arrayLayers = 1;
16909 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16910 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16911 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16912 image_create_info.flags = 0;
16913 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16914 ASSERT_VK_SUCCESS(err);
16915
16916 VkMemoryRequirements memory_reqs;
16917 VkDeviceMemory image_memory;
16918 bool pass;
16919 VkMemoryAllocateInfo memory_info = {};
16920 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16921 memory_info.pNext = NULL;
16922 memory_info.allocationSize = 0;
16923 memory_info.memoryTypeIndex = 0;
16924 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16925 memory_info.allocationSize = memory_reqs.size;
16926 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16927 ASSERT_TRUE(pass);
16928 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16929 ASSERT_VK_SUCCESS(err);
16930 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16931 ASSERT_VK_SUCCESS(err);
16932
16933 VkImageViewCreateInfo image_view_create_info = {};
16934 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16935 image_view_create_info.image = image;
16936 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16937 image_view_create_info.format = tex_format;
16938 image_view_create_info.subresourceRange.layerCount = 1;
16939 image_view_create_info.subresourceRange.baseMipLevel = 0;
16940 image_view_create_info.subresourceRange.levelCount = 1;
16941 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16942
16943 VkImageView view;
16944 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16945 ASSERT_VK_SUCCESS(err);
16946
16947 VkDescriptorPoolSize ds_type_count = {};
16948 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16949 ds_type_count.descriptorCount = 1;
16950
16951 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16952 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16953 ds_pool_ci.pNext = NULL;
16954 ds_pool_ci.maxSets = 1;
16955 ds_pool_ci.poolSizeCount = 1;
16956 ds_pool_ci.pPoolSizes = &ds_type_count;
16957
16958 VkDescriptorPool ds_pool;
16959 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16960 ASSERT_VK_SUCCESS(err);
16961
16962 VkDescriptorSetLayoutBinding dsl_binding = {};
16963 dsl_binding.binding = 0;
16964 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16965 dsl_binding.descriptorCount = 1;
16966 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16967 dsl_binding.pImmutableSamplers = NULL;
16968
16969 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16970 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16971 ds_layout_ci.pNext = NULL;
16972 ds_layout_ci.bindingCount = 1;
16973 ds_layout_ci.pBindings = &dsl_binding;
16974 VkDescriptorSetLayout ds_layout;
16975 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16976 ASSERT_VK_SUCCESS(err);
16977
16978 VkDescriptorSet descriptor_set;
16979 VkDescriptorSetAllocateInfo alloc_info = {};
16980 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16981 alloc_info.descriptorSetCount = 1;
16982 alloc_info.descriptorPool = ds_pool;
16983 alloc_info.pSetLayouts = &ds_layout;
16984 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16985 ASSERT_VK_SUCCESS(err);
16986
16987 VkDescriptorImageInfo image_info = {};
16988 image_info.imageView = view;
16989 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16990
16991 VkWriteDescriptorSet descriptor_write;
16992 memset(&descriptor_write, 0, sizeof(descriptor_write));
16993 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16994 descriptor_write.dstSet = descriptor_set;
16995 descriptor_write.dstBinding = 0;
16996 descriptor_write.descriptorCount = 1;
16997 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16998 descriptor_write.pImageInfo = &image_info;
16999
17000 // Set pBufferInfo and pTexelBufferView to invalid values, which should
17001 // be
17002 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
17003 // This will most likely produce a crash if the parameter_validation
17004 // layer
17005 // does not correctly ignore pBufferInfo.
17006 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17007 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17008
17009 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17010
17011 m_errorMonitor->VerifyNotFound();
17012
17013 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17014 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17015 vkDestroyImageView(m_device->device(), view, NULL);
17016 vkDestroyImage(m_device->device(), image, NULL);
17017 vkFreeMemory(m_device->device(), image_memory, NULL);
17018 }
17019
17020 // Buffer Case
17021 {
17022 m_errorMonitor->ExpectSuccess();
17023
17024 VkBuffer buffer;
17025 uint32_t queue_family_index = 0;
17026 VkBufferCreateInfo buffer_create_info = {};
17027 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17028 buffer_create_info.size = 1024;
17029 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17030 buffer_create_info.queueFamilyIndexCount = 1;
17031 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17032
17033 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17034 ASSERT_VK_SUCCESS(err);
17035
17036 VkMemoryRequirements memory_reqs;
17037 VkDeviceMemory buffer_memory;
17038 bool pass;
17039 VkMemoryAllocateInfo memory_info = {};
17040 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17041 memory_info.pNext = NULL;
17042 memory_info.allocationSize = 0;
17043 memory_info.memoryTypeIndex = 0;
17044
17045 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
17046 memory_info.allocationSize = memory_reqs.size;
17047 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17048 ASSERT_TRUE(pass);
17049
17050 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17051 ASSERT_VK_SUCCESS(err);
17052 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17053 ASSERT_VK_SUCCESS(err);
17054
17055 VkDescriptorPoolSize ds_type_count = {};
17056 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17057 ds_type_count.descriptorCount = 1;
17058
17059 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17060 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17061 ds_pool_ci.pNext = NULL;
17062 ds_pool_ci.maxSets = 1;
17063 ds_pool_ci.poolSizeCount = 1;
17064 ds_pool_ci.pPoolSizes = &ds_type_count;
17065
17066 VkDescriptorPool ds_pool;
17067 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17068 ASSERT_VK_SUCCESS(err);
17069
17070 VkDescriptorSetLayoutBinding dsl_binding = {};
17071 dsl_binding.binding = 0;
17072 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17073 dsl_binding.descriptorCount = 1;
17074 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17075 dsl_binding.pImmutableSamplers = NULL;
17076
17077 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17078 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17079 ds_layout_ci.pNext = NULL;
17080 ds_layout_ci.bindingCount = 1;
17081 ds_layout_ci.pBindings = &dsl_binding;
17082 VkDescriptorSetLayout ds_layout;
17083 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17084 ASSERT_VK_SUCCESS(err);
17085
17086 VkDescriptorSet descriptor_set;
17087 VkDescriptorSetAllocateInfo alloc_info = {};
17088 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17089 alloc_info.descriptorSetCount = 1;
17090 alloc_info.descriptorPool = ds_pool;
17091 alloc_info.pSetLayouts = &ds_layout;
17092 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17093 ASSERT_VK_SUCCESS(err);
17094
17095 VkDescriptorBufferInfo buffer_info = {};
17096 buffer_info.buffer = buffer;
17097 buffer_info.offset = 0;
17098 buffer_info.range = 1024;
17099
17100 VkWriteDescriptorSet descriptor_write;
17101 memset(&descriptor_write, 0, sizeof(descriptor_write));
17102 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17103 descriptor_write.dstSet = descriptor_set;
17104 descriptor_write.dstBinding = 0;
17105 descriptor_write.descriptorCount = 1;
17106 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17107 descriptor_write.pBufferInfo = &buffer_info;
17108
17109 // Set pImageInfo and pTexelBufferView to invalid values, which should
17110 // be
17111 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
17112 // This will most likely produce a crash if the parameter_validation
17113 // layer
17114 // does not correctly ignore pImageInfo.
17115 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17116 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17117
17118 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17119
17120 m_errorMonitor->VerifyNotFound();
17121
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017122 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17123 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17124 vkDestroyBuffer(m_device->device(), buffer, NULL);
17125 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17126 }
17127
17128 // Texel Buffer Case
17129 {
17130 m_errorMonitor->ExpectSuccess();
17131
17132 VkBuffer buffer;
17133 uint32_t queue_family_index = 0;
17134 VkBufferCreateInfo buffer_create_info = {};
17135 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17136 buffer_create_info.size = 1024;
17137 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
17138 buffer_create_info.queueFamilyIndexCount = 1;
17139 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17140
17141 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17142 ASSERT_VK_SUCCESS(err);
17143
17144 VkMemoryRequirements memory_reqs;
17145 VkDeviceMemory buffer_memory;
17146 bool pass;
17147 VkMemoryAllocateInfo memory_info = {};
17148 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17149 memory_info.pNext = NULL;
17150 memory_info.allocationSize = 0;
17151 memory_info.memoryTypeIndex = 0;
17152
17153 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
17154 memory_info.allocationSize = memory_reqs.size;
17155 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17156 ASSERT_TRUE(pass);
17157
17158 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17159 ASSERT_VK_SUCCESS(err);
17160 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17161 ASSERT_VK_SUCCESS(err);
17162
17163 VkBufferViewCreateInfo buff_view_ci = {};
17164 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
17165 buff_view_ci.buffer = buffer;
17166 buff_view_ci.format = VK_FORMAT_R8_UNORM;
17167 buff_view_ci.range = VK_WHOLE_SIZE;
17168 VkBufferView buffer_view;
17169 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
17170
17171 VkDescriptorPoolSize ds_type_count = {};
17172 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17173 ds_type_count.descriptorCount = 1;
17174
17175 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17176 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17177 ds_pool_ci.pNext = NULL;
17178 ds_pool_ci.maxSets = 1;
17179 ds_pool_ci.poolSizeCount = 1;
17180 ds_pool_ci.pPoolSizes = &ds_type_count;
17181
17182 VkDescriptorPool ds_pool;
17183 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17184 ASSERT_VK_SUCCESS(err);
17185
17186 VkDescriptorSetLayoutBinding dsl_binding = {};
17187 dsl_binding.binding = 0;
17188 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17189 dsl_binding.descriptorCount = 1;
17190 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17191 dsl_binding.pImmutableSamplers = NULL;
17192
17193 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17194 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17195 ds_layout_ci.pNext = NULL;
17196 ds_layout_ci.bindingCount = 1;
17197 ds_layout_ci.pBindings = &dsl_binding;
17198 VkDescriptorSetLayout ds_layout;
17199 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17200 ASSERT_VK_SUCCESS(err);
17201
17202 VkDescriptorSet descriptor_set;
17203 VkDescriptorSetAllocateInfo alloc_info = {};
17204 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17205 alloc_info.descriptorSetCount = 1;
17206 alloc_info.descriptorPool = ds_pool;
17207 alloc_info.pSetLayouts = &ds_layout;
17208 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17209 ASSERT_VK_SUCCESS(err);
17210
17211 VkWriteDescriptorSet descriptor_write;
17212 memset(&descriptor_write, 0, sizeof(descriptor_write));
17213 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17214 descriptor_write.dstSet = descriptor_set;
17215 descriptor_write.dstBinding = 0;
17216 descriptor_write.descriptorCount = 1;
17217 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17218 descriptor_write.pTexelBufferView = &buffer_view;
17219
17220 // Set pImageInfo and pBufferInfo to invalid values, which should be
17221 // ignored for descriptorType ==
17222 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
17223 // This will most likely produce a crash if the parameter_validation
17224 // layer
17225 // does not correctly ignore pImageInfo and pBufferInfo.
17226 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17227 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17228
17229 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17230
17231 m_errorMonitor->VerifyNotFound();
17232
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017233 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17234 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17235 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
17236 vkDestroyBuffer(m_device->device(), buffer, NULL);
17237 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17238 }
17239}
17240
Tobin Ehlisf7428442016-10-25 07:58:24 -060017241TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
17242 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
17243
17244 ASSERT_NO_FATAL_FAILURE(InitState());
17245 // Create layout where two binding #s are "1"
17246 static const uint32_t NUM_BINDINGS = 3;
17247 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17248 dsl_binding[0].binding = 1;
17249 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17250 dsl_binding[0].descriptorCount = 1;
17251 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17252 dsl_binding[0].pImmutableSamplers = NULL;
17253 dsl_binding[1].binding = 0;
17254 dsl_binding[1].descriptorCount = 1;
17255 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17256 dsl_binding[1].descriptorCount = 1;
17257 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17258 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017259 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060017260 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17261 dsl_binding[2].descriptorCount = 1;
17262 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17263 dsl_binding[2].pImmutableSamplers = NULL;
17264
17265 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17266 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17267 ds_layout_ci.pNext = NULL;
17268 ds_layout_ci.bindingCount = NUM_BINDINGS;
17269 ds_layout_ci.pBindings = dsl_binding;
17270 VkDescriptorSetLayout ds_layout;
17271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
17272 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17273 m_errorMonitor->VerifyFound();
17274}
17275
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017276TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017277 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
17278
17279 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017280
Tony Barbour552f6c02016-12-21 14:34:07 -070017281 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017282
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017283 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
17284
17285 {
17286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
17287 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
17288 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17289 m_errorMonitor->VerifyFound();
17290 }
17291
17292 {
17293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
17294 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
17295 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17296 m_errorMonitor->VerifyFound();
17297 }
17298
17299 {
17300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17301 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
17302 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17303 m_errorMonitor->VerifyFound();
17304 }
17305
17306 {
17307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17308 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
17309 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17310 m_errorMonitor->VerifyFound();
17311 }
17312
17313 {
17314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
17315 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
17316 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17317 m_errorMonitor->VerifyFound();
17318 }
17319
17320 {
17321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
17322 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
17323 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17324 m_errorMonitor->VerifyFound();
17325 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017326
17327 {
17328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17329 VkRect2D scissor = {{-1, 0}, {16, 16}};
17330 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17331 m_errorMonitor->VerifyFound();
17332 }
17333
17334 {
17335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17336 VkRect2D scissor = {{0, -2}, {16, 16}};
17337 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17338 m_errorMonitor->VerifyFound();
17339 }
17340
17341 {
17342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
17343 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
17344 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17345 m_errorMonitor->VerifyFound();
17346 }
17347
17348 {
17349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
17350 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
17351 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17352 m_errorMonitor->VerifyFound();
17353 }
17354
Tony Barbour552f6c02016-12-21 14:34:07 -070017355 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017356}
17357
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017358// This is a positive test. No failures are expected.
17359TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
17360 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
17361 VkResult err;
17362
17363 ASSERT_NO_FATAL_FAILURE(InitState());
17364 m_errorMonitor->ExpectSuccess();
17365 VkDescriptorPoolSize ds_type_count = {};
17366 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17367 ds_type_count.descriptorCount = 2;
17368
17369 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17370 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17371 ds_pool_ci.pNext = NULL;
17372 ds_pool_ci.maxSets = 1;
17373 ds_pool_ci.poolSizeCount = 1;
17374 ds_pool_ci.pPoolSizes = &ds_type_count;
17375
17376 VkDescriptorPool ds_pool;
17377 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17378 ASSERT_VK_SUCCESS(err);
17379
17380 // Create layout with two uniform buffer descriptors w/ empty binding between them
17381 static const uint32_t NUM_BINDINGS = 3;
17382 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17383 dsl_binding[0].binding = 0;
17384 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17385 dsl_binding[0].descriptorCount = 1;
17386 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
17387 dsl_binding[0].pImmutableSamplers = NULL;
17388 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017389 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017390 dsl_binding[2].binding = 2;
17391 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17392 dsl_binding[2].descriptorCount = 1;
17393 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
17394 dsl_binding[2].pImmutableSamplers = NULL;
17395
17396 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17397 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17398 ds_layout_ci.pNext = NULL;
17399 ds_layout_ci.bindingCount = NUM_BINDINGS;
17400 ds_layout_ci.pBindings = dsl_binding;
17401 VkDescriptorSetLayout ds_layout;
17402 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17403 ASSERT_VK_SUCCESS(err);
17404
17405 VkDescriptorSet descriptor_set = {};
17406 VkDescriptorSetAllocateInfo alloc_info = {};
17407 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17408 alloc_info.descriptorSetCount = 1;
17409 alloc_info.descriptorPool = ds_pool;
17410 alloc_info.pSetLayouts = &ds_layout;
17411 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17412 ASSERT_VK_SUCCESS(err);
17413
17414 // Create a buffer to be used for update
17415 VkBufferCreateInfo buff_ci = {};
17416 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17417 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17418 buff_ci.size = 256;
17419 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17420 VkBuffer buffer;
17421 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
17422 ASSERT_VK_SUCCESS(err);
17423 // Have to bind memory to buffer before descriptor update
17424 VkMemoryAllocateInfo mem_alloc = {};
17425 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17426 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017427 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017428 mem_alloc.memoryTypeIndex = 0;
17429
17430 VkMemoryRequirements mem_reqs;
17431 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17432 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
17433 if (!pass) {
17434 vkDestroyBuffer(m_device->device(), buffer, NULL);
17435 return;
17436 }
17437
17438 VkDeviceMemory mem;
17439 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17440 ASSERT_VK_SUCCESS(err);
17441 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17442 ASSERT_VK_SUCCESS(err);
17443
17444 // Only update the descriptor at binding 2
17445 VkDescriptorBufferInfo buff_info = {};
17446 buff_info.buffer = buffer;
17447 buff_info.offset = 0;
17448 buff_info.range = VK_WHOLE_SIZE;
17449 VkWriteDescriptorSet descriptor_write = {};
17450 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17451 descriptor_write.dstBinding = 2;
17452 descriptor_write.descriptorCount = 1;
17453 descriptor_write.pTexelBufferView = nullptr;
17454 descriptor_write.pBufferInfo = &buff_info;
17455 descriptor_write.pImageInfo = nullptr;
17456 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17457 descriptor_write.dstSet = descriptor_set;
17458
17459 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17460
17461 m_errorMonitor->VerifyNotFound();
17462 // Cleanup
17463 vkFreeMemory(m_device->device(), mem, NULL);
17464 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17465 vkDestroyBuffer(m_device->device(), buffer, NULL);
17466 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17467}
17468
17469// This is a positive test. No failures are expected.
17470TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
17471 VkResult err;
17472 bool pass;
17473
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017474 TEST_DESCRIPTION(
17475 "Create a buffer, allocate memory, bind memory, destroy "
17476 "the buffer, create an image, and bind the same memory to "
17477 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017478
17479 m_errorMonitor->ExpectSuccess();
17480
17481 ASSERT_NO_FATAL_FAILURE(InitState());
17482
17483 VkBuffer buffer;
17484 VkImage image;
17485 VkDeviceMemory mem;
17486 VkMemoryRequirements mem_reqs;
17487
17488 VkBufferCreateInfo buf_info = {};
17489 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17490 buf_info.pNext = NULL;
17491 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17492 buf_info.size = 256;
17493 buf_info.queueFamilyIndexCount = 0;
17494 buf_info.pQueueFamilyIndices = NULL;
17495 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17496 buf_info.flags = 0;
17497 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
17498 ASSERT_VK_SUCCESS(err);
17499
17500 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17501
17502 VkMemoryAllocateInfo alloc_info = {};
17503 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17504 alloc_info.pNext = NULL;
17505 alloc_info.memoryTypeIndex = 0;
17506
17507 // Ensure memory is big enough for both bindings
17508 alloc_info.allocationSize = 0x10000;
17509
17510 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17511 if (!pass) {
17512 vkDestroyBuffer(m_device->device(), buffer, NULL);
17513 return;
17514 }
17515
17516 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17517 ASSERT_VK_SUCCESS(err);
17518
17519 uint8_t *pData;
17520 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
17521 ASSERT_VK_SUCCESS(err);
17522
17523 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
17524
17525 vkUnmapMemory(m_device->device(), mem);
17526
17527 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17528 ASSERT_VK_SUCCESS(err);
17529
17530 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
17531 // memory. In fact, it was never used by the GPU.
17532 // Just be be sure, wait for idle.
17533 vkDestroyBuffer(m_device->device(), buffer, NULL);
17534 vkDeviceWaitIdle(m_device->device());
17535
Tobin Ehlis6a005702016-12-28 15:25:56 -070017536 // Use optimal as some platforms report linear support but then fail image creation
17537 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
17538 VkImageFormatProperties image_format_properties;
17539 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
17540 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
17541 if (image_format_properties.maxExtent.width == 0) {
17542 printf("Image format not supported; skipped.\n");
17543 vkFreeMemory(m_device->device(), mem, NULL);
17544 return;
17545 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017546 VkImageCreateInfo image_create_info = {};
17547 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17548 image_create_info.pNext = NULL;
17549 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17550 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
17551 image_create_info.extent.width = 64;
17552 image_create_info.extent.height = 64;
17553 image_create_info.extent.depth = 1;
17554 image_create_info.mipLevels = 1;
17555 image_create_info.arrayLayers = 1;
17556 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070017557 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017558 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
17559 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17560 image_create_info.queueFamilyIndexCount = 0;
17561 image_create_info.pQueueFamilyIndices = NULL;
17562 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17563 image_create_info.flags = 0;
17564
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017565 /* Create a mappable image. It will be the texture if linear images are ok
17566 * to be textures or it will be the staging image if they are not.
17567 */
17568 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17569 ASSERT_VK_SUCCESS(err);
17570
17571 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
17572
Tobin Ehlis6a005702016-12-28 15:25:56 -070017573 VkMemoryAllocateInfo mem_alloc = {};
17574 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17575 mem_alloc.pNext = NULL;
17576 mem_alloc.allocationSize = 0;
17577 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017578 mem_alloc.allocationSize = mem_reqs.size;
17579
17580 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17581 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070017582 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017583 vkDestroyImage(m_device->device(), image, NULL);
17584 return;
17585 }
17586
17587 // VALIDATION FAILURE:
17588 err = vkBindImageMemory(m_device->device(), image, mem, 0);
17589 ASSERT_VK_SUCCESS(err);
17590
17591 m_errorMonitor->VerifyNotFound();
17592
17593 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017594 vkDestroyImage(m_device->device(), image, NULL);
17595}
17596
Tony Barbourab713912017-02-02 14:17:35 -070017597// This is a positive test. No failures are expected.
17598TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
17599 VkResult err;
17600
17601 TEST_DESCRIPTION(
17602 "Call all applicable destroy and free routines with NULL"
17603 "handles, expecting no validation errors");
17604
17605 m_errorMonitor->ExpectSuccess();
17606
17607 ASSERT_NO_FATAL_FAILURE(InitState());
17608 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
17609 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
17610 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
17611 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
17612 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
17613 vkDestroyDevice(VK_NULL_HANDLE, NULL);
17614 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
17615 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
17616 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
17617 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
17618 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
17619 vkDestroyInstance(VK_NULL_HANDLE, NULL);
17620 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
17621 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
17622 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
17623 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
17624 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
17625 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
17626 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
17627 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
17628
17629 VkCommandPool command_pool;
17630 VkCommandPoolCreateInfo pool_create_info{};
17631 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17632 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17633 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17634 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17635 VkCommandBuffer command_buffers[3] = {};
17636 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17637 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17638 command_buffer_allocate_info.commandPool = command_pool;
17639 command_buffer_allocate_info.commandBufferCount = 1;
17640 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17641 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
17642 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
17643 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17644
17645 VkDescriptorPoolSize ds_type_count = {};
17646 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17647 ds_type_count.descriptorCount = 1;
17648
17649 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17650 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17651 ds_pool_ci.pNext = NULL;
17652 ds_pool_ci.maxSets = 1;
17653 ds_pool_ci.poolSizeCount = 1;
17654 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
17655 ds_pool_ci.pPoolSizes = &ds_type_count;
17656
17657 VkDescriptorPool ds_pool;
17658 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17659 ASSERT_VK_SUCCESS(err);
17660
17661 VkDescriptorSetLayoutBinding dsl_binding = {};
17662 dsl_binding.binding = 2;
17663 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17664 dsl_binding.descriptorCount = 1;
17665 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17666 dsl_binding.pImmutableSamplers = NULL;
17667 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17668 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17669 ds_layout_ci.pNext = NULL;
17670 ds_layout_ci.bindingCount = 1;
17671 ds_layout_ci.pBindings = &dsl_binding;
17672 VkDescriptorSetLayout ds_layout;
17673 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17674 ASSERT_VK_SUCCESS(err);
17675
17676 VkDescriptorSet descriptor_sets[3] = {};
17677 VkDescriptorSetAllocateInfo alloc_info = {};
17678 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17679 alloc_info.descriptorSetCount = 1;
17680 alloc_info.descriptorPool = ds_pool;
17681 alloc_info.pSetLayouts = &ds_layout;
17682 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
17683 ASSERT_VK_SUCCESS(err);
17684 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
17685 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17686 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17687
17688 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
17689
17690 m_errorMonitor->VerifyNotFound();
17691}
17692
Tobin Ehlis953e8392016-11-17 10:54:13 -070017693TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
17694 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
17695 // We previously had a bug where dynamic offset of inactive bindings was still being used
17696 VkResult err;
17697 m_errorMonitor->ExpectSuccess();
17698
17699 ASSERT_NO_FATAL_FAILURE(InitState());
17700 ASSERT_NO_FATAL_FAILURE(InitViewport());
17701 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17702
17703 VkDescriptorPoolSize ds_type_count = {};
17704 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17705 ds_type_count.descriptorCount = 3;
17706
17707 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17708 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17709 ds_pool_ci.pNext = NULL;
17710 ds_pool_ci.maxSets = 1;
17711 ds_pool_ci.poolSizeCount = 1;
17712 ds_pool_ci.pPoolSizes = &ds_type_count;
17713
17714 VkDescriptorPool ds_pool;
17715 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17716 ASSERT_VK_SUCCESS(err);
17717
17718 const uint32_t BINDING_COUNT = 3;
17719 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017720 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017721 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17722 dsl_binding[0].descriptorCount = 1;
17723 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17724 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017725 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017726 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17727 dsl_binding[1].descriptorCount = 1;
17728 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17729 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017730 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017731 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17732 dsl_binding[2].descriptorCount = 1;
17733 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17734 dsl_binding[2].pImmutableSamplers = NULL;
17735
17736 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17737 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17738 ds_layout_ci.pNext = NULL;
17739 ds_layout_ci.bindingCount = BINDING_COUNT;
17740 ds_layout_ci.pBindings = dsl_binding;
17741 VkDescriptorSetLayout ds_layout;
17742 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17743 ASSERT_VK_SUCCESS(err);
17744
17745 VkDescriptorSet descriptor_set;
17746 VkDescriptorSetAllocateInfo alloc_info = {};
17747 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17748 alloc_info.descriptorSetCount = 1;
17749 alloc_info.descriptorPool = ds_pool;
17750 alloc_info.pSetLayouts = &ds_layout;
17751 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17752 ASSERT_VK_SUCCESS(err);
17753
17754 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17755 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17756 pipeline_layout_ci.pNext = NULL;
17757 pipeline_layout_ci.setLayoutCount = 1;
17758 pipeline_layout_ci.pSetLayouts = &ds_layout;
17759
17760 VkPipelineLayout pipeline_layout;
17761 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17762 ASSERT_VK_SUCCESS(err);
17763
17764 // Create two buffers to update the descriptors with
17765 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17766 uint32_t qfi = 0;
17767 VkBufferCreateInfo buffCI = {};
17768 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17769 buffCI.size = 2048;
17770 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17771 buffCI.queueFamilyIndexCount = 1;
17772 buffCI.pQueueFamilyIndices = &qfi;
17773
17774 VkBuffer dyub1;
17775 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17776 ASSERT_VK_SUCCESS(err);
17777 // buffer2
17778 buffCI.size = 1024;
17779 VkBuffer dyub2;
17780 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17781 ASSERT_VK_SUCCESS(err);
17782 // Allocate memory and bind to buffers
17783 VkMemoryAllocateInfo mem_alloc[2] = {};
17784 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17785 mem_alloc[0].pNext = NULL;
17786 mem_alloc[0].memoryTypeIndex = 0;
17787 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17788 mem_alloc[1].pNext = NULL;
17789 mem_alloc[1].memoryTypeIndex = 0;
17790
17791 VkMemoryRequirements mem_reqs1;
17792 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17793 VkMemoryRequirements mem_reqs2;
17794 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17795 mem_alloc[0].allocationSize = mem_reqs1.size;
17796 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17797 mem_alloc[1].allocationSize = mem_reqs2.size;
17798 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17799 if (!pass) {
17800 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17801 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17802 return;
17803 }
17804
17805 VkDeviceMemory mem1;
17806 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17807 ASSERT_VK_SUCCESS(err);
17808 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17809 ASSERT_VK_SUCCESS(err);
17810 VkDeviceMemory mem2;
17811 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17812 ASSERT_VK_SUCCESS(err);
17813 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17814 ASSERT_VK_SUCCESS(err);
17815 // Update descriptors
17816 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17817 buff_info[0].buffer = dyub1;
17818 buff_info[0].offset = 0;
17819 buff_info[0].range = 256;
17820 buff_info[1].buffer = dyub1;
17821 buff_info[1].offset = 256;
17822 buff_info[1].range = 512;
17823 buff_info[2].buffer = dyub2;
17824 buff_info[2].offset = 0;
17825 buff_info[2].range = 512;
17826
17827 VkWriteDescriptorSet descriptor_write;
17828 memset(&descriptor_write, 0, sizeof(descriptor_write));
17829 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17830 descriptor_write.dstSet = descriptor_set;
17831 descriptor_write.dstBinding = 0;
17832 descriptor_write.descriptorCount = BINDING_COUNT;
17833 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17834 descriptor_write.pBufferInfo = buff_info;
17835
17836 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17837
Tony Barbour552f6c02016-12-21 14:34:07 -070017838 m_commandBuffer->BeginCommandBuffer();
17839 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017840
17841 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017842 char const *vsSource =
17843 "#version 450\n"
17844 "\n"
17845 "out gl_PerVertex { \n"
17846 " vec4 gl_Position;\n"
17847 "};\n"
17848 "void main(){\n"
17849 " gl_Position = vec4(1);\n"
17850 "}\n";
17851 char const *fsSource =
17852 "#version 450\n"
17853 "\n"
17854 "layout(location=0) out vec4 x;\n"
17855 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17856 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17857 "void main(){\n"
17858 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17859 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070017860 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17861 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17862 VkPipelineObj pipe(m_device);
17863 pipe.SetViewport(m_viewports);
17864 pipe.SetScissor(m_scissors);
17865 pipe.AddShader(&vs);
17866 pipe.AddShader(&fs);
17867 pipe.AddColorAttachment();
17868 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17869
17870 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17871 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17872 // we used to have a bug in this case.
17873 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17874 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17875 &descriptor_set, BINDING_COUNT, dyn_off);
17876 Draw(1, 0, 0, 0);
17877 m_errorMonitor->VerifyNotFound();
17878
17879 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17880 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17881 vkFreeMemory(m_device->device(), mem1, NULL);
17882 vkFreeMemory(m_device->device(), mem2, NULL);
17883
17884 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17885 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17886 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17887}
17888
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017889TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017890 TEST_DESCRIPTION(
17891 "Ensure that validations handling of non-coherent memory "
17892 "mapping while using VK_WHOLE_SIZE does not cause access "
17893 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017894 VkResult err;
17895 uint8_t *pData;
17896 ASSERT_NO_FATAL_FAILURE(InitState());
17897
17898 VkDeviceMemory mem;
17899 VkMemoryRequirements mem_reqs;
17900 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017901 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017902 VkMemoryAllocateInfo alloc_info = {};
17903 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17904 alloc_info.pNext = NULL;
17905 alloc_info.memoryTypeIndex = 0;
17906
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017907 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017908 alloc_info.allocationSize = allocation_size;
17909
17910 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17911 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 -070017912 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017913 if (!pass) {
17914 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017915 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17916 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017917 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017918 pass = m_device->phy().set_memory_type(
17919 mem_reqs.memoryTypeBits, &alloc_info,
17920 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17921 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017922 if (!pass) {
17923 return;
17924 }
17925 }
17926 }
17927
17928 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17929 ASSERT_VK_SUCCESS(err);
17930
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017931 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017932 m_errorMonitor->ExpectSuccess();
17933 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17934 ASSERT_VK_SUCCESS(err);
17935 VkMappedMemoryRange mmr = {};
17936 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17937 mmr.memory = mem;
17938 mmr.offset = 0;
17939 mmr.size = VK_WHOLE_SIZE;
17940 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17941 ASSERT_VK_SUCCESS(err);
17942 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17943 ASSERT_VK_SUCCESS(err);
17944 m_errorMonitor->VerifyNotFound();
17945 vkUnmapMemory(m_device->device(), mem);
17946
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017947 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017948 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017949 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017950 ASSERT_VK_SUCCESS(err);
17951 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17952 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017953 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017954 mmr.size = VK_WHOLE_SIZE;
17955 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17956 ASSERT_VK_SUCCESS(err);
17957 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17958 ASSERT_VK_SUCCESS(err);
17959 m_errorMonitor->VerifyNotFound();
17960 vkUnmapMemory(m_device->device(), mem);
17961
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017962 // Map with offset and size
17963 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017964 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017965 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017966 ASSERT_VK_SUCCESS(err);
17967 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17968 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017969 mmr.offset = 4 * atom_size;
17970 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017971 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17972 ASSERT_VK_SUCCESS(err);
17973 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17974 ASSERT_VK_SUCCESS(err);
17975 m_errorMonitor->VerifyNotFound();
17976 vkUnmapMemory(m_device->device(), mem);
17977
17978 // Map without offset and flush WHOLE_SIZE with two separate offsets
17979 m_errorMonitor->ExpectSuccess();
17980 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17981 ASSERT_VK_SUCCESS(err);
17982 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17983 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017984 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017985 mmr.size = VK_WHOLE_SIZE;
17986 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17987 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017988 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017989 mmr.size = VK_WHOLE_SIZE;
17990 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17991 ASSERT_VK_SUCCESS(err);
17992 m_errorMonitor->VerifyNotFound();
17993 vkUnmapMemory(m_device->device(), mem);
17994
17995 vkFreeMemory(m_device->device(), mem, NULL);
17996}
17997
17998// This is a positive test. We used to expect error in this case but spec now allows it
17999TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
18000 m_errorMonitor->ExpectSuccess();
18001 vk_testing::Fence testFence;
18002 VkFenceCreateInfo fenceInfo = {};
18003 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18004 fenceInfo.pNext = NULL;
18005
18006 ASSERT_NO_FATAL_FAILURE(InitState());
18007 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018008 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018009 VkResult result = vkResetFences(m_device->device(), 1, fences);
18010 ASSERT_VK_SUCCESS(result);
18011
18012 m_errorMonitor->VerifyNotFound();
18013}
18014
18015TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
18016 m_errorMonitor->ExpectSuccess();
18017
18018 ASSERT_NO_FATAL_FAILURE(InitState());
18019 VkResult err;
18020
18021 // Record (empty!) command buffer that can be submitted multiple times
18022 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018023 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
18024 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018025 m_commandBuffer->BeginCommandBuffer(&cbbi);
18026 m_commandBuffer->EndCommandBuffer();
18027
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018028 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018029 VkFence fence;
18030 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
18031 ASSERT_VK_SUCCESS(err);
18032
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018033 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018034 VkSemaphore s1, s2;
18035 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
18036 ASSERT_VK_SUCCESS(err);
18037 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
18038 ASSERT_VK_SUCCESS(err);
18039
18040 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018041 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018042 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
18043 ASSERT_VK_SUCCESS(err);
18044
18045 // Submit CB again, signaling s2.
18046 si.pSignalSemaphores = &s2;
18047 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
18048 ASSERT_VK_SUCCESS(err);
18049
18050 // Wait for fence.
18051 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18052 ASSERT_VK_SUCCESS(err);
18053
18054 // CB is still in flight from second submission, but semaphore s1 is no
18055 // longer in flight. delete it.
18056 vkDestroySemaphore(m_device->device(), s1, nullptr);
18057
18058 m_errorMonitor->VerifyNotFound();
18059
18060 // Force device idle and clean up remaining objects
18061 vkDeviceWaitIdle(m_device->device());
18062 vkDestroySemaphore(m_device->device(), s2, nullptr);
18063 vkDestroyFence(m_device->device(), fence, nullptr);
18064}
18065
18066TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
18067 m_errorMonitor->ExpectSuccess();
18068
18069 ASSERT_NO_FATAL_FAILURE(InitState());
18070 VkResult err;
18071
18072 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018073 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018074 VkFence f1;
18075 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
18076 ASSERT_VK_SUCCESS(err);
18077
18078 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018079 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018080 VkFence f2;
18081 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
18082 ASSERT_VK_SUCCESS(err);
18083
18084 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018085 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018086 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
18087
18088 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018089 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018090 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
18091
18092 // Should have both retired!
18093 vkDestroyFence(m_device->device(), f1, nullptr);
18094 vkDestroyFence(m_device->device(), f2, nullptr);
18095
18096 m_errorMonitor->VerifyNotFound();
18097}
18098
18099TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018100 TEST_DESCRIPTION(
18101 "Verify that creating an image view from an image with valid usage "
18102 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018103
18104 ASSERT_NO_FATAL_FAILURE(InitState());
18105
18106 m_errorMonitor->ExpectSuccess();
18107 // Verify that we can create a view with usage INPUT_ATTACHMENT
18108 VkImageObj image(m_device);
18109 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18110 ASSERT_TRUE(image.initialized());
18111 VkImageView imageView;
18112 VkImageViewCreateInfo ivci = {};
18113 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18114 ivci.image = image.handle();
18115 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
18116 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
18117 ivci.subresourceRange.layerCount = 1;
18118 ivci.subresourceRange.baseMipLevel = 0;
18119 ivci.subresourceRange.levelCount = 1;
18120 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18121
18122 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
18123 m_errorMonitor->VerifyNotFound();
18124 vkDestroyImageView(m_device->device(), imageView, NULL);
18125}
18126
18127// This is a positive test. No failures are expected.
18128TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018129 TEST_DESCRIPTION(
18130 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
18131 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018132
18133 ASSERT_NO_FATAL_FAILURE(InitState());
18134
18135 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018136 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018137
18138 m_errorMonitor->ExpectSuccess();
18139
18140 VkImage image;
18141 VkImageCreateInfo image_create_info = {};
18142 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18143 image_create_info.pNext = NULL;
18144 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18145 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18146 image_create_info.extent.width = 64;
18147 image_create_info.extent.height = 64;
18148 image_create_info.extent.depth = 1;
18149 image_create_info.mipLevels = 1;
18150 image_create_info.arrayLayers = 1;
18151 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18152 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18153 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
18154 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
18155 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18156 ASSERT_VK_SUCCESS(err);
18157
18158 VkMemoryRequirements memory_reqs;
18159 VkDeviceMemory memory_one, memory_two;
18160 bool pass;
18161 VkMemoryAllocateInfo memory_info = {};
18162 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18163 memory_info.pNext = NULL;
18164 memory_info.allocationSize = 0;
18165 memory_info.memoryTypeIndex = 0;
18166 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18167 // Find an image big enough to allow sparse mapping of 2 memory regions
18168 // Increase the image size until it is at least twice the
18169 // size of the required alignment, to ensure we can bind both
18170 // allocated memory blocks to the image on aligned offsets.
18171 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
18172 vkDestroyImage(m_device->device(), image, nullptr);
18173 image_create_info.extent.width *= 2;
18174 image_create_info.extent.height *= 2;
18175 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
18176 ASSERT_VK_SUCCESS(err);
18177 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18178 }
18179 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
18180 // at the end of the first
18181 memory_info.allocationSize = memory_reqs.alignment;
18182 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18183 ASSERT_TRUE(pass);
18184 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
18185 ASSERT_VK_SUCCESS(err);
18186 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
18187 ASSERT_VK_SUCCESS(err);
18188 VkSparseMemoryBind binds[2];
18189 binds[0].flags = 0;
18190 binds[0].memory = memory_one;
18191 binds[0].memoryOffset = 0;
18192 binds[0].resourceOffset = 0;
18193 binds[0].size = memory_info.allocationSize;
18194 binds[1].flags = 0;
18195 binds[1].memory = memory_two;
18196 binds[1].memoryOffset = 0;
18197 binds[1].resourceOffset = memory_info.allocationSize;
18198 binds[1].size = memory_info.allocationSize;
18199
18200 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
18201 opaqueBindInfo.image = image;
18202 opaqueBindInfo.bindCount = 2;
18203 opaqueBindInfo.pBinds = binds;
18204
18205 VkFence fence = VK_NULL_HANDLE;
18206 VkBindSparseInfo bindSparseInfo = {};
18207 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
18208 bindSparseInfo.imageOpaqueBindCount = 1;
18209 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
18210
18211 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
18212 vkQueueWaitIdle(m_device->m_queue);
18213 vkDestroyImage(m_device->device(), image, NULL);
18214 vkFreeMemory(m_device->device(), memory_one, NULL);
18215 vkFreeMemory(m_device->device(), memory_two, NULL);
18216 m_errorMonitor->VerifyNotFound();
18217}
18218
18219TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018220 TEST_DESCRIPTION(
18221 "Ensure that CmdBeginRenderPass with an attachment's "
18222 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
18223 "the command buffer has prior knowledge of that "
18224 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018225
18226 m_errorMonitor->ExpectSuccess();
18227
18228 ASSERT_NO_FATAL_FAILURE(InitState());
18229
18230 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018231 VkAttachmentDescription attachment = {0,
18232 VK_FORMAT_R8G8B8A8_UNORM,
18233 VK_SAMPLE_COUNT_1_BIT,
18234 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18235 VK_ATTACHMENT_STORE_OP_STORE,
18236 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18237 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18238 VK_IMAGE_LAYOUT_UNDEFINED,
18239 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018240
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018241 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018242
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018243 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018244
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018245 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018246
18247 VkRenderPass rp;
18248 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18249 ASSERT_VK_SUCCESS(err);
18250
18251 // A compatible framebuffer.
18252 VkImageObj image(m_device);
18253 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18254 ASSERT_TRUE(image.initialized());
18255
18256 VkImageViewCreateInfo ivci = {
18257 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18258 nullptr,
18259 0,
18260 image.handle(),
18261 VK_IMAGE_VIEW_TYPE_2D,
18262 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018263 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18264 VK_COMPONENT_SWIZZLE_IDENTITY},
18265 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018266 };
18267 VkImageView view;
18268 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18269 ASSERT_VK_SUCCESS(err);
18270
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018271 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018272 VkFramebuffer fb;
18273 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18274 ASSERT_VK_SUCCESS(err);
18275
18276 // Record a single command buffer which uses this renderpass twice. The
18277 // bug is triggered at the beginning of the second renderpass, when the
18278 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018279 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 -070018280 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018281 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18282 vkCmdEndRenderPass(m_commandBuffer->handle());
18283 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18284
18285 m_errorMonitor->VerifyNotFound();
18286
18287 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018288 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018289
18290 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18291 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18292 vkDestroyImageView(m_device->device(), view, nullptr);
18293}
18294
18295TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018296 TEST_DESCRIPTION(
18297 "This test should pass. Create a Framebuffer and "
18298 "command buffer, bind them together, then destroy "
18299 "command pool and framebuffer and verify there are no "
18300 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018301
18302 m_errorMonitor->ExpectSuccess();
18303
18304 ASSERT_NO_FATAL_FAILURE(InitState());
18305
18306 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018307 VkAttachmentDescription attachment = {0,
18308 VK_FORMAT_R8G8B8A8_UNORM,
18309 VK_SAMPLE_COUNT_1_BIT,
18310 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18311 VK_ATTACHMENT_STORE_OP_STORE,
18312 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18313 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18314 VK_IMAGE_LAYOUT_UNDEFINED,
18315 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018316
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018317 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018318
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018319 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018320
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018321 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018322
18323 VkRenderPass rp;
18324 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18325 ASSERT_VK_SUCCESS(err);
18326
18327 // A compatible framebuffer.
18328 VkImageObj image(m_device);
18329 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18330 ASSERT_TRUE(image.initialized());
18331
18332 VkImageViewCreateInfo ivci = {
18333 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18334 nullptr,
18335 0,
18336 image.handle(),
18337 VK_IMAGE_VIEW_TYPE_2D,
18338 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018339 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18340 VK_COMPONENT_SWIZZLE_IDENTITY},
18341 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018342 };
18343 VkImageView view;
18344 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18345 ASSERT_VK_SUCCESS(err);
18346
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018347 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018348 VkFramebuffer fb;
18349 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18350 ASSERT_VK_SUCCESS(err);
18351
18352 // Explicitly create a command buffer to bind the FB to so that we can then
18353 // destroy the command pool in order to implicitly free command buffer
18354 VkCommandPool command_pool;
18355 VkCommandPoolCreateInfo pool_create_info{};
18356 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18357 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18358 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18359 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18360
18361 VkCommandBuffer command_buffer;
18362 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18363 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18364 command_buffer_allocate_info.commandPool = command_pool;
18365 command_buffer_allocate_info.commandBufferCount = 1;
18366 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18367 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18368
18369 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018370 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 -060018371 VkCommandBufferBeginInfo begin_info{};
18372 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18373 vkBeginCommandBuffer(command_buffer, &begin_info);
18374
18375 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18376 vkCmdEndRenderPass(command_buffer);
18377 vkEndCommandBuffer(command_buffer);
18378 vkDestroyImageView(m_device->device(), view, nullptr);
18379 // Destroy command pool to implicitly free command buffer
18380 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18381 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18382 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18383 m_errorMonitor->VerifyNotFound();
18384}
18385
18386TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018387 TEST_DESCRIPTION(
18388 "Ensure that CmdBeginRenderPass applies the layout "
18389 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018390
18391 m_errorMonitor->ExpectSuccess();
18392
18393 ASSERT_NO_FATAL_FAILURE(InitState());
18394
18395 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018396 VkAttachmentDescription attachment = {0,
18397 VK_FORMAT_R8G8B8A8_UNORM,
18398 VK_SAMPLE_COUNT_1_BIT,
18399 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18400 VK_ATTACHMENT_STORE_OP_STORE,
18401 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18402 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18403 VK_IMAGE_LAYOUT_UNDEFINED,
18404 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018405
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018406 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018407
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018408 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018409
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018410 VkSubpassDependency dep = {0,
18411 0,
18412 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18413 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18414 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18415 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18416 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018417
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018418 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018419
18420 VkResult err;
18421 VkRenderPass rp;
18422 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18423 ASSERT_VK_SUCCESS(err);
18424
18425 // A compatible framebuffer.
18426 VkImageObj image(m_device);
18427 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18428 ASSERT_TRUE(image.initialized());
18429
18430 VkImageViewCreateInfo ivci = {
18431 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18432 nullptr,
18433 0,
18434 image.handle(),
18435 VK_IMAGE_VIEW_TYPE_2D,
18436 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018437 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18438 VK_COMPONENT_SWIZZLE_IDENTITY},
18439 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018440 };
18441 VkImageView view;
18442 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18443 ASSERT_VK_SUCCESS(err);
18444
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018445 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018446 VkFramebuffer fb;
18447 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18448 ASSERT_VK_SUCCESS(err);
18449
18450 // Record a single command buffer which issues a pipeline barrier w/
18451 // image memory barrier for the attachment. This detects the previously
18452 // missing tracking of the subpass layout by throwing a validation error
18453 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018454 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 -070018455 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018456 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18457
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018458 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
18459 nullptr,
18460 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18461 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18462 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18463 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18464 VK_QUEUE_FAMILY_IGNORED,
18465 VK_QUEUE_FAMILY_IGNORED,
18466 image.handle(),
18467 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018468 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018469 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18470 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018471
18472 vkCmdEndRenderPass(m_commandBuffer->handle());
18473 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018474 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018475
18476 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18477 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18478 vkDestroyImageView(m_device->device(), view, nullptr);
18479}
18480
18481TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018482 TEST_DESCRIPTION(
18483 "Validate that when an imageView of a depth/stencil image "
18484 "is used as a depth/stencil framebuffer attachment, the "
18485 "aspectMask is ignored and both depth and stencil image "
18486 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018487
18488 VkFormatProperties format_properties;
18489 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
18490 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
18491 return;
18492 }
18493
18494 m_errorMonitor->ExpectSuccess();
18495
18496 ASSERT_NO_FATAL_FAILURE(InitState());
18497
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018498 VkAttachmentDescription attachment = {0,
18499 VK_FORMAT_D32_SFLOAT_S8_UINT,
18500 VK_SAMPLE_COUNT_1_BIT,
18501 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18502 VK_ATTACHMENT_STORE_OP_STORE,
18503 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18504 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18505 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
18506 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018507
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018508 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018509
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018510 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018511
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018512 VkSubpassDependency dep = {0,
18513 0,
18514 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18515 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18516 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18517 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18518 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018519
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018520 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018521
18522 VkResult err;
18523 VkRenderPass rp;
18524 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18525 ASSERT_VK_SUCCESS(err);
18526
18527 VkImageObj image(m_device);
18528 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018529 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018530 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018531 ASSERT_TRUE(image.initialized());
18532 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
18533
18534 VkImageViewCreateInfo ivci = {
18535 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18536 nullptr,
18537 0,
18538 image.handle(),
18539 VK_IMAGE_VIEW_TYPE_2D,
18540 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018541 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
18542 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018543 };
18544 VkImageView view;
18545 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18546 ASSERT_VK_SUCCESS(err);
18547
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018548 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018549 VkFramebuffer fb;
18550 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18551 ASSERT_VK_SUCCESS(err);
18552
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018553 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 -070018554 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018555 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18556
18557 VkImageMemoryBarrier imb = {};
18558 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18559 imb.pNext = nullptr;
18560 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18561 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18562 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18563 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18564 imb.srcQueueFamilyIndex = 0;
18565 imb.dstQueueFamilyIndex = 0;
18566 imb.image = image.handle();
18567 imb.subresourceRange.aspectMask = 0x6;
18568 imb.subresourceRange.baseMipLevel = 0;
18569 imb.subresourceRange.levelCount = 0x1;
18570 imb.subresourceRange.baseArrayLayer = 0;
18571 imb.subresourceRange.layerCount = 0x1;
18572
18573 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018574 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18575 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018576
18577 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018578 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018579 QueueCommandBuffer(false);
18580 m_errorMonitor->VerifyNotFound();
18581
18582 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18583 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18584 vkDestroyImageView(m_device->device(), view, nullptr);
18585}
18586
18587TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018588 TEST_DESCRIPTION(
18589 "Ensure that layout transitions work correctly without "
18590 "errors, when an attachment reference is "
18591 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018592
18593 m_errorMonitor->ExpectSuccess();
18594
18595 ASSERT_NO_FATAL_FAILURE(InitState());
18596
18597 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018598 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018599
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018600 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018601
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018602 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018603
18604 VkRenderPass rp;
18605 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18606 ASSERT_VK_SUCCESS(err);
18607
18608 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018609 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018610 VkFramebuffer fb;
18611 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18612 ASSERT_VK_SUCCESS(err);
18613
18614 // Record a command buffer which just begins and ends the renderpass. The
18615 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018616 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 -070018617 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018618 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18619 vkCmdEndRenderPass(m_commandBuffer->handle());
18620 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018621 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018622
18623 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18624 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18625}
18626
18627// This is a positive test. No errors are expected.
18628TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018629 TEST_DESCRIPTION(
18630 "Create a stencil-only attachment with a LOAD_OP set to "
18631 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018632 VkResult result = VK_SUCCESS;
18633 VkImageFormatProperties formatProps;
18634 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018635 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
18636 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018637 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
18638 return;
18639 }
18640
18641 ASSERT_NO_FATAL_FAILURE(InitState());
18642 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
18643 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018644 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018645 VkAttachmentDescription att = {};
18646 VkAttachmentReference ref = {};
18647 att.format = depth_stencil_fmt;
18648 att.samples = VK_SAMPLE_COUNT_1_BIT;
18649 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
18650 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18651 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18652 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
18653 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18654 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18655
18656 VkClearValue clear;
18657 clear.depthStencil.depth = 1.0;
18658 clear.depthStencil.stencil = 0;
18659 ref.attachment = 0;
18660 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18661
18662 VkSubpassDescription subpass = {};
18663 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
18664 subpass.flags = 0;
18665 subpass.inputAttachmentCount = 0;
18666 subpass.pInputAttachments = NULL;
18667 subpass.colorAttachmentCount = 0;
18668 subpass.pColorAttachments = NULL;
18669 subpass.pResolveAttachments = NULL;
18670 subpass.pDepthStencilAttachment = &ref;
18671 subpass.preserveAttachmentCount = 0;
18672 subpass.pPreserveAttachments = NULL;
18673
18674 VkRenderPass rp;
18675 VkRenderPassCreateInfo rp_info = {};
18676 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18677 rp_info.attachmentCount = 1;
18678 rp_info.pAttachments = &att;
18679 rp_info.subpassCount = 1;
18680 rp_info.pSubpasses = &subpass;
18681 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
18682 ASSERT_VK_SUCCESS(result);
18683
18684 VkImageView *depthView = m_depthStencil->BindInfo();
18685 VkFramebufferCreateInfo fb_info = {};
18686 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
18687 fb_info.pNext = NULL;
18688 fb_info.renderPass = rp;
18689 fb_info.attachmentCount = 1;
18690 fb_info.pAttachments = depthView;
18691 fb_info.width = 100;
18692 fb_info.height = 100;
18693 fb_info.layers = 1;
18694 VkFramebuffer fb;
18695 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
18696 ASSERT_VK_SUCCESS(result);
18697
18698 VkRenderPassBeginInfo rpbinfo = {};
18699 rpbinfo.clearValueCount = 1;
18700 rpbinfo.pClearValues = &clear;
18701 rpbinfo.pNext = NULL;
18702 rpbinfo.renderPass = rp;
18703 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
18704 rpbinfo.renderArea.extent.width = 100;
18705 rpbinfo.renderArea.extent.height = 100;
18706 rpbinfo.renderArea.offset.x = 0;
18707 rpbinfo.renderArea.offset.y = 0;
18708 rpbinfo.framebuffer = fb;
18709
18710 VkFence fence = {};
18711 VkFenceCreateInfo fence_ci = {};
18712 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18713 fence_ci.pNext = nullptr;
18714 fence_ci.flags = 0;
18715 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
18716 ASSERT_VK_SUCCESS(result);
18717
18718 m_commandBuffer->BeginCommandBuffer();
18719 m_commandBuffer->BeginRenderPass(rpbinfo);
18720 m_commandBuffer->EndRenderPass();
18721 m_commandBuffer->EndCommandBuffer();
18722 m_commandBuffer->QueueCommandBuffer(fence);
18723
18724 VkImageObj destImage(m_device);
18725 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 -070018726 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018727 VkImageMemoryBarrier barrier = {};
18728 VkImageSubresourceRange range;
18729 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18730 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18731 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
18732 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18733 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18734 barrier.image = m_depthStencil->handle();
18735 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18736 range.baseMipLevel = 0;
18737 range.levelCount = 1;
18738 range.baseArrayLayer = 0;
18739 range.layerCount = 1;
18740 barrier.subresourceRange = range;
18741 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18742 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18743 cmdbuf.BeginCommandBuffer();
18744 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 -070018745 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018746 barrier.srcAccessMask = 0;
18747 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18748 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18749 barrier.image = destImage.handle();
18750 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18751 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 -070018752 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018753 VkImageCopy cregion;
18754 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18755 cregion.srcSubresource.mipLevel = 0;
18756 cregion.srcSubresource.baseArrayLayer = 0;
18757 cregion.srcSubresource.layerCount = 1;
18758 cregion.srcOffset.x = 0;
18759 cregion.srcOffset.y = 0;
18760 cregion.srcOffset.z = 0;
18761 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18762 cregion.dstSubresource.mipLevel = 0;
18763 cregion.dstSubresource.baseArrayLayer = 0;
18764 cregion.dstSubresource.layerCount = 1;
18765 cregion.dstOffset.x = 0;
18766 cregion.dstOffset.y = 0;
18767 cregion.dstOffset.z = 0;
18768 cregion.extent.width = 100;
18769 cregion.extent.height = 100;
18770 cregion.extent.depth = 1;
18771 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018772 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018773 cmdbuf.EndCommandBuffer();
18774
18775 VkSubmitInfo submit_info;
18776 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18777 submit_info.pNext = NULL;
18778 submit_info.waitSemaphoreCount = 0;
18779 submit_info.pWaitSemaphores = NULL;
18780 submit_info.pWaitDstStageMask = NULL;
18781 submit_info.commandBufferCount = 1;
18782 submit_info.pCommandBuffers = &cmdbuf.handle();
18783 submit_info.signalSemaphoreCount = 0;
18784 submit_info.pSignalSemaphores = NULL;
18785
18786 m_errorMonitor->ExpectSuccess();
18787 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18788 m_errorMonitor->VerifyNotFound();
18789
18790 vkQueueWaitIdle(m_device->m_queue);
18791 vkDestroyFence(m_device->device(), fence, nullptr);
18792 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18793 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18794}
18795
18796// This is a positive test. No errors should be generated.
18797TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18798 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18799
18800 m_errorMonitor->ExpectSuccess();
18801 ASSERT_NO_FATAL_FAILURE(InitState());
18802
18803 VkEvent event;
18804 VkEventCreateInfo event_create_info{};
18805 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18806 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18807
18808 VkCommandPool command_pool;
18809 VkCommandPoolCreateInfo pool_create_info{};
18810 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18811 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18812 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18813 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18814
18815 VkCommandBuffer command_buffer;
18816 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18817 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18818 command_buffer_allocate_info.commandPool = command_pool;
18819 command_buffer_allocate_info.commandBufferCount = 1;
18820 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18821 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18822
18823 VkQueue queue = VK_NULL_HANDLE;
18824 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18825
18826 {
18827 VkCommandBufferBeginInfo begin_info{};
18828 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18829 vkBeginCommandBuffer(command_buffer, &begin_info);
18830
18831 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 -070018832 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018833 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18834 vkEndCommandBuffer(command_buffer);
18835 }
18836 {
18837 VkSubmitInfo submit_info{};
18838 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18839 submit_info.commandBufferCount = 1;
18840 submit_info.pCommandBuffers = &command_buffer;
18841 submit_info.signalSemaphoreCount = 0;
18842 submit_info.pSignalSemaphores = nullptr;
18843 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18844 }
18845 { vkSetEvent(m_device->device(), event); }
18846
18847 vkQueueWaitIdle(queue);
18848
18849 vkDestroyEvent(m_device->device(), event, nullptr);
18850 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18851 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18852
18853 m_errorMonitor->VerifyNotFound();
18854}
18855// This is a positive test. No errors should be generated.
18856TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18857 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18858
18859 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018860 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018861
18862 m_errorMonitor->ExpectSuccess();
18863
18864 VkQueryPool query_pool;
18865 VkQueryPoolCreateInfo query_pool_create_info{};
18866 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18867 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18868 query_pool_create_info.queryCount = 1;
18869 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18870
18871 VkCommandPool command_pool;
18872 VkCommandPoolCreateInfo pool_create_info{};
18873 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18874 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18875 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18876 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18877
18878 VkCommandBuffer command_buffer;
18879 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18880 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18881 command_buffer_allocate_info.commandPool = command_pool;
18882 command_buffer_allocate_info.commandBufferCount = 1;
18883 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18884 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18885
18886 VkCommandBuffer secondary_command_buffer;
18887 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18888 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18889
18890 VkQueue queue = VK_NULL_HANDLE;
18891 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18892
18893 uint32_t qfi = 0;
18894 VkBufferCreateInfo buff_create_info = {};
18895 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18896 buff_create_info.size = 1024;
18897 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18898 buff_create_info.queueFamilyIndexCount = 1;
18899 buff_create_info.pQueueFamilyIndices = &qfi;
18900
18901 VkResult err;
18902 VkBuffer buffer;
18903 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18904 ASSERT_VK_SUCCESS(err);
18905 VkMemoryAllocateInfo mem_alloc = {};
18906 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18907 mem_alloc.pNext = NULL;
18908 mem_alloc.allocationSize = 1024;
18909 mem_alloc.memoryTypeIndex = 0;
18910
18911 VkMemoryRequirements memReqs;
18912 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18913 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18914 if (!pass) {
18915 vkDestroyBuffer(m_device->device(), buffer, NULL);
18916 return;
18917 }
18918
18919 VkDeviceMemory mem;
18920 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18921 ASSERT_VK_SUCCESS(err);
18922 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18923 ASSERT_VK_SUCCESS(err);
18924
18925 VkCommandBufferInheritanceInfo hinfo = {};
18926 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18927 hinfo.renderPass = VK_NULL_HANDLE;
18928 hinfo.subpass = 0;
18929 hinfo.framebuffer = VK_NULL_HANDLE;
18930 hinfo.occlusionQueryEnable = VK_FALSE;
18931 hinfo.queryFlags = 0;
18932 hinfo.pipelineStatistics = 0;
18933
18934 {
18935 VkCommandBufferBeginInfo begin_info{};
18936 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18937 begin_info.pInheritanceInfo = &hinfo;
18938 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18939
18940 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18941 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18942
18943 vkEndCommandBuffer(secondary_command_buffer);
18944
18945 begin_info.pInheritanceInfo = nullptr;
18946 vkBeginCommandBuffer(command_buffer, &begin_info);
18947
18948 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18949 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18950
18951 vkEndCommandBuffer(command_buffer);
18952 }
18953 {
18954 VkSubmitInfo submit_info{};
18955 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18956 submit_info.commandBufferCount = 1;
18957 submit_info.pCommandBuffers = &command_buffer;
18958 submit_info.signalSemaphoreCount = 0;
18959 submit_info.pSignalSemaphores = nullptr;
18960 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18961 }
18962
18963 vkQueueWaitIdle(queue);
18964
18965 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18966 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18967 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18968 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18969 vkDestroyBuffer(m_device->device(), buffer, NULL);
18970 vkFreeMemory(m_device->device(), mem, NULL);
18971
18972 m_errorMonitor->VerifyNotFound();
18973}
18974
18975// This is a positive test. No errors should be generated.
18976TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18977 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18978
18979 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018980 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018981
18982 m_errorMonitor->ExpectSuccess();
18983
18984 VkQueryPool query_pool;
18985 VkQueryPoolCreateInfo query_pool_create_info{};
18986 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18987 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18988 query_pool_create_info.queryCount = 1;
18989 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18990
18991 VkCommandPool command_pool;
18992 VkCommandPoolCreateInfo pool_create_info{};
18993 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18994 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18995 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18996 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18997
18998 VkCommandBuffer command_buffer[2];
18999 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19000 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19001 command_buffer_allocate_info.commandPool = command_pool;
19002 command_buffer_allocate_info.commandBufferCount = 2;
19003 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19004 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19005
19006 VkQueue queue = VK_NULL_HANDLE;
19007 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19008
19009 uint32_t qfi = 0;
19010 VkBufferCreateInfo buff_create_info = {};
19011 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19012 buff_create_info.size = 1024;
19013 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
19014 buff_create_info.queueFamilyIndexCount = 1;
19015 buff_create_info.pQueueFamilyIndices = &qfi;
19016
19017 VkResult err;
19018 VkBuffer buffer;
19019 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
19020 ASSERT_VK_SUCCESS(err);
19021 VkMemoryAllocateInfo mem_alloc = {};
19022 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19023 mem_alloc.pNext = NULL;
19024 mem_alloc.allocationSize = 1024;
19025 mem_alloc.memoryTypeIndex = 0;
19026
19027 VkMemoryRequirements memReqs;
19028 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
19029 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
19030 if (!pass) {
19031 vkDestroyBuffer(m_device->device(), buffer, NULL);
19032 return;
19033 }
19034
19035 VkDeviceMemory mem;
19036 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19037 ASSERT_VK_SUCCESS(err);
19038 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19039 ASSERT_VK_SUCCESS(err);
19040
19041 {
19042 VkCommandBufferBeginInfo begin_info{};
19043 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19044 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19045
19046 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
19047 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
19048
19049 vkEndCommandBuffer(command_buffer[0]);
19050
19051 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19052
19053 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
19054
19055 vkEndCommandBuffer(command_buffer[1]);
19056 }
19057 {
19058 VkSubmitInfo submit_info{};
19059 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19060 submit_info.commandBufferCount = 2;
19061 submit_info.pCommandBuffers = command_buffer;
19062 submit_info.signalSemaphoreCount = 0;
19063 submit_info.pSignalSemaphores = nullptr;
19064 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19065 }
19066
19067 vkQueueWaitIdle(queue);
19068
19069 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
19070 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
19071 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19072 vkDestroyBuffer(m_device->device(), buffer, NULL);
19073 vkFreeMemory(m_device->device(), mem, NULL);
19074
19075 m_errorMonitor->VerifyNotFound();
19076}
19077
Tony Barbourc46924f2016-11-04 11:49:52 -060019078TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019079 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
19080
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019081 ASSERT_NO_FATAL_FAILURE(InitState());
19082 VkEvent event;
19083 VkEventCreateInfo event_create_info{};
19084 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19085 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19086
19087 VkCommandPool command_pool;
19088 VkCommandPoolCreateInfo pool_create_info{};
19089 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19090 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19091 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19092 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19093
19094 VkCommandBuffer command_buffer;
19095 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19096 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19097 command_buffer_allocate_info.commandPool = command_pool;
19098 command_buffer_allocate_info.commandBufferCount = 1;
19099 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19100 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19101
19102 VkQueue queue = VK_NULL_HANDLE;
19103 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19104
19105 {
19106 VkCommandBufferBeginInfo begin_info{};
19107 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19108 vkBeginCommandBuffer(command_buffer, &begin_info);
19109
19110 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019111 vkEndCommandBuffer(command_buffer);
19112 }
19113 {
19114 VkSubmitInfo submit_info{};
19115 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19116 submit_info.commandBufferCount = 1;
19117 submit_info.pCommandBuffers = &command_buffer;
19118 submit_info.signalSemaphoreCount = 0;
19119 submit_info.pSignalSemaphores = nullptr;
19120 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19121 }
19122 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19124 "that is already in use by a "
19125 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019126 vkSetEvent(m_device->device(), event);
19127 m_errorMonitor->VerifyFound();
19128 }
19129
19130 vkQueueWaitIdle(queue);
19131
19132 vkDestroyEvent(m_device->device(), event, nullptr);
19133 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19134 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19135}
19136
19137// This is a positive test. No errors should be generated.
19138TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019139 TEST_DESCRIPTION(
19140 "Two command buffers with two separate fences are each "
19141 "run through a Submit & WaitForFences cycle 3 times. This "
19142 "previously revealed a bug so running this positive test "
19143 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019144 m_errorMonitor->ExpectSuccess();
19145
19146 ASSERT_NO_FATAL_FAILURE(InitState());
19147 VkQueue queue = VK_NULL_HANDLE;
19148 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19149
19150 static const uint32_t NUM_OBJECTS = 2;
19151 static const uint32_t NUM_FRAMES = 3;
19152 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
19153 VkFence fences[NUM_OBJECTS] = {};
19154
19155 VkCommandPool cmd_pool;
19156 VkCommandPoolCreateInfo cmd_pool_ci = {};
19157 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19158 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
19159 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19160 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
19161 ASSERT_VK_SUCCESS(err);
19162
19163 VkCommandBufferAllocateInfo cmd_buf_info = {};
19164 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19165 cmd_buf_info.commandPool = cmd_pool;
19166 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19167 cmd_buf_info.commandBufferCount = 1;
19168
19169 VkFenceCreateInfo fence_ci = {};
19170 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19171 fence_ci.pNext = nullptr;
19172 fence_ci.flags = 0;
19173
19174 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19175 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
19176 ASSERT_VK_SUCCESS(err);
19177 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
19178 ASSERT_VK_SUCCESS(err);
19179 }
19180
19181 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
19182 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
19183 // Create empty cmd buffer
19184 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
19185 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19186
19187 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
19188 ASSERT_VK_SUCCESS(err);
19189 err = vkEndCommandBuffer(cmd_buffers[obj]);
19190 ASSERT_VK_SUCCESS(err);
19191
19192 VkSubmitInfo submit_info = {};
19193 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19194 submit_info.commandBufferCount = 1;
19195 submit_info.pCommandBuffers = &cmd_buffers[obj];
19196 // Submit cmd buffer and wait for fence
19197 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
19198 ASSERT_VK_SUCCESS(err);
19199 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
19200 ASSERT_VK_SUCCESS(err);
19201 err = vkResetFences(m_device->device(), 1, &fences[obj]);
19202 ASSERT_VK_SUCCESS(err);
19203 }
19204 }
19205 m_errorMonitor->VerifyNotFound();
19206 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
19207 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19208 vkDestroyFence(m_device->device(), fences[i], nullptr);
19209 }
19210}
19211// This is a positive test. No errors should be generated.
19212TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019213 TEST_DESCRIPTION(
19214 "Two command buffers, each in a separate QueueSubmit call "
19215 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019216
19217 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019218 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019219
19220 m_errorMonitor->ExpectSuccess();
19221
19222 VkSemaphore semaphore;
19223 VkSemaphoreCreateInfo semaphore_create_info{};
19224 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19225 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19226
19227 VkCommandPool command_pool;
19228 VkCommandPoolCreateInfo pool_create_info{};
19229 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19230 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19231 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19232 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19233
19234 VkCommandBuffer command_buffer[2];
19235 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19236 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19237 command_buffer_allocate_info.commandPool = command_pool;
19238 command_buffer_allocate_info.commandBufferCount = 2;
19239 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19240 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19241
19242 VkQueue queue = VK_NULL_HANDLE;
19243 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19244
19245 {
19246 VkCommandBufferBeginInfo begin_info{};
19247 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19248 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19249
19250 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 -070019251 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019252
19253 VkViewport viewport{};
19254 viewport.maxDepth = 1.0f;
19255 viewport.minDepth = 0.0f;
19256 viewport.width = 512;
19257 viewport.height = 512;
19258 viewport.x = 0;
19259 viewport.y = 0;
19260 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19261 vkEndCommandBuffer(command_buffer[0]);
19262 }
19263 {
19264 VkCommandBufferBeginInfo begin_info{};
19265 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19266 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19267
19268 VkViewport viewport{};
19269 viewport.maxDepth = 1.0f;
19270 viewport.minDepth = 0.0f;
19271 viewport.width = 512;
19272 viewport.height = 512;
19273 viewport.x = 0;
19274 viewport.y = 0;
19275 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19276 vkEndCommandBuffer(command_buffer[1]);
19277 }
19278 {
19279 VkSubmitInfo submit_info{};
19280 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19281 submit_info.commandBufferCount = 1;
19282 submit_info.pCommandBuffers = &command_buffer[0];
19283 submit_info.signalSemaphoreCount = 1;
19284 submit_info.pSignalSemaphores = &semaphore;
19285 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19286 }
19287 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019288 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019289 VkSubmitInfo submit_info{};
19290 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19291 submit_info.commandBufferCount = 1;
19292 submit_info.pCommandBuffers = &command_buffer[1];
19293 submit_info.waitSemaphoreCount = 1;
19294 submit_info.pWaitSemaphores = &semaphore;
19295 submit_info.pWaitDstStageMask = flags;
19296 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19297 }
19298
19299 vkQueueWaitIdle(m_device->m_queue);
19300
19301 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19302 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19303 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19304
19305 m_errorMonitor->VerifyNotFound();
19306}
19307
19308// This is a positive test. No errors should be generated.
19309TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019310 TEST_DESCRIPTION(
19311 "Two command buffers, each in a separate QueueSubmit call "
19312 "submitted on separate queues, the second having a fence"
19313 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019314
19315 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019316 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019317
19318 m_errorMonitor->ExpectSuccess();
19319
19320 VkFence fence;
19321 VkFenceCreateInfo fence_create_info{};
19322 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19323 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19324
19325 VkSemaphore semaphore;
19326 VkSemaphoreCreateInfo semaphore_create_info{};
19327 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19328 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19329
19330 VkCommandPool command_pool;
19331 VkCommandPoolCreateInfo pool_create_info{};
19332 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19333 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19334 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19335 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19336
19337 VkCommandBuffer command_buffer[2];
19338 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19339 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19340 command_buffer_allocate_info.commandPool = command_pool;
19341 command_buffer_allocate_info.commandBufferCount = 2;
19342 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19343 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19344
19345 VkQueue queue = VK_NULL_HANDLE;
19346 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19347
19348 {
19349 VkCommandBufferBeginInfo begin_info{};
19350 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19351 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19352
19353 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 -070019354 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019355
19356 VkViewport viewport{};
19357 viewport.maxDepth = 1.0f;
19358 viewport.minDepth = 0.0f;
19359 viewport.width = 512;
19360 viewport.height = 512;
19361 viewport.x = 0;
19362 viewport.y = 0;
19363 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19364 vkEndCommandBuffer(command_buffer[0]);
19365 }
19366 {
19367 VkCommandBufferBeginInfo begin_info{};
19368 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19369 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19370
19371 VkViewport viewport{};
19372 viewport.maxDepth = 1.0f;
19373 viewport.minDepth = 0.0f;
19374 viewport.width = 512;
19375 viewport.height = 512;
19376 viewport.x = 0;
19377 viewport.y = 0;
19378 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19379 vkEndCommandBuffer(command_buffer[1]);
19380 }
19381 {
19382 VkSubmitInfo submit_info{};
19383 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19384 submit_info.commandBufferCount = 1;
19385 submit_info.pCommandBuffers = &command_buffer[0];
19386 submit_info.signalSemaphoreCount = 1;
19387 submit_info.pSignalSemaphores = &semaphore;
19388 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19389 }
19390 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019391 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019392 VkSubmitInfo submit_info{};
19393 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19394 submit_info.commandBufferCount = 1;
19395 submit_info.pCommandBuffers = &command_buffer[1];
19396 submit_info.waitSemaphoreCount = 1;
19397 submit_info.pWaitSemaphores = &semaphore;
19398 submit_info.pWaitDstStageMask = flags;
19399 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19400 }
19401
19402 vkQueueWaitIdle(m_device->m_queue);
19403
19404 vkDestroyFence(m_device->device(), fence, nullptr);
19405 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19406 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19407 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19408
19409 m_errorMonitor->VerifyNotFound();
19410}
19411
19412// This is a positive test. No errors should be generated.
19413TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019414 TEST_DESCRIPTION(
19415 "Two command buffers, each in a separate QueueSubmit call "
19416 "submitted on separate queues, the second having a fence"
19417 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019418
19419 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019420 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019421
19422 m_errorMonitor->ExpectSuccess();
19423
19424 VkFence fence;
19425 VkFenceCreateInfo fence_create_info{};
19426 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19427 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19428
19429 VkSemaphore semaphore;
19430 VkSemaphoreCreateInfo semaphore_create_info{};
19431 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19432 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19433
19434 VkCommandPool command_pool;
19435 VkCommandPoolCreateInfo pool_create_info{};
19436 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19437 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19438 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19439 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19440
19441 VkCommandBuffer command_buffer[2];
19442 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19443 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19444 command_buffer_allocate_info.commandPool = command_pool;
19445 command_buffer_allocate_info.commandBufferCount = 2;
19446 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19447 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19448
19449 VkQueue queue = VK_NULL_HANDLE;
19450 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19451
19452 {
19453 VkCommandBufferBeginInfo begin_info{};
19454 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19455 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19456
19457 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 -070019458 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019459
19460 VkViewport viewport{};
19461 viewport.maxDepth = 1.0f;
19462 viewport.minDepth = 0.0f;
19463 viewport.width = 512;
19464 viewport.height = 512;
19465 viewport.x = 0;
19466 viewport.y = 0;
19467 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19468 vkEndCommandBuffer(command_buffer[0]);
19469 }
19470 {
19471 VkCommandBufferBeginInfo begin_info{};
19472 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19473 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19474
19475 VkViewport viewport{};
19476 viewport.maxDepth = 1.0f;
19477 viewport.minDepth = 0.0f;
19478 viewport.width = 512;
19479 viewport.height = 512;
19480 viewport.x = 0;
19481 viewport.y = 0;
19482 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19483 vkEndCommandBuffer(command_buffer[1]);
19484 }
19485 {
19486 VkSubmitInfo submit_info{};
19487 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19488 submit_info.commandBufferCount = 1;
19489 submit_info.pCommandBuffers = &command_buffer[0];
19490 submit_info.signalSemaphoreCount = 1;
19491 submit_info.pSignalSemaphores = &semaphore;
19492 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19493 }
19494 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019495 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019496 VkSubmitInfo submit_info{};
19497 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19498 submit_info.commandBufferCount = 1;
19499 submit_info.pCommandBuffers = &command_buffer[1];
19500 submit_info.waitSemaphoreCount = 1;
19501 submit_info.pWaitSemaphores = &semaphore;
19502 submit_info.pWaitDstStageMask = flags;
19503 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19504 }
19505
19506 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19507 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19508
19509 vkDestroyFence(m_device->device(), fence, nullptr);
19510 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19511 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19512 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19513
19514 m_errorMonitor->VerifyNotFound();
19515}
19516
19517TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019518 ASSERT_NO_FATAL_FAILURE(InitState());
19519 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
19520 printf("Test requires two queues, skipping\n");
19521 return;
19522 }
19523
19524 VkResult err;
19525
19526 m_errorMonitor->ExpectSuccess();
19527
19528 VkQueue q0 = m_device->m_queue;
19529 VkQueue q1 = nullptr;
19530 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
19531 ASSERT_NE(q1, nullptr);
19532
19533 // An (empty) command buffer. We must have work in the first submission --
19534 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019535 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019536 VkCommandPool pool;
19537 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
19538 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019539 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
19540 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019541 VkCommandBuffer cb;
19542 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
19543 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019544 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019545 err = vkBeginCommandBuffer(cb, &cbbi);
19546 ASSERT_VK_SUCCESS(err);
19547 err = vkEndCommandBuffer(cb);
19548 ASSERT_VK_SUCCESS(err);
19549
19550 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019551 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019552 VkSemaphore s;
19553 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
19554 ASSERT_VK_SUCCESS(err);
19555
19556 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019557 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019558
19559 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
19560 ASSERT_VK_SUCCESS(err);
19561
19562 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019563 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019564 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019565
19566 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
19567 ASSERT_VK_SUCCESS(err);
19568
19569 // Wait for q0 idle
19570 err = vkQueueWaitIdle(q0);
19571 ASSERT_VK_SUCCESS(err);
19572
19573 // Command buffer should have been completed (it was on q0); reset the pool.
19574 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
19575
19576 m_errorMonitor->VerifyNotFound();
19577
19578 // Force device completely idle and clean up resources
19579 vkDeviceWaitIdle(m_device->device());
19580 vkDestroyCommandPool(m_device->device(), pool, nullptr);
19581 vkDestroySemaphore(m_device->device(), s, nullptr);
19582}
19583
19584// This is a positive test. No errors should be generated.
19585TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019586 TEST_DESCRIPTION(
19587 "Two command buffers, each in a separate QueueSubmit call "
19588 "submitted on separate queues, the second having a fence, "
19589 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019590
19591 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019592 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019593
19594 m_errorMonitor->ExpectSuccess();
19595
19596 ASSERT_NO_FATAL_FAILURE(InitState());
19597 VkFence fence;
19598 VkFenceCreateInfo fence_create_info{};
19599 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19600 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19601
19602 VkSemaphore semaphore;
19603 VkSemaphoreCreateInfo semaphore_create_info{};
19604 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19605 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19606
19607 VkCommandPool command_pool;
19608 VkCommandPoolCreateInfo pool_create_info{};
19609 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19610 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19611 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19612 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19613
19614 VkCommandBuffer command_buffer[2];
19615 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19616 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19617 command_buffer_allocate_info.commandPool = command_pool;
19618 command_buffer_allocate_info.commandBufferCount = 2;
19619 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19620 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19621
19622 VkQueue queue = VK_NULL_HANDLE;
19623 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19624
19625 {
19626 VkCommandBufferBeginInfo begin_info{};
19627 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19628 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19629
19630 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 -070019631 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019632
19633 VkViewport viewport{};
19634 viewport.maxDepth = 1.0f;
19635 viewport.minDepth = 0.0f;
19636 viewport.width = 512;
19637 viewport.height = 512;
19638 viewport.x = 0;
19639 viewport.y = 0;
19640 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19641 vkEndCommandBuffer(command_buffer[0]);
19642 }
19643 {
19644 VkCommandBufferBeginInfo begin_info{};
19645 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19646 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19647
19648 VkViewport viewport{};
19649 viewport.maxDepth = 1.0f;
19650 viewport.minDepth = 0.0f;
19651 viewport.width = 512;
19652 viewport.height = 512;
19653 viewport.x = 0;
19654 viewport.y = 0;
19655 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19656 vkEndCommandBuffer(command_buffer[1]);
19657 }
19658 {
19659 VkSubmitInfo submit_info{};
19660 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19661 submit_info.commandBufferCount = 1;
19662 submit_info.pCommandBuffers = &command_buffer[0];
19663 submit_info.signalSemaphoreCount = 1;
19664 submit_info.pSignalSemaphores = &semaphore;
19665 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19666 }
19667 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019668 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019669 VkSubmitInfo submit_info{};
19670 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19671 submit_info.commandBufferCount = 1;
19672 submit_info.pCommandBuffers = &command_buffer[1];
19673 submit_info.waitSemaphoreCount = 1;
19674 submit_info.pWaitSemaphores = &semaphore;
19675 submit_info.pWaitDstStageMask = flags;
19676 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19677 }
19678
19679 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19680
19681 vkDestroyFence(m_device->device(), fence, nullptr);
19682 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19683 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19684 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19685
19686 m_errorMonitor->VerifyNotFound();
19687}
19688
19689// This is a positive test. No errors should be generated.
19690TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019691 TEST_DESCRIPTION(
19692 "Two command buffers, each in a separate QueueSubmit call "
19693 "on the same queue, sharing a signal/wait semaphore, the "
19694 "second having a fence, "
19695 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019696
19697 m_errorMonitor->ExpectSuccess();
19698
19699 ASSERT_NO_FATAL_FAILURE(InitState());
19700 VkFence fence;
19701 VkFenceCreateInfo fence_create_info{};
19702 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19703 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19704
19705 VkSemaphore semaphore;
19706 VkSemaphoreCreateInfo semaphore_create_info{};
19707 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19708 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19709
19710 VkCommandPool command_pool;
19711 VkCommandPoolCreateInfo pool_create_info{};
19712 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19713 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19714 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19715 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19716
19717 VkCommandBuffer command_buffer[2];
19718 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19719 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19720 command_buffer_allocate_info.commandPool = command_pool;
19721 command_buffer_allocate_info.commandBufferCount = 2;
19722 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19723 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19724
19725 {
19726 VkCommandBufferBeginInfo begin_info{};
19727 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19728 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19729
19730 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 -070019731 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019732
19733 VkViewport viewport{};
19734 viewport.maxDepth = 1.0f;
19735 viewport.minDepth = 0.0f;
19736 viewport.width = 512;
19737 viewport.height = 512;
19738 viewport.x = 0;
19739 viewport.y = 0;
19740 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19741 vkEndCommandBuffer(command_buffer[0]);
19742 }
19743 {
19744 VkCommandBufferBeginInfo begin_info{};
19745 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19746 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19747
19748 VkViewport viewport{};
19749 viewport.maxDepth = 1.0f;
19750 viewport.minDepth = 0.0f;
19751 viewport.width = 512;
19752 viewport.height = 512;
19753 viewport.x = 0;
19754 viewport.y = 0;
19755 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19756 vkEndCommandBuffer(command_buffer[1]);
19757 }
19758 {
19759 VkSubmitInfo submit_info{};
19760 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19761 submit_info.commandBufferCount = 1;
19762 submit_info.pCommandBuffers = &command_buffer[0];
19763 submit_info.signalSemaphoreCount = 1;
19764 submit_info.pSignalSemaphores = &semaphore;
19765 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19766 }
19767 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019768 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019769 VkSubmitInfo submit_info{};
19770 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19771 submit_info.commandBufferCount = 1;
19772 submit_info.pCommandBuffers = &command_buffer[1];
19773 submit_info.waitSemaphoreCount = 1;
19774 submit_info.pWaitSemaphores = &semaphore;
19775 submit_info.pWaitDstStageMask = flags;
19776 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19777 }
19778
19779 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19780
19781 vkDestroyFence(m_device->device(), fence, nullptr);
19782 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19783 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19784 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19785
19786 m_errorMonitor->VerifyNotFound();
19787}
19788
19789// This is a positive test. No errors should be generated.
19790TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019791 TEST_DESCRIPTION(
19792 "Two command buffers, each in a separate QueueSubmit call "
19793 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19794 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019795
19796 m_errorMonitor->ExpectSuccess();
19797
19798 ASSERT_NO_FATAL_FAILURE(InitState());
19799 VkFence fence;
19800 VkFenceCreateInfo fence_create_info{};
19801 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19802 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19803
19804 VkCommandPool command_pool;
19805 VkCommandPoolCreateInfo pool_create_info{};
19806 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19807 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19808 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19809 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19810
19811 VkCommandBuffer command_buffer[2];
19812 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19813 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19814 command_buffer_allocate_info.commandPool = command_pool;
19815 command_buffer_allocate_info.commandBufferCount = 2;
19816 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19817 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19818
19819 {
19820 VkCommandBufferBeginInfo begin_info{};
19821 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19822 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19823
19824 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 -070019825 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019826
19827 VkViewport viewport{};
19828 viewport.maxDepth = 1.0f;
19829 viewport.minDepth = 0.0f;
19830 viewport.width = 512;
19831 viewport.height = 512;
19832 viewport.x = 0;
19833 viewport.y = 0;
19834 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19835 vkEndCommandBuffer(command_buffer[0]);
19836 }
19837 {
19838 VkCommandBufferBeginInfo begin_info{};
19839 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19840 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19841
19842 VkViewport viewport{};
19843 viewport.maxDepth = 1.0f;
19844 viewport.minDepth = 0.0f;
19845 viewport.width = 512;
19846 viewport.height = 512;
19847 viewport.x = 0;
19848 viewport.y = 0;
19849 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19850 vkEndCommandBuffer(command_buffer[1]);
19851 }
19852 {
19853 VkSubmitInfo submit_info{};
19854 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19855 submit_info.commandBufferCount = 1;
19856 submit_info.pCommandBuffers = &command_buffer[0];
19857 submit_info.signalSemaphoreCount = 0;
19858 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19859 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19860 }
19861 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019862 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019863 VkSubmitInfo submit_info{};
19864 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19865 submit_info.commandBufferCount = 1;
19866 submit_info.pCommandBuffers = &command_buffer[1];
19867 submit_info.waitSemaphoreCount = 0;
19868 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19869 submit_info.pWaitDstStageMask = flags;
19870 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19871 }
19872
19873 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19874
19875 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19876 ASSERT_VK_SUCCESS(err);
19877
19878 vkDestroyFence(m_device->device(), fence, nullptr);
19879 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19880 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19881
19882 m_errorMonitor->VerifyNotFound();
19883}
19884
19885// This is a positive test. No errors should be generated.
19886TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019887 TEST_DESCRIPTION(
19888 "Two command buffers, each in a separate QueueSubmit call "
19889 "on the same queue, the second having a fence, followed "
19890 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019891
19892 m_errorMonitor->ExpectSuccess();
19893
19894 ASSERT_NO_FATAL_FAILURE(InitState());
19895 VkFence fence;
19896 VkFenceCreateInfo fence_create_info{};
19897 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19898 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19899
19900 VkCommandPool command_pool;
19901 VkCommandPoolCreateInfo pool_create_info{};
19902 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19903 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19904 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19905 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19906
19907 VkCommandBuffer command_buffer[2];
19908 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19909 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19910 command_buffer_allocate_info.commandPool = command_pool;
19911 command_buffer_allocate_info.commandBufferCount = 2;
19912 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19913 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19914
19915 {
19916 VkCommandBufferBeginInfo begin_info{};
19917 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19918 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19919
19920 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 -070019921 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019922
19923 VkViewport viewport{};
19924 viewport.maxDepth = 1.0f;
19925 viewport.minDepth = 0.0f;
19926 viewport.width = 512;
19927 viewport.height = 512;
19928 viewport.x = 0;
19929 viewport.y = 0;
19930 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19931 vkEndCommandBuffer(command_buffer[0]);
19932 }
19933 {
19934 VkCommandBufferBeginInfo begin_info{};
19935 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19936 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19937
19938 VkViewport viewport{};
19939 viewport.maxDepth = 1.0f;
19940 viewport.minDepth = 0.0f;
19941 viewport.width = 512;
19942 viewport.height = 512;
19943 viewport.x = 0;
19944 viewport.y = 0;
19945 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19946 vkEndCommandBuffer(command_buffer[1]);
19947 }
19948 {
19949 VkSubmitInfo submit_info{};
19950 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19951 submit_info.commandBufferCount = 1;
19952 submit_info.pCommandBuffers = &command_buffer[0];
19953 submit_info.signalSemaphoreCount = 0;
19954 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19955 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19956 }
19957 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019958 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019959 VkSubmitInfo submit_info{};
19960 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19961 submit_info.commandBufferCount = 1;
19962 submit_info.pCommandBuffers = &command_buffer[1];
19963 submit_info.waitSemaphoreCount = 0;
19964 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19965 submit_info.pWaitDstStageMask = flags;
19966 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19967 }
19968
19969 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19970
19971 vkDestroyFence(m_device->device(), fence, nullptr);
19972 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19973 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19974
19975 m_errorMonitor->VerifyNotFound();
19976}
19977
19978// This is a positive test. No errors should be generated.
19979TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019980 TEST_DESCRIPTION(
19981 "Two command buffers each in a separate SubmitInfo sent in a single "
19982 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019983 ASSERT_NO_FATAL_FAILURE(InitState());
19984
19985 m_errorMonitor->ExpectSuccess();
19986
19987 VkFence fence;
19988 VkFenceCreateInfo fence_create_info{};
19989 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19990 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19991
19992 VkSemaphore semaphore;
19993 VkSemaphoreCreateInfo semaphore_create_info{};
19994 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19995 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19996
19997 VkCommandPool command_pool;
19998 VkCommandPoolCreateInfo pool_create_info{};
19999 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20000 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20001 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20002 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20003
20004 VkCommandBuffer command_buffer[2];
20005 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20006 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20007 command_buffer_allocate_info.commandPool = command_pool;
20008 command_buffer_allocate_info.commandBufferCount = 2;
20009 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20010 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20011
20012 {
20013 VkCommandBufferBeginInfo begin_info{};
20014 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20015 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20016
20017 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 -070020018 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020019
20020 VkViewport viewport{};
20021 viewport.maxDepth = 1.0f;
20022 viewport.minDepth = 0.0f;
20023 viewport.width = 512;
20024 viewport.height = 512;
20025 viewport.x = 0;
20026 viewport.y = 0;
20027 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20028 vkEndCommandBuffer(command_buffer[0]);
20029 }
20030 {
20031 VkCommandBufferBeginInfo begin_info{};
20032 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20033 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20034
20035 VkViewport viewport{};
20036 viewport.maxDepth = 1.0f;
20037 viewport.minDepth = 0.0f;
20038 viewport.width = 512;
20039 viewport.height = 512;
20040 viewport.x = 0;
20041 viewport.y = 0;
20042 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20043 vkEndCommandBuffer(command_buffer[1]);
20044 }
20045 {
20046 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020047 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020048
20049 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20050 submit_info[0].pNext = NULL;
20051 submit_info[0].commandBufferCount = 1;
20052 submit_info[0].pCommandBuffers = &command_buffer[0];
20053 submit_info[0].signalSemaphoreCount = 1;
20054 submit_info[0].pSignalSemaphores = &semaphore;
20055 submit_info[0].waitSemaphoreCount = 0;
20056 submit_info[0].pWaitSemaphores = NULL;
20057 submit_info[0].pWaitDstStageMask = 0;
20058
20059 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20060 submit_info[1].pNext = NULL;
20061 submit_info[1].commandBufferCount = 1;
20062 submit_info[1].pCommandBuffers = &command_buffer[1];
20063 submit_info[1].waitSemaphoreCount = 1;
20064 submit_info[1].pWaitSemaphores = &semaphore;
20065 submit_info[1].pWaitDstStageMask = flags;
20066 submit_info[1].signalSemaphoreCount = 0;
20067 submit_info[1].pSignalSemaphores = NULL;
20068 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
20069 }
20070
20071 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20072
20073 vkDestroyFence(m_device->device(), fence, nullptr);
20074 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20075 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20076 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20077
20078 m_errorMonitor->VerifyNotFound();
20079}
20080
20081TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
20082 m_errorMonitor->ExpectSuccess();
20083
20084 ASSERT_NO_FATAL_FAILURE(InitState());
20085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20086
Tony Barbour552f6c02016-12-21 14:34:07 -070020087 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020088
20089 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
20090 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
20091 m_errorMonitor->VerifyNotFound();
20092 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
20093 m_errorMonitor->VerifyNotFound();
20094 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
20095 m_errorMonitor->VerifyNotFound();
20096
20097 m_commandBuffer->EndCommandBuffer();
20098 m_errorMonitor->VerifyNotFound();
20099}
20100
20101TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020102 TEST_DESCRIPTION(
20103 "Positive test where we create a renderpass with an "
20104 "attachment that uses LOAD_OP_CLEAR, the first subpass "
20105 "has a valid layout, and a second subpass then uses a "
20106 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020107 m_errorMonitor->ExpectSuccess();
20108 ASSERT_NO_FATAL_FAILURE(InitState());
20109
20110 VkAttachmentReference attach[2] = {};
20111 attach[0].attachment = 0;
20112 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20113 attach[1].attachment = 0;
20114 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
20115 VkSubpassDescription subpasses[2] = {};
20116 // First subpass clears DS attach on load
20117 subpasses[0].pDepthStencilAttachment = &attach[0];
20118 // 2nd subpass reads in DS as input attachment
20119 subpasses[1].inputAttachmentCount = 1;
20120 subpasses[1].pInputAttachments = &attach[1];
20121 VkAttachmentDescription attach_desc = {};
20122 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
20123 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
20124 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
20125 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
20126 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20127 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20128 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20129 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
20130 VkRenderPassCreateInfo rpci = {};
20131 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20132 rpci.attachmentCount = 1;
20133 rpci.pAttachments = &attach_desc;
20134 rpci.subpassCount = 2;
20135 rpci.pSubpasses = subpasses;
20136
20137 // Now create RenderPass and verify no errors
20138 VkRenderPass rp;
20139 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
20140 m_errorMonitor->VerifyNotFound();
20141
20142 vkDestroyRenderPass(m_device->device(), rp, NULL);
20143}
20144
20145TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020146 TEST_DESCRIPTION(
20147 "Test that pipeline validation accepts matrices passed "
20148 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020149 m_errorMonitor->ExpectSuccess();
20150
20151 ASSERT_NO_FATAL_FAILURE(InitState());
20152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20153
20154 VkVertexInputBindingDescription input_binding;
20155 memset(&input_binding, 0, sizeof(input_binding));
20156
20157 VkVertexInputAttributeDescription input_attribs[2];
20158 memset(input_attribs, 0, sizeof(input_attribs));
20159
20160 for (int i = 0; i < 2; i++) {
20161 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20162 input_attribs[i].location = i;
20163 }
20164
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020165 char const *vsSource =
20166 "#version 450\n"
20167 "\n"
20168 "layout(location=0) in mat2x4 x;\n"
20169 "out gl_PerVertex {\n"
20170 " vec4 gl_Position;\n"
20171 "};\n"
20172 "void main(){\n"
20173 " gl_Position = x[0] + x[1];\n"
20174 "}\n";
20175 char const *fsSource =
20176 "#version 450\n"
20177 "\n"
20178 "layout(location=0) out vec4 color;\n"
20179 "void main(){\n"
20180 " color = vec4(1);\n"
20181 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020182
20183 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20184 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20185
20186 VkPipelineObj pipe(m_device);
20187 pipe.AddColorAttachment();
20188 pipe.AddShader(&vs);
20189 pipe.AddShader(&fs);
20190
20191 pipe.AddVertexInputBindings(&input_binding, 1);
20192 pipe.AddVertexInputAttribs(input_attribs, 2);
20193
20194 VkDescriptorSetObj descriptorSet(m_device);
20195 descriptorSet.AppendDummy();
20196 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20197
20198 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20199
20200 /* expect success */
20201 m_errorMonitor->VerifyNotFound();
20202}
20203
20204TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
20205 m_errorMonitor->ExpectSuccess();
20206
20207 ASSERT_NO_FATAL_FAILURE(InitState());
20208 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20209
20210 VkVertexInputBindingDescription input_binding;
20211 memset(&input_binding, 0, sizeof(input_binding));
20212
20213 VkVertexInputAttributeDescription input_attribs[2];
20214 memset(input_attribs, 0, sizeof(input_attribs));
20215
20216 for (int i = 0; i < 2; i++) {
20217 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20218 input_attribs[i].location = i;
20219 }
20220
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020221 char const *vsSource =
20222 "#version 450\n"
20223 "\n"
20224 "layout(location=0) in vec4 x[2];\n"
20225 "out gl_PerVertex {\n"
20226 " vec4 gl_Position;\n"
20227 "};\n"
20228 "void main(){\n"
20229 " gl_Position = x[0] + x[1];\n"
20230 "}\n";
20231 char const *fsSource =
20232 "#version 450\n"
20233 "\n"
20234 "layout(location=0) out vec4 color;\n"
20235 "void main(){\n"
20236 " color = vec4(1);\n"
20237 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020238
20239 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20240 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20241
20242 VkPipelineObj pipe(m_device);
20243 pipe.AddColorAttachment();
20244 pipe.AddShader(&vs);
20245 pipe.AddShader(&fs);
20246
20247 pipe.AddVertexInputBindings(&input_binding, 1);
20248 pipe.AddVertexInputAttribs(input_attribs, 2);
20249
20250 VkDescriptorSetObj descriptorSet(m_device);
20251 descriptorSet.AppendDummy();
20252 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20253
20254 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20255
20256 m_errorMonitor->VerifyNotFound();
20257}
20258
20259TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020260 TEST_DESCRIPTION(
20261 "Test that pipeline validation accepts consuming a vertex attribute "
20262 "through multiple vertex shader inputs, each consuming a different "
20263 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020264 m_errorMonitor->ExpectSuccess();
20265
20266 ASSERT_NO_FATAL_FAILURE(InitState());
20267 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20268
20269 VkVertexInputBindingDescription input_binding;
20270 memset(&input_binding, 0, sizeof(input_binding));
20271
20272 VkVertexInputAttributeDescription input_attribs[3];
20273 memset(input_attribs, 0, sizeof(input_attribs));
20274
20275 for (int i = 0; i < 3; i++) {
20276 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20277 input_attribs[i].location = i;
20278 }
20279
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020280 char const *vsSource =
20281 "#version 450\n"
20282 "\n"
20283 "layout(location=0) in vec4 x;\n"
20284 "layout(location=1) in vec3 y1;\n"
20285 "layout(location=1, component=3) in float y2;\n"
20286 "layout(location=2) in vec4 z;\n"
20287 "out gl_PerVertex {\n"
20288 " vec4 gl_Position;\n"
20289 "};\n"
20290 "void main(){\n"
20291 " gl_Position = x + vec4(y1, y2) + z;\n"
20292 "}\n";
20293 char const *fsSource =
20294 "#version 450\n"
20295 "\n"
20296 "layout(location=0) out vec4 color;\n"
20297 "void main(){\n"
20298 " color = vec4(1);\n"
20299 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020300
20301 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20302 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20303
20304 VkPipelineObj pipe(m_device);
20305 pipe.AddColorAttachment();
20306 pipe.AddShader(&vs);
20307 pipe.AddShader(&fs);
20308
20309 pipe.AddVertexInputBindings(&input_binding, 1);
20310 pipe.AddVertexInputAttribs(input_attribs, 3);
20311
20312 VkDescriptorSetObj descriptorSet(m_device);
20313 descriptorSet.AppendDummy();
20314 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20315
20316 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20317
20318 m_errorMonitor->VerifyNotFound();
20319}
20320
20321TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
20322 m_errorMonitor->ExpectSuccess();
20323
20324 ASSERT_NO_FATAL_FAILURE(InitState());
20325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20326
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020327 char const *vsSource =
20328 "#version 450\n"
20329 "out gl_PerVertex {\n"
20330 " vec4 gl_Position;\n"
20331 "};\n"
20332 "void main(){\n"
20333 " gl_Position = vec4(0);\n"
20334 "}\n";
20335 char const *fsSource =
20336 "#version 450\n"
20337 "\n"
20338 "layout(location=0) out vec4 color;\n"
20339 "void main(){\n"
20340 " color = vec4(1);\n"
20341 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020342
20343 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20344 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20345
20346 VkPipelineObj pipe(m_device);
20347 pipe.AddColorAttachment();
20348 pipe.AddShader(&vs);
20349 pipe.AddShader(&fs);
20350
20351 VkDescriptorSetObj descriptorSet(m_device);
20352 descriptorSet.AppendDummy();
20353 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20354
20355 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20356
20357 m_errorMonitor->VerifyNotFound();
20358}
20359
20360TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020361 TEST_DESCRIPTION(
20362 "Test that pipeline validation accepts the relaxed type matching rules "
20363 "set out in 14.1.3: fundamental type must match, and producer side must "
20364 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020365 m_errorMonitor->ExpectSuccess();
20366
20367 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
20368
20369 ASSERT_NO_FATAL_FAILURE(InitState());
20370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20371
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020372 char const *vsSource =
20373 "#version 450\n"
20374 "out gl_PerVertex {\n"
20375 " vec4 gl_Position;\n"
20376 "};\n"
20377 "layout(location=0) out vec3 x;\n"
20378 "layout(location=1) out ivec3 y;\n"
20379 "layout(location=2) out vec3 z;\n"
20380 "void main(){\n"
20381 " gl_Position = vec4(0);\n"
20382 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
20383 "}\n";
20384 char const *fsSource =
20385 "#version 450\n"
20386 "\n"
20387 "layout(location=0) out vec4 color;\n"
20388 "layout(location=0) in float x;\n"
20389 "layout(location=1) flat in int y;\n"
20390 "layout(location=2) in vec2 z;\n"
20391 "void main(){\n"
20392 " color = vec4(1 + x + y + z.x);\n"
20393 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020394
20395 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20396 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20397
20398 VkPipelineObj pipe(m_device);
20399 pipe.AddColorAttachment();
20400 pipe.AddShader(&vs);
20401 pipe.AddShader(&fs);
20402
20403 VkDescriptorSetObj descriptorSet(m_device);
20404 descriptorSet.AppendDummy();
20405 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20406
20407 VkResult err = VK_SUCCESS;
20408 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20409 ASSERT_VK_SUCCESS(err);
20410
20411 m_errorMonitor->VerifyNotFound();
20412}
20413
20414TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020415 TEST_DESCRIPTION(
20416 "Test that pipeline validation accepts per-vertex variables "
20417 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020418 m_errorMonitor->ExpectSuccess();
20419
20420 ASSERT_NO_FATAL_FAILURE(InitState());
20421 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20422
20423 if (!m_device->phy().features().tessellationShader) {
20424 printf("Device does not support tessellation shaders; skipped.\n");
20425 return;
20426 }
20427
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020428 char const *vsSource =
20429 "#version 450\n"
20430 "void main(){}\n";
20431 char const *tcsSource =
20432 "#version 450\n"
20433 "layout(location=0) out int x[];\n"
20434 "layout(vertices=3) out;\n"
20435 "void main(){\n"
20436 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
20437 " gl_TessLevelInner[0] = 1;\n"
20438 " x[gl_InvocationID] = gl_InvocationID;\n"
20439 "}\n";
20440 char const *tesSource =
20441 "#version 450\n"
20442 "layout(triangles, equal_spacing, cw) in;\n"
20443 "layout(location=0) in int x[];\n"
20444 "out gl_PerVertex { vec4 gl_Position; };\n"
20445 "void main(){\n"
20446 " gl_Position.xyz = gl_TessCoord;\n"
20447 " gl_Position.w = x[0] + x[1] + x[2];\n"
20448 "}\n";
20449 char const *fsSource =
20450 "#version 450\n"
20451 "layout(location=0) out vec4 color;\n"
20452 "void main(){\n"
20453 " color = vec4(1);\n"
20454 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020455
20456 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20457 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
20458 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
20459 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20460
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020461 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
20462 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020463
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020464 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020465
20466 VkPipelineObj pipe(m_device);
20467 pipe.SetInputAssembly(&iasci);
20468 pipe.SetTessellation(&tsci);
20469 pipe.AddColorAttachment();
20470 pipe.AddShader(&vs);
20471 pipe.AddShader(&tcs);
20472 pipe.AddShader(&tes);
20473 pipe.AddShader(&fs);
20474
20475 VkDescriptorSetObj descriptorSet(m_device);
20476 descriptorSet.AppendDummy();
20477 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20478
20479 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20480
20481 m_errorMonitor->VerifyNotFound();
20482}
20483
20484TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020485 TEST_DESCRIPTION(
20486 "Test that pipeline validation accepts a user-defined "
20487 "interface block passed into the geometry shader. This "
20488 "is interesting because the 'extra' array level is not "
20489 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020490 m_errorMonitor->ExpectSuccess();
20491
20492 ASSERT_NO_FATAL_FAILURE(InitState());
20493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20494
20495 if (!m_device->phy().features().geometryShader) {
20496 printf("Device does not support geometry shaders; skipped.\n");
20497 return;
20498 }
20499
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020500 char const *vsSource =
20501 "#version 450\n"
20502 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
20503 "void main(){\n"
20504 " vs_out.x = vec4(1);\n"
20505 "}\n";
20506 char const *gsSource =
20507 "#version 450\n"
20508 "layout(triangles) in;\n"
20509 "layout(triangle_strip, max_vertices=3) out;\n"
20510 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
20511 "out gl_PerVertex { vec4 gl_Position; };\n"
20512 "void main() {\n"
20513 " gl_Position = gs_in[0].x;\n"
20514 " EmitVertex();\n"
20515 "}\n";
20516 char const *fsSource =
20517 "#version 450\n"
20518 "layout(location=0) out vec4 color;\n"
20519 "void main(){\n"
20520 " color = vec4(1);\n"
20521 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020522
20523 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20524 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
20525 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20526
20527 VkPipelineObj pipe(m_device);
20528 pipe.AddColorAttachment();
20529 pipe.AddShader(&vs);
20530 pipe.AddShader(&gs);
20531 pipe.AddShader(&fs);
20532
20533 VkDescriptorSetObj descriptorSet(m_device);
20534 descriptorSet.AppendDummy();
20535 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20536
20537 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20538
20539 m_errorMonitor->VerifyNotFound();
20540}
20541
20542TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020543 TEST_DESCRIPTION(
20544 "Test that pipeline validation accepts basic use of 64bit vertex "
20545 "attributes. This is interesting because they consume multiple "
20546 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020547 m_errorMonitor->ExpectSuccess();
20548
20549 ASSERT_NO_FATAL_FAILURE(InitState());
20550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20551
20552 if (!m_device->phy().features().shaderFloat64) {
20553 printf("Device does not support 64bit vertex attributes; skipped.\n");
20554 return;
20555 }
20556
20557 VkVertexInputBindingDescription input_bindings[1];
20558 memset(input_bindings, 0, sizeof(input_bindings));
20559
20560 VkVertexInputAttributeDescription input_attribs[4];
20561 memset(input_attribs, 0, sizeof(input_attribs));
20562 input_attribs[0].location = 0;
20563 input_attribs[0].offset = 0;
20564 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20565 input_attribs[1].location = 2;
20566 input_attribs[1].offset = 32;
20567 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20568 input_attribs[2].location = 4;
20569 input_attribs[2].offset = 64;
20570 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20571 input_attribs[3].location = 6;
20572 input_attribs[3].offset = 96;
20573 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20574
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020575 char const *vsSource =
20576 "#version 450\n"
20577 "\n"
20578 "layout(location=0) in dmat4 x;\n"
20579 "out gl_PerVertex {\n"
20580 " vec4 gl_Position;\n"
20581 "};\n"
20582 "void main(){\n"
20583 " gl_Position = vec4(x[0][0]);\n"
20584 "}\n";
20585 char const *fsSource =
20586 "#version 450\n"
20587 "\n"
20588 "layout(location=0) out vec4 color;\n"
20589 "void main(){\n"
20590 " color = vec4(1);\n"
20591 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020592
20593 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20594 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20595
20596 VkPipelineObj pipe(m_device);
20597 pipe.AddColorAttachment();
20598 pipe.AddShader(&vs);
20599 pipe.AddShader(&fs);
20600
20601 pipe.AddVertexInputBindings(input_bindings, 1);
20602 pipe.AddVertexInputAttribs(input_attribs, 4);
20603
20604 VkDescriptorSetObj descriptorSet(m_device);
20605 descriptorSet.AppendDummy();
20606 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20607
20608 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20609
20610 m_errorMonitor->VerifyNotFound();
20611}
20612
20613TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
20614 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
20615 m_errorMonitor->ExpectSuccess();
20616
20617 ASSERT_NO_FATAL_FAILURE(InitState());
20618
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020619 char const *vsSource =
20620 "#version 450\n"
20621 "\n"
20622 "out gl_PerVertex {\n"
20623 " vec4 gl_Position;\n"
20624 "};\n"
20625 "void main(){\n"
20626 " gl_Position = vec4(1);\n"
20627 "}\n";
20628 char const *fsSource =
20629 "#version 450\n"
20630 "\n"
20631 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
20632 "layout(location=0) out vec4 color;\n"
20633 "void main() {\n"
20634 " color = subpassLoad(x);\n"
20635 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020636
20637 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20638 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20639
20640 VkPipelineObj pipe(m_device);
20641 pipe.AddShader(&vs);
20642 pipe.AddShader(&fs);
20643 pipe.AddColorAttachment();
20644 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20645
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020646 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
20647 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020648 VkDescriptorSetLayout dsl;
20649 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20650 ASSERT_VK_SUCCESS(err);
20651
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020652 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020653 VkPipelineLayout pl;
20654 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20655 ASSERT_VK_SUCCESS(err);
20656
20657 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020658 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20659 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20660 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
20661 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20662 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 -060020663 };
20664 VkAttachmentReference color = {
20665 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20666 };
20667 VkAttachmentReference input = {
20668 1, VK_IMAGE_LAYOUT_GENERAL,
20669 };
20670
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020671 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020672
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020673 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020674 VkRenderPass rp;
20675 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20676 ASSERT_VK_SUCCESS(err);
20677
20678 // should be OK. would go wrong here if it's going to...
20679 pipe.CreateVKPipeline(pl, rp);
20680
20681 m_errorMonitor->VerifyNotFound();
20682
20683 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20684 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20685 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20686}
20687
20688TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020689 TEST_DESCRIPTION(
20690 "Test that pipeline validation accepts a compute pipeline which declares a "
20691 "descriptor-backed resource which is not provided, but the shader does not "
20692 "statically use it. This is interesting because it requires compute pipelines "
20693 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020694 m_errorMonitor->ExpectSuccess();
20695
20696 ASSERT_NO_FATAL_FAILURE(InitState());
20697
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020698 char const *csSource =
20699 "#version 450\n"
20700 "\n"
20701 "layout(local_size_x=1) in;\n"
20702 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
20703 "void main(){\n"
20704 " // x is not used.\n"
20705 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020706
20707 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20708
20709 VkDescriptorSetObj descriptorSet(m_device);
20710 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20711
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020712 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20713 nullptr,
20714 0,
20715 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20716 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20717 descriptorSet.GetPipelineLayout(),
20718 VK_NULL_HANDLE,
20719 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020720
20721 VkPipeline pipe;
20722 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20723
20724 m_errorMonitor->VerifyNotFound();
20725
20726 if (err == VK_SUCCESS) {
20727 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20728 }
20729}
20730
20731TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020732 TEST_DESCRIPTION(
20733 "Test that pipeline validation accepts a shader consuming only the "
20734 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020735 m_errorMonitor->ExpectSuccess();
20736
20737 ASSERT_NO_FATAL_FAILURE(InitState());
20738
20739 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020740 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20741 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20742 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020743 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020744 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020745 VkDescriptorSetLayout dsl;
20746 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20747 ASSERT_VK_SUCCESS(err);
20748
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020749 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020750 VkPipelineLayout pl;
20751 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20752 ASSERT_VK_SUCCESS(err);
20753
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020754 char const *csSource =
20755 "#version 450\n"
20756 "\n"
20757 "layout(local_size_x=1) in;\n"
20758 "layout(set=0, binding=0) uniform sampler s;\n"
20759 "layout(set=0, binding=1) uniform texture2D t;\n"
20760 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20761 "void main() {\n"
20762 " x = texture(sampler2D(t, s), vec2(0));\n"
20763 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020764 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20765
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020766 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20767 nullptr,
20768 0,
20769 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20770 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20771 pl,
20772 VK_NULL_HANDLE,
20773 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020774
20775 VkPipeline pipe;
20776 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20777
20778 m_errorMonitor->VerifyNotFound();
20779
20780 if (err == VK_SUCCESS) {
20781 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20782 }
20783
20784 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20785 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20786}
20787
20788TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020789 TEST_DESCRIPTION(
20790 "Test that pipeline validation accepts a shader consuming only the "
20791 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020792 m_errorMonitor->ExpectSuccess();
20793
20794 ASSERT_NO_FATAL_FAILURE(InitState());
20795
20796 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020797 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20798 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20799 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020800 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020801 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020802 VkDescriptorSetLayout dsl;
20803 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20804 ASSERT_VK_SUCCESS(err);
20805
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020806 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020807 VkPipelineLayout pl;
20808 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20809 ASSERT_VK_SUCCESS(err);
20810
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020811 char const *csSource =
20812 "#version 450\n"
20813 "\n"
20814 "layout(local_size_x=1) in;\n"
20815 "layout(set=0, binding=0) uniform texture2D t;\n"
20816 "layout(set=0, binding=1) uniform sampler s;\n"
20817 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20818 "void main() {\n"
20819 " x = texture(sampler2D(t, s), vec2(0));\n"
20820 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020821 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20822
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020823 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20824 nullptr,
20825 0,
20826 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20827 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20828 pl,
20829 VK_NULL_HANDLE,
20830 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020831
20832 VkPipeline pipe;
20833 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20834
20835 m_errorMonitor->VerifyNotFound();
20836
20837 if (err == VK_SUCCESS) {
20838 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20839 }
20840
20841 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20842 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20843}
20844
20845TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020846 TEST_DESCRIPTION(
20847 "Test that pipeline validation accepts a shader consuming "
20848 "both the sampler and the image of a combined image+sampler "
20849 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020850 m_errorMonitor->ExpectSuccess();
20851
20852 ASSERT_NO_FATAL_FAILURE(InitState());
20853
20854 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020855 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20856 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020857 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020858 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020859 VkDescriptorSetLayout dsl;
20860 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20861 ASSERT_VK_SUCCESS(err);
20862
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020863 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020864 VkPipelineLayout pl;
20865 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20866 ASSERT_VK_SUCCESS(err);
20867
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020868 char const *csSource =
20869 "#version 450\n"
20870 "\n"
20871 "layout(local_size_x=1) in;\n"
20872 "layout(set=0, binding=0) uniform texture2D t;\n"
20873 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20874 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20875 "void main() {\n"
20876 " x = texture(sampler2D(t, s), vec2(0));\n"
20877 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020878 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20879
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020880 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20881 nullptr,
20882 0,
20883 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20884 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20885 pl,
20886 VK_NULL_HANDLE,
20887 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020888
20889 VkPipeline pipe;
20890 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20891
20892 m_errorMonitor->VerifyNotFound();
20893
20894 if (err == VK_SUCCESS) {
20895 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20896 }
20897
20898 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20899 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20900}
20901
20902TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20903 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20904
20905 ASSERT_NO_FATAL_FAILURE(InitState());
20906
20907 // Positive test to check parameter_validation and unique_objects support
20908 // for NV_dedicated_allocation
20909 uint32_t extension_count = 0;
20910 bool supports_nv_dedicated_allocation = false;
20911 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20912 ASSERT_VK_SUCCESS(err);
20913
20914 if (extension_count > 0) {
20915 std::vector<VkExtensionProperties> available_extensions(extension_count);
20916
20917 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20918 ASSERT_VK_SUCCESS(err);
20919
20920 for (const auto &extension_props : available_extensions) {
20921 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20922 supports_nv_dedicated_allocation = true;
20923 }
20924 }
20925 }
20926
20927 if (supports_nv_dedicated_allocation) {
20928 m_errorMonitor->ExpectSuccess();
20929
20930 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20931 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20932 dedicated_buffer_create_info.pNext = nullptr;
20933 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20934
20935 uint32_t queue_family_index = 0;
20936 VkBufferCreateInfo buffer_create_info = {};
20937 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20938 buffer_create_info.pNext = &dedicated_buffer_create_info;
20939 buffer_create_info.size = 1024;
20940 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20941 buffer_create_info.queueFamilyIndexCount = 1;
20942 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20943
20944 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070020945 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020946 ASSERT_VK_SUCCESS(err);
20947
20948 VkMemoryRequirements memory_reqs;
20949 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20950
20951 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20952 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20953 dedicated_memory_info.pNext = nullptr;
20954 dedicated_memory_info.buffer = buffer;
20955 dedicated_memory_info.image = VK_NULL_HANDLE;
20956
20957 VkMemoryAllocateInfo memory_info = {};
20958 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20959 memory_info.pNext = &dedicated_memory_info;
20960 memory_info.allocationSize = memory_reqs.size;
20961
20962 bool pass;
20963 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20964 ASSERT_TRUE(pass);
20965
20966 VkDeviceMemory buffer_memory;
20967 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20968 ASSERT_VK_SUCCESS(err);
20969
20970 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20971 ASSERT_VK_SUCCESS(err);
20972
20973 vkDestroyBuffer(m_device->device(), buffer, NULL);
20974 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20975
20976 m_errorMonitor->VerifyNotFound();
20977 }
20978}
20979
20980TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20981 VkResult err;
20982
20983 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20984
20985 ASSERT_NO_FATAL_FAILURE(InitState());
20986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20987
20988 std::vector<const char *> device_extension_names;
20989 auto features = m_device->phy().features();
20990 // Artificially disable support for non-solid fill modes
20991 features.fillModeNonSolid = false;
20992 // The sacrificial device object
20993 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20994
20995 VkRenderpassObj render_pass(&test_device);
20996
20997 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20998 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20999 pipeline_layout_ci.setLayoutCount = 0;
21000 pipeline_layout_ci.pSetLayouts = NULL;
21001
21002 VkPipelineLayout pipeline_layout;
21003 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21004 ASSERT_VK_SUCCESS(err);
21005
21006 VkPipelineRasterizationStateCreateInfo rs_ci = {};
21007 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
21008 rs_ci.pNext = nullptr;
21009 rs_ci.lineWidth = 1.0f;
21010 rs_ci.rasterizerDiscardEnable = true;
21011
21012 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
21013 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21014
21015 // Set polygonMode=FILL. No error is expected
21016 m_errorMonitor->ExpectSuccess();
21017 {
21018 VkPipelineObj pipe(&test_device);
21019 pipe.AddShader(&vs);
21020 pipe.AddShader(&fs);
21021 pipe.AddColorAttachment();
21022 // Set polygonMode to a good value
21023 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
21024 pipe.SetRasterization(&rs_ci);
21025 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
21026 }
21027 m_errorMonitor->VerifyNotFound();
21028
21029 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
21030}
21031
21032TEST_F(VkPositiveLayerTest, ValidPushConstants) {
21033 VkResult err;
21034 ASSERT_NO_FATAL_FAILURE(InitState());
21035 ASSERT_NO_FATAL_FAILURE(InitViewport());
21036 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21037
21038 VkPipelineLayout pipeline_layout;
21039 VkPushConstantRange pc_range = {};
21040 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
21041 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
21042 pipeline_layout_ci.pushConstantRangeCount = 1;
21043 pipeline_layout_ci.pPushConstantRanges = &pc_range;
21044
21045 //
21046 // Check for invalid push constant ranges in pipeline layouts.
21047 //
21048 struct PipelineLayoutTestCase {
21049 VkPushConstantRange const range;
21050 char const *msg;
21051 };
21052
21053 // Check for overlapping ranges
21054 const uint32_t ranges_per_test = 5;
21055 struct OverlappingRangeTestCase {
21056 VkPushConstantRange const ranges[ranges_per_test];
21057 char const *msg;
21058 };
21059
21060 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021061 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
21062 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
21063 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
21064 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
21065 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
21066 ""},
21067 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
21068 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
21069 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
21070 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
21071 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
21072 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021073 for (const auto &iter : overlapping_range_tests_pos) {
21074 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
21075 m_errorMonitor->ExpectSuccess();
21076 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21077 m_errorMonitor->VerifyNotFound();
21078 if (VK_SUCCESS == err) {
21079 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
21080 }
21081 }
21082
21083 //
21084 // CmdPushConstants tests
21085 //
21086 const uint8_t dummy_values[100] = {};
21087
Tony Barbour552f6c02016-12-21 14:34:07 -070021088 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021089
21090 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021091 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
21092 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
21093 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
21094 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
21095 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
21096 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021097
21098 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
21099 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021100 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
21101 {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 -060021102 };
21103
21104 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
21105 pipeline_layout_ci.pPushConstantRanges = pc_range4;
21106 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21107 ASSERT_VK_SUCCESS(err);
21108 for (const auto &iter : cmd_overlap_tests_pos) {
21109 m_errorMonitor->ExpectSuccess();
21110 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021111 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021112 m_errorMonitor->VerifyNotFound();
21113 }
21114 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
21115
Tony Barbour552f6c02016-12-21 14:34:07 -070021116 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021117}
21118
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021119#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021120TEST_F(VkPositiveLayerTest, LongFenceChain)
21121{
21122 m_errorMonitor->ExpectSuccess();
21123
21124 ASSERT_NO_FATAL_FAILURE(InitState());
21125 VkResult err;
21126
21127 std::vector<VkFence> fences;
21128
21129 const int chainLength = 32768;
21130
21131 for (int i = 0; i < chainLength; i++) {
21132 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
21133 VkFence fence;
21134 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
21135 ASSERT_VK_SUCCESS(err);
21136
21137 fences.push_back(fence);
21138
21139 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
21140 0, nullptr, 0, nullptr };
21141 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
21142 ASSERT_VK_SUCCESS(err);
21143
21144 }
21145
21146 // BOOM, stack overflow.
21147 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
21148
21149 for (auto fence : fences)
21150 vkDestroyFence(m_device->device(), fence, nullptr);
21151
21152 m_errorMonitor->VerifyNotFound();
21153}
21154#endif
21155
Cody Northrop1242dfd2016-07-13 17:24:59 -060021156#if defined(ANDROID) && defined(VALIDATION_APK)
21157static bool initialized = false;
21158static bool active = false;
21159
21160// Convert Intents to argv
21161// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021162std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021163 std::vector<std::string> args;
21164 JavaVM &vm = *app.activity->vm;
21165 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021166 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021167
21168 JNIEnv &env = *p_env;
21169 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021170 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021171 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021172 jmethodID get_string_extra_method =
21173 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021174 jvalue get_string_extra_args;
21175 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021176 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060021177
21178 std::string args_str;
21179 if (extra_str) {
21180 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
21181 args_str = extra_utf;
21182 env.ReleaseStringUTFChars(extra_str, extra_utf);
21183 env.DeleteLocalRef(extra_str);
21184 }
21185
21186 env.DeleteLocalRef(get_string_extra_args.l);
21187 env.DeleteLocalRef(intent);
21188 vm.DetachCurrentThread();
21189
21190 // split args_str
21191 std::stringstream ss(args_str);
21192 std::string arg;
21193 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021194 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021195 }
21196
21197 return args;
21198}
21199
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021200static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021201
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021202static void processCommand(struct android_app *app, int32_t cmd) {
21203 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021204 case APP_CMD_INIT_WINDOW: {
21205 if (app->window) {
21206 initialized = true;
21207 }
21208 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021209 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021210 case APP_CMD_GAINED_FOCUS: {
21211 active = true;
21212 break;
21213 }
21214 case APP_CMD_LOST_FOCUS: {
21215 active = false;
21216 break;
21217 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021218 }
21219}
21220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021221void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021222 app_dummy();
21223
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021224 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060021225
21226 int vulkanSupport = InitVulkan();
21227 if (vulkanSupport == 0) {
21228 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
21229 return;
21230 }
21231
21232 app->onAppCmd = processCommand;
21233 app->onInputEvent = processInput;
21234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021235 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021236 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021237 struct android_poll_source *source;
21238 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021239 if (source) {
21240 source->process(app, source);
21241 }
21242
21243 if (app->destroyRequested != 0) {
21244 VkTestFramework::Finish();
21245 return;
21246 }
21247 }
21248
21249 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021250 // Use the following key to send arguments to gtest, i.e.
21251 // --es args "--gtest_filter=-VkLayerTest.foo"
21252 const char key[] = "args";
21253 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021255 std::string filter = "";
21256 if (args.size() > 0) {
21257 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
21258 filter += args[0];
21259 } else {
21260 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
21261 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021262
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021263 int argc = 2;
21264 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
21265 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021267 // Route output to files until we can override the gtest output
21268 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
21269 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021271 ::testing::InitGoogleTest(&argc, argv);
21272 VkTestFramework::InitArgs(&argc, argv);
21273 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021274
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021275 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060021276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021277 if (result != 0) {
21278 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
21279 } else {
21280 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
21281 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021282
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021283 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060021284
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021285 fclose(stdout);
21286 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021287
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021288 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021290 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021291 }
21292 }
21293}
21294#endif
21295
Tony Barbour300a6082015-04-07 13:44:53 -060021296int main(int argc, char **argv) {
21297 int result;
21298
Cody Northrop8e54a402016-03-08 22:25:52 -070021299#ifdef ANDROID
21300 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021301 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070021302#endif
21303
Tony Barbour300a6082015-04-07 13:44:53 -060021304 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060021305 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060021306
21307 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
21308
21309 result = RUN_ALL_TESTS();
21310
Tony Barbour6918cd52015-04-09 12:58:51 -060021311 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060021312 return result;
21313}