blob: 103322887a3d02cea472c2c668c6408ff85fd58a [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
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"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070039
40#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060041#include <limits.h>
42#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060043
Mark Lobodzinski3780e142015-05-14 15:08:13 -050044#define GLM_FORCE_RADIANS
45#include "glm/glm.hpp"
46#include <glm/gtc/matrix_transform.hpp>
47
48//--------------------------------------------------------------------------------------
49// Mesh and VertexFormat Data
50//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070051struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070052 float posX, posY, posZ, posW; // Position data
53 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050054};
55
Karl Schultz6addd812016-02-02 17:17:23 -070056#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050057
58typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070059 BsoFailNone = 0x00000000,
60 BsoFailLineWidth = 0x00000001,
61 BsoFailDepthBias = 0x00000002,
62 BsoFailViewport = 0x00000004,
63 BsoFailScissor = 0x00000008,
64 BsoFailBlend = 0x00000010,
65 BsoFailDepthBounds = 0x00000020,
66 BsoFailStencilReadMask = 0x00000040,
67 BsoFailStencilWriteMask = 0x00000080,
68 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060069 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060070 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050071} BsoFailSelect;
72
73struct vktriangle_vs_uniform {
74 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070075 float mvp[4][4];
76 float position[3][4];
77 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078};
79
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070080static const char bindStateVertShaderText[] =
81 "#version 450\n"
82 "vec2 vertices[3];\n"
83 "out gl_PerVertex {\n"
84 " vec4 gl_Position;\n"
85 "};\n"
86 "void main() {\n"
87 " vertices[0] = vec2(-1.0, -1.0);\n"
88 " vertices[1] = vec2( 1.0, -1.0);\n"
89 " vertices[2] = vec2( 0.0, 1.0);\n"
90 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
91 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050092
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070093static const char bindStateFragShaderText[] =
94 "#version 450\n"
95 "\n"
96 "layout(location = 0) out vec4 uFragColor;\n"
97 "void main(){\n"
98 " uFragColor = vec4(0,1,0,1);\n"
99 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500100
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600101static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
102 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
103 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600104
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600105// ErrorMonitor Usage:
106//
Dave Houltonfbf52152017-01-06 12:55:29 -0700107// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600108// encountered log messages, or a validation error enum identifying
109// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
110// will match all log messages. logMsg will return true for skipCall
111// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600112//
Dave Houltonfbf52152017-01-06 12:55:29 -0700113// Call VerifyFound to determine if all desired failure messages
114// were encountered. Call VerifyNotFound to determine if any unexpected
115// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600116class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700117 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700118 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700119 test_platform_thread_create_mutex(&mutex_);
120 test_platform_thread_lock_mutex(&mutex_);
121 Reset();
122 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600123 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600124
Dave Houltonfbf52152017-01-06 12:55:29 -0700125 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600126
Dave Houltonfbf52152017-01-06 12:55:29 -0700127 // Set monitor to pristine state
128 void Reset() {
129 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
130 bailout_ = NULL;
131 message_found_ = VK_FALSE;
132 failure_message_strings_.clear();
133 desired_message_strings_.clear();
134 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700135 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700136 other_messages_.clear();
137 message_outstanding_count_ = 0;
138 }
139
140 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700141 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700142 test_platform_thread_lock_mutex(&mutex_);
143 desired_message_strings_.insert(msgString);
144 message_flags_ |= msgFlags;
145 message_outstanding_count_++;
146 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600147 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600148
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700149 // ErrorMonitor will look for an error message containing the specified string(s)
150 template <typename Iter>
151 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
152 for (; iter != end; ++iter) {
153 SetDesiredFailureMsg(msgFlags, *iter);
154 }
155 }
156
Dave Houltonfbf52152017-01-06 12:55:29 -0700157 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700158 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700159 test_platform_thread_lock_mutex(&mutex_);
160 desired_message_ids_.insert(msg_id);
161 message_flags_ |= msgFlags;
162 message_outstanding_count_++;
163 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600164 }
165
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700166 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
167 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
168 // function and its definition.
169 void SetUnexpectedError(const char *const msg) {
170 test_platform_thread_lock_mutex(&mutex_);
171
172 ignore_message_strings_.emplace_back(msg);
173
174 test_platform_thread_unlock_mutex(&mutex_);
175 }
176
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700177 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600178 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700179 test_platform_thread_lock_mutex(&mutex_);
180 if (bailout_ != NULL) {
181 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600182 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600183 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600184 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600185
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700186 if (!IgnoreMessage(errorString)) {
187 for (auto desired_msg : desired_message_strings_) {
188 if (desired_msg.length() == 0) {
189 // An empty desired_msg string "" indicates a positive test - not expecting an error.
190 // Return true to avoid calling layers/driver with this error.
191 // And don't erase the "" string, so it remains if another error is found.
192 result = VK_TRUE;
193 found_expected = true;
194 message_found_ = VK_TRUE;
195 failure_message_strings_.insert(errorString);
196 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600197 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700198 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700199 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700200 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700201 result = VK_TRUE;
202 // We only want one match for each expected error so remove from set here
203 // Since we're about the break the loop it's ok to remove from set we're iterating over
204 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600205 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600206 }
207 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700208 for (auto desired_id : desired_message_ids_) {
209 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
210 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
211 // Return true to avoid calling layers/driver with this error.
212 result = VK_TRUE;
213 } else if (desired_id == message_code) {
214 // Double-check that the string matches the error enum
215 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
216 found_expected = true;
217 message_outstanding_count_--;
218 result = VK_TRUE;
219 message_found_ = VK_TRUE;
220 desired_message_ids_.erase(desired_id);
221 break;
222 } else {
223 // Treat this message as a regular unexpected error, but print a warning jic
224 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
225 errorString.c_str(), desired_id, validation_error_map[desired_id]);
226 }
227 }
228 }
229
230 if (!found_expected) {
231 printf("Unexpected: %s\n", msgString);
232 other_messages_.push_back(errorString);
233 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600234 }
235
Dave Houltonfbf52152017-01-06 12:55:29 -0700236 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600237 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600238 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600239
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700240 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600241
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700242 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600243
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700244 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600245
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700246 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700247
248 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600249
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700250 void DumpFailureMsgs(void) const {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600251 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600252 if (otherMsgs.size()) {
253 cout << "Other error messages logged for this test were:" << endl;
254 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
255 cout << " " << *iter << endl;
256 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600257 }
258 }
259
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600260 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200261
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600262 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700263 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600264 // Match ANY message matching specified type
265 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700266 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200267 }
268
269 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600270 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700271 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200272 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700273 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700274 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600275 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700276 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700277 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600278 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200279 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700280 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200281 }
282
283 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600284 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700285 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200286 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700287 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700288 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600289 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200290 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700291 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200292 }
293
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700294 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700295 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
296 // function and its definition.
297 bool IgnoreMessage(std::string const &msg) const {
298 if (ignore_message_strings_.empty()) {
299 return false;
300 }
301
302 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
303 return msg.find(str) != std::string::npos;
304 }) != ignore_message_strings_.end();
305 }
306
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700307 VkFlags message_flags_;
308 std::unordered_set<uint32_t> desired_message_ids_;
309 std::unordered_set<string> desired_message_strings_;
310 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700311 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700312 vector<string> other_messages_;
313 test_platform_thread_mutex mutex_;
314 bool *bailout_;
315 VkBool32 message_found_;
316 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600317};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500318
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600319static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
320 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
321 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600322 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
323 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600324 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600325 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600326 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600327}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500328
Karl Schultz6addd812016-02-02 17:17:23 -0700329class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700330 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600331 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
332 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700333 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600334 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
335 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700336 }
Tony Barbour300a6082015-04-07 13:44:53 -0600337
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600338 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
339 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700340 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600341 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700342 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600343 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700344 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600345 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
346 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
347 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700348 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
349 }
350 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
351 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
352 }
353
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700354 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700355 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600356 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600357
358 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600359 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600360 std::vector<const char *> instance_extension_names;
361 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600362
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700363 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600364 /*
365 * Since CreateDbgMsgCallback is an instance level extension call
366 * any extension / layer that utilizes that feature also needs
367 * to be enabled at create instance time.
368 */
Karl Schultz6addd812016-02-02 17:17:23 -0700369 // Use Threading layer first to protect others from
370 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700371 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600372 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800373 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700374 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800375 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600376 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700377 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600378
Ian Elliott2c1daf52016-05-12 09:41:46 -0600379 if (m_enableWSI) {
380 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
381 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
382#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
383#if defined(VK_USE_PLATFORM_ANDROID_KHR)
384 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700385#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600386#if defined(VK_USE_PLATFORM_MIR_KHR)
387 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700388#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600389#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
390 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700391#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600392#if defined(VK_USE_PLATFORM_WIN32_KHR)
393 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700394#endif // VK_USE_PLATFORM_WIN32_KHR
395#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600396#if defined(VK_USE_PLATFORM_XCB_KHR)
397 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
398#elif defined(VK_USE_PLATFORM_XLIB_KHR)
399 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700400#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600401 }
402
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600403 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600404 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800405 this->app_info.pApplicationName = "layer_tests";
406 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600407 this->app_info.pEngineName = "unittest";
408 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600409 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600410
Tony Barbour15524c32015-04-29 17:34:29 -0600411 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600412 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600413 }
414
415 virtual void TearDown() {
416 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600417 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600418 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600419 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600420
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600421 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600422};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600424void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 // Create identity matrix
426 int i;
427 struct vktriangle_vs_uniform data;
428
429 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700430 glm::mat4 View = glm::mat4(1.0f);
431 glm::mat4 Model = glm::mat4(1.0f);
432 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700434 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500435
436 memcpy(&data.mvp, &MVP[0][0], matrixSize);
437
Karl Schultz6addd812016-02-02 17:17:23 -0700438 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600439 {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 -0500440 };
441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 data.position[i][0] = tri_data[i].posX;
444 data.position[i][1] = tri_data[i].posY;
445 data.position[i][2] = tri_data[i].posZ;
446 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700447 data.color[i][0] = tri_data[i].r;
448 data.color[i][1] = tri_data[i].g;
449 data.color[i][2] = tri_data[i].b;
450 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500451 }
452
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 ASSERT_NO_FATAL_FAILURE(InitViewport());
454
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200455 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
456 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457
Karl Schultz6addd812016-02-02 17:17:23 -0700458 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600459 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500460
461 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800462 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500463 pipelineobj.AddShader(&vs);
464 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600465 if (failMask & BsoFailLineWidth) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
470 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600471 }
472 if (failMask & BsoFailDepthBias) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600474 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600475 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600476 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600477 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600478 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600479 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700480 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700481 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600482 if (failMask & BsoFailViewport) {
483 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
484 }
485 if (failMask & BsoFailScissor) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
487 }
488 if (failMask & BsoFailBlend) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600490 VkPipelineColorBlendAttachmentState att_state = {};
491 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
492 att_state.blendEnable = VK_TRUE;
493 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600494 }
495 if (failMask & BsoFailDepthBounds) {
496 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
497 }
498 if (failMask & BsoFailStencilReadMask) {
499 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
500 }
501 if (failMask & BsoFailStencilWriteMask) {
502 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
503 }
504 if (failMask & BsoFailStencilReference) {
505 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
506 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500507
508 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600509 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500510
511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700512 m_commandBuffer->BeginCommandBuffer();
513 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514
Tony Barbourfe3351b2015-07-28 10:17:20 -0600515 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
517 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600518 if (failMask & BsoFailIndexBuffer) {
519 // Use DrawIndexed w/o an index buffer bound
520 DrawIndexed(3, 1, 0, 0, 0);
521 } else {
522 Draw(3, 1, 0, 0);
523 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500524
Mark Muellerd4914412016-06-13 17:52:06 -0600525 if (failMask & BsoFailCmdClearAttachments) {
526 VkClearAttachment color_attachment = {};
527 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700528 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600529 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
530
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600531 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600532 }
533
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700535 m_commandBuffer->EndRenderPass();
536 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600537 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538}
539
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600540void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
541 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600543 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500544 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600545 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500546 }
547
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800548 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700549 // Make sure depthWriteEnable is set so that Depth fail test will work
550 // correctly
551 // Make sure stencilTestEnable is set so that Stencil fail test will work
552 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600553 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800554 stencil.failOp = VK_STENCIL_OP_KEEP;
555 stencil.passOp = VK_STENCIL_OP_KEEP;
556 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
557 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600558
559 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
560 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600561 ds_ci.pNext = NULL;
562 ds_ci.depthTestEnable = VK_FALSE;
563 ds_ci.depthWriteEnable = VK_TRUE;
564 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
565 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600566 if (failMask & BsoFailDepthBounds) {
567 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600568 ds_ci.maxDepthBounds = 0.0f;
569 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600570 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600571 ds_ci.stencilTestEnable = VK_TRUE;
572 ds_ci.front = stencil;
573 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600574
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600575 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600576 pipelineobj.SetViewport(m_viewports);
577 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800578 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600579 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600580 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800581 commandBuffer->BindPipeline(pipelineobj);
582 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500583}
584
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600585class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700586 public:
587 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600588};
589
Ian Elliott2c1daf52016-05-12 09:41:46 -0600590class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700591 public:
592 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600593 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600594};
595
Mark Muellerdfe37552016-07-07 14:47:42 -0600596class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700597 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600598 enum eTestEnFlags {
599 eDoubleDelete,
600 eInvalidDeviceOffset,
601 eInvalidMemoryOffset,
602 eBindNullBuffer,
603 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600604 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600605 };
606
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600607 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600608
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600609 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
610 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600611 return true;
612 }
613 VkDeviceSize offset_limit = 0;
614 if (eInvalidMemoryOffset == aTestFlag) {
615 VkBuffer vulkanBuffer;
616 VkBufferCreateInfo buffer_create_info = {};
617 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
618 buffer_create_info.size = 32;
619 buffer_create_info.usage = aBufferUsage;
620
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600622 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600623
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
626 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600627 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
628 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600629 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600631 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600632 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600633 }
634 if (eOffsetAlignment < offset_limit) {
635 return true;
636 }
637 return false;
638 }
639
640 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600641 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
642 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600643 if (eBindNullBuffer == aTestFlag) {
644 VulkanMemory = 0;
645 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
646 } else {
647 VkBufferCreateInfo buffer_create_info = {};
648 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
649 buffer_create_info.size = 32;
650 buffer_create_info.usage = aBufferUsage;
651
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600653
654 CreateCurrent = true;
655
656 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600657 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600658
659 VkMemoryAllocateInfo memory_allocate_info = {};
660 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
661 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
663 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 if (!pass) {
665 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
666 return;
667 }
668
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600669 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600670 AllocateCurrent = true;
671 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
673 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 BoundCurrent = true;
675
676 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
677 }
678 }
679
680 ~VkBufferTest() {
681 if (CreateCurrent) {
682 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
683 }
684 if (AllocateCurrent) {
685 if (InvalidDeleteEn) {
686 union {
687 VkDeviceMemory device_memory;
688 unsigned long long index_access;
689 } bad_index;
690
691 bad_index.device_memory = VulkanMemory;
692 bad_index.index_access++;
693
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600694 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600695 }
696 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
697 }
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600701
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600702 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600703
704 void TestDoubleDestroy() {
705 // Destroy the buffer but leave the flag set, which will cause
706 // the buffer to be destroyed again in the destructor.
707 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
708 }
709
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700710 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600711 bool AllocateCurrent;
712 bool BoundCurrent;
713 bool CreateCurrent;
714 bool InvalidDeleteEn;
715
716 VkBuffer VulkanBuffer;
717 VkDevice VulkanDevice;
718 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600719};
720
721class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700722 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600723 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600724 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700725 : BoundCurrent(false),
726 AttributeCount(aAttributeCount),
727 BindingCount(aBindingCount),
728 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600729 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600730 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
731 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700732 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600733
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
735 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600736
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
738 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
739 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
740 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
741 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600742
743 unsigned i = 0;
744 do {
745 VertexInputAttributeDescription[i].binding = BindId;
746 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
748 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600749 i++;
750 } while (AttributeCount < i);
751
752 i = 0;
753 do {
754 VertexInputBindingDescription[i].binding = BindId;
755 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600756 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600757 i++;
758 } while (BindingCount < i);
759 }
760
761 ~VkVerticesObj() {
762 if (VertexInputAttributeDescription) {
763 delete[] VertexInputAttributeDescription;
764 }
765 if (VertexInputBindingDescription) {
766 delete[] VertexInputBindingDescription;
767 }
768 }
769
770 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
772 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600773 return true;
774 }
775
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600776 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600777 VkDeviceSize *offsetList;
778 unsigned offsetCount;
779
780 if (aOffsetCount) {
781 offsetList = aOffsetList;
782 offsetCount = aOffsetCount;
783 } else {
784 offsetList = new VkDeviceSize[1]();
785 offsetCount = 1;
786 }
787
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600788 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600789 BoundCurrent = true;
790
791 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600792 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600793 }
794 }
795
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700796 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600797 static uint32_t BindIdGenerator;
798
799 bool BoundCurrent;
800 unsigned AttributeCount;
801 unsigned BindingCount;
802 uint32_t BindId;
803
804 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
805 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
806 VkVertexInputBindingDescription *VertexInputBindingDescription;
807 VkConstantBufferObj VulkanMemoryBuffer;
808};
809
810uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500811// ********************************************************************************************************************
812// ********************************************************************************************************************
813// ********************************************************************************************************************
814// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600815TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700816 TEST_DESCRIPTION(
817 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
818 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600819
820 ASSERT_NO_FATAL_FAILURE(InitState());
821
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600823 // Specify NULL for a pointer to a handle
824 // Expected to trigger an error with
825 // parameter_validation::validate_required_pointer
826 vkGetPhysicalDeviceFeatures(gpu(), NULL);
827 m_errorMonitor->VerifyFound();
828
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
830 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for pointer to array count
832 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600833 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify 0 for a required array count
838 // Expected to trigger an error with parameter_validation::validate_array
839 VkViewport view_port = {};
840 m_commandBuffer->SetViewport(0, 0, &view_port);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600844 // Specify NULL for a required array
845 // Expected to trigger an error with parameter_validation::validate_array
846 m_commandBuffer->SetViewport(0, 1, NULL);
847 m_errorMonitor->VerifyFound();
848
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600850 // Specify VK_NULL_HANDLE for a required handle
851 // Expected to trigger an error with
852 // parameter_validation::validate_required_handle
853 vkUnmapMemory(device(), VK_NULL_HANDLE);
854 m_errorMonitor->VerifyFound();
855
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
857 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600858 // Specify VK_NULL_HANDLE for a required handle array entry
859 // Expected to trigger an error with
860 // parameter_validation::validate_required_handle_array
861 VkFence fence = VK_NULL_HANDLE;
862 vkResetFences(device(), 1, &fence);
863 m_errorMonitor->VerifyFound();
864
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600866 // Specify NULL for a required struct pointer
867 // Expected to trigger an error with
868 // parameter_validation::validate_struct_type
869 VkDeviceMemory memory = VK_NULL_HANDLE;
870 vkAllocateMemory(device(), NULL, NULL, &memory);
871 m_errorMonitor->VerifyFound();
872
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600874 // Specify 0 for a required VkFlags parameter
875 // Expected to trigger an error with parameter_validation::validate_flags
876 m_commandBuffer->SetStencilReference(0, 0);
877 m_errorMonitor->VerifyFound();
878
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600879 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 -0600880 // Specify 0 for a required VkFlags array entry
881 // Expected to trigger an error with
882 // parameter_validation::validate_flags_array
883 VkSemaphore semaphore = VK_NULL_HANDLE;
884 VkPipelineStageFlags stageFlags = 0;
885 VkSubmitInfo submitInfo = {};
886 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
887 submitInfo.waitSemaphoreCount = 1;
888 submitInfo.pWaitSemaphores = &semaphore;
889 submitInfo.pWaitDstStageMask = &stageFlags;
890 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
891 m_errorMonitor->VerifyFound();
892}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600893
Dustin Gravesfce74c02016-05-10 11:42:58 -0600894TEST_F(VkLayerTest, ReservedParameter) {
895 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
896
897 ASSERT_NO_FATAL_FAILURE(InitState());
898
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600900 // Specify 0 for a reserved VkFlags parameter
901 // Expected to trigger an error with
902 // parameter_validation::validate_reserved_flags
903 VkEvent event_handle = VK_NULL_HANDLE;
904 VkEventCreateInfo event_info = {};
905 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
906 event_info.flags = 1;
907 vkCreateEvent(device(), &event_info, NULL, &event_handle);
908 m_errorMonitor->VerifyFound();
909}
910
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600911TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700912 TEST_DESCRIPTION(
913 "Specify an invalid VkStructureType for a Vulkan "
914 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915
916 ASSERT_NO_FATAL_FAILURE(InitState());
917
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600919 // Zero struct memory, effectively setting sType to
920 // VK_STRUCTURE_TYPE_APPLICATION_INFO
921 // Expected to trigger an error with
922 // parameter_validation::validate_struct_type
923 VkMemoryAllocateInfo alloc_info = {};
924 VkDeviceMemory memory = VK_NULL_HANDLE;
925 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
926 m_errorMonitor->VerifyFound();
927
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929 // Zero struct memory, effectively setting sType to
930 // VK_STRUCTURE_TYPE_APPLICATION_INFO
931 // Expected to trigger an error with
932 // parameter_validation::validate_struct_type_array
933 VkSubmitInfo submit_info = {};
934 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
935 m_errorMonitor->VerifyFound();
936}
937
938TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600939 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600940
941 ASSERT_NO_FATAL_FAILURE(InitState());
942
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600945 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600946 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600947 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600948 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600949 // Zero-initialization will provide the correct sType
950 VkApplicationInfo app_info = {};
951 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
952 event_alloc_info.pNext = &app_info;
953 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
954 m_errorMonitor->VerifyFound();
955
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
957 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600958 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
959 // a function that has allowed pNext structure types and specify
960 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600961 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600962 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600963 VkMemoryAllocateInfo memory_alloc_info = {};
964 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
965 memory_alloc_info.pNext = &app_info;
966 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600967 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600968}
Dustin Graves5d33d532016-05-09 16:21:12 -0600969
970TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972
973 ASSERT_NO_FATAL_FAILURE(InitState());
974
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
976 "does not fall within the begin..end "
977 "range of the core VkFormat "
978 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600979 // Specify an invalid VkFormat value
980 // Expected to trigger an error with
981 // parameter_validation::validate_ranged_enum
982 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600983 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600984 m_errorMonitor->VerifyFound();
985
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600986 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 -0600987 // Specify an invalid VkFlags bitmask value
988 // Expected to trigger an error with parameter_validation::validate_flags
989 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600990 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
991 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600992 m_errorMonitor->VerifyFound();
993
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600994 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 -0600995 // Specify an invalid VkFlags array entry
996 // Expected to trigger an error with
997 // parameter_validation::validate_flags_array
998 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600999 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001000 VkSubmitInfo submit_info = {};
1001 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1002 submit_info.waitSemaphoreCount = 1;
1003 submit_info.pWaitSemaphores = &semaphore;
1004 submit_info.pWaitDstStageMask = &stage_flags;
1005 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1006 m_errorMonitor->VerifyFound();
1007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001009 // Specify an invalid VkBool32 value
1010 // Expected to trigger a warning with
1011 // parameter_validation::validate_bool32
1012 VkSampler sampler = VK_NULL_HANDLE;
1013 VkSamplerCreateInfo sampler_info = {};
1014 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1015 sampler_info.pNext = NULL;
1016 sampler_info.magFilter = VK_FILTER_NEAREST;
1017 sampler_info.minFilter = VK_FILTER_NEAREST;
1018 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1019 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1022 sampler_info.mipLodBias = 1.0;
1023 sampler_info.maxAnisotropy = 1;
1024 sampler_info.compareEnable = VK_FALSE;
1025 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1026 sampler_info.minLod = 1.0;
1027 sampler_info.maxLod = 1.0;
1028 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1029 sampler_info.unnormalizedCoordinates = VK_FALSE;
1030 // Not VK_TRUE or VK_FALSE
1031 sampler_info.anisotropyEnable = 3;
1032 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1033 m_errorMonitor->VerifyFound();
1034}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001035
1036TEST_F(VkLayerTest, FailedReturnValue) {
1037 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1038
1039 ASSERT_NO_FATAL_FAILURE(InitState());
1040
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001041 // Find an unsupported image format
1042 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1043 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1044 VkFormat format = static_cast<VkFormat>(f);
1045 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001046 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 unsupported = format;
1048 break;
1049 }
1050 }
1051
1052 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1054 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001055 // Specify an unsupported VkFormat value to generate a
1056 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1057 // Expected to trigger a warning from
1058 // parameter_validation::validate_result
1059 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001060 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1061 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001062 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1063 m_errorMonitor->VerifyFound();
1064 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001065}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001066
1067TEST_F(VkLayerTest, UpdateBufferAlignment) {
1068 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070
1071 ASSERT_NO_FATAL_FAILURE(InitState());
1072
1073 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1074 vk_testing::Buffer buffer;
1075 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1076
Tony Barbour552f6c02016-12-21 14:34:07 -07001077 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001078 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001080 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1081 m_errorMonitor->VerifyFound();
1082
1083 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 // Introduce failure by using dataSize that is < 0
1089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001090 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001091 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1092 m_errorMonitor->VerifyFound();
1093
1094 // Introduce failure by using dataSize that is > 65536
1095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001096 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001097 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1098 m_errorMonitor->VerifyFound();
1099
Tony Barbour552f6c02016-12-21 14:34:07 -07001100 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101}
1102
1103TEST_F(VkLayerTest, FillBufferAlignment) {
1104 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1105
1106 ASSERT_NO_FATAL_FAILURE(InitState());
1107
1108 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1109 vk_testing::Buffer buffer;
1110 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1111
Tony Barbour552f6c02016-12-21 14:34:07 -07001112 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001113
1114 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001116 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1117 m_errorMonitor->VerifyFound();
1118
1119 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001121 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1122 m_errorMonitor->VerifyFound();
1123
1124 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1127 m_errorMonitor->VerifyFound();
1128
Tony Barbour552f6c02016-12-21 14:34:07 -07001129 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001130}
Dustin Graves40f35822016-06-23 11:12:53 -06001131
Cortd889ff92016-07-27 09:51:27 -07001132TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1133 VkResult err;
1134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001135 TEST_DESCRIPTION(
1136 "Attempt to use a non-solid polygon fill mode in a "
1137 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001138
1139 ASSERT_NO_FATAL_FAILURE(InitState());
1140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1141
1142 std::vector<const char *> device_extension_names;
1143 auto features = m_device->phy().features();
1144 // Artificially disable support for non-solid fill modes
1145 features.fillModeNonSolid = false;
1146 // The sacrificial device object
1147 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1148
1149 VkRenderpassObj render_pass(&test_device);
1150
1151 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1152 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1153 pipeline_layout_ci.setLayoutCount = 0;
1154 pipeline_layout_ci.pSetLayouts = NULL;
1155
1156 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001158 ASSERT_VK_SUCCESS(err);
1159
1160 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1161 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1162 rs_ci.pNext = nullptr;
1163 rs_ci.lineWidth = 1.0f;
1164 rs_ci.rasterizerDiscardEnable = true;
1165
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001166 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1167 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001168
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001169 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1171 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001172 {
1173 VkPipelineObj pipe(&test_device);
1174 pipe.AddShader(&vs);
1175 pipe.AddShader(&fs);
1176 pipe.AddColorAttachment();
1177 // Introduce failure by setting unsupported polygon mode
1178 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1179 pipe.SetRasterization(&rs_ci);
1180 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1181 }
1182 m_errorMonitor->VerifyFound();
1183
1184 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1186 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001187 {
1188 VkPipelineObj pipe(&test_device);
1189 pipe.AddShader(&vs);
1190 pipe.AddShader(&fs);
1191 pipe.AddColorAttachment();
1192 // Introduce failure by setting unsupported polygon mode
1193 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1194 pipe.SetRasterization(&rs_ci);
1195 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1196 }
1197 m_errorMonitor->VerifyFound();
1198
Cortd889ff92016-07-27 09:51:27 -07001199 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1200}
1201
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001202#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001203TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001204{
1205 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001206 VkFenceCreateInfo fenceInfo = {};
1207 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1208 fenceInfo.pNext = NULL;
1209 fenceInfo.flags = 0;
1210
Mike Weiblencce7ec72016-10-17 19:33:05 -06001211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001212
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001213 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001214
1215 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1216 vk_testing::Buffer buffer;
1217 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001218
Tony Barbourfe3351b2015-07-28 10:17:20 -06001219 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001220 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001221 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001222
1223 testFence.init(*m_device, fenceInfo);
1224
1225 // Bypass framework since it does the waits automatically
1226 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001227 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1229 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001230 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001231 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001232 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001233 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001235 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001236 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001237
1238 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001239 ASSERT_VK_SUCCESS( err );
1240
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001241 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001242 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001243
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001244 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001245}
1246
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001247TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001248{
1249 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001250 VkFenceCreateInfo fenceInfo = {};
1251 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1252 fenceInfo.pNext = NULL;
1253 fenceInfo.flags = 0;
1254
Mike Weiblencce7ec72016-10-17 19:33:05 -06001255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001256
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001257 ASSERT_NO_FATAL_FAILURE(InitState());
1258 ASSERT_NO_FATAL_FAILURE(InitViewport());
1259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1260
Tony Barbourfe3351b2015-07-28 10:17:20 -06001261 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001262 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001263 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001264
1265 testFence.init(*m_device, fenceInfo);
1266
1267 // Bypass framework since it does the waits automatically
1268 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001269 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001270 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1271 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001272 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001273 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001274 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001275 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001276 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001277 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001278 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001279
1280 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001281 ASSERT_VK_SUCCESS( err );
1282
Jon Ashburnf19916e2016-01-11 13:12:43 -07001283 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001284 VkCommandBufferBeginInfo info = {};
1285 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1286 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001287 info.renderPass = VK_NULL_HANDLE;
1288 info.subpass = 0;
1289 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001290 info.occlusionQueryEnable = VK_FALSE;
1291 info.queryFlags = 0;
1292 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001293
1294 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001295 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001297 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001298}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001299#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001300
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001301TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1302 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1303
1304 ASSERT_NO_FATAL_FAILURE(InitState());
1305
1306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1307 VkBuffer buffer;
1308 VkBufferCreateInfo buf_info = {};
1309 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1310 buf_info.pNext = NULL;
1311 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1312 buf_info.size = 2048;
1313 buf_info.queueFamilyIndexCount = 0;
1314 buf_info.pQueueFamilyIndices = NULL;
1315 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1316 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1317 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1318 m_errorMonitor->VerifyFound();
1319
1320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1321 VkImage image;
1322 VkImageCreateInfo image_create_info = {};
1323 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1324 image_create_info.pNext = NULL;
1325 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1326 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1327 image_create_info.extent.width = 512;
1328 image_create_info.extent.height = 64;
1329 image_create_info.extent.depth = 1;
1330 image_create_info.mipLevels = 1;
1331 image_create_info.arrayLayers = 1;
1332 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1333 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1334 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1335 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1336 image_create_info.queueFamilyIndexCount = 0;
1337 image_create_info.pQueueFamilyIndices = NULL;
1338 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1339 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1340 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1341 m_errorMonitor->VerifyFound();
1342}
1343
Dave Houlton829c0d82017-01-24 15:09:17 -07001344TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1345 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1346
1347 // Determine which device feature are available
1348 VkPhysicalDeviceFeatures available_features;
1349 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1350
1351 // Mask out device features we don't want
1352 VkPhysicalDeviceFeatures desired_features = available_features;
1353 desired_features.sparseResidencyImage2D = VK_FALSE;
1354 desired_features.sparseResidencyImage3D = VK_FALSE;
1355 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1356
1357 VkImage image = VK_NULL_HANDLE;
1358 VkResult result = VK_RESULT_MAX_ENUM;
1359 VkImageCreateInfo image_create_info = {};
1360 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1361 image_create_info.pNext = NULL;
1362 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1363 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1364 image_create_info.extent.width = 512;
1365 image_create_info.extent.height = 1;
1366 image_create_info.extent.depth = 1;
1367 image_create_info.mipLevels = 1;
1368 image_create_info.arrayLayers = 1;
1369 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1370 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1371 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1372 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1373 image_create_info.queueFamilyIndexCount = 0;
1374 image_create_info.pQueueFamilyIndices = NULL;
1375 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1376 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1377
1378 // 1D image w/ sparse residency is an error
1379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1380 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1381 m_errorMonitor->VerifyFound();
1382 if (VK_SUCCESS == result) {
1383 vkDestroyImage(m_device->device(), image, NULL);
1384 image = VK_NULL_HANDLE;
1385 }
1386
1387 // 2D image w/ sparse residency when feature isn't available
1388 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1389 image_create_info.extent.height = 64;
1390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1391 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1392 m_errorMonitor->VerifyFound();
1393 if (VK_SUCCESS == result) {
1394 vkDestroyImage(m_device->device(), image, NULL);
1395 image = VK_NULL_HANDLE;
1396 }
1397
1398 // 3D image w/ sparse residency when feature isn't available
1399 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1400 image_create_info.extent.depth = 8;
1401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1402 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1403 m_errorMonitor->VerifyFound();
1404 if (VK_SUCCESS == result) {
1405 vkDestroyImage(m_device->device(), image, NULL);
1406 image = VK_NULL_HANDLE;
1407 }
1408}
1409
1410TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1411 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1412
1413 // Determine which device feature are available
1414 VkPhysicalDeviceFeatures available_features;
1415 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1416
1417 // These tests all require that the device support sparse residency for 2D images
1418 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1419 return;
1420 }
1421
1422 // Mask out device features we don't want
1423 VkPhysicalDeviceFeatures desired_features = available_features;
1424 desired_features.sparseResidency2Samples = VK_FALSE;
1425 desired_features.sparseResidency4Samples = VK_FALSE;
1426 desired_features.sparseResidency8Samples = VK_FALSE;
1427 desired_features.sparseResidency16Samples = VK_FALSE;
1428 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1429
1430 VkImage image = VK_NULL_HANDLE;
1431 VkResult result = VK_RESULT_MAX_ENUM;
1432 VkImageCreateInfo image_create_info = {};
1433 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1434 image_create_info.pNext = NULL;
1435 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1436 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1437 image_create_info.extent.width = 64;
1438 image_create_info.extent.height = 64;
1439 image_create_info.extent.depth = 1;
1440 image_create_info.mipLevels = 1;
1441 image_create_info.arrayLayers = 1;
1442 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1443 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1444 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1445 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1446 image_create_info.queueFamilyIndexCount = 0;
1447 image_create_info.pQueueFamilyIndices = NULL;
1448 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1449 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1450
1451 // 2D image w/ sparse residency and linear tiling is an error
1452 m_errorMonitor->SetDesiredFailureMsg(
1453 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1454 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1455 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1456 m_errorMonitor->VerifyFound();
1457 if (VK_SUCCESS == result) {
1458 vkDestroyImage(m_device->device(), image, NULL);
1459 image = VK_NULL_HANDLE;
1460 }
1461 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1462
1463 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1464 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1466 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1467 m_errorMonitor->VerifyFound();
1468 if (VK_SUCCESS == result) {
1469 vkDestroyImage(m_device->device(), image, NULL);
1470 image = VK_NULL_HANDLE;
1471 }
1472
1473 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1475 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1476 m_errorMonitor->VerifyFound();
1477 if (VK_SUCCESS == result) {
1478 vkDestroyImage(m_device->device(), image, NULL);
1479 image = VK_NULL_HANDLE;
1480 }
1481
1482 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1484 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1485 m_errorMonitor->VerifyFound();
1486 if (VK_SUCCESS == result) {
1487 vkDestroyImage(m_device->device(), image, NULL);
1488 image = VK_NULL_HANDLE;
1489 }
1490
1491 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1493 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1494 m_errorMonitor->VerifyFound();
1495 if (VK_SUCCESS == result) {
1496 vkDestroyImage(m_device->device(), image, NULL);
1497 image = VK_NULL_HANDLE;
1498 }
1499}
1500
Tobin Ehlisf11be982016-05-11 13:52:53 -06001501TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001502 TEST_DESCRIPTION(
1503 "Create a buffer and image, allocate memory, and bind the "
1504 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001505 VkResult err;
1506 bool pass;
1507 ASSERT_NO_FATAL_FAILURE(InitState());
1508
Tobin Ehlis077ded32016-05-12 17:39:13 -06001509 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001510 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001511 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001512 VkDeviceMemory mem; // buffer will be bound first
1513 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001514 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001515 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001516
1517 VkBufferCreateInfo buf_info = {};
1518 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1519 buf_info.pNext = NULL;
1520 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1521 buf_info.size = 256;
1522 buf_info.queueFamilyIndexCount = 0;
1523 buf_info.pQueueFamilyIndices = NULL;
1524 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1525 buf_info.flags = 0;
1526 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1527 ASSERT_VK_SUCCESS(err);
1528
Tobin Ehlis077ded32016-05-12 17:39:13 -06001529 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001530
1531 VkImageCreateInfo image_create_info = {};
1532 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1533 image_create_info.pNext = NULL;
1534 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1535 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1536 image_create_info.extent.width = 64;
1537 image_create_info.extent.height = 64;
1538 image_create_info.extent.depth = 1;
1539 image_create_info.mipLevels = 1;
1540 image_create_info.arrayLayers = 1;
1541 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001542 // Image tiling must be optimal to trigger error when aliasing linear buffer
1543 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001544 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1545 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1546 image_create_info.queueFamilyIndexCount = 0;
1547 image_create_info.pQueueFamilyIndices = NULL;
1548 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1549 image_create_info.flags = 0;
1550
Tobin Ehlisf11be982016-05-11 13:52:53 -06001551 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1552 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001553 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1554 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001555
Tobin Ehlis077ded32016-05-12 17:39:13 -06001556 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1557
1558 VkMemoryAllocateInfo alloc_info = {};
1559 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1560 alloc_info.pNext = NULL;
1561 alloc_info.memoryTypeIndex = 0;
1562 // Ensure memory is big enough for both bindings
1563 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001564 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1565 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001566 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001567 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001568 vkDestroyImage(m_device->device(), image, NULL);
1569 return;
1570 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001571 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1572 ASSERT_VK_SUCCESS(err);
1573 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1574 ASSERT_VK_SUCCESS(err);
1575
Rene Lindsayd14f5572016-12-16 14:57:18 -07001576 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1577
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001579 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001580 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1581 m_errorMonitor->VerifyFound();
1582
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001583 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001584 // aliasing buffer2
1585 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1586 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001587 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1588 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001589 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001590 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001592 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001593 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001594 m_errorMonitor->VerifyFound();
1595
1596 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001597 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001598 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001599 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001600 vkFreeMemory(m_device->device(), mem, NULL);
1601 vkFreeMemory(m_device->device(), mem_img, NULL);
1602}
1603
Tobin Ehlis35372522016-05-12 08:32:31 -06001604TEST_F(VkLayerTest, InvalidMemoryMapping) {
1605 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1606 VkResult err;
1607 bool pass;
1608 ASSERT_NO_FATAL_FAILURE(InitState());
1609
1610 VkBuffer buffer;
1611 VkDeviceMemory mem;
1612 VkMemoryRequirements mem_reqs;
1613
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001614 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1615
Tobin Ehlis35372522016-05-12 08:32:31 -06001616 VkBufferCreateInfo buf_info = {};
1617 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1618 buf_info.pNext = NULL;
1619 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1620 buf_info.size = 256;
1621 buf_info.queueFamilyIndexCount = 0;
1622 buf_info.pQueueFamilyIndices = NULL;
1623 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1624 buf_info.flags = 0;
1625 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1626 ASSERT_VK_SUCCESS(err);
1627
1628 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1629 VkMemoryAllocateInfo alloc_info = {};
1630 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1631 alloc_info.pNext = NULL;
1632 alloc_info.memoryTypeIndex = 0;
1633
1634 // Ensure memory is big enough for both bindings
1635 static const VkDeviceSize allocation_size = 0x10000;
1636 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001637 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 -06001638 if (!pass) {
1639 vkDestroyBuffer(m_device->device(), buffer, NULL);
1640 return;
1641 }
1642 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1643 ASSERT_VK_SUCCESS(err);
1644
1645 uint8_t *pData;
1646 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001647 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 -06001648 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1649 m_errorMonitor->VerifyFound();
1650 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001651 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001652 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1654 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1655 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001656 m_errorMonitor->VerifyFound();
1657
1658 // Unmap the memory to avoid re-map error
1659 vkUnmapMemory(m_device->device(), mem);
1660 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1662 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1663 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001664 m_errorMonitor->VerifyFound();
1665 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1667 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001668 m_errorMonitor->VerifyFound();
1669 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001671 vkUnmapMemory(m_device->device(), mem);
1672 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001673
Tobin Ehlis35372522016-05-12 08:32:31 -06001674 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001675 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001676 ASSERT_VK_SUCCESS(err);
1677 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001678 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001679 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001680 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001682 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1683 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001684
Tobin Ehlis35372522016-05-12 08:32:31 -06001685 // Now flush range that oversteps mapped range
1686 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001687 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001688 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001689 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001690 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1692 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1693 m_errorMonitor->VerifyFound();
1694
1695 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1696 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001697 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001698 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001699 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001700 mmr.size = VK_WHOLE_SIZE;
1701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001702 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1703 m_errorMonitor->VerifyFound();
1704
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001705#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001706 // Some platforms have an atomsize of 1 which makes the test meaningless
1707 if (atom_size > 3) {
1708 // Now with an offset NOT a multiple of the device limit
1709 vkUnmapMemory(m_device->device(), mem);
1710 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1711 ASSERT_VK_SUCCESS(err);
1712 mmr.offset = 3; // Not a multiple of atom_size
1713 mmr.size = VK_WHOLE_SIZE;
1714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1715 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1716 m_errorMonitor->VerifyFound();
1717
1718 // Now with a size NOT a multiple of the device limit
1719 vkUnmapMemory(m_device->device(), mem);
1720 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1721 ASSERT_VK_SUCCESS(err);
1722 mmr.offset = atom_size;
1723 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1725 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1726 m_errorMonitor->VerifyFound();
1727 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001728#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001729 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1730 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001731 if (!pass) {
1732 vkFreeMemory(m_device->device(), mem, NULL);
1733 vkDestroyBuffer(m_device->device(), buffer, NULL);
1734 return;
1735 }
1736 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1737 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1738
1739 vkDestroyBuffer(m_device->device(), buffer, NULL);
1740 vkFreeMemory(m_device->device(), mem, NULL);
1741}
1742
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001743#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001744TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1745 VkResult err;
1746 bool pass;
1747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001748 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1749 // following declaration (which is temporarily being moved below):
1750 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001751 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001752 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001753 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001754 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001755 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001756 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001757
1758 ASSERT_NO_FATAL_FAILURE(InitState());
1759
Ian Elliott3f06ce52016-04-29 14:46:21 -06001760#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1761#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1762 // Use the functions from the VK_KHR_android_surface extension without
1763 // enabling that extension:
1764
1765 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001766 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001767 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1768 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001769 pass = (err != VK_SUCCESS);
1770 ASSERT_TRUE(pass);
1771 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001772#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001773
Ian Elliott3f06ce52016-04-29 14:46:21 -06001774#if defined(VK_USE_PLATFORM_MIR_KHR)
1775 // Use the functions from the VK_KHR_mir_surface extension without enabling
1776 // that extension:
1777
1778 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001779 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001781 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1782 pass = (err != VK_SUCCESS);
1783 ASSERT_TRUE(pass);
1784 m_errorMonitor->VerifyFound();
1785
1786 // Tell whether an mir_connection supports presentation:
1787 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1789 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001790 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001791#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001792
Ian Elliott3f06ce52016-04-29 14:46:21 -06001793#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1794 // Use the functions from the VK_KHR_wayland_surface extension without
1795 // enabling that extension:
1796
1797 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001798 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1800 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001801 pass = (err != VK_SUCCESS);
1802 ASSERT_TRUE(pass);
1803 m_errorMonitor->VerifyFound();
1804
1805 // Tell whether an wayland_display supports presentation:
1806 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1808 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001809 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001810#endif // VK_USE_PLATFORM_WAYLAND_KHR
1811#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001812
Ian Elliott3f06ce52016-04-29 14:46:21 -06001813#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001814 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1815 // TO NON-LINUX PLATFORMS:
1816 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001817 // Use the functions from the VK_KHR_win32_surface extension without
1818 // enabling that extension:
1819
1820 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001821 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1823 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001824 pass = (err != VK_SUCCESS);
1825 ASSERT_TRUE(pass);
1826 m_errorMonitor->VerifyFound();
1827
1828 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001830 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001831 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001832// Set this (for now, until all platforms are supported and tested):
1833#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001834#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001835#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001836 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1837 // TO NON-LINUX PLATFORMS:
1838 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001839#endif
1840#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001841 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1842 // that extension:
1843
1844 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001845 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001847 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1848 pass = (err != VK_SUCCESS);
1849 ASSERT_TRUE(pass);
1850 m_errorMonitor->VerifyFound();
1851
1852 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001853 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001854 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1856 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001857 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001858// Set this (for now, until all platforms are supported and tested):
1859#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001860#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001861
Ian Elliott12630812016-04-29 14:35:43 -06001862#if defined(VK_USE_PLATFORM_XLIB_KHR)
1863 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1864 // that extension:
1865
1866 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001867 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001869 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1870 pass = (err != VK_SUCCESS);
1871 ASSERT_TRUE(pass);
1872 m_errorMonitor->VerifyFound();
1873
1874 // Tell whether an Xlib VisualID supports presentation:
1875 Display *dpy = NULL;
1876 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001878 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1879 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001880// Set this (for now, until all platforms are supported and tested):
1881#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001882#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001883
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001884// Use the functions from the VK_KHR_surface extension without enabling
1885// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001886
Ian Elliott489eec02016-05-05 14:12:44 -06001887#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001888 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001890 vkDestroySurfaceKHR(instance(), surface, NULL);
1891 m_errorMonitor->VerifyFound();
1892
1893 // Check if surface supports presentation:
1894 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001896 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1897 pass = (err != VK_SUCCESS);
1898 ASSERT_TRUE(pass);
1899 m_errorMonitor->VerifyFound();
1900
1901 // Check surface capabilities:
1902 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1904 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001905 pass = (err != VK_SUCCESS);
1906 ASSERT_TRUE(pass);
1907 m_errorMonitor->VerifyFound();
1908
1909 // Check surface formats:
1910 uint32_t format_count = 0;
1911 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1913 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001914 pass = (err != VK_SUCCESS);
1915 ASSERT_TRUE(pass);
1916 m_errorMonitor->VerifyFound();
1917
1918 // Check surface present modes:
1919 uint32_t present_mode_count = 0;
1920 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1922 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001923 pass = (err != VK_SUCCESS);
1924 ASSERT_TRUE(pass);
1925 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001926#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001927
Ian Elliott1c32c772016-04-28 14:47:13 -06001928 // Use the functions from the VK_KHR_swapchain extension without enabling
1929 // that extension:
1930
1931 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001933 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1934 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001935 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001936 pass = (err != VK_SUCCESS);
1937 ASSERT_TRUE(pass);
1938 m_errorMonitor->VerifyFound();
1939
1940 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1942 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001943 pass = (err != VK_SUCCESS);
1944 ASSERT_TRUE(pass);
1945 m_errorMonitor->VerifyFound();
1946
Chris Forbeseb7d5502016-09-13 18:19:21 +12001947 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1948 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1949 VkFence fence;
1950 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1951
Ian Elliott1c32c772016-04-28 14:47:13 -06001952 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001954 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001955 pass = (err != VK_SUCCESS);
1956 ASSERT_TRUE(pass);
1957 m_errorMonitor->VerifyFound();
1958
Chris Forbeseb7d5502016-09-13 18:19:21 +12001959 vkDestroyFence(m_device->device(), fence, nullptr);
1960
Ian Elliott1c32c772016-04-28 14:47:13 -06001961 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001962 //
1963 // NOTE: Currently can't test this because a real swapchain is needed (as
1964 // opposed to the fake one we created) in order for the layer to lookup the
1965 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001966
1967 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001969 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1970 m_errorMonitor->VerifyFound();
1971}
Chris Forbes09368e42016-10-13 11:59:22 +13001972#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001973
Karl Schultz6addd812016-02-02 17:17:23 -07001974TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1975 VkResult err;
1976 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001977
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1979 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001980
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001981 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001982
1983 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001984 VkImage image;
1985 VkDeviceMemory mem;
1986 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001987
Karl Schultz6addd812016-02-02 17:17:23 -07001988 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1989 const int32_t tex_width = 32;
1990 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001991
Tony Barboureb254902015-07-15 12:50:33 -06001992 VkImageCreateInfo image_create_info = {};
1993 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001994 image_create_info.pNext = NULL;
1995 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1996 image_create_info.format = tex_format;
1997 image_create_info.extent.width = tex_width;
1998 image_create_info.extent.height = tex_height;
1999 image_create_info.extent.depth = 1;
2000 image_create_info.mipLevels = 1;
2001 image_create_info.arrayLayers = 1;
2002 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2003 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2004 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2005 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002006 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002007
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002008 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002009 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002010 mem_alloc.pNext = NULL;
2011 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002012
Chia-I Wuf7458c52015-10-26 21:10:41 +08002013 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002014 ASSERT_VK_SUCCESS(err);
2015
Karl Schultz6addd812016-02-02 17:17:23 -07002016 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002017
Mark Lobodzinski23065352015-05-29 09:32:35 -05002018 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002019
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002020 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 -07002021 if (!pass) { // If we can't find any unmappable memory this test doesn't
2022 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002023 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002024 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002025 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002026
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002027 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002028 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002029 ASSERT_VK_SUCCESS(err);
2030
2031 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002032 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002033 ASSERT_VK_SUCCESS(err);
2034
2035 // Map memory as if to initialize the image
2036 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002037 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002038
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002039 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002040
Chia-I Wuf7458c52015-10-26 21:10:41 +08002041 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002042 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002043}
2044
Karl Schultz6addd812016-02-02 17:17:23 -07002045TEST_F(VkLayerTest, RebindMemory) {
2046 VkResult err;
2047 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002048
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002050
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002051 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002052
2053 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002054 VkImage image;
2055 VkDeviceMemory mem1;
2056 VkDeviceMemory mem2;
2057 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002058
Karl Schultz6addd812016-02-02 17:17:23 -07002059 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2060 const int32_t tex_width = 32;
2061 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002062
Tony Barboureb254902015-07-15 12:50:33 -06002063 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002064 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2065 image_create_info.pNext = NULL;
2066 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2067 image_create_info.format = tex_format;
2068 image_create_info.extent.width = tex_width;
2069 image_create_info.extent.height = tex_height;
2070 image_create_info.extent.depth = 1;
2071 image_create_info.mipLevels = 1;
2072 image_create_info.arrayLayers = 1;
2073 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2074 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2075 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2076 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002077
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002078 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002079 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2080 mem_alloc.pNext = NULL;
2081 mem_alloc.allocationSize = 0;
2082 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002083
Karl Schultz6addd812016-02-02 17:17:23 -07002084 // Introduce failure, do NOT set memProps to
2085 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002086 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002087 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002088 ASSERT_VK_SUCCESS(err);
2089
Karl Schultz6addd812016-02-02 17:17:23 -07002090 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002091
2092 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002093 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002094 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002095
2096 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002097 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002098 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002099 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002100 ASSERT_VK_SUCCESS(err);
2101
2102 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002103 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002104 ASSERT_VK_SUCCESS(err);
2105
Karl Schultz6addd812016-02-02 17:17:23 -07002106 // Introduce validation failure, try to bind a different memory object to
2107 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002108 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002109
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002110 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002111
Chia-I Wuf7458c52015-10-26 21:10:41 +08002112 vkDestroyImage(m_device->device(), image, NULL);
2113 vkFreeMemory(m_device->device(), mem1, NULL);
2114 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002115}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002116
Karl Schultz6addd812016-02-02 17:17:23 -07002117TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002118 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002119
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2121 "submitted in SIGNALED state. Fences "
2122 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002123
2124 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002125 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2126 fenceInfo.pNext = NULL;
2127 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002128
Tony Barbour300a6082015-04-07 13:44:53 -06002129 ASSERT_NO_FATAL_FAILURE(InitState());
2130 ASSERT_NO_FATAL_FAILURE(InitViewport());
2131 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2132
Tony Barbour552f6c02016-12-21 14:34:07 -07002133 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002134 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002135 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002136
2137 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002138
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002139 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002140 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2141 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002142 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002143 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002144 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002145 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002146 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002147 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002148 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002149
2150 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002151 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002152
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002153 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002154}
Chris Forbes4e44c912016-06-16 10:20:00 +12002155
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002156TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002157 TEST_DESCRIPTION(
2158 "Specify wrong usage for image then create conflicting view of image "
2159 "Initialize buffer with wrong usage then perform copy expecting errors "
2160 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002162
2163 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002164
2165 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
2166
Tony Barbourf92621a2016-05-02 14:28:12 -06002167 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002168 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002169 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002170 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002171
Tony Barbourf92621a2016-05-02 14:28:12 -06002172 VkImageView dsv;
2173 VkImageViewCreateInfo dsvci = {};
2174 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2175 dsvci.image = image.handle();
2176 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002177 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002178 dsvci.subresourceRange.layerCount = 1;
2179 dsvci.subresourceRange.baseMipLevel = 0;
2180 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002181 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002182
Tony Barbourf92621a2016-05-02 14:28:12 -06002183 // Create a view with depth / stencil aspect for image with different usage
2184 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002185
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002186 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002187
2188 // Initialize buffer with TRANSFER_DST usage
2189 vk_testing::Buffer buffer;
2190 VkMemoryPropertyFlags reqs = 0;
2191 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2192 VkBufferImageCopy region = {};
2193 region.bufferRowLength = 128;
2194 region.bufferImageHeight = 128;
2195 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2196 region.imageSubresource.layerCount = 1;
2197 region.imageExtent.height = 16;
2198 region.imageExtent.width = 16;
2199 region.imageExtent.depth = 1;
2200
Tony Barbourf92621a2016-05-02 14:28:12 -06002201 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2202 // TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002203 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002204
Chris Forbesda581202016-10-06 18:25:26 +13002205 // two separate errors from this call:
2206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002209 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2210 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002211 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002212}
Tony Barbour75d79f02016-08-30 09:39:07 -06002213
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002214TEST_F(VkLayerTest, LeakAnObject) {
2215 VkResult err;
2216
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002217 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002218
2219 // Note that we have to create a new device since destroying the
2220 // framework's device causes Teardown() to fail and just calling Teardown
2221 // will destroy the errorMonitor.
2222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002224
2225 ASSERT_NO_FATAL_FAILURE(InitState());
2226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002227 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002228 std::vector<VkDeviceQueueCreateInfo> queue_info;
2229 queue_info.reserve(queue_props.size());
2230 std::vector<std::vector<float>> queue_priorities;
2231 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2232 VkDeviceQueueCreateInfo qi = {};
2233 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2234 qi.pNext = NULL;
2235 qi.queueFamilyIndex = i;
2236 qi.queueCount = queue_props[i].queueCount;
2237 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2238 qi.pQueuePriorities = queue_priorities[i].data();
2239 queue_info.push_back(qi);
2240 }
2241
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002242 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002243
2244 // The sacrificial device object
2245 VkDevice testDevice;
2246 VkDeviceCreateInfo device_create_info = {};
2247 auto features = m_device->phy().features();
2248 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2249 device_create_info.pNext = NULL;
2250 device_create_info.queueCreateInfoCount = queue_info.size();
2251 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002252 device_create_info.enabledLayerCount = 0;
2253 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002254 device_create_info.pEnabledFeatures = &features;
2255 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2256 ASSERT_VK_SUCCESS(err);
2257
2258 VkFence fence;
2259 VkFenceCreateInfo fence_create_info = {};
2260 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2261 fence_create_info.pNext = NULL;
2262 fence_create_info.flags = 0;
2263 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2264 ASSERT_VK_SUCCESS(err);
2265
2266 // Induce failure by not calling vkDestroyFence
2267 vkDestroyDevice(testDevice, NULL);
2268 m_errorMonitor->VerifyFound();
2269}
2270
2271TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002272 TEST_DESCRIPTION(
2273 "Allocate command buffers from one command pool and "
2274 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002275
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002277
Cody Northropc31a84f2016-08-22 10:41:47 -06002278 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002279 VkCommandPool command_pool_one;
2280 VkCommandPool command_pool_two;
2281
2282 VkCommandPoolCreateInfo pool_create_info{};
2283 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2284 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2285 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002287 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002289 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002290
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002291 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002292 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002293 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002294 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002295 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002296 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002297 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002298
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002299 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002300
2301 m_errorMonitor->VerifyFound();
2302
2303 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2304 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2305}
2306
2307TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2308 VkResult err;
2309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002310 TEST_DESCRIPTION(
2311 "Allocate descriptor sets from one DS pool and "
2312 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002313
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002315
2316 ASSERT_NO_FATAL_FAILURE(InitState());
2317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2318
2319 VkDescriptorPoolSize ds_type_count = {};
2320 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2321 ds_type_count.descriptorCount = 1;
2322
2323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2325 ds_pool_ci.pNext = NULL;
2326 ds_pool_ci.flags = 0;
2327 ds_pool_ci.maxSets = 1;
2328 ds_pool_ci.poolSizeCount = 1;
2329 ds_pool_ci.pPoolSizes = &ds_type_count;
2330
2331 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002332 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002333 ASSERT_VK_SUCCESS(err);
2334
2335 // Create a second descriptor pool
2336 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002337 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002338 ASSERT_VK_SUCCESS(err);
2339
2340 VkDescriptorSetLayoutBinding dsl_binding = {};
2341 dsl_binding.binding = 0;
2342 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2343 dsl_binding.descriptorCount = 1;
2344 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2345 dsl_binding.pImmutableSamplers = NULL;
2346
2347 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2348 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2349 ds_layout_ci.pNext = NULL;
2350 ds_layout_ci.bindingCount = 1;
2351 ds_layout_ci.pBindings = &dsl_binding;
2352
2353 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002354 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002355 ASSERT_VK_SUCCESS(err);
2356
2357 VkDescriptorSet descriptorSet;
2358 VkDescriptorSetAllocateInfo alloc_info = {};
2359 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2360 alloc_info.descriptorSetCount = 1;
2361 alloc_info.descriptorPool = ds_pool_one;
2362 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002363 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002364 ASSERT_VK_SUCCESS(err);
2365
2366 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2367
2368 m_errorMonitor->VerifyFound();
2369
2370 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2371 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2372 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2373}
2374
2375TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002378 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002379
2380 ASSERT_NO_FATAL_FAILURE(InitState());
2381
2382 // Pass bogus handle into GetImageMemoryRequirements
2383 VkMemoryRequirements mem_reqs;
2384 uint64_t fakeImageHandle = 0xCADECADE;
2385 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2386
2387 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2388
2389 m_errorMonitor->VerifyFound();
2390}
2391
Karl Schultz6addd812016-02-02 17:17:23 -07002392TEST_F(VkLayerTest, PipelineNotBound) {
2393 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002394
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002395 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002396
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002398
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002399 ASSERT_NO_FATAL_FAILURE(InitState());
2400 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002401
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002402 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002403 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2404 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002405
2406 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002407 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2408 ds_pool_ci.pNext = NULL;
2409 ds_pool_ci.maxSets = 1;
2410 ds_pool_ci.poolSizeCount = 1;
2411 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002412
2413 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002414 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002415 ASSERT_VK_SUCCESS(err);
2416
2417 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002418 dsl_binding.binding = 0;
2419 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2420 dsl_binding.descriptorCount = 1;
2421 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2422 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002423
2424 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002425 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2426 ds_layout_ci.pNext = NULL;
2427 ds_layout_ci.bindingCount = 1;
2428 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002429
2430 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002431 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002432 ASSERT_VK_SUCCESS(err);
2433
2434 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002435 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002436 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002437 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002438 alloc_info.descriptorPool = ds_pool;
2439 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002440 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002441 ASSERT_VK_SUCCESS(err);
2442
2443 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002444 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2445 pipeline_layout_ci.pNext = NULL;
2446 pipeline_layout_ci.setLayoutCount = 1;
2447 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002448
2449 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002450 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002451 ASSERT_VK_SUCCESS(err);
2452
Mark Youngad779052016-01-06 14:26:04 -07002453 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002454
Tony Barbour552f6c02016-12-21 14:34:07 -07002455 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002456 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002457
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002458 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002459
Chia-I Wuf7458c52015-10-26 21:10:41 +08002460 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2461 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002463}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002464
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002465TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2466 VkResult err;
2467
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002468 TEST_DESCRIPTION(
2469 "Test validation check for an invalid memory type index "
2470 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002471
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002472 ASSERT_NO_FATAL_FAILURE(InitState());
2473
2474 // Create an image, allocate memory, set a bad typeIndex and then try to
2475 // bind it
2476 VkImage image;
2477 VkDeviceMemory mem;
2478 VkMemoryRequirements mem_reqs;
2479 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2480 const int32_t tex_width = 32;
2481 const int32_t tex_height = 32;
2482
2483 VkImageCreateInfo image_create_info = {};
2484 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2485 image_create_info.pNext = NULL;
2486 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2487 image_create_info.format = tex_format;
2488 image_create_info.extent.width = tex_width;
2489 image_create_info.extent.height = tex_height;
2490 image_create_info.extent.depth = 1;
2491 image_create_info.mipLevels = 1;
2492 image_create_info.arrayLayers = 1;
2493 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2494 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2495 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2496 image_create_info.flags = 0;
2497
2498 VkMemoryAllocateInfo mem_alloc = {};
2499 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2500 mem_alloc.pNext = NULL;
2501 mem_alloc.allocationSize = 0;
2502 mem_alloc.memoryTypeIndex = 0;
2503
2504 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2505 ASSERT_VK_SUCCESS(err);
2506
2507 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2508 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002509
2510 // Introduce Failure, select invalid TypeIndex
2511 VkPhysicalDeviceMemoryProperties memory_info;
2512
2513 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2514 unsigned int i;
2515 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2516 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2517 mem_alloc.memoryTypeIndex = i;
2518 break;
2519 }
2520 }
2521 if (i >= memory_info.memoryTypeCount) {
2522 printf("No invalid memory type index could be found; skipped.\n");
2523 vkDestroyImage(m_device->device(), image, NULL);
2524 return;
2525 }
2526
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002527 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 -06002528
2529 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2530 ASSERT_VK_SUCCESS(err);
2531
2532 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2533 (void)err;
2534
2535 m_errorMonitor->VerifyFound();
2536
2537 vkDestroyImage(m_device->device(), image, NULL);
2538 vkFreeMemory(m_device->device(), mem, NULL);
2539}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002540
Karl Schultz6addd812016-02-02 17:17:23 -07002541TEST_F(VkLayerTest, BindInvalidMemory) {
2542 VkResult err;
2543 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002544
2545 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002546
Cortf801b982017-01-17 18:10:21 -08002547 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -07002548 const int32_t tex_width = 32;
2549 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002550
2551 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002552 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2553 image_create_info.pNext = NULL;
2554 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2555 image_create_info.format = tex_format;
2556 image_create_info.extent.width = tex_width;
2557 image_create_info.extent.height = tex_height;
2558 image_create_info.extent.depth = 1;
2559 image_create_info.mipLevels = 1;
2560 image_create_info.arrayLayers = 1;
2561 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002562 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002563 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2564 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002565
Cortf801b982017-01-17 18:10:21 -08002566 VkBufferCreateInfo buffer_create_info = {};
2567 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2568 buffer_create_info.pNext = NULL;
2569 buffer_create_info.flags = 0;
2570 buffer_create_info.size = tex_width;
2571 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
2572 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002573
Cortf801b982017-01-17 18:10:21 -08002574 // Create an image/buffer, allocate memory, free it, and then try to bind it
2575 {
2576 VkImage image = VK_NULL_HANDLE;
2577 VkBuffer buffer = VK_NULL_HANDLE;
2578 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2579 ASSERT_VK_SUCCESS(err);
2580 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2581 ASSERT_VK_SUCCESS(err);
2582 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2583 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2584 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002585
Cortf801b982017-01-17 18:10:21 -08002586 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2587 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2588 image_mem_alloc.allocationSize = image_mem_reqs.size;
2589 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2590 ASSERT_TRUE(pass);
2591 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2592 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2593 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2594 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002595
Cortf801b982017-01-17 18:10:21 -08002596 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2597 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2598 ASSERT_VK_SUCCESS(err);
2599 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2600 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002601
Cortf801b982017-01-17 18:10:21 -08002602 vkFreeMemory(device(), image_mem, NULL);
2603 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002604
Cortf801b982017-01-17 18:10:21 -08002605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2606 err = vkBindImageMemory(device(), image, image_mem, 0);
2607 (void)err; // This may very well return an error.
2608 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002609
Cortf801b982017-01-17 18:10:21 -08002610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2611 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2612 (void)err; // This may very well return an error.
2613 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002614
Cortf801b982017-01-17 18:10:21 -08002615 vkDestroyImage(m_device->device(), image, NULL);
2616 vkDestroyBuffer(m_device->device(), buffer, NULL);
2617 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002618
2619 // Try to bind memory to an object that already has a memory binding
2620 {
2621 VkImage image = VK_NULL_HANDLE;
2622 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2623 ASSERT_VK_SUCCESS(err);
2624 VkBuffer buffer = VK_NULL_HANDLE;
2625 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2626 ASSERT_VK_SUCCESS(err);
2627 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2628 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2629 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2630 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2631 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2632 image_alloc_info.allocationSize = image_mem_reqs.size;
2633 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2634 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2635 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2636 ASSERT_TRUE(pass);
2637 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2638 ASSERT_TRUE(pass);
2639 VkDeviceMemory image_mem, buffer_mem;
2640 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2641 ASSERT_VK_SUCCESS(err);
2642 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2643 ASSERT_VK_SUCCESS(err);
2644
2645 err = vkBindImageMemory(device(), image, image_mem, 0);
2646 ASSERT_VK_SUCCESS(err);
2647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2648 err = vkBindImageMemory(device(), image, image_mem, 0);
2649 (void)err; // This may very well return an error.
2650 m_errorMonitor->VerifyFound();
2651
2652 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2653 ASSERT_VK_SUCCESS(err);
2654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2655 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2656 (void)err; // This may very well return an error.
2657 m_errorMonitor->VerifyFound();
2658
2659 vkFreeMemory(device(), image_mem, NULL);
2660 vkFreeMemory(device(), buffer_mem, NULL);
2661 vkDestroyImage(device(), image, NULL);
2662 vkDestroyBuffer(device(), buffer, NULL);
2663 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002664
Cort6c7dff72017-01-27 18:34:50 -08002665 // Try to bind memory to an object with an out-of-range memoryOffset
2666 {
2667 VkImage image = VK_NULL_HANDLE;
2668 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2669 ASSERT_VK_SUCCESS(err);
2670 VkBuffer buffer = VK_NULL_HANDLE;
2671 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2672 ASSERT_VK_SUCCESS(err);
2673 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2674 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2675 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2676 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2677 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2678 image_alloc_info.allocationSize = image_mem_reqs.size;
2679 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2680 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2681 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2682 ASSERT_TRUE(pass);
2683 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2684 ASSERT_TRUE(pass);
2685 VkDeviceMemory image_mem, buffer_mem;
2686 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2687 ASSERT_VK_SUCCESS(err);
2688 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2689 ASSERT_VK_SUCCESS(err);
2690
2691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2692 VkDeviceSize image_offset = (image_mem_reqs.size + (image_mem_reqs.alignment - 1)) & ~(image_mem_reqs.alignment - 1);
2693 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2694 (void)err; // This may very well return an error.
2695 m_errorMonitor->VerifyFound();
2696
2697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2698 VkDeviceSize buffer_offset = (buffer_mem_reqs.size + (buffer_mem_reqs.alignment - 1)) & ~(buffer_mem_reqs.alignment - 1);
2699 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2700 (void)err; // This may very well return an error.
2701 m_errorMonitor->VerifyFound();
2702
2703 vkFreeMemory(device(), image_mem, NULL);
2704 vkFreeMemory(device(), buffer_mem, NULL);
2705 vkDestroyImage(device(), image, NULL);
2706 vkDestroyBuffer(device(), buffer, NULL);
2707 }
2708
Cort Stratton4c38bb52017-01-28 13:33:10 -08002709 // Try to bind memory to an object with an invalid memory type
2710 {
2711 VkImage image = VK_NULL_HANDLE;
2712 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2713 ASSERT_VK_SUCCESS(err);
2714 VkBuffer buffer = VK_NULL_HANDLE;
2715 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2716 ASSERT_VK_SUCCESS(err);
2717 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2718 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2719 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2720 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2721 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2722 image_alloc_info.allocationSize = image_mem_reqs.size;
2723 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2724 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002725 // Create a mask of available memory types *not* supported by these resources,
2726 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002727 VkPhysicalDeviceMemoryProperties memory_properties = {};
2728 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002729 VkDeviceMemory image_mem, buffer_mem;
2730
Cort Stratton4c38bb52017-01-28 13:33:10 -08002731 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002732 if (image_unsupported_mem_type_bits != 0) {
2733 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2734 ASSERT_TRUE(pass);
2735 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2736 ASSERT_VK_SUCCESS(err);
2737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2738 err = vkBindImageMemory(device(), image, image_mem, 0);
2739 (void)err; // This may very well return an error.
2740 m_errorMonitor->VerifyFound();
2741 vkFreeMemory(device(), image_mem, NULL);
2742 }
2743
Cort Stratton4c38bb52017-01-28 13:33:10 -08002744 uint32_t buffer_unsupported_mem_type_bits =
2745 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002746 if (buffer_unsupported_mem_type_bits != 0) {
2747 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2748 ASSERT_TRUE(pass);
2749 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2750 ASSERT_VK_SUCCESS(err);
2751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2752 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2753 (void)err; // This may very well return an error.
2754 m_errorMonitor->VerifyFound();
2755 vkFreeMemory(device(), buffer_mem, NULL);
2756 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002757
Cort Stratton4c38bb52017-01-28 13:33:10 -08002758 vkDestroyImage(device(), image, NULL);
2759 vkDestroyBuffer(device(), buffer, NULL);
2760 }
2761
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002762 // Try to bind memory to an image created with sparse memory flags
2763 {
2764 VkImageCreateInfo sparse_image_create_info = image_create_info;
2765 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2766 VkImageFormatProperties image_format_properties = {};
2767 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2768 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2769 sparse_image_create_info.usage, sparse_image_create_info.flags,
2770 &image_format_properties);
2771 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2772 // most likely means sparse formats aren't supported here; skip this test.
2773 } else {
2774 ASSERT_VK_SUCCESS(err);
2775 if (image_format_properties.maxExtent.width == 0) {
2776 printf("sparse image format not supported; skipped.\n");
2777 return;
2778 } else {
2779 VkImage sparse_image = VK_NULL_HANDLE;
2780 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2781 ASSERT_VK_SUCCESS(err);
2782 VkMemoryRequirements sparse_mem_reqs = {};
2783 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2784 if (sparse_mem_reqs.memoryTypeBits != 0) {
2785 VkMemoryAllocateInfo sparse_mem_alloc = {};
2786 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2787 sparse_mem_alloc.pNext = NULL;
2788 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2789 sparse_mem_alloc.memoryTypeIndex = 0;
2790 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2791 ASSERT_TRUE(pass);
2792 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2793 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2794 ASSERT_VK_SUCCESS(err);
2795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2796 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2797 // This may very well return an error.
2798 (void)err;
2799 m_errorMonitor->VerifyFound();
2800 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2801 }
2802 vkDestroyImage(m_device->device(), sparse_image, NULL);
2803 }
2804 }
2805 }
2806
2807 // Try to bind memory to a buffer created with sparse memory flags
2808 {
2809 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2810 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2811 if (!m_device->phy().features().sparseResidencyBuffer) {
2812 // most likely means sparse formats aren't supported here; skip this test.
2813 } else {
2814 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2815 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2816 ASSERT_VK_SUCCESS(err);
2817 VkMemoryRequirements sparse_mem_reqs = {};
2818 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2819 if (sparse_mem_reqs.memoryTypeBits != 0) {
2820 VkMemoryAllocateInfo sparse_mem_alloc = {};
2821 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2822 sparse_mem_alloc.pNext = NULL;
2823 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2824 sparse_mem_alloc.memoryTypeIndex = 0;
2825 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2826 ASSERT_TRUE(pass);
2827 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2828 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2829 ASSERT_VK_SUCCESS(err);
2830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2831 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2832 // This may very well return an error.
2833 (void)err;
2834 m_errorMonitor->VerifyFound();
2835 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2836 }
2837 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2838 }
2839 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002840}
2841
Karl Schultz6addd812016-02-02 17:17:23 -07002842TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2843 VkResult err;
2844 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002845
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002847
Tobin Ehlisec598302015-09-15 15:02:17 -06002848 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002849
Karl Schultz6addd812016-02-02 17:17:23 -07002850 // Create an image object, allocate memory, destroy the object and then try
2851 // to bind it
2852 VkImage image;
2853 VkDeviceMemory mem;
2854 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002855
Karl Schultz6addd812016-02-02 17:17:23 -07002856 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2857 const int32_t tex_width = 32;
2858 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002859
2860 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002861 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2862 image_create_info.pNext = NULL;
2863 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2864 image_create_info.format = tex_format;
2865 image_create_info.extent.width = tex_width;
2866 image_create_info.extent.height = tex_height;
2867 image_create_info.extent.depth = 1;
2868 image_create_info.mipLevels = 1;
2869 image_create_info.arrayLayers = 1;
2870 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2871 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2872 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2873 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002874
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002875 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002876 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2877 mem_alloc.pNext = NULL;
2878 mem_alloc.allocationSize = 0;
2879 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002880
Chia-I Wuf7458c52015-10-26 21:10:41 +08002881 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002882 ASSERT_VK_SUCCESS(err);
2883
Karl Schultz6addd812016-02-02 17:17:23 -07002884 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002885
2886 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002887 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002888 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002889
2890 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002891 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002892 ASSERT_VK_SUCCESS(err);
2893
2894 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002895 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002896 ASSERT_VK_SUCCESS(err);
2897
2898 // Now Try to bind memory to this destroyed object
2899 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2900 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002901 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002902
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002903 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002904
Chia-I Wuf7458c52015-10-26 21:10:41 +08002905 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002906}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002907
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002908TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2909 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2910
2911 ASSERT_NO_FATAL_FAILURE(InitState());
2912 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2913
2914 VkVertexInputBindingDescription input_binding;
2915 memset(&input_binding, 0, sizeof(input_binding));
2916
2917 VkVertexInputAttributeDescription input_attribs;
2918 memset(&input_attribs, 0, sizeof(input_attribs));
2919
2920 // Pick a really bad format for this purpose and make sure it should fail
2921 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2922 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2923 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2924 printf("Format unsuitable for test; skipped.\n");
2925 return;
2926 }
2927
2928 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002929 char const *vsSource =
2930 "#version 450\n"
2931 "\n"
2932 "out gl_PerVertex {\n"
2933 " vec4 gl_Position;\n"
2934 "};\n"
2935 "void main(){\n"
2936 " gl_Position = vec4(1);\n"
2937 "}\n";
2938 char const *fsSource =
2939 "#version 450\n"
2940 "\n"
2941 "layout(location=0) out vec4 color;\n"
2942 "void main(){\n"
2943 " color = vec4(1);\n"
2944 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002945
2946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2947 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2948 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2949
2950 VkPipelineObj pipe(m_device);
2951 pipe.AddColorAttachment();
2952 pipe.AddShader(&vs);
2953 pipe.AddShader(&fs);
2954
2955 pipe.AddVertexInputBindings(&input_binding, 1);
2956 pipe.AddVertexInputAttribs(&input_attribs, 1);
2957
2958 VkDescriptorSetObj descriptorSet(m_device);
2959 descriptorSet.AppendDummy();
2960 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2961
2962 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2963
2964 m_errorMonitor->VerifyFound();
2965}
2966
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002967TEST_F(VkLayerTest, ImageSampleCounts) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002968 TEST_DESCRIPTION(
2969 "Use bad sample counts in image transfer calls to trigger "
2970 "validation errors.");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002971 ASSERT_NO_FATAL_FAILURE(InitState());
2972
2973 VkMemoryPropertyFlags reqs = 0;
2974 VkImageCreateInfo image_create_info = {};
2975 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2976 image_create_info.pNext = NULL;
2977 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2978 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2979 image_create_info.extent.width = 256;
2980 image_create_info.extent.height = 256;
2981 image_create_info.extent.depth = 1;
2982 image_create_info.mipLevels = 1;
2983 image_create_info.arrayLayers = 1;
2984 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2985 image_create_info.flags = 0;
2986
2987 VkImageBlit blit_region = {};
2988 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2989 blit_region.srcSubresource.baseArrayLayer = 0;
2990 blit_region.srcSubresource.layerCount = 1;
2991 blit_region.srcSubresource.mipLevel = 0;
2992 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2993 blit_region.dstSubresource.baseArrayLayer = 0;
2994 blit_region.dstSubresource.layerCount = 1;
2995 blit_region.dstSubresource.mipLevel = 0;
2996
2997 // Create two images, the source with sampleCount = 2, and attempt to blit
2998 // between them
2999 {
3000 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003001 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003002 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003003 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003004 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003005 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003006 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003007 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003008 m_errorMonitor->SetUnexpectedError("attempts to implicitly reset cmdBuffer created from command pool");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003009 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3011 "was created with a sample count "
3012 "of VK_SAMPLE_COUNT_2_BIT but "
3013 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003014 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3015 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003016 m_errorMonitor->VerifyFound();
3017 m_commandBuffer->EndCommandBuffer();
3018 }
3019
3020 // Create two images, the dest with sampleCount = 4, and attempt to blit
3021 // between them
3022 {
3023 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003024 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003025 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003026 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003027 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003028 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003029 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003030 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003031 m_errorMonitor->SetUnexpectedError("attempts to implicitly reset cmdBuffer created from command pool");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003032 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3034 "was created with a sample count "
3035 "of VK_SAMPLE_COUNT_4_BIT but "
3036 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003037 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3038 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003039 m_errorMonitor->VerifyFound();
3040 m_commandBuffer->EndCommandBuffer();
3041 }
3042
3043 VkBufferImageCopy copy_region = {};
3044 copy_region.bufferRowLength = 128;
3045 copy_region.bufferImageHeight = 128;
3046 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3047 copy_region.imageSubresource.layerCount = 1;
3048 copy_region.imageExtent.height = 64;
3049 copy_region.imageExtent.width = 64;
3050 copy_region.imageExtent.depth = 1;
3051
3052 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3053 // buffer to image
3054 {
3055 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003056 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3057 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003058 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003059 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003060 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003061 m_errorMonitor->SetUnexpectedError(
3062 "If commandBuffer was allocated from a VkCommandPool which did not have the "
3063 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003064 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3066 "was created with a sample count "
3067 "of VK_SAMPLE_COUNT_8_BIT but "
3068 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003069 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3070 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003071 m_errorMonitor->VerifyFound();
3072 m_commandBuffer->EndCommandBuffer();
3073 }
3074
3075 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3076 // image to buffer
3077 {
3078 vk_testing::Buffer dst_buffer;
3079 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3080 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003081 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003082 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003083 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003084 m_errorMonitor->SetUnexpectedError("attempts to implicitly reset cmdBuffer created from command pool");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003085 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3087 "was created with a sample count "
3088 "of VK_SAMPLE_COUNT_2_BIT but "
3089 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003090 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003091 dst_buffer.handle(), 1, &copy_region);
3092 m_errorMonitor->VerifyFound();
3093 m_commandBuffer->EndCommandBuffer();
3094 }
3095}
3096
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003097TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003098 ASSERT_NO_FATAL_FAILURE(InitState());
3099
3100 VkImageObj src_image(m_device);
3101 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3102 VkImageObj dst_image(m_device);
3103 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3104 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003105 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 -06003106
3107 VkImageBlit blitRegion = {};
3108 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3109 blitRegion.srcSubresource.baseArrayLayer = 0;
3110 blitRegion.srcSubresource.layerCount = 1;
3111 blitRegion.srcSubresource.mipLevel = 0;
3112 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3113 blitRegion.dstSubresource.baseArrayLayer = 0;
3114 blitRegion.dstSubresource.layerCount = 1;
3115 blitRegion.dstSubresource.mipLevel = 0;
3116
Dave Houlton34df4cb2016-12-01 16:43:06 -07003117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3118
3119 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3120 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003121
3122 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003123 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003124 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3125 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003126
3127 m_errorMonitor->VerifyFound();
3128
Dave Houlton34df4cb2016-12-01 16:43:06 -07003129 // Test should generate 2 VU failures
3130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003132
3133 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003134 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3135 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003136
Dave Houlton34df4cb2016-12-01 16:43:06 -07003137 // TODO: Note that this only verifies that at least one of the VU enums was found
3138 // 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 -06003139 m_errorMonitor->VerifyFound();
3140
Tony Barbour552f6c02016-12-21 14:34:07 -07003141 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003142}
3143
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003144TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3145 VkResult err;
3146 bool pass;
3147
3148 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3149 ASSERT_NO_FATAL_FAILURE(InitState());
3150
3151 // If w/d/h granularity is 1, test is not meaningful
3152 // TODO: When virtual device limits are available, create a set of limits for this test that
3153 // will always have a granularity of > 1 for w, h, and d
3154 auto index = m_device->graphics_queue_node_index_;
3155 auto queue_family_properties = m_device->phy().queue_properties();
3156
3157 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3158 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3159 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3160 return;
3161 }
3162
3163 // Create two images of different types and try to copy between them
3164 VkImage srcImage;
3165 VkImage dstImage;
3166 VkDeviceMemory srcMem;
3167 VkDeviceMemory destMem;
3168 VkMemoryRequirements memReqs;
3169
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003170 VkImageCreateInfo image_create_info = {};
3171 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3172 image_create_info.pNext = NULL;
3173 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3174 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3175 image_create_info.extent.width = 32;
3176 image_create_info.extent.height = 32;
3177 image_create_info.extent.depth = 1;
3178 image_create_info.mipLevels = 1;
3179 image_create_info.arrayLayers = 4;
3180 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3181 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3182 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3183 image_create_info.flags = 0;
3184
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003185 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003186 ASSERT_VK_SUCCESS(err);
3187
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003188 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003189 ASSERT_VK_SUCCESS(err);
3190
3191 // Allocate memory
3192 VkMemoryAllocateInfo memAlloc = {};
3193 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3194 memAlloc.pNext = NULL;
3195 memAlloc.allocationSize = 0;
3196 memAlloc.memoryTypeIndex = 0;
3197
3198 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3199 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003200 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003201 ASSERT_TRUE(pass);
3202 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3203 ASSERT_VK_SUCCESS(err);
3204
3205 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3206 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003207 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003208 ASSERT_VK_SUCCESS(err);
3209 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3210 ASSERT_VK_SUCCESS(err);
3211
3212 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3213 ASSERT_VK_SUCCESS(err);
3214 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3215 ASSERT_VK_SUCCESS(err);
3216
Tony Barbour552f6c02016-12-21 14:34:07 -07003217 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003218 VkImageCopy copyRegion;
3219 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3220 copyRegion.srcSubresource.mipLevel = 0;
3221 copyRegion.srcSubresource.baseArrayLayer = 0;
3222 copyRegion.srcSubresource.layerCount = 1;
3223 copyRegion.srcOffset.x = 0;
3224 copyRegion.srcOffset.y = 0;
3225 copyRegion.srcOffset.z = 0;
3226 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3227 copyRegion.dstSubresource.mipLevel = 0;
3228 copyRegion.dstSubresource.baseArrayLayer = 0;
3229 copyRegion.dstSubresource.layerCount = 1;
3230 copyRegion.dstOffset.x = 0;
3231 copyRegion.dstOffset.y = 0;
3232 copyRegion.dstOffset.z = 0;
3233 copyRegion.extent.width = 1;
3234 copyRegion.extent.height = 1;
3235 copyRegion.extent.depth = 1;
3236
3237 // Introduce failure by setting srcOffset to a bad granularity value
3238 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3240 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003241 m_errorMonitor->VerifyFound();
3242
3243 // Introduce failure by setting extent to a bad granularity value
3244 copyRegion.srcOffset.y = 0;
3245 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3247 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003248 m_errorMonitor->VerifyFound();
3249
3250 // Now do some buffer/image copies
3251 vk_testing::Buffer buffer;
3252 VkMemoryPropertyFlags reqs = 0;
3253 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3254 VkBufferImageCopy region = {};
3255 region.bufferOffset = 0;
3256 region.bufferRowLength = 3;
3257 region.bufferImageHeight = 128;
3258 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3259 region.imageSubresource.layerCount = 1;
3260 region.imageExtent.height = 16;
3261 region.imageExtent.width = 16;
3262 region.imageExtent.depth = 1;
3263 region.imageOffset.x = 0;
3264 region.imageOffset.y = 0;
3265 region.imageOffset.z = 0;
3266
3267 // Introduce failure by setting bufferRowLength to a bad granularity value
3268 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3270 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3271 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003272 m_errorMonitor->VerifyFound();
3273 region.bufferRowLength = 128;
3274
3275 // Introduce failure by setting bufferOffset to a bad granularity value
3276 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3278 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3279 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003280 m_errorMonitor->VerifyFound();
3281 region.bufferOffset = 0;
3282
3283 // Introduce failure by setting bufferImageHeight to a bad granularity value
3284 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3286 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3287 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003288 m_errorMonitor->VerifyFound();
3289 region.bufferImageHeight = 128;
3290
3291 // Introduce failure by setting imageExtent to a bad granularity value
3292 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3294 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3295 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003296 m_errorMonitor->VerifyFound();
3297 region.imageExtent.width = 16;
3298
3299 // Introduce failure by setting imageOffset to a bad granularity value
3300 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3302 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3303 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003304 m_errorMonitor->VerifyFound();
3305
Tony Barbour552f6c02016-12-21 14:34:07 -07003306 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003307
3308 vkDestroyImage(m_device->device(), srcImage, NULL);
3309 vkDestroyImage(m_device->device(), dstImage, NULL);
3310 vkFreeMemory(m_device->device(), srcMem, NULL);
3311 vkFreeMemory(m_device->device(), destMem, NULL);
3312}
3313
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003314TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003315 TEST_DESCRIPTION(
3316 "Submit command buffer created using one queue family and "
3317 "attempt to submit them on a queue created in a different "
3318 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003319
Cody Northropc31a84f2016-08-22 10:41:47 -06003320 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003321
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003322 // This test is meaningless unless we have multiple queue families
3323 auto queue_family_properties = m_device->phy().queue_properties();
3324 if (queue_family_properties.size() < 2) {
3325 return;
3326 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003328 // Get safe index of another queue family
3329 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3330 ASSERT_NO_FATAL_FAILURE(InitState());
3331 // Create a second queue using a different queue family
3332 VkQueue other_queue;
3333 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3334
3335 // Record an empty cmd buffer
3336 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3337 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3338 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3339 vkEndCommandBuffer(m_commandBuffer->handle());
3340
3341 // And submit on the wrong queue
3342 VkSubmitInfo submit_info = {};
3343 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3344 submit_info.commandBufferCount = 1;
3345 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003346 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003347
3348 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003349}
3350
Chris Forbes4c24a922016-11-16 08:59:10 +13003351TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3352 ASSERT_NO_FATAL_FAILURE(InitState());
3353
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003354 // There are no attachments, but refer to attachment 0.
3355 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003356 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003357 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003358 };
3359
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003360 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003361 VkRenderPass rp;
3362
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003363 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003365 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3366 m_errorMonitor->VerifyFound();
3367}
3368
Chris Forbesa58c4522016-09-28 15:19:39 +13003369TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3370 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3371 ASSERT_NO_FATAL_FAILURE(InitState());
3372
3373 // A renderpass with two subpasses, both writing the same attachment.
3374 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003375 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3376 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3377 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003378 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003379 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003380 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003381 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3382 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003383 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003384 VkSubpassDependency dep = {0,
3385 1,
3386 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3387 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3388 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3389 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3390 VK_DEPENDENCY_BY_REGION_BIT};
3391 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003392 VkRenderPass rp;
3393 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3394 ASSERT_VK_SUCCESS(err);
3395
3396 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003397 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 +13003398 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3399
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003400 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003401 VkFramebuffer fb;
3402 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3403 ASSERT_VK_SUCCESS(err);
3404
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003405 char const *vsSource =
3406 "#version 450\n"
3407 "void main() { gl_Position = vec4(1); }\n";
3408 char const *fsSource =
3409 "#version 450\n"
3410 "layout(location=0) out vec4 color;\n"
3411 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003412
3413 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3414 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3415 VkPipelineObj pipe(m_device);
3416 pipe.AddColorAttachment();
3417 pipe.AddShader(&vs);
3418 pipe.AddShader(&fs);
3419 VkViewport view_port = {};
3420 m_viewports.push_back(view_port);
3421 pipe.SetViewport(m_viewports);
3422 VkRect2D rect = {};
3423 m_scissors.push_back(rect);
3424 pipe.SetScissor(m_scissors);
3425
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003426 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003427 VkPipelineLayout pl;
3428 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3429 ASSERT_VK_SUCCESS(err);
3430 pipe.CreateVKPipeline(pl, rp);
3431
Tony Barbour552f6c02016-12-21 14:34:07 -07003432 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003433
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003434 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3435 nullptr,
3436 rp,
3437 fb,
3438 {{
3439 0, 0,
3440 },
3441 {32, 32}},
3442 0,
3443 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003444
3445 // subtest 1: bind in the wrong subpass
3446 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3447 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003448 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 +13003449 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3450 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3451 m_errorMonitor->VerifyFound();
3452
3453 vkCmdEndRenderPass(m_commandBuffer->handle());
3454
3455 // subtest 2: bind in correct subpass, then transition to next subpass
3456 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3457 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3458 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003459 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 +13003460 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3461 m_errorMonitor->VerifyFound();
3462
3463 vkCmdEndRenderPass(m_commandBuffer->handle());
3464
Tony Barbour552f6c02016-12-21 14:34:07 -07003465 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003466
3467 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3468 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3469 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3470}
3471
Tony Barbour4e919972016-08-09 13:27:40 -06003472TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003473 TEST_DESCRIPTION(
3474 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3475 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003476 ASSERT_NO_FATAL_FAILURE(InitState());
3477 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3478
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3480 "Cannot execute a render pass with renderArea "
3481 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003482
3483 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3484 m_renderPassBeginInfo.renderArea.extent.width = 257;
3485 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003486 m_commandBuffer->BeginCommandBuffer();
3487 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003488 m_errorMonitor->VerifyFound();
3489}
3490
3491TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003492 TEST_DESCRIPTION(
3493 "Generate INDEPENDENT_BLEND by disabling independent "
3494 "blend and then specifying different blend states for two "
3495 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003496 VkPhysicalDeviceFeatures features = {};
3497 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003498 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003499
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3501 "Invalid Pipeline CreateInfo: If independent blend feature not "
3502 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003503
Cody Northropc31a84f2016-08-22 10:41:47 -06003504 VkDescriptorSetObj descriptorSet(m_device);
3505 descriptorSet.AppendDummy();
3506 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003507
Cody Northropc31a84f2016-08-22 10:41:47 -06003508 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003509 // Create a renderPass with two color attachments
3510 VkAttachmentReference attachments[2] = {};
3511 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3512 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3513
3514 VkSubpassDescription subpass = {};
3515 subpass.pColorAttachments = attachments;
3516 subpass.colorAttachmentCount = 2;
3517
3518 VkRenderPassCreateInfo rpci = {};
3519 rpci.subpassCount = 1;
3520 rpci.pSubpasses = &subpass;
3521 rpci.attachmentCount = 1;
3522
3523 VkAttachmentDescription attach_desc = {};
3524 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3525 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3526 attach_desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3527 attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3528
3529 rpci.pAttachments = &attach_desc;
3530 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3531
3532 VkRenderPass renderpass;
3533 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003534 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003535 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003536
Cody Northropc31a84f2016-08-22 10:41:47 -06003537 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3538 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3539 att_state1.blendEnable = VK_TRUE;
3540 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3541 att_state2.blendEnable = VK_FALSE;
3542 pipeline.AddColorAttachment(0, &att_state1);
3543 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003544 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003545 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003546 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003547}
3548
Mike Weiblen40b160e2017-02-06 19:21:52 -07003549// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3550TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3551 TEST_DESCRIPTION(
3552 "Create a graphics pipeline that is incompatible with the requirements "
3553 "of its contained Renderpass/subpasses.");
3554 ASSERT_NO_FATAL_FAILURE(InitState());
3555
3556 VkDescriptorSetObj ds_obj(m_device);
3557 ds_obj.AppendDummy();
3558 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3559
3560 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3561
3562 VkPipelineColorBlendAttachmentState att_state1 = {};
3563 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3564 att_state1.blendEnable = VK_TRUE;
3565
3566 VkRenderpassObj rp_obj(m_device);
3567
3568 {
3569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3570 VkPipelineObj pipeline(m_device);
3571 pipeline.AddShader(&vs_obj);
3572 pipeline.AddColorAttachment(0, &att_state1);
3573
3574 VkGraphicsPipelineCreateInfo info = {};
3575 pipeline.InitGraphicsPipelineCreateInfo(&info);
3576 info.pColorBlendState = nullptr;
3577
3578 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3579 m_errorMonitor->VerifyFound();
3580 }
3581}
3582
Chris Forbes26ec2122016-11-29 08:58:33 +13003583#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003584TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3585 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3586 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003587 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003588
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3590 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003591
3592 // Create a renderPass with a single color attachment
3593 VkAttachmentReference attach = {};
3594 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3595 VkSubpassDescription subpass = {};
3596 VkRenderPassCreateInfo rpci = {};
3597 rpci.subpassCount = 1;
3598 rpci.pSubpasses = &subpass;
3599 rpci.attachmentCount = 1;
3600 VkAttachmentDescription attach_desc = {};
3601 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3602 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3603 rpci.pAttachments = &attach_desc;
3604 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3605 VkRenderPass rp;
3606 subpass.pDepthStencilAttachment = &attach;
3607 subpass.pColorAttachments = NULL;
3608 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3609 m_errorMonitor->VerifyFound();
3610}
Chris Forbes26ec2122016-11-29 08:58:33 +13003611#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003612
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003613TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003614 TEST_DESCRIPTION(
3615 "Create a framebuffer where a subpass has a preserve "
3616 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003617
3618 ASSERT_NO_FATAL_FAILURE(InitState());
3619 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3620
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003622
3623 VkAttachmentReference color_attach = {};
3624 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3625 color_attach.attachment = 0;
3626 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3627 VkSubpassDescription subpass = {};
3628 subpass.colorAttachmentCount = 1;
3629 subpass.pColorAttachments = &color_attach;
3630 subpass.preserveAttachmentCount = 1;
3631 subpass.pPreserveAttachments = &preserve_attachment;
3632
3633 VkRenderPassCreateInfo rpci = {};
3634 rpci.subpassCount = 1;
3635 rpci.pSubpasses = &subpass;
3636 rpci.attachmentCount = 1;
3637 VkAttachmentDescription attach_desc = {};
3638 attach_desc.format = VK_FORMAT_UNDEFINED;
3639 rpci.pAttachments = &attach_desc;
3640 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3641 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003642 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003643
3644 m_errorMonitor->VerifyFound();
3645
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003646 if (result == VK_SUCCESS) {
3647 vkDestroyRenderPass(m_device->device(), rp, NULL);
3648 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003649}
3650
Chris Forbesc5389742016-06-29 11:49:23 +12003651TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003652 TEST_DESCRIPTION(
3653 "Ensure that CreateRenderPass produces a validation error "
3654 "when the source of a subpass multisample resolve "
3655 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003656
Chris Forbesc5389742016-06-29 11:49:23 +12003657 ASSERT_NO_FATAL_FAILURE(InitState());
3658
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3660 "Subpass 0 requests multisample resolve from attachment 0 which has "
3661 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003662
3663 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003664 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3665 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3666 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3667 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3668 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3669 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003670 };
3671
3672 VkAttachmentReference color = {
3673 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3674 };
3675
3676 VkAttachmentReference resolve = {
3677 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3678 };
3679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003680 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003681
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003682 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003683
3684 VkRenderPass rp;
3685 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3686
3687 m_errorMonitor->VerifyFound();
3688
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003689 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003690}
3691
3692TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003693 TEST_DESCRIPTION(
3694 "Ensure CreateRenderPass produces a validation error "
3695 "when a subpass multisample resolve operation is "
3696 "requested, and the destination of that resolve has "
3697 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003698
Chris Forbesc5389742016-06-29 11:49:23 +12003699 ASSERT_NO_FATAL_FAILURE(InitState());
3700
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3702 "Subpass 0 requests multisample resolve into attachment 1, which "
3703 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003704
3705 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003706 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3707 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3708 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3709 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3710 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3711 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003712 };
3713
3714 VkAttachmentReference color = {
3715 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3716 };
3717
3718 VkAttachmentReference resolve = {
3719 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3720 };
3721
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003722 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003723
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003724 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003725
3726 VkRenderPass rp;
3727 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3728
3729 m_errorMonitor->VerifyFound();
3730
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003731 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003732}
3733
Chris Forbes3f128ef2016-06-29 14:58:53 +12003734TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003735 TEST_DESCRIPTION(
3736 "Ensure CreateRenderPass produces a validation error "
3737 "when the color and depth attachments used by a subpass "
3738 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003739
Chris Forbes3f128ef2016-06-29 14:58:53 +12003740 ASSERT_NO_FATAL_FAILURE(InitState());
3741
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3743 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003744
3745 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003746 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3747 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3748 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3749 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3750 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3751 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003752 };
3753
3754 VkAttachmentReference color[] = {
3755 {
3756 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3757 },
3758 {
3759 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3760 },
3761 };
3762
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003763 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003764
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003765 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003766
3767 VkRenderPass rp;
3768 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3769
3770 m_errorMonitor->VerifyFound();
3771
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003772 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003773}
3774
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003775TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003776 TEST_DESCRIPTION(
3777 "Hit errors when attempting to create a framebuffer :\n"
3778 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3779 " 2. Use a color image as depthStencil attachment\n"
3780 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3781 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3782 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3783 " 6. Framebuffer attachment where dimensions don't match\n"
3784 " 7. Framebuffer attachment w/o identity swizzle\n"
3785 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003786
3787 ASSERT_NO_FATAL_FAILURE(InitState());
3788 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3789
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3791 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3792 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003793
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003794 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003795 VkAttachmentReference attach = {};
3796 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3797 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003798 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003799 VkRenderPassCreateInfo rpci = {};
3800 rpci.subpassCount = 1;
3801 rpci.pSubpasses = &subpass;
3802 rpci.attachmentCount = 1;
3803 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003804 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003805 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003806 rpci.pAttachments = &attach_desc;
3807 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3808 VkRenderPass rp;
3809 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3810 ASSERT_VK_SUCCESS(err);
3811
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003812 VkImageView ivs[2];
3813 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3814 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003815 VkFramebufferCreateInfo fb_info = {};
3816 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3817 fb_info.pNext = NULL;
3818 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003819 // Set mis-matching attachmentCount
3820 fb_info.attachmentCount = 2;
3821 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003822 fb_info.width = 100;
3823 fb_info.height = 100;
3824 fb_info.layers = 1;
3825
3826 VkFramebuffer fb;
3827 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3828
3829 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003830 if (err == VK_SUCCESS) {
3831 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3832 }
3833 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003834
3835 // Create a renderPass with a depth-stencil attachment created with
3836 // IMAGE_USAGE_COLOR_ATTACHMENT
3837 // Add our color attachment to pDepthStencilAttachment
3838 subpass.pDepthStencilAttachment = &attach;
3839 subpass.pColorAttachments = NULL;
3840 VkRenderPass rp_ds;
3841 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3842 ASSERT_VK_SUCCESS(err);
3843 // Set correct attachment count, but attachment has COLOR usage bit set
3844 fb_info.attachmentCount = 1;
3845 fb_info.renderPass = rp_ds;
3846
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003848 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3849
3850 m_errorMonitor->VerifyFound();
3851 if (err == VK_SUCCESS) {
3852 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3853 }
3854 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003855
3856 // Create new renderpass with alternate attachment format from fb
3857 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3858 subpass.pDepthStencilAttachment = NULL;
3859 subpass.pColorAttachments = &attach;
3860 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3861 ASSERT_VK_SUCCESS(err);
3862
3863 // Cause error due to mis-matched formats between rp & fb
3864 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3865 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3867 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003868 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3869
3870 m_errorMonitor->VerifyFound();
3871 if (err == VK_SUCCESS) {
3872 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3873 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003874 vkDestroyRenderPass(m_device->device(), rp, NULL);
3875
3876 // Create new renderpass with alternate sample count from fb
3877 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3878 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3879 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3880 ASSERT_VK_SUCCESS(err);
3881
3882 // Cause error due to mis-matched sample count between rp & fb
3883 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3885 " has VK_SAMPLE_COUNT_1_BIT samples "
3886 "that do not match the "
3887 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003888 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3889
3890 m_errorMonitor->VerifyFound();
3891 if (err == VK_SUCCESS) {
3892 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3893 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003894
3895 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003896
3897 // Create a custom imageView with non-1 mip levels
3898 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003899 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 -06003900 ASSERT_TRUE(image.initialized());
3901
3902 VkImageView view;
3903 VkImageViewCreateInfo ivci = {};
3904 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3905 ivci.image = image.handle();
3906 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3907 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3908 ivci.subresourceRange.layerCount = 1;
3909 ivci.subresourceRange.baseMipLevel = 0;
3910 // Set level count 2 (only 1 is allowed for FB attachment)
3911 ivci.subresourceRange.levelCount = 2;
3912 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3913 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3914 ASSERT_VK_SUCCESS(err);
3915 // Re-create renderpass to have matching sample count
3916 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3917 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3918 ASSERT_VK_SUCCESS(err);
3919
3920 fb_info.renderPass = rp;
3921 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003923 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3924
3925 m_errorMonitor->VerifyFound();
3926 if (err == VK_SUCCESS) {
3927 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3928 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003929 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003930 // Update view to original color buffer and grow FB dimensions too big
3931 fb_info.pAttachments = ivs;
3932 fb_info.height = 1024;
3933 fb_info.width = 1024;
3934 fb_info.layers = 2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3936 " Attachment dimensions must be at "
3937 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003938 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3939
3940 m_errorMonitor->VerifyFound();
3941 if (err == VK_SUCCESS) {
3942 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3943 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003944 // Create view attachment with non-identity swizzle
3945 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3946 ivci.image = image.handle();
3947 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3948 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3949 ivci.subresourceRange.layerCount = 1;
3950 ivci.subresourceRange.baseMipLevel = 0;
3951 ivci.subresourceRange.levelCount = 1;
3952 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3953 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3954 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3955 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3956 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3957 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3958 ASSERT_VK_SUCCESS(err);
3959
3960 fb_info.pAttachments = &view;
3961 fb_info.height = 100;
3962 fb_info.width = 100;
3963 fb_info.layers = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3965 " has non-identy swizzle. All "
3966 "framebuffer attachments must have "
3967 "been created with the identity "
3968 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003969 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3970
3971 m_errorMonitor->VerifyFound();
3972 if (err == VK_SUCCESS) {
3973 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3974 }
3975 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003976 // reset attachment to color attachment
3977 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003978
3979 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003980 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003981 fb_info.height = 100;
3982 fb_info.layers = 1;
3983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003984 m_errorMonitor->SetUnexpectedError(
3985 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
3986 "Here are the respective dimensions for attachment");
3987
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003988 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3989
3990 m_errorMonitor->VerifyFound();
3991 if (err == VK_SUCCESS) {
3992 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3993 }
3994
3995 // Request fb that exceeds max height
3996 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003997 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003998 fb_info.layers = 1;
3999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004000 m_errorMonitor->SetUnexpectedError(
4001 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4002 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004003 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4004
4005 m_errorMonitor->VerifyFound();
4006 if (err == VK_SUCCESS) {
4007 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4008 }
4009
4010 // Request fb that exceeds max layers
4011 fb_info.width = 100;
4012 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004013 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004015 m_errorMonitor->SetUnexpectedError(
4016 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4017 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004018 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4019
4020 m_errorMonitor->VerifyFound();
4021 if (err == VK_SUCCESS) {
4022 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4023 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004024
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004025 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004026}
4027
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004028TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004029 TEST_DESCRIPTION(
4030 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4031 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004032
Cody Northropc31a84f2016-08-22 10:41:47 -06004033 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004034 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4036 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004037 m_errorMonitor->VerifyFound();
4038}
4039
4040TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004041 TEST_DESCRIPTION(
4042 "Run a simple draw calls to validate failure when Line Width dynamic "
4043 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004044
Cody Northropc31a84f2016-08-22 10:41:47 -06004045 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004046 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4048 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004049 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004050}
4051
4052TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004053 TEST_DESCRIPTION(
4054 "Run a simple draw calls to validate failure when Viewport dynamic "
4055 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004056
Cody Northropc31a84f2016-08-22 10:41:47 -06004057 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004058 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4060 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004061 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004062 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004063}
4064
4065TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004066 TEST_DESCRIPTION(
4067 "Run a simple draw calls to validate failure when Scissor dynamic "
4068 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004069
Cody Northropc31a84f2016-08-22 10:41:47 -06004070 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004071 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4073 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004074 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004075 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004076}
4077
Cortd713fe82016-07-27 09:51:27 -07004078TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004079 TEST_DESCRIPTION(
4080 "Run a simple draw calls to validate failure when Blend Constants "
4081 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004082
4083 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004084 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4086 "Dynamic blend constants state not set for this command buffer");
4087 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004088 m_errorMonitor->VerifyFound();
4089}
4090
4091TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004092 TEST_DESCRIPTION(
4093 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4094 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004095
4096 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004097 if (!m_device->phy().features().depthBounds) {
4098 printf("Device does not support depthBounds test; skipped.\n");
4099 return;
4100 }
4101 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4103 "Dynamic depth bounds state not set for this command buffer");
4104 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004105 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004106}
4107
4108TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004109 TEST_DESCRIPTION(
4110 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4111 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004112
4113 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004114 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4116 "Dynamic stencil read mask state not set for this command buffer");
4117 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004118 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004119}
4120
4121TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004122 TEST_DESCRIPTION(
4123 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4124 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004125
4126 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004127 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4129 "Dynamic stencil write mask state not set for this command buffer");
4130 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004131 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004132}
4133
4134TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004135 TEST_DESCRIPTION(
4136 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4137 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004138
4139 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004140 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4142 "Dynamic stencil reference state not set for this command buffer");
4143 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004144 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004145}
4146
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004147TEST_F(VkLayerTest, IndexBufferNotBound) {
4148 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004149
4150 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4152 "Index buffer object not bound to this command buffer when Indexed ");
4153 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004154 m_errorMonitor->VerifyFound();
4155}
4156
Karl Schultz6addd812016-02-02 17:17:23 -07004157TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4159 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4160 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004161
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004162 ASSERT_NO_FATAL_FAILURE(InitState());
4163 ASSERT_NO_FATAL_FAILURE(InitViewport());
4164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4165
Karl Schultz6addd812016-02-02 17:17:23 -07004166 // We luck out b/c by default the framework creates CB w/ the
4167 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004168 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004169 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004170 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004171
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004172 // Bypass framework since it does the waits automatically
4173 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004174 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004175 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4176 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004177 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004178 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004179 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004180 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004181 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004182 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004183 submit_info.pSignalSemaphores = NULL;
4184
Chris Forbes40028e22016-06-13 09:59:34 +12004185 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004186 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004187 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004188
Karl Schultz6addd812016-02-02 17:17:23 -07004189 // Cause validation error by re-submitting cmd buffer that should only be
4190 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004191 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004192 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004193
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004194 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004195}
4196
Karl Schultz6addd812016-02-02 17:17:23 -07004197TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004198 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004199 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004200
4201 ASSERT_NO_FATAL_FAILURE(InitState());
4202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004203
Karl Schultz6addd812016-02-02 17:17:23 -07004204 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4205 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004206 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004207 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004208 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004209
4210 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004211 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4212 ds_pool_ci.pNext = NULL;
4213 ds_pool_ci.flags = 0;
4214 ds_pool_ci.maxSets = 1;
4215 ds_pool_ci.poolSizeCount = 1;
4216 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004217
4218 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004219 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004220 ASSERT_VK_SUCCESS(err);
4221
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004222 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4223 dsl_binding_samp.binding = 0;
4224 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4225 dsl_binding_samp.descriptorCount = 1;
4226 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4227 dsl_binding_samp.pImmutableSamplers = NULL;
4228
4229 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4230 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4231 ds_layout_ci.pNext = NULL;
4232 ds_layout_ci.bindingCount = 1;
4233 ds_layout_ci.pBindings = &dsl_binding_samp;
4234
4235 VkDescriptorSetLayout ds_layout_samp;
4236 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4237 ASSERT_VK_SUCCESS(err);
4238
4239 // Try to allocate 2 sets when pool only has 1 set
4240 VkDescriptorSet descriptor_sets[2];
4241 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4242 VkDescriptorSetAllocateInfo alloc_info = {};
4243 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4244 alloc_info.descriptorSetCount = 2;
4245 alloc_info.descriptorPool = ds_pool;
4246 alloc_info.pSetLayouts = set_layouts;
4247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4248 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4249 m_errorMonitor->VerifyFound();
4250
4251 alloc_info.descriptorSetCount = 1;
4252 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004253 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004254 dsl_binding.binding = 0;
4255 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4256 dsl_binding.descriptorCount = 1;
4257 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4258 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004259
Karl Schultz6addd812016-02-02 17:17:23 -07004260 ds_layout_ci.bindingCount = 1;
4261 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004262
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004263 VkDescriptorSetLayout ds_layout_ub;
4264 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004265 ASSERT_VK_SUCCESS(err);
4266
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004267 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004268 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004269 alloc_info.pSetLayouts = &ds_layout_ub;
4270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4271 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004272
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004273 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004274
Karl Schultz2825ab92016-12-02 08:23:14 -07004275 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004276 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004277 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004278}
4279
Karl Schultz6addd812016-02-02 17:17:23 -07004280TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4281 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004282
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004284
Tobin Ehlise735c692015-10-08 13:13:50 -06004285 ASSERT_NO_FATAL_FAILURE(InitState());
4286 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004287
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004288 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004289 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4290 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004291
4292 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004293 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4294 ds_pool_ci.pNext = NULL;
4295 ds_pool_ci.maxSets = 1;
4296 ds_pool_ci.poolSizeCount = 1;
4297 ds_pool_ci.flags = 0;
4298 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4299 // app can only call vkResetDescriptorPool on this pool.;
4300 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004301
4302 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004303 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004304 ASSERT_VK_SUCCESS(err);
4305
4306 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004307 dsl_binding.binding = 0;
4308 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4309 dsl_binding.descriptorCount = 1;
4310 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4311 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004312
4313 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004314 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4315 ds_layout_ci.pNext = NULL;
4316 ds_layout_ci.bindingCount = 1;
4317 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004318
4319 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004320 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004321 ASSERT_VK_SUCCESS(err);
4322
4323 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004324 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004325 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004326 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004327 alloc_info.descriptorPool = ds_pool;
4328 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004329 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004330 ASSERT_VK_SUCCESS(err);
4331
4332 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004333 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004334
Chia-I Wuf7458c52015-10-26 21:10:41 +08004335 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4336 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004337}
4338
Karl Schultz6addd812016-02-02 17:17:23 -07004339TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004340 // Attempt to clear Descriptor Pool with bad object.
4341 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004342
4343 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004345 uint64_t fake_pool_handle = 0xbaad6001;
4346 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4347 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004348 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004349}
4350
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004351TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004352 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4353 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004354 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004355 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004356
4357 uint64_t fake_set_handle = 0xbaad6001;
4358 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004359 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004361
4362 ASSERT_NO_FATAL_FAILURE(InitState());
4363
4364 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4365 layout_bindings[0].binding = 0;
4366 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4367 layout_bindings[0].descriptorCount = 1;
4368 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4369 layout_bindings[0].pImmutableSamplers = NULL;
4370
4371 VkDescriptorSetLayout descriptor_set_layout;
4372 VkDescriptorSetLayoutCreateInfo dslci = {};
4373 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4374 dslci.pNext = NULL;
4375 dslci.bindingCount = 1;
4376 dslci.pBindings = layout_bindings;
4377 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004378 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004379
4380 VkPipelineLayout pipeline_layout;
4381 VkPipelineLayoutCreateInfo plci = {};
4382 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4383 plci.pNext = NULL;
4384 plci.setLayoutCount = 1;
4385 plci.pSetLayouts = &descriptor_set_layout;
4386 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004387 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004388
Tony Barbour552f6c02016-12-21 14:34:07 -07004389 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004390 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4391 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004392 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004393 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004394 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4395 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004396}
4397
Karl Schultz6addd812016-02-02 17:17:23 -07004398TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004399 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4400 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004401 uint64_t fake_layout_handle = 0xbaad6001;
4402 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004404 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004405 VkPipelineLayout pipeline_layout;
4406 VkPipelineLayoutCreateInfo plci = {};
4407 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4408 plci.pNext = NULL;
4409 plci.setLayoutCount = 1;
4410 plci.pSetLayouts = &bad_layout;
4411 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4412
4413 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004414}
4415
Mark Muellerd4914412016-06-13 17:52:06 -06004416TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004417 TEST_DESCRIPTION(
4418 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4419 "1) A uniform buffer update must have a valid buffer index."
4420 "2) When using an array of descriptors in a single WriteDescriptor,"
4421 " the descriptor types and stageflags must all be the same."
4422 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004423
Mike Weiblena6666382017-01-05 15:16:11 -07004424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004425
4426 ASSERT_NO_FATAL_FAILURE(InitState());
4427 VkDescriptorPoolSize ds_type_count[4] = {};
4428 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4429 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004430 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004431 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004432 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004433 ds_type_count[2].descriptorCount = 1;
4434 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4435 ds_type_count[3].descriptorCount = 1;
4436
4437 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4438 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4439 ds_pool_ci.maxSets = 1;
4440 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4441 ds_pool_ci.pPoolSizes = ds_type_count;
4442
4443 VkDescriptorPool ds_pool;
4444 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4445 ASSERT_VK_SUCCESS(err);
4446
Mark Muellerb9896722016-06-16 09:54:29 -06004447 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004448 layout_binding[0].binding = 0;
4449 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4450 layout_binding[0].descriptorCount = 1;
4451 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4452 layout_binding[0].pImmutableSamplers = NULL;
4453
4454 layout_binding[1].binding = 1;
4455 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4456 layout_binding[1].descriptorCount = 1;
4457 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4458 layout_binding[1].pImmutableSamplers = NULL;
4459
4460 VkSamplerCreateInfo sampler_ci = {};
4461 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4462 sampler_ci.pNext = NULL;
4463 sampler_ci.magFilter = VK_FILTER_NEAREST;
4464 sampler_ci.minFilter = VK_FILTER_NEAREST;
4465 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4466 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4467 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4468 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4469 sampler_ci.mipLodBias = 1.0;
4470 sampler_ci.anisotropyEnable = VK_FALSE;
4471 sampler_ci.maxAnisotropy = 1;
4472 sampler_ci.compareEnable = VK_FALSE;
4473 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4474 sampler_ci.minLod = 1.0;
4475 sampler_ci.maxLod = 1.0;
4476 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4477 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4478 VkSampler sampler;
4479
4480 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4481 ASSERT_VK_SUCCESS(err);
4482
4483 layout_binding[2].binding = 2;
4484 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4485 layout_binding[2].descriptorCount = 1;
4486 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4487 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4488
Mark Muellerd4914412016-06-13 17:52:06 -06004489 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4490 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4491 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4492 ds_layout_ci.pBindings = layout_binding;
4493 VkDescriptorSetLayout ds_layout;
4494 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4495 ASSERT_VK_SUCCESS(err);
4496
4497 VkDescriptorSetAllocateInfo alloc_info = {};
4498 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4499 alloc_info.descriptorSetCount = 1;
4500 alloc_info.descriptorPool = ds_pool;
4501 alloc_info.pSetLayouts = &ds_layout;
4502 VkDescriptorSet descriptorSet;
4503 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4504 ASSERT_VK_SUCCESS(err);
4505
4506 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4507 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4508 pipeline_layout_ci.pNext = NULL;
4509 pipeline_layout_ci.setLayoutCount = 1;
4510 pipeline_layout_ci.pSetLayouts = &ds_layout;
4511
4512 VkPipelineLayout pipeline_layout;
4513 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4514 ASSERT_VK_SUCCESS(err);
4515
Mark Mueller5c838ce2016-06-16 09:54:29 -06004516 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004517 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4518 descriptor_write.dstSet = descriptorSet;
4519 descriptor_write.dstBinding = 0;
4520 descriptor_write.descriptorCount = 1;
4521 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4522
Mark Mueller5c838ce2016-06-16 09:54:29 -06004523 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004524 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4525 m_errorMonitor->VerifyFound();
4526
4527 // Create a buffer to update the descriptor with
4528 uint32_t qfi = 0;
4529 VkBufferCreateInfo buffCI = {};
4530 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4531 buffCI.size = 1024;
4532 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4533 buffCI.queueFamilyIndexCount = 1;
4534 buffCI.pQueueFamilyIndices = &qfi;
4535
4536 VkBuffer dyub;
4537 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4538 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004539
Tony Barboure132c5f2016-12-12 11:50:20 -07004540 VkDeviceMemory mem;
4541 VkMemoryRequirements mem_reqs;
4542 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4543
4544 VkMemoryAllocateInfo mem_alloc_info = {};
4545 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4546 mem_alloc_info.allocationSize = mem_reqs.size;
4547 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4548 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4549 ASSERT_VK_SUCCESS(err);
4550
4551 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4552 ASSERT_VK_SUCCESS(err);
4553
4554 VkDescriptorBufferInfo buffInfo[2] = {};
4555 buffInfo[0].buffer = dyub;
4556 buffInfo[0].offset = 0;
4557 buffInfo[0].range = 1024;
4558 buffInfo[1].buffer = dyub;
4559 buffInfo[1].offset = 0;
4560 buffInfo[1].range = 1024;
4561 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004562 descriptor_write.descriptorCount = 2;
4563
Mark Mueller5c838ce2016-06-16 09:54:29 -06004564 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004566 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4567 m_errorMonitor->VerifyFound();
4568
Mark Mueller5c838ce2016-06-16 09:54:29 -06004569 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4570 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004571 descriptor_write.dstBinding = 1;
4572 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004573
Mark Mueller5c838ce2016-06-16 09:54:29 -06004574 // Make pImageInfo index non-null to avoid complaints of it missing
4575 VkDescriptorImageInfo imageInfo = {};
4576 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4577 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004579 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4580 m_errorMonitor->VerifyFound();
4581
Mark Muellerd4914412016-06-13 17:52:06 -06004582 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004583 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004584 vkDestroySampler(m_device->device(), sampler, NULL);
4585 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4586 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4587 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4588}
4589
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004590TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004591 TEST_DESCRIPTION(
4592 "Attempt to draw with a command buffer that is invalid "
4593 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004594 ASSERT_NO_FATAL_FAILURE(InitState());
4595
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004596 VkBuffer buffer;
4597 VkDeviceMemory mem;
4598 VkMemoryRequirements mem_reqs;
4599
4600 VkBufferCreateInfo buf_info = {};
4601 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004602 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004603 buf_info.size = 256;
4604 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4605 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4606 ASSERT_VK_SUCCESS(err);
4607
4608 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4609
4610 VkMemoryAllocateInfo alloc_info = {};
4611 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4612 alloc_info.allocationSize = 256;
4613 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004614 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 -06004615 if (!pass) {
4616 vkDestroyBuffer(m_device->device(), buffer, NULL);
4617 return;
4618 }
4619 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4620 ASSERT_VK_SUCCESS(err);
4621
4622 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4623 ASSERT_VK_SUCCESS(err);
4624
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004625 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004626 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004627 m_commandBuffer->EndCommandBuffer();
4628
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004630 // Destroy buffer dependency prior to submit to cause ERROR
4631 vkDestroyBuffer(m_device->device(), buffer, NULL);
4632
4633 VkSubmitInfo submit_info = {};
4634 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4635 submit_info.commandBufferCount = 1;
4636 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004637 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted buffer");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004638 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4639
4640 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004641 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004642 vkFreeMemory(m_device->handle(), mem, NULL);
4643}
4644
Tobin Ehlisea413442016-09-28 10:23:59 -06004645TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4646 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4647
4648 ASSERT_NO_FATAL_FAILURE(InitState());
4649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4650
4651 VkDescriptorPoolSize ds_type_count;
4652 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4653 ds_type_count.descriptorCount = 1;
4654
4655 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4656 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4657 ds_pool_ci.maxSets = 1;
4658 ds_pool_ci.poolSizeCount = 1;
4659 ds_pool_ci.pPoolSizes = &ds_type_count;
4660
4661 VkDescriptorPool ds_pool;
4662 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4663 ASSERT_VK_SUCCESS(err);
4664
4665 VkDescriptorSetLayoutBinding layout_binding;
4666 layout_binding.binding = 0;
4667 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4668 layout_binding.descriptorCount = 1;
4669 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4670 layout_binding.pImmutableSamplers = NULL;
4671
4672 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4673 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4674 ds_layout_ci.bindingCount = 1;
4675 ds_layout_ci.pBindings = &layout_binding;
4676 VkDescriptorSetLayout ds_layout;
4677 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4678 ASSERT_VK_SUCCESS(err);
4679
4680 VkDescriptorSetAllocateInfo alloc_info = {};
4681 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4682 alloc_info.descriptorSetCount = 1;
4683 alloc_info.descriptorPool = ds_pool;
4684 alloc_info.pSetLayouts = &ds_layout;
4685 VkDescriptorSet descriptor_set;
4686 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4687 ASSERT_VK_SUCCESS(err);
4688
4689 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4690 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4691 pipeline_layout_ci.pNext = NULL;
4692 pipeline_layout_ci.setLayoutCount = 1;
4693 pipeline_layout_ci.pSetLayouts = &ds_layout;
4694
4695 VkPipelineLayout pipeline_layout;
4696 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4697 ASSERT_VK_SUCCESS(err);
4698
4699 VkBuffer buffer;
4700 uint32_t queue_family_index = 0;
4701 VkBufferCreateInfo buffer_create_info = {};
4702 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4703 buffer_create_info.size = 1024;
4704 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4705 buffer_create_info.queueFamilyIndexCount = 1;
4706 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4707
4708 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4709 ASSERT_VK_SUCCESS(err);
4710
4711 VkMemoryRequirements memory_reqs;
4712 VkDeviceMemory buffer_memory;
4713
4714 VkMemoryAllocateInfo memory_info = {};
4715 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4716 memory_info.allocationSize = 0;
4717 memory_info.memoryTypeIndex = 0;
4718
4719 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4720 memory_info.allocationSize = memory_reqs.size;
4721 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4722 ASSERT_TRUE(pass);
4723
4724 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4725 ASSERT_VK_SUCCESS(err);
4726 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4727 ASSERT_VK_SUCCESS(err);
4728
4729 VkBufferView view;
4730 VkBufferViewCreateInfo bvci = {};
4731 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4732 bvci.buffer = buffer;
4733 bvci.format = VK_FORMAT_R8_UNORM;
4734 bvci.range = VK_WHOLE_SIZE;
4735
4736 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4737 ASSERT_VK_SUCCESS(err);
4738
4739 VkWriteDescriptorSet descriptor_write = {};
4740 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4741 descriptor_write.dstSet = descriptor_set;
4742 descriptor_write.dstBinding = 0;
4743 descriptor_write.descriptorCount = 1;
4744 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4745 descriptor_write.pTexelBufferView = &view;
4746
4747 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4748
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004749 char const *vsSource =
4750 "#version 450\n"
4751 "\n"
4752 "out gl_PerVertex { \n"
4753 " vec4 gl_Position;\n"
4754 "};\n"
4755 "void main(){\n"
4756 " gl_Position = vec4(1);\n"
4757 "}\n";
4758 char const *fsSource =
4759 "#version 450\n"
4760 "\n"
4761 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4762 "layout(location=0) out vec4 x;\n"
4763 "void main(){\n"
4764 " x = imageLoad(s, 0);\n"
4765 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004766 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4767 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4768 VkPipelineObj pipe(m_device);
4769 pipe.AddShader(&vs);
4770 pipe.AddShader(&fs);
4771 pipe.AddColorAttachment();
4772 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4773
4774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4776
Tony Barbour552f6c02016-12-21 14:34:07 -07004777 m_commandBuffer->BeginCommandBuffer();
4778 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4779
Tobin Ehlisea413442016-09-28 10:23:59 -06004780 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4781 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4782 VkRect2D scissor = {{0, 0}, {16, 16}};
4783 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4784 // Bind pipeline to cmd buffer
4785 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4786 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4787 &descriptor_set, 0, nullptr);
4788 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004789 m_commandBuffer->EndRenderPass();
4790 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004791
4792 // Delete BufferView in order to invalidate cmd buffer
4793 vkDestroyBufferView(m_device->device(), view, NULL);
4794 // Now attempt submit of cmd buffer
4795 VkSubmitInfo submit_info = {};
4796 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4797 submit_info.commandBufferCount = 1;
4798 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4799 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4800 m_errorMonitor->VerifyFound();
4801
4802 // Clean-up
4803 vkDestroyBuffer(m_device->device(), buffer, NULL);
4804 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4805 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4806 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4807 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4808}
4809
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004810TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004811 TEST_DESCRIPTION(
4812 "Attempt to draw with a command buffer that is invalid "
4813 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004814 ASSERT_NO_FATAL_FAILURE(InitState());
4815
4816 VkImage image;
4817 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4818 VkImageCreateInfo image_create_info = {};
4819 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4820 image_create_info.pNext = NULL;
4821 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4822 image_create_info.format = tex_format;
4823 image_create_info.extent.width = 32;
4824 image_create_info.extent.height = 32;
4825 image_create_info.extent.depth = 1;
4826 image_create_info.mipLevels = 1;
4827 image_create_info.arrayLayers = 1;
4828 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4829 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004830 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004831 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004832 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004833 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004834 // Have to bind memory to image before recording cmd in cmd buffer using it
4835 VkMemoryRequirements mem_reqs;
4836 VkDeviceMemory image_mem;
4837 bool pass;
4838 VkMemoryAllocateInfo mem_alloc = {};
4839 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4840 mem_alloc.pNext = NULL;
4841 mem_alloc.memoryTypeIndex = 0;
4842 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4843 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004844 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004845 ASSERT_TRUE(pass);
4846 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4847 ASSERT_VK_SUCCESS(err);
4848 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4849 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004850
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004851 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004852 VkClearColorValue ccv;
4853 ccv.float32[0] = 1.0f;
4854 ccv.float32[1] = 1.0f;
4855 ccv.float32[2] = 1.0f;
4856 ccv.float32[3] = 1.0f;
4857 VkImageSubresourceRange isr = {};
4858 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004859 isr.baseArrayLayer = 0;
4860 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004861 isr.layerCount = 1;
4862 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004863 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004864 m_commandBuffer->EndCommandBuffer();
4865
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004867 // Destroy image dependency prior to submit to cause ERROR
4868 vkDestroyImage(m_device->device(), image, NULL);
4869
4870 VkSubmitInfo submit_info = {};
4871 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4872 submit_info.commandBufferCount = 1;
4873 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004874 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004875 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4876
4877 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004878 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004879}
4880
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004881TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004882 TEST_DESCRIPTION(
4883 "Attempt to draw with a command buffer that is invalid "
4884 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004885 VkFormatProperties format_properties;
4886 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004887 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4888 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004889 return;
4890 }
4891
4892 ASSERT_NO_FATAL_FAILURE(InitState());
4893 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4894
4895 VkImageCreateInfo image_ci = {};
4896 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4897 image_ci.pNext = NULL;
4898 image_ci.imageType = VK_IMAGE_TYPE_2D;
4899 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4900 image_ci.extent.width = 32;
4901 image_ci.extent.height = 32;
4902 image_ci.extent.depth = 1;
4903 image_ci.mipLevels = 1;
4904 image_ci.arrayLayers = 1;
4905 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4906 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004907 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004908 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4909 image_ci.flags = 0;
4910 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004911 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004912
4913 VkMemoryRequirements memory_reqs;
4914 VkDeviceMemory image_memory;
4915 bool pass;
4916 VkMemoryAllocateInfo memory_info = {};
4917 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4918 memory_info.pNext = NULL;
4919 memory_info.allocationSize = 0;
4920 memory_info.memoryTypeIndex = 0;
4921 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4922 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004923 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004924 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004925 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004926 ASSERT_VK_SUCCESS(err);
4927 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4928 ASSERT_VK_SUCCESS(err);
4929
4930 VkImageViewCreateInfo ivci = {
4931 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4932 nullptr,
4933 0,
4934 image,
4935 VK_IMAGE_VIEW_TYPE_2D,
4936 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004937 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004938 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4939 };
4940 VkImageView view;
4941 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4942 ASSERT_VK_SUCCESS(err);
4943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004944 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004945 VkFramebuffer fb;
4946 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4947 ASSERT_VK_SUCCESS(err);
4948
4949 // Just use default renderpass with our framebuffer
4950 m_renderPassBeginInfo.framebuffer = fb;
4951 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004952 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004953 m_errorMonitor->SetUnexpectedError("Cannot execute a render pass with renderArea not within the bound of the framebuffer.");
Tony Barbour552f6c02016-12-21 14:34:07 -07004954 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4955 m_commandBuffer->EndRenderPass();
4956 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004957 // Destroy image attached to framebuffer to invalidate cmd buffer
4958 vkDestroyImage(m_device->device(), image, NULL);
4959 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004961 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004962 QueueCommandBuffer(false);
4963 m_errorMonitor->VerifyFound();
4964
4965 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4966 vkDestroyImageView(m_device->device(), view, nullptr);
4967 vkFreeMemory(m_device->device(), image_memory, nullptr);
4968}
4969
Tobin Ehlisb329f992016-10-12 13:20:29 -06004970TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4971 TEST_DESCRIPTION("Delete in-use framebuffer.");
4972 VkFormatProperties format_properties;
4973 VkResult err = VK_SUCCESS;
4974 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4975
4976 ASSERT_NO_FATAL_FAILURE(InitState());
4977 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4978
4979 VkImageObj image(m_device);
4980 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4981 ASSERT_TRUE(image.initialized());
4982 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4983
4984 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4985 VkFramebuffer fb;
4986 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4987 ASSERT_VK_SUCCESS(err);
4988
4989 // Just use default renderpass with our framebuffer
4990 m_renderPassBeginInfo.framebuffer = fb;
4991 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004992 m_commandBuffer->BeginCommandBuffer();
4993 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4994 m_commandBuffer->EndRenderPass();
4995 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06004996 // Submit cmd buffer to put it in-flight
4997 VkSubmitInfo submit_info = {};
4998 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4999 submit_info.commandBufferCount = 1;
5000 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5001 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5002 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005004 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5005 m_errorMonitor->VerifyFound();
5006 // Wait for queue to complete so we can safely destroy everything
5007 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005008 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5009 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005010 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5011}
5012
Tobin Ehlis88becd72016-09-21 14:33:41 -06005013TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5014 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5015 VkFormatProperties format_properties;
5016 VkResult err = VK_SUCCESS;
5017 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005018
5019 ASSERT_NO_FATAL_FAILURE(InitState());
5020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5021
5022 VkImageCreateInfo image_ci = {};
5023 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5024 image_ci.pNext = NULL;
5025 image_ci.imageType = VK_IMAGE_TYPE_2D;
5026 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5027 image_ci.extent.width = 256;
5028 image_ci.extent.height = 256;
5029 image_ci.extent.depth = 1;
5030 image_ci.mipLevels = 1;
5031 image_ci.arrayLayers = 1;
5032 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5033 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005034 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005035 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5036 image_ci.flags = 0;
5037 VkImage image;
5038 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5039
5040 VkMemoryRequirements memory_reqs;
5041 VkDeviceMemory image_memory;
5042 bool pass;
5043 VkMemoryAllocateInfo memory_info = {};
5044 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5045 memory_info.pNext = NULL;
5046 memory_info.allocationSize = 0;
5047 memory_info.memoryTypeIndex = 0;
5048 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5049 memory_info.allocationSize = memory_reqs.size;
5050 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5051 ASSERT_TRUE(pass);
5052 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5053 ASSERT_VK_SUCCESS(err);
5054 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5055 ASSERT_VK_SUCCESS(err);
5056
5057 VkImageViewCreateInfo ivci = {
5058 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5059 nullptr,
5060 0,
5061 image,
5062 VK_IMAGE_VIEW_TYPE_2D,
5063 VK_FORMAT_B8G8R8A8_UNORM,
5064 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5065 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5066 };
5067 VkImageView view;
5068 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5069 ASSERT_VK_SUCCESS(err);
5070
5071 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5072 VkFramebuffer fb;
5073 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5074 ASSERT_VK_SUCCESS(err);
5075
5076 // Just use default renderpass with our framebuffer
5077 m_renderPassBeginInfo.framebuffer = fb;
5078 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005079 m_commandBuffer->BeginCommandBuffer();
5080 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5081 m_commandBuffer->EndRenderPass();
5082 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005083 // Submit cmd buffer to put it (and attached imageView) in-flight
5084 VkSubmitInfo submit_info = {};
5085 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5086 submit_info.commandBufferCount = 1;
5087 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5088 // Submit cmd buffer to put framebuffer and children in-flight
5089 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5090 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005092 vkDestroyImage(m_device->device(), image, NULL);
5093 m_errorMonitor->VerifyFound();
5094 // Wait for queue to complete so we can safely destroy image and other objects
5095 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005096 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5097 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005098 vkDestroyImage(m_device->device(), image, NULL);
5099 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5100 vkDestroyImageView(m_device->device(), view, nullptr);
5101 vkFreeMemory(m_device->device(), image_memory, nullptr);
5102}
5103
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005104TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5105 TEST_DESCRIPTION("Delete in-use renderPass.");
5106
5107 ASSERT_NO_FATAL_FAILURE(InitState());
5108 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5109
5110 // Create simple renderpass
5111 VkAttachmentReference attach = {};
5112 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5113 VkSubpassDescription subpass = {};
5114 subpass.pColorAttachments = &attach;
5115 VkRenderPassCreateInfo rpci = {};
5116 rpci.subpassCount = 1;
5117 rpci.pSubpasses = &subpass;
5118 rpci.attachmentCount = 1;
5119 VkAttachmentDescription attach_desc = {};
5120 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5121 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5122 rpci.pAttachments = &attach_desc;
5123 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5124 VkRenderPass rp;
5125 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5126 ASSERT_VK_SUCCESS(err);
5127
5128 // Create a pipeline that uses the given renderpass
5129 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5130 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5131
5132 VkPipelineLayout pipeline_layout;
5133 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5134 ASSERT_VK_SUCCESS(err);
5135
5136 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5137 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5138 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005139 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005140 vp_state_ci.pViewports = &vp;
5141 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005142 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005143 vp_state_ci.pScissors = &scissors;
5144
5145 VkPipelineShaderStageCreateInfo shaderStages[2];
5146 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5147
5148 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005149 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 -06005150 // but add it to be able to run on more devices
5151 shaderStages[0] = vs.GetStageCreateInfo();
5152 shaderStages[1] = fs.GetStageCreateInfo();
5153
5154 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5155 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5156
5157 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5158 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5159 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5160
5161 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5162 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5163 rs_ci.rasterizerDiscardEnable = true;
5164 rs_ci.lineWidth = 1.0f;
5165
5166 VkPipelineColorBlendAttachmentState att = {};
5167 att.blendEnable = VK_FALSE;
5168 att.colorWriteMask = 0xf;
5169
5170 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5171 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5172 cb_ci.attachmentCount = 1;
5173 cb_ci.pAttachments = &att;
5174
5175 VkGraphicsPipelineCreateInfo gp_ci = {};
5176 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5177 gp_ci.stageCount = 2;
5178 gp_ci.pStages = shaderStages;
5179 gp_ci.pVertexInputState = &vi_ci;
5180 gp_ci.pInputAssemblyState = &ia_ci;
5181 gp_ci.pViewportState = &vp_state_ci;
5182 gp_ci.pRasterizationState = &rs_ci;
5183 gp_ci.pColorBlendState = &cb_ci;
5184 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5185 gp_ci.layout = pipeline_layout;
5186 gp_ci.renderPass = rp;
5187
5188 VkPipelineCacheCreateInfo pc_ci = {};
5189 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5190
5191 VkPipeline pipeline;
5192 VkPipelineCache pipe_cache;
5193 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5194 ASSERT_VK_SUCCESS(err);
5195
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005196 m_errorMonitor->SetUnexpectedError(
5197 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5198 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005199 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5200 ASSERT_VK_SUCCESS(err);
5201 // Bind pipeline to cmd buffer, will also bind renderpass
5202 m_commandBuffer->BeginCommandBuffer();
5203 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5204 m_commandBuffer->EndCommandBuffer();
5205
5206 VkSubmitInfo submit_info = {};
5207 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5208 submit_info.commandBufferCount = 1;
5209 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5210 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5211
5212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5213 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5214 m_errorMonitor->VerifyFound();
5215
5216 // Wait for queue to complete so we can safely destroy everything
5217 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005218 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5219 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005220 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5221 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5222 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5223 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5224}
5225
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005226TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005227 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005228 ASSERT_NO_FATAL_FAILURE(InitState());
5229
5230 VkImage image;
5231 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5232 VkImageCreateInfo image_create_info = {};
5233 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5234 image_create_info.pNext = NULL;
5235 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5236 image_create_info.format = tex_format;
5237 image_create_info.extent.width = 32;
5238 image_create_info.extent.height = 32;
5239 image_create_info.extent.depth = 1;
5240 image_create_info.mipLevels = 1;
5241 image_create_info.arrayLayers = 1;
5242 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5243 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005244 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005245 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005246 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005247 ASSERT_VK_SUCCESS(err);
5248 // Have to bind memory to image before recording cmd in cmd buffer using it
5249 VkMemoryRequirements mem_reqs;
5250 VkDeviceMemory image_mem;
5251 bool pass;
5252 VkMemoryAllocateInfo mem_alloc = {};
5253 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5254 mem_alloc.pNext = NULL;
5255 mem_alloc.memoryTypeIndex = 0;
5256 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5257 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005258 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005259 ASSERT_TRUE(pass);
5260 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5261 ASSERT_VK_SUCCESS(err);
5262
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005263 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005265 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005266
5267 m_commandBuffer->BeginCommandBuffer();
5268 VkClearColorValue ccv;
5269 ccv.float32[0] = 1.0f;
5270 ccv.float32[1] = 1.0f;
5271 ccv.float32[2] = 1.0f;
5272 ccv.float32[3] = 1.0f;
5273 VkImageSubresourceRange isr = {};
5274 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5275 isr.baseArrayLayer = 0;
5276 isr.baseMipLevel = 0;
5277 isr.layerCount = 1;
5278 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005279 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005280 m_commandBuffer->EndCommandBuffer();
5281
5282 m_errorMonitor->VerifyFound();
5283 vkDestroyImage(m_device->device(), image, NULL);
5284 vkFreeMemory(m_device->device(), image_mem, nullptr);
5285}
5286
5287TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005288 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005289 ASSERT_NO_FATAL_FAILURE(InitState());
5290
5291 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005292 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 -06005293 VK_IMAGE_TILING_OPTIMAL, 0);
5294 ASSERT_TRUE(image.initialized());
5295
5296 VkBuffer buffer;
5297 VkDeviceMemory mem;
5298 VkMemoryRequirements mem_reqs;
5299
5300 VkBufferCreateInfo buf_info = {};
5301 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005302 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005303 buf_info.size = 256;
5304 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5305 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5306 ASSERT_VK_SUCCESS(err);
5307
5308 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5309
5310 VkMemoryAllocateInfo alloc_info = {};
5311 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5312 alloc_info.allocationSize = 256;
5313 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005314 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 -06005315 if (!pass) {
5316 vkDestroyBuffer(m_device->device(), buffer, NULL);
5317 return;
5318 }
5319 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5320 ASSERT_VK_SUCCESS(err);
5321
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005322 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005324 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005325 VkBufferImageCopy region = {};
5326 region.bufferRowLength = 128;
5327 region.bufferImageHeight = 128;
5328 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5329
5330 region.imageSubresource.layerCount = 1;
5331 region.imageExtent.height = 4;
5332 region.imageExtent.width = 4;
5333 region.imageExtent.depth = 1;
5334 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005335 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5336 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005337 m_commandBuffer->EndCommandBuffer();
5338
5339 m_errorMonitor->VerifyFound();
5340
5341 vkDestroyBuffer(m_device->device(), buffer, NULL);
5342 vkFreeMemory(m_device->handle(), mem, NULL);
5343}
5344
Tobin Ehlis85940f52016-07-07 16:57:21 -06005345TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005346 TEST_DESCRIPTION(
5347 "Attempt to draw with a command buffer that is invalid "
5348 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005349 ASSERT_NO_FATAL_FAILURE(InitState());
5350
5351 VkEvent event;
5352 VkEventCreateInfo evci = {};
5353 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5354 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5355 ASSERT_VK_SUCCESS(result);
5356
5357 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005358 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005359 m_commandBuffer->EndCommandBuffer();
5360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005362 // Destroy event dependency prior to submit to cause ERROR
5363 vkDestroyEvent(m_device->device(), event, NULL);
5364
5365 VkSubmitInfo submit_info = {};
5366 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5367 submit_info.commandBufferCount = 1;
5368 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005369 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted event");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005370 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5371
5372 m_errorMonitor->VerifyFound();
5373}
5374
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005375TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005376 TEST_DESCRIPTION(
5377 "Attempt to draw with a command buffer that is invalid "
5378 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005379 ASSERT_NO_FATAL_FAILURE(InitState());
5380
5381 VkQueryPool query_pool;
5382 VkQueryPoolCreateInfo qpci{};
5383 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5384 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5385 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005386 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005387 ASSERT_VK_SUCCESS(result);
5388
5389 m_commandBuffer->BeginCommandBuffer();
5390 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5391 m_commandBuffer->EndCommandBuffer();
5392
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005394 // Destroy query pool dependency prior to submit to cause ERROR
5395 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5396
5397 VkSubmitInfo submit_info = {};
5398 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5399 submit_info.commandBufferCount = 1;
5400 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005401 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted query pool");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005402 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5403
5404 m_errorMonitor->VerifyFound();
5405}
5406
Tobin Ehlis24130d92016-07-08 15:50:53 -06005407TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005408 TEST_DESCRIPTION(
5409 "Attempt to draw with a command buffer that is invalid "
5410 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005411 ASSERT_NO_FATAL_FAILURE(InitState());
5412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5413
5414 VkResult err;
5415
5416 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5417 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5418
5419 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005420 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005421 ASSERT_VK_SUCCESS(err);
5422
5423 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5424 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5425 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005426 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005427 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005428 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005429 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005430 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005431
5432 VkPipelineShaderStageCreateInfo shaderStages[2];
5433 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5434
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005435 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005436 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 -06005437 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005438 shaderStages[0] = vs.GetStageCreateInfo();
5439 shaderStages[1] = fs.GetStageCreateInfo();
5440
5441 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5442 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5443
5444 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5445 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5446 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5447
5448 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5449 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005450 rs_ci.rasterizerDiscardEnable = true;
5451 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005452
5453 VkPipelineColorBlendAttachmentState att = {};
5454 att.blendEnable = VK_FALSE;
5455 att.colorWriteMask = 0xf;
5456
5457 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5458 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5459 cb_ci.attachmentCount = 1;
5460 cb_ci.pAttachments = &att;
5461
5462 VkGraphicsPipelineCreateInfo gp_ci = {};
5463 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5464 gp_ci.stageCount = 2;
5465 gp_ci.pStages = shaderStages;
5466 gp_ci.pVertexInputState = &vi_ci;
5467 gp_ci.pInputAssemblyState = &ia_ci;
5468 gp_ci.pViewportState = &vp_state_ci;
5469 gp_ci.pRasterizationState = &rs_ci;
5470 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005471 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5472 gp_ci.layout = pipeline_layout;
5473 gp_ci.renderPass = renderPass();
5474
5475 VkPipelineCacheCreateInfo pc_ci = {};
5476 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5477
5478 VkPipeline pipeline;
5479 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005480 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005481 ASSERT_VK_SUCCESS(err);
5482
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005483 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005484 ASSERT_VK_SUCCESS(err);
5485
5486 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005487 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005488 m_commandBuffer->EndCommandBuffer();
5489 // Now destroy pipeline in order to cause error when submitting
5490 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5491
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005493
5494 VkSubmitInfo submit_info = {};
5495 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5496 submit_info.commandBufferCount = 1;
5497 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005498 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted pipeline");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005499 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5500
5501 m_errorMonitor->VerifyFound();
5502 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5503 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5504}
5505
Tobin Ehlis31289162016-08-17 14:57:58 -06005506TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005507 TEST_DESCRIPTION(
5508 "Attempt to draw with a command buffer that is invalid "
5509 "due to a bound descriptor set with a buffer dependency "
5510 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005511 ASSERT_NO_FATAL_FAILURE(InitState());
5512 ASSERT_NO_FATAL_FAILURE(InitViewport());
5513 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5514
5515 VkDescriptorPoolSize ds_type_count = {};
5516 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5517 ds_type_count.descriptorCount = 1;
5518
5519 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5520 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5521 ds_pool_ci.pNext = NULL;
5522 ds_pool_ci.maxSets = 1;
5523 ds_pool_ci.poolSizeCount = 1;
5524 ds_pool_ci.pPoolSizes = &ds_type_count;
5525
5526 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005527 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005528 ASSERT_VK_SUCCESS(err);
5529
5530 VkDescriptorSetLayoutBinding dsl_binding = {};
5531 dsl_binding.binding = 0;
5532 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5533 dsl_binding.descriptorCount = 1;
5534 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5535 dsl_binding.pImmutableSamplers = NULL;
5536
5537 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5538 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5539 ds_layout_ci.pNext = NULL;
5540 ds_layout_ci.bindingCount = 1;
5541 ds_layout_ci.pBindings = &dsl_binding;
5542 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005543 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005544 ASSERT_VK_SUCCESS(err);
5545
5546 VkDescriptorSet descriptorSet;
5547 VkDescriptorSetAllocateInfo alloc_info = {};
5548 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5549 alloc_info.descriptorSetCount = 1;
5550 alloc_info.descriptorPool = ds_pool;
5551 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005552 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005553 ASSERT_VK_SUCCESS(err);
5554
5555 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5556 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5557 pipeline_layout_ci.pNext = NULL;
5558 pipeline_layout_ci.setLayoutCount = 1;
5559 pipeline_layout_ci.pSetLayouts = &ds_layout;
5560
5561 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005562 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005563 ASSERT_VK_SUCCESS(err);
5564
5565 // Create a buffer to update the descriptor with
5566 uint32_t qfi = 0;
5567 VkBufferCreateInfo buffCI = {};
5568 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5569 buffCI.size = 1024;
5570 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5571 buffCI.queueFamilyIndexCount = 1;
5572 buffCI.pQueueFamilyIndices = &qfi;
5573
5574 VkBuffer buffer;
5575 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5576 ASSERT_VK_SUCCESS(err);
5577 // Allocate memory and bind to buffer so we can make it to the appropriate
5578 // error
5579 VkMemoryAllocateInfo mem_alloc = {};
5580 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5581 mem_alloc.pNext = NULL;
5582 mem_alloc.allocationSize = 1024;
5583 mem_alloc.memoryTypeIndex = 0;
5584
5585 VkMemoryRequirements memReqs;
5586 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005587 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005588 if (!pass) {
5589 vkDestroyBuffer(m_device->device(), buffer, NULL);
5590 return;
5591 }
5592
5593 VkDeviceMemory mem;
5594 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5595 ASSERT_VK_SUCCESS(err);
5596 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5597 ASSERT_VK_SUCCESS(err);
5598 // Correctly update descriptor to avoid "NOT_UPDATED" error
5599 VkDescriptorBufferInfo buffInfo = {};
5600 buffInfo.buffer = buffer;
5601 buffInfo.offset = 0;
5602 buffInfo.range = 1024;
5603
5604 VkWriteDescriptorSet descriptor_write;
5605 memset(&descriptor_write, 0, sizeof(descriptor_write));
5606 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5607 descriptor_write.dstSet = descriptorSet;
5608 descriptor_write.dstBinding = 0;
5609 descriptor_write.descriptorCount = 1;
5610 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5611 descriptor_write.pBufferInfo = &buffInfo;
5612
5613 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5614
5615 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005616 char const *vsSource =
5617 "#version 450\n"
5618 "\n"
5619 "out gl_PerVertex { \n"
5620 " vec4 gl_Position;\n"
5621 "};\n"
5622 "void main(){\n"
5623 " gl_Position = vec4(1);\n"
5624 "}\n";
5625 char const *fsSource =
5626 "#version 450\n"
5627 "\n"
5628 "layout(location=0) out vec4 x;\n"
5629 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5630 "void main(){\n"
5631 " x = vec4(bar.y);\n"
5632 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005633 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5634 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5635 VkPipelineObj pipe(m_device);
5636 pipe.AddShader(&vs);
5637 pipe.AddShader(&fs);
5638 pipe.AddColorAttachment();
5639 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5640
Tony Barbour552f6c02016-12-21 14:34:07 -07005641 m_commandBuffer->BeginCommandBuffer();
5642 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005643 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5644 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5645 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005646
5647 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5648 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5649
Tobin Ehlis31289162016-08-17 14:57:58 -06005650 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005651 m_commandBuffer->EndRenderPass();
5652 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005654 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5655 vkDestroyBuffer(m_device->device(), buffer, NULL);
5656 // Attempt to submit cmd buffer
5657 VkSubmitInfo submit_info = {};
5658 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5659 submit_info.commandBufferCount = 1;
5660 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005661 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted buffer");
Tobin Ehlis31289162016-08-17 14:57:58 -06005662 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5663 m_errorMonitor->VerifyFound();
5664 // Cleanup
5665 vkFreeMemory(m_device->device(), mem, NULL);
5666
5667 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5668 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5669 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5670}
5671
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005672TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005673 TEST_DESCRIPTION(
5674 "Attempt to draw with a command buffer that is invalid "
5675 "due to a bound descriptor sets with a combined image "
5676 "sampler having their image, sampler, and descriptor set "
5677 "each respectively destroyed and then attempting to "
5678 "submit associated cmd buffers. Attempt to destroy a "
5679 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005680 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005681 ASSERT_NO_FATAL_FAILURE(InitViewport());
5682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5683
5684 VkDescriptorPoolSize ds_type_count = {};
5685 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5686 ds_type_count.descriptorCount = 1;
5687
5688 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5689 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5690 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005691 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005692 ds_pool_ci.maxSets = 1;
5693 ds_pool_ci.poolSizeCount = 1;
5694 ds_pool_ci.pPoolSizes = &ds_type_count;
5695
5696 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005697 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005698 ASSERT_VK_SUCCESS(err);
5699
5700 VkDescriptorSetLayoutBinding dsl_binding = {};
5701 dsl_binding.binding = 0;
5702 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5703 dsl_binding.descriptorCount = 1;
5704 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5705 dsl_binding.pImmutableSamplers = NULL;
5706
5707 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5708 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5709 ds_layout_ci.pNext = NULL;
5710 ds_layout_ci.bindingCount = 1;
5711 ds_layout_ci.pBindings = &dsl_binding;
5712 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005713 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005714 ASSERT_VK_SUCCESS(err);
5715
5716 VkDescriptorSet descriptorSet;
5717 VkDescriptorSetAllocateInfo alloc_info = {};
5718 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5719 alloc_info.descriptorSetCount = 1;
5720 alloc_info.descriptorPool = ds_pool;
5721 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005722 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005723 ASSERT_VK_SUCCESS(err);
5724
5725 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5726 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5727 pipeline_layout_ci.pNext = NULL;
5728 pipeline_layout_ci.setLayoutCount = 1;
5729 pipeline_layout_ci.pSetLayouts = &ds_layout;
5730
5731 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005732 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005733 ASSERT_VK_SUCCESS(err);
5734
5735 // Create images to update the descriptor with
5736 VkImage image;
5737 VkImage image2;
5738 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5739 const int32_t tex_width = 32;
5740 const int32_t tex_height = 32;
5741 VkImageCreateInfo image_create_info = {};
5742 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5743 image_create_info.pNext = NULL;
5744 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5745 image_create_info.format = tex_format;
5746 image_create_info.extent.width = tex_width;
5747 image_create_info.extent.height = tex_height;
5748 image_create_info.extent.depth = 1;
5749 image_create_info.mipLevels = 1;
5750 image_create_info.arrayLayers = 1;
5751 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5752 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5753 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5754 image_create_info.flags = 0;
5755 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5756 ASSERT_VK_SUCCESS(err);
5757 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5758 ASSERT_VK_SUCCESS(err);
5759
5760 VkMemoryRequirements memory_reqs;
5761 VkDeviceMemory image_memory;
5762 bool pass;
5763 VkMemoryAllocateInfo memory_info = {};
5764 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5765 memory_info.pNext = NULL;
5766 memory_info.allocationSize = 0;
5767 memory_info.memoryTypeIndex = 0;
5768 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5769 // Allocate enough memory for both images
5770 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005771 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005772 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005773 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005774 ASSERT_VK_SUCCESS(err);
5775 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5776 ASSERT_VK_SUCCESS(err);
5777 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005779 ASSERT_VK_SUCCESS(err);
5780
5781 VkImageViewCreateInfo image_view_create_info = {};
5782 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5783 image_view_create_info.image = image;
5784 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5785 image_view_create_info.format = tex_format;
5786 image_view_create_info.subresourceRange.layerCount = 1;
5787 image_view_create_info.subresourceRange.baseMipLevel = 0;
5788 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005789 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005790
5791 VkImageView view;
5792 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005794 ASSERT_VK_SUCCESS(err);
5795 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005796 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005797 ASSERT_VK_SUCCESS(err);
5798 // Create Samplers
5799 VkSamplerCreateInfo sampler_ci = {};
5800 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5801 sampler_ci.pNext = NULL;
5802 sampler_ci.magFilter = VK_FILTER_NEAREST;
5803 sampler_ci.minFilter = VK_FILTER_NEAREST;
5804 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5805 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5806 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5807 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5808 sampler_ci.mipLodBias = 1.0;
5809 sampler_ci.anisotropyEnable = VK_FALSE;
5810 sampler_ci.maxAnisotropy = 1;
5811 sampler_ci.compareEnable = VK_FALSE;
5812 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5813 sampler_ci.minLod = 1.0;
5814 sampler_ci.maxLod = 1.0;
5815 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5816 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5817 VkSampler sampler;
5818 VkSampler sampler2;
5819 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5820 ASSERT_VK_SUCCESS(err);
5821 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5822 ASSERT_VK_SUCCESS(err);
5823 // Update descriptor with image and sampler
5824 VkDescriptorImageInfo img_info = {};
5825 img_info.sampler = sampler;
5826 img_info.imageView = view;
5827 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5828
5829 VkWriteDescriptorSet descriptor_write;
5830 memset(&descriptor_write, 0, sizeof(descriptor_write));
5831 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5832 descriptor_write.dstSet = descriptorSet;
5833 descriptor_write.dstBinding = 0;
5834 descriptor_write.descriptorCount = 1;
5835 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5836 descriptor_write.pImageInfo = &img_info;
5837
5838 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5839
5840 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005841 char const *vsSource =
5842 "#version 450\n"
5843 "\n"
5844 "out gl_PerVertex { \n"
5845 " vec4 gl_Position;\n"
5846 "};\n"
5847 "void main(){\n"
5848 " gl_Position = vec4(1);\n"
5849 "}\n";
5850 char const *fsSource =
5851 "#version 450\n"
5852 "\n"
5853 "layout(set=0, binding=0) uniform sampler2D s;\n"
5854 "layout(location=0) out vec4 x;\n"
5855 "void main(){\n"
5856 " x = texture(s, vec2(1));\n"
5857 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005858 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5859 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5860 VkPipelineObj pipe(m_device);
5861 pipe.AddShader(&vs);
5862 pipe.AddShader(&fs);
5863 pipe.AddColorAttachment();
5864 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5865
5866 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005868 m_commandBuffer->BeginCommandBuffer();
5869 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005870 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5871 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5872 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005873 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5874 VkRect2D scissor = {{0, 0}, {16, 16}};
5875 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5876 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005877 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005878 m_commandBuffer->EndRenderPass();
5879 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005880 // Destroy sampler invalidates the cmd buffer, causing error on submit
5881 vkDestroySampler(m_device->device(), sampler, NULL);
5882 // Attempt to submit cmd buffer
5883 VkSubmitInfo submit_info = {};
5884 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5885 submit_info.commandBufferCount = 1;
5886 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005887 m_errorMonitor->SetUnexpectedError("that is invalid because bound sampler");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005888 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5889 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005890
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005891 // Now re-update descriptor with valid sampler and delete image
5892 img_info.sampler = sampler2;
5893 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005894
5895 VkCommandBufferBeginInfo info = {};
5896 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5897 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5898
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005900 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005901 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005902 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5903 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5904 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005905 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5906 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005907 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005908 m_commandBuffer->EndRenderPass();
5909 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005910 // Destroy image invalidates the cmd buffer, causing error on submit
5911 vkDestroyImage(m_device->device(), image, NULL);
5912 // Attempt to submit cmd buffer
5913 submit_info = {};
5914 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5915 submit_info.commandBufferCount = 1;
5916 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005917 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005918 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5919 m_errorMonitor->VerifyFound();
5920 // Now update descriptor to be valid, but then free descriptor
5921 img_info.imageView = view2;
5922 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005923 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005924 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005925 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5926 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5927 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005928 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5929 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005930 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005931 m_commandBuffer->EndRenderPass();
5932 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07005933 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07005934
5935 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005937 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005938 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005939
5940 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07005941 // 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 -07005942 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005943 m_errorMonitor->SetUnexpectedError(
5944 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
5945 "either be a valid handle or VK_NULL_HANDLE");
5946 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07005947 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5948
5949 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005950 submit_info = {};
5951 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5952 submit_info.commandBufferCount = 1;
5953 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005955 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted descriptor set");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005956 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5957 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005958
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005959 // Cleanup
5960 vkFreeMemory(m_device->device(), image_memory, NULL);
5961 vkDestroySampler(m_device->device(), sampler2, NULL);
5962 vkDestroyImage(m_device->device(), image2, NULL);
5963 vkDestroyImageView(m_device->device(), view, NULL);
5964 vkDestroyImageView(m_device->device(), view2, NULL);
5965 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5966 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5967 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5968}
5969
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005970TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5971 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5972 ASSERT_NO_FATAL_FAILURE(InitState());
5973 ASSERT_NO_FATAL_FAILURE(InitViewport());
5974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5975
5976 VkDescriptorPoolSize ds_type_count = {};
5977 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5978 ds_type_count.descriptorCount = 1;
5979
5980 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5981 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5982 ds_pool_ci.pNext = NULL;
5983 ds_pool_ci.maxSets = 1;
5984 ds_pool_ci.poolSizeCount = 1;
5985 ds_pool_ci.pPoolSizes = &ds_type_count;
5986
5987 VkDescriptorPool ds_pool;
5988 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5989 ASSERT_VK_SUCCESS(err);
5990
5991 VkDescriptorSetLayoutBinding dsl_binding = {};
5992 dsl_binding.binding = 0;
5993 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5994 dsl_binding.descriptorCount = 1;
5995 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5996 dsl_binding.pImmutableSamplers = NULL;
5997
5998 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5999 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6000 ds_layout_ci.pNext = NULL;
6001 ds_layout_ci.bindingCount = 1;
6002 ds_layout_ci.pBindings = &dsl_binding;
6003 VkDescriptorSetLayout ds_layout;
6004 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6005 ASSERT_VK_SUCCESS(err);
6006
6007 VkDescriptorSet descriptor_set;
6008 VkDescriptorSetAllocateInfo alloc_info = {};
6009 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6010 alloc_info.descriptorSetCount = 1;
6011 alloc_info.descriptorPool = ds_pool;
6012 alloc_info.pSetLayouts = &ds_layout;
6013 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6014 ASSERT_VK_SUCCESS(err);
6015
6016 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6017 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6018 pipeline_layout_ci.pNext = NULL;
6019 pipeline_layout_ci.setLayoutCount = 1;
6020 pipeline_layout_ci.pSetLayouts = &ds_layout;
6021
6022 VkPipelineLayout pipeline_layout;
6023 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6024 ASSERT_VK_SUCCESS(err);
6025
6026 // Create image to update the descriptor with
6027 VkImageObj image(m_device);
6028 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6029 ASSERT_TRUE(image.initialized());
6030
6031 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6032 // Create Sampler
6033 VkSamplerCreateInfo sampler_ci = {};
6034 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6035 sampler_ci.pNext = NULL;
6036 sampler_ci.magFilter = VK_FILTER_NEAREST;
6037 sampler_ci.minFilter = VK_FILTER_NEAREST;
6038 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6039 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6040 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6041 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6042 sampler_ci.mipLodBias = 1.0;
6043 sampler_ci.anisotropyEnable = VK_FALSE;
6044 sampler_ci.maxAnisotropy = 1;
6045 sampler_ci.compareEnable = VK_FALSE;
6046 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6047 sampler_ci.minLod = 1.0;
6048 sampler_ci.maxLod = 1.0;
6049 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6050 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6051 VkSampler sampler;
6052 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6053 ASSERT_VK_SUCCESS(err);
6054 // Update descriptor with image and sampler
6055 VkDescriptorImageInfo img_info = {};
6056 img_info.sampler = sampler;
6057 img_info.imageView = view;
6058 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6059
6060 VkWriteDescriptorSet descriptor_write;
6061 memset(&descriptor_write, 0, sizeof(descriptor_write));
6062 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6063 descriptor_write.dstSet = descriptor_set;
6064 descriptor_write.dstBinding = 0;
6065 descriptor_write.descriptorCount = 1;
6066 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6067 descriptor_write.pImageInfo = &img_info;
6068
6069 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6070
6071 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006072 char const *vsSource =
6073 "#version 450\n"
6074 "\n"
6075 "out gl_PerVertex { \n"
6076 " vec4 gl_Position;\n"
6077 "};\n"
6078 "void main(){\n"
6079 " gl_Position = vec4(1);\n"
6080 "}\n";
6081 char const *fsSource =
6082 "#version 450\n"
6083 "\n"
6084 "layout(set=0, binding=0) uniform sampler2D s;\n"
6085 "layout(location=0) out vec4 x;\n"
6086 "void main(){\n"
6087 " x = texture(s, vec2(1));\n"
6088 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006089 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6090 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6091 VkPipelineObj pipe(m_device);
6092 pipe.AddShader(&vs);
6093 pipe.AddShader(&fs);
6094 pipe.AddColorAttachment();
6095 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6096
Tony Barbour552f6c02016-12-21 14:34:07 -07006097 m_commandBuffer->BeginCommandBuffer();
6098 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006099 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6100 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6101 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006102
6103 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6104 VkRect2D scissor = {{0, 0}, {16, 16}};
6105 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6106 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6107
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006108 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006109 m_commandBuffer->EndRenderPass();
6110 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006111 // Submit cmd buffer to put pool in-flight
6112 VkSubmitInfo submit_info = {};
6113 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6114 submit_info.commandBufferCount = 1;
6115 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6116 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6117 // Destroy pool while in-flight, causing error
6118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6119 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6120 m_errorMonitor->VerifyFound();
6121 vkQueueWaitIdle(m_device->m_queue);
6122 // Cleanup
6123 vkDestroySampler(m_device->device(), sampler, NULL);
6124 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6125 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006126 m_errorMonitor->SetUnexpectedError(
6127 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6128 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006129 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006130 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006131}
6132
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006133TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6134 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6135 ASSERT_NO_FATAL_FAILURE(InitState());
6136 ASSERT_NO_FATAL_FAILURE(InitViewport());
6137 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6138
6139 VkDescriptorPoolSize ds_type_count = {};
6140 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6141 ds_type_count.descriptorCount = 1;
6142
6143 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6144 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6145 ds_pool_ci.pNext = NULL;
6146 ds_pool_ci.maxSets = 1;
6147 ds_pool_ci.poolSizeCount = 1;
6148 ds_pool_ci.pPoolSizes = &ds_type_count;
6149
6150 VkDescriptorPool ds_pool;
6151 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6152 ASSERT_VK_SUCCESS(err);
6153
6154 VkDescriptorSetLayoutBinding dsl_binding = {};
6155 dsl_binding.binding = 0;
6156 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6157 dsl_binding.descriptorCount = 1;
6158 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6159 dsl_binding.pImmutableSamplers = NULL;
6160
6161 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6162 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6163 ds_layout_ci.pNext = NULL;
6164 ds_layout_ci.bindingCount = 1;
6165 ds_layout_ci.pBindings = &dsl_binding;
6166 VkDescriptorSetLayout ds_layout;
6167 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6168 ASSERT_VK_SUCCESS(err);
6169
6170 VkDescriptorSet descriptorSet;
6171 VkDescriptorSetAllocateInfo alloc_info = {};
6172 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6173 alloc_info.descriptorSetCount = 1;
6174 alloc_info.descriptorPool = ds_pool;
6175 alloc_info.pSetLayouts = &ds_layout;
6176 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6177 ASSERT_VK_SUCCESS(err);
6178
6179 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6180 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6181 pipeline_layout_ci.pNext = NULL;
6182 pipeline_layout_ci.setLayoutCount = 1;
6183 pipeline_layout_ci.pSetLayouts = &ds_layout;
6184
6185 VkPipelineLayout pipeline_layout;
6186 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6187 ASSERT_VK_SUCCESS(err);
6188
6189 // Create images to update the descriptor with
6190 VkImage image;
6191 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6192 const int32_t tex_width = 32;
6193 const int32_t tex_height = 32;
6194 VkImageCreateInfo image_create_info = {};
6195 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6196 image_create_info.pNext = NULL;
6197 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6198 image_create_info.format = tex_format;
6199 image_create_info.extent.width = tex_width;
6200 image_create_info.extent.height = tex_height;
6201 image_create_info.extent.depth = 1;
6202 image_create_info.mipLevels = 1;
6203 image_create_info.arrayLayers = 1;
6204 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6205 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6206 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6207 image_create_info.flags = 0;
6208 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6209 ASSERT_VK_SUCCESS(err);
6210 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6211 VkMemoryRequirements memory_reqs;
6212 VkDeviceMemory image_memory;
6213 bool pass;
6214 VkMemoryAllocateInfo memory_info = {};
6215 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6216 memory_info.pNext = NULL;
6217 memory_info.allocationSize = 0;
6218 memory_info.memoryTypeIndex = 0;
6219 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6220 // Allocate enough memory for image
6221 memory_info.allocationSize = memory_reqs.size;
6222 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6223 ASSERT_TRUE(pass);
6224 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6225 ASSERT_VK_SUCCESS(err);
6226 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6227 ASSERT_VK_SUCCESS(err);
6228
6229 VkImageViewCreateInfo image_view_create_info = {};
6230 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6231 image_view_create_info.image = image;
6232 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6233 image_view_create_info.format = tex_format;
6234 image_view_create_info.subresourceRange.layerCount = 1;
6235 image_view_create_info.subresourceRange.baseMipLevel = 0;
6236 image_view_create_info.subresourceRange.levelCount = 1;
6237 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6238
6239 VkImageView view;
6240 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6241 ASSERT_VK_SUCCESS(err);
6242 // Create Samplers
6243 VkSamplerCreateInfo sampler_ci = {};
6244 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6245 sampler_ci.pNext = NULL;
6246 sampler_ci.magFilter = VK_FILTER_NEAREST;
6247 sampler_ci.minFilter = VK_FILTER_NEAREST;
6248 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6249 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6250 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6251 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6252 sampler_ci.mipLodBias = 1.0;
6253 sampler_ci.anisotropyEnable = VK_FALSE;
6254 sampler_ci.maxAnisotropy = 1;
6255 sampler_ci.compareEnable = VK_FALSE;
6256 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6257 sampler_ci.minLod = 1.0;
6258 sampler_ci.maxLod = 1.0;
6259 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6260 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6261 VkSampler sampler;
6262 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6263 ASSERT_VK_SUCCESS(err);
6264 // Update descriptor with image and sampler
6265 VkDescriptorImageInfo img_info = {};
6266 img_info.sampler = sampler;
6267 img_info.imageView = view;
6268 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6269
6270 VkWriteDescriptorSet descriptor_write;
6271 memset(&descriptor_write, 0, sizeof(descriptor_write));
6272 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6273 descriptor_write.dstSet = descriptorSet;
6274 descriptor_write.dstBinding = 0;
6275 descriptor_write.descriptorCount = 1;
6276 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6277 descriptor_write.pImageInfo = &img_info;
6278 // Break memory binding and attempt update
6279 vkFreeMemory(m_device->device(), image_memory, nullptr);
6280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006281 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6283 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6284 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6285 m_errorMonitor->VerifyFound();
6286 // Cleanup
6287 vkDestroyImage(m_device->device(), image, NULL);
6288 vkDestroySampler(m_device->device(), sampler, NULL);
6289 vkDestroyImageView(m_device->device(), view, NULL);
6290 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6291 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6292 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6293}
6294
Karl Schultz6addd812016-02-02 17:17:23 -07006295TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006296 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6297 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006298 // Create a valid cmd buffer
6299 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006300 uint64_t fake_pipeline_handle = 0xbaad6001;
6301 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006302 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6304
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006306 m_commandBuffer->BeginCommandBuffer();
6307 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006308 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006309 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006310
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006311 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006312 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 -06006313 Draw(1, 0, 0, 0);
6314 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006315
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006316 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006317 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 -07006318 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006319 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6320 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006321}
6322
Karl Schultz6addd812016-02-02 17:17:23 -07006323TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006324 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006325 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006326
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006328
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006329 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006330 ASSERT_NO_FATAL_FAILURE(InitViewport());
6331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006332 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006333 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6334 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006335
6336 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006337 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6338 ds_pool_ci.pNext = NULL;
6339 ds_pool_ci.maxSets = 1;
6340 ds_pool_ci.poolSizeCount = 1;
6341 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006342
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006343 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006344 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006345 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006346
Tony Barboureb254902015-07-15 12:50:33 -06006347 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006348 dsl_binding.binding = 0;
6349 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6350 dsl_binding.descriptorCount = 1;
6351 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6352 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006353
Tony Barboureb254902015-07-15 12:50:33 -06006354 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006355 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6356 ds_layout_ci.pNext = NULL;
6357 ds_layout_ci.bindingCount = 1;
6358 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006359 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006360 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006361 ASSERT_VK_SUCCESS(err);
6362
6363 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006364 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006365 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006366 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006367 alloc_info.descriptorPool = ds_pool;
6368 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006369 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006370 ASSERT_VK_SUCCESS(err);
6371
Tony Barboureb254902015-07-15 12:50:33 -06006372 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006373 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6374 pipeline_layout_ci.pNext = NULL;
6375 pipeline_layout_ci.setLayoutCount = 1;
6376 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006377
6378 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006379 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006380 ASSERT_VK_SUCCESS(err);
6381
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006382 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006383 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006384 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006386
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006387 VkPipelineObj pipe(m_device);
6388 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006389 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006390 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006391 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006392
Tony Barbour552f6c02016-12-21 14:34:07 -07006393 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006394 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6395 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6396 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006397
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006398 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006399
Chia-I Wuf7458c52015-10-26 21:10:41 +08006400 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6401 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6402 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006403}
6404
Karl Schultz6addd812016-02-02 17:17:23 -07006405TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006406 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006407 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006408
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006410
6411 ASSERT_NO_FATAL_FAILURE(InitState());
6412 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006413 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6414 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006415
6416 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006417 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6418 ds_pool_ci.pNext = NULL;
6419 ds_pool_ci.maxSets = 1;
6420 ds_pool_ci.poolSizeCount = 1;
6421 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006422
6423 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006424 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006425 ASSERT_VK_SUCCESS(err);
6426
6427 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006428 dsl_binding.binding = 0;
6429 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6430 dsl_binding.descriptorCount = 1;
6431 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6432 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006433
6434 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006435 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6436 ds_layout_ci.pNext = NULL;
6437 ds_layout_ci.bindingCount = 1;
6438 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006439 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006440 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006441 ASSERT_VK_SUCCESS(err);
6442
6443 VkDescriptorSet descriptorSet;
6444 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006445 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006446 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006447 alloc_info.descriptorPool = ds_pool;
6448 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006449 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006450 ASSERT_VK_SUCCESS(err);
6451
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006452 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006453 VkWriteDescriptorSet descriptor_write;
6454 memset(&descriptor_write, 0, sizeof(descriptor_write));
6455 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6456 descriptor_write.dstSet = descriptorSet;
6457 descriptor_write.dstBinding = 0;
6458 descriptor_write.descriptorCount = 1;
6459 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6460 descriptor_write.pTexelBufferView = &view;
6461
6462 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6463
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006464 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006465
6466 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6467 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6468}
6469
Mark Youngd339ba32016-05-30 13:28:35 -06006470TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006471 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 -06006472
6473 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006475 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006476
6477 ASSERT_NO_FATAL_FAILURE(InitState());
6478
6479 // Create a buffer with no bound memory and then attempt to create
6480 // a buffer view.
6481 VkBufferCreateInfo buff_ci = {};
6482 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006483 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006484 buff_ci.size = 256;
6485 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6486 VkBuffer buffer;
6487 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6488 ASSERT_VK_SUCCESS(err);
6489
6490 VkBufferViewCreateInfo buff_view_ci = {};
6491 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6492 buff_view_ci.buffer = buffer;
6493 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6494 buff_view_ci.range = VK_WHOLE_SIZE;
6495 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006496 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006497
6498 m_errorMonitor->VerifyFound();
6499 vkDestroyBuffer(m_device->device(), buffer, NULL);
6500 // If last error is success, it still created the view, so delete it.
6501 if (err == VK_SUCCESS) {
6502 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6503 }
6504}
6505
Karl Schultz6addd812016-02-02 17:17:23 -07006506TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6507 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6508 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006509 // 1. No dynamicOffset supplied
6510 // 2. Too many dynamicOffsets supplied
6511 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006512 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6514 " requires 1 dynamicOffsets, but only "
6515 "0 dynamicOffsets are left in "
6516 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006517
6518 ASSERT_NO_FATAL_FAILURE(InitState());
6519 ASSERT_NO_FATAL_FAILURE(InitViewport());
6520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6521
6522 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006523 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6524 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006525
6526 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006527 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6528 ds_pool_ci.pNext = NULL;
6529 ds_pool_ci.maxSets = 1;
6530 ds_pool_ci.poolSizeCount = 1;
6531 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006532
6533 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006534 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006535 ASSERT_VK_SUCCESS(err);
6536
6537 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006538 dsl_binding.binding = 0;
6539 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6540 dsl_binding.descriptorCount = 1;
6541 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6542 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006543
6544 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006545 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6546 ds_layout_ci.pNext = NULL;
6547 ds_layout_ci.bindingCount = 1;
6548 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006549 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006550 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006551 ASSERT_VK_SUCCESS(err);
6552
6553 VkDescriptorSet descriptorSet;
6554 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006555 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006556 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006557 alloc_info.descriptorPool = ds_pool;
6558 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006559 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006560 ASSERT_VK_SUCCESS(err);
6561
6562 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006563 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6564 pipeline_layout_ci.pNext = NULL;
6565 pipeline_layout_ci.setLayoutCount = 1;
6566 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006567
6568 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006569 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006570 ASSERT_VK_SUCCESS(err);
6571
6572 // Create a buffer to update the descriptor with
6573 uint32_t qfi = 0;
6574 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006575 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6576 buffCI.size = 1024;
6577 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6578 buffCI.queueFamilyIndexCount = 1;
6579 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006580
6581 VkBuffer dyub;
6582 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6583 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006584 // Allocate memory and bind to buffer so we can make it to the appropriate
6585 // error
6586 VkMemoryAllocateInfo mem_alloc = {};
6587 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6588 mem_alloc.pNext = NULL;
6589 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006590 mem_alloc.memoryTypeIndex = 0;
6591
6592 VkMemoryRequirements memReqs;
6593 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006594 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006595 if (!pass) {
6596 vkDestroyBuffer(m_device->device(), dyub, NULL);
6597 return;
6598 }
6599
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006600 VkDeviceMemory mem;
6601 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6602 ASSERT_VK_SUCCESS(err);
6603 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6604 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006605 // Correctly update descriptor to avoid "NOT_UPDATED" error
6606 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006607 buffInfo.buffer = dyub;
6608 buffInfo.offset = 0;
6609 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006610
6611 VkWriteDescriptorSet descriptor_write;
6612 memset(&descriptor_write, 0, sizeof(descriptor_write));
6613 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6614 descriptor_write.dstSet = descriptorSet;
6615 descriptor_write.dstBinding = 0;
6616 descriptor_write.descriptorCount = 1;
6617 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6618 descriptor_write.pBufferInfo = &buffInfo;
6619
6620 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6621
Tony Barbour552f6c02016-12-21 14:34:07 -07006622 m_commandBuffer->BeginCommandBuffer();
6623 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006624 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6625 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006626 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006627 uint32_t pDynOff[2] = {512, 756};
6628 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6630 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6631 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6632 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006633 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006634 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6636 " dynamic offset 512 combined with "
6637 "offset 0 and range 1024 that "
6638 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006639 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006640 char const *vsSource =
6641 "#version 450\n"
6642 "\n"
6643 "out gl_PerVertex { \n"
6644 " vec4 gl_Position;\n"
6645 "};\n"
6646 "void main(){\n"
6647 " gl_Position = vec4(1);\n"
6648 "}\n";
6649 char const *fsSource =
6650 "#version 450\n"
6651 "\n"
6652 "layout(location=0) out vec4 x;\n"
6653 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6654 "void main(){\n"
6655 " x = vec4(bar.y);\n"
6656 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006657 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6658 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6659 VkPipelineObj pipe(m_device);
6660 pipe.AddShader(&vs);
6661 pipe.AddShader(&fs);
6662 pipe.AddColorAttachment();
6663 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6664
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006665 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6666 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6667 VkRect2D scissor = {{0, 0}, {16, 16}};
6668 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6669
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006670 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006671 // This update should succeed, but offset size of 512 will overstep buffer
6672 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006673 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6674 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006675 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006676 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006677
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006678 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006679 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006680
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006681 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006682 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006683 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6684}
6685
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006686TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006687 TEST_DESCRIPTION(
6688 "Attempt to update a descriptor with a non-sparse buffer "
6689 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006690 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006692 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6694 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006695
6696 ASSERT_NO_FATAL_FAILURE(InitState());
6697 ASSERT_NO_FATAL_FAILURE(InitViewport());
6698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6699
6700 VkDescriptorPoolSize ds_type_count = {};
6701 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6702 ds_type_count.descriptorCount = 1;
6703
6704 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6705 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6706 ds_pool_ci.pNext = NULL;
6707 ds_pool_ci.maxSets = 1;
6708 ds_pool_ci.poolSizeCount = 1;
6709 ds_pool_ci.pPoolSizes = &ds_type_count;
6710
6711 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006712 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006713 ASSERT_VK_SUCCESS(err);
6714
6715 VkDescriptorSetLayoutBinding dsl_binding = {};
6716 dsl_binding.binding = 0;
6717 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6718 dsl_binding.descriptorCount = 1;
6719 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6720 dsl_binding.pImmutableSamplers = NULL;
6721
6722 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6723 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6724 ds_layout_ci.pNext = NULL;
6725 ds_layout_ci.bindingCount = 1;
6726 ds_layout_ci.pBindings = &dsl_binding;
6727 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006728 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006729 ASSERT_VK_SUCCESS(err);
6730
6731 VkDescriptorSet descriptorSet;
6732 VkDescriptorSetAllocateInfo alloc_info = {};
6733 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6734 alloc_info.descriptorSetCount = 1;
6735 alloc_info.descriptorPool = ds_pool;
6736 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006737 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006738 ASSERT_VK_SUCCESS(err);
6739
6740 // Create a buffer to update the descriptor with
6741 uint32_t qfi = 0;
6742 VkBufferCreateInfo buffCI = {};
6743 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6744 buffCI.size = 1024;
6745 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6746 buffCI.queueFamilyIndexCount = 1;
6747 buffCI.pQueueFamilyIndices = &qfi;
6748
6749 VkBuffer dyub;
6750 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6751 ASSERT_VK_SUCCESS(err);
6752
6753 // Attempt to update descriptor without binding memory to it
6754 VkDescriptorBufferInfo buffInfo = {};
6755 buffInfo.buffer = dyub;
6756 buffInfo.offset = 0;
6757 buffInfo.range = 1024;
6758
6759 VkWriteDescriptorSet descriptor_write;
6760 memset(&descriptor_write, 0, sizeof(descriptor_write));
6761 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6762 descriptor_write.dstSet = descriptorSet;
6763 descriptor_write.dstBinding = 0;
6764 descriptor_write.descriptorCount = 1;
6765 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6766 descriptor_write.pBufferInfo = &buffInfo;
6767
6768 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6769 m_errorMonitor->VerifyFound();
6770
6771 vkDestroyBuffer(m_device->device(), dyub, NULL);
6772 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6773 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6774}
6775
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006776TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006777 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006778 ASSERT_NO_FATAL_FAILURE(InitState());
6779 ASSERT_NO_FATAL_FAILURE(InitViewport());
6780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6781
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006782 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006783 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006784 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6785 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6786 pipeline_layout_ci.pushConstantRangeCount = 1;
6787 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6788
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006789 //
6790 // Check for invalid push constant ranges in pipeline layouts.
6791 //
6792 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006793 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006794 char const *msg;
6795 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006796
Karl Schultzc81037d2016-05-12 08:11:23 -06006797 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6798 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6799 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6800 "vkCreatePipelineLayout() call has push constants index 0 with "
6801 "size 0."},
6802 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6803 "vkCreatePipelineLayout() call has push constants index 0 with "
6804 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006805 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006806 "vkCreatePipelineLayout() call has push constants index 0 with "
6807 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006808 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006809 "vkCreatePipelineLayout() call has push constants index 0 with "
6810 "size 0."},
6811 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6812 "vkCreatePipelineLayout() call has push constants index 0 with "
6813 "offset 1. Offset must"},
6814 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6815 "vkCreatePipelineLayout() call has push constants index 0 "
6816 "with offset "},
6817 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6818 "vkCreatePipelineLayout() call has push constants "
6819 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006820 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006821 "vkCreatePipelineLayout() call has push constants index 0 "
6822 "with offset "},
6823 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6824 "vkCreatePipelineLayout() call has push "
6825 "constants index 0 with offset "},
6826 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6827 "vkCreatePipelineLayout() call has push "
6828 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006829 }};
6830
6831 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006832 for (const auto &iter : range_tests) {
6833 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6835 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006836 m_errorMonitor->VerifyFound();
6837 if (VK_SUCCESS == err) {
6838 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6839 }
6840 }
6841
6842 // Check for invalid stage flag
6843 pc_range.offset = 0;
6844 pc_range.size = 16;
6845 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006846 m_errorMonitor->SetDesiredFailureMsg(
6847 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6848 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006849 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006850 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006851 if (VK_SUCCESS == err) {
6852 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6853 }
6854
6855 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006856 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006857 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006858 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006859 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006860 };
6861
Karl Schultzc81037d2016-05-12 08:11:23 -06006862 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006863 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6864 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6865 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6866 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6867 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006868 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 1:[0, 4)",
6869 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 2:[0, 4)",
6870 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 3:[0, 4)",
6871 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 4:[0, 4)",
6872 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 2:[0, 4)",
6873 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 3:[0, 4)",
6874 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 4:[0, 4)",
6875 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 3:[0, 4)",
6876 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 4:[0, 4)",
6877 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[0, 4), 4:[0, 4)"}},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006878 {
6879 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6880 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6881 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6882 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6883 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006884 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006885 },
6886 {
6887 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6888 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6889 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6890 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6891 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006892 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006893 },
6894 {
6895 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6896 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6897 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6898 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6899 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006900 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006901 },
6902 {
6903 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6904 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6905 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6906 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6907 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006908 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 2:[4, 100)",
6909 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[32, 36), 2:[4, 100)",
6910 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 3:[40, 48)",
6911 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 4:[52, 56)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006912 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006913
Karl Schultzc81037d2016-05-12 08:11:23 -06006914 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006915 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006916 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006918 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006919 m_errorMonitor->VerifyFound();
6920 if (VK_SUCCESS == err) {
6921 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6922 }
6923 }
6924
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006925 //
6926 // CmdPushConstants tests
6927 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006928 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006929
6930 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006931 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6932 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006933 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006934 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6935 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006936 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006937 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6938 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006939 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006940 "vkCmdPushConstants() call has push constants with offset 1. "
6941 "Offset must be a multiple of 4."},
6942 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6943 "vkCmdPushConstants() call has push constants with offset 1. "
6944 "Offset must be a multiple of 4."},
6945 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6946 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6947 "0x1 not within flag-matching ranges in pipeline layout"},
6948 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6949 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6950 "0x1 not within flag-matching ranges in pipeline layout"},
6951 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6952 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6953 "0x1 not within flag-matching ranges in pipeline layout"},
6954 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6955 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6956 "0x1 not within flag-matching ranges in pipeline layout"},
6957 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6958 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6959 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006960 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006961 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6962 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006963 }};
6964
Tony Barbour552f6c02016-12-21 14:34:07 -07006965 m_commandBuffer->BeginCommandBuffer();
6966 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006967
6968 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006969 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006970 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006971 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006972 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006973 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006974 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006975 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006976 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6978 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006979 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006980 m_errorMonitor->VerifyFound();
6981 }
6982
6983 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006985 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006986 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006987 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006988
Karl Schultzc81037d2016-05-12 08:11:23 -06006989 // overlapping range tests with cmd
6990 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6991 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6992 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6993 "0x1 not within flag-matching ranges in pipeline layout"},
6994 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6995 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6996 "0x1 not within flag-matching ranges in pipeline layout"},
6997 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6998 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6999 "0x1 not within flag-matching ranges in pipeline layout"},
7000 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007001 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06007002 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007003 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
7004 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06007005 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007006 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06007007 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007008 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06007009 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06007010 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7012 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06007013 iter.range.size, dummy_values);
7014 m_errorMonitor->VerifyFound();
7015 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007016 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7017
Tony Barbour552f6c02016-12-21 14:34:07 -07007018 m_commandBuffer->EndRenderPass();
7019 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007020}
7021
Karl Schultz6addd812016-02-02 17:17:23 -07007022TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007023 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007024 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007025
7026 ASSERT_NO_FATAL_FAILURE(InitState());
7027 ASSERT_NO_FATAL_FAILURE(InitViewport());
7028 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7029
7030 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7031 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007032 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7033 ds_type_count[0].descriptorCount = 10;
7034 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7035 ds_type_count[1].descriptorCount = 2;
7036 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7037 ds_type_count[2].descriptorCount = 2;
7038 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7039 ds_type_count[3].descriptorCount = 5;
7040 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7041 // type
7042 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7043 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7044 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007045
7046 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007047 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7048 ds_pool_ci.pNext = NULL;
7049 ds_pool_ci.maxSets = 5;
7050 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7051 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007052
7053 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007054 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007055 ASSERT_VK_SUCCESS(err);
7056
7057 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7058 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007059 dsl_binding[0].binding = 0;
7060 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7061 dsl_binding[0].descriptorCount = 5;
7062 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7063 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007064
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007065 // Create layout identical to set0 layout but w/ different stageFlags
7066 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007067 dsl_fs_stage_only.binding = 0;
7068 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7069 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007070 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7071 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007072 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007073 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007074 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7075 ds_layout_ci.pNext = NULL;
7076 ds_layout_ci.bindingCount = 1;
7077 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007078 static const uint32_t NUM_LAYOUTS = 4;
7079 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007080 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007081 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7082 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007083 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007084 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007085 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007086 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007087 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007088 dsl_binding[0].binding = 0;
7089 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007090 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007091 dsl_binding[1].binding = 1;
7092 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7093 dsl_binding[1].descriptorCount = 2;
7094 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7095 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007096 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007097 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007098 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007099 ASSERT_VK_SUCCESS(err);
7100 dsl_binding[0].binding = 0;
7101 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007102 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007103 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007104 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007105 ASSERT_VK_SUCCESS(err);
7106 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007107 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007108 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007109 ASSERT_VK_SUCCESS(err);
7110
7111 static const uint32_t NUM_SETS = 4;
7112 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7113 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007114 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007115 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007116 alloc_info.descriptorPool = ds_pool;
7117 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007118 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007119 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007120 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007121 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007122 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007123 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007124 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007125
7126 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007127 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7128 pipeline_layout_ci.pNext = NULL;
7129 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7130 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007131
7132 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007133 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007134 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007135 // Create pipelineLayout with only one setLayout
7136 pipeline_layout_ci.setLayoutCount = 1;
7137 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007138 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007139 ASSERT_VK_SUCCESS(err);
7140 // Create pipelineLayout with 2 descriptor setLayout at index 0
7141 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7142 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007143 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007144 ASSERT_VK_SUCCESS(err);
7145 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7146 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7147 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007148 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007149 ASSERT_VK_SUCCESS(err);
7150 // Create pipelineLayout with UB type, but stageFlags for FS only
7151 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7152 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007153 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007154 ASSERT_VK_SUCCESS(err);
7155 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7156 VkDescriptorSetLayout pl_bad_s0[2] = {};
7157 pl_bad_s0[0] = ds_layout_fs_only;
7158 pl_bad_s0[1] = ds_layout[1];
7159 pipeline_layout_ci.setLayoutCount = 2;
7160 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7161 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007162 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007163 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007164
Tobin Ehlis88452832015-12-03 09:40:56 -07007165 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007166 char const *vsSource =
7167 "#version 450\n"
7168 "\n"
7169 "out gl_PerVertex {\n"
7170 " vec4 gl_Position;\n"
7171 "};\n"
7172 "void main(){\n"
7173 " gl_Position = vec4(1);\n"
7174 "}\n";
7175 char const *fsSource =
7176 "#version 450\n"
7177 "\n"
7178 "layout(location=0) out vec4 x;\n"
7179 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7180 "void main(){\n"
7181 " x = vec4(bar.y);\n"
7182 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007183 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7184 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007185 VkPipelineObj pipe(m_device);
7186 pipe.AddShader(&vs);
7187 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007188 pipe.AddColorAttachment();
7189 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007190
Tony Barbour552f6c02016-12-21 14:34:07 -07007191 m_commandBuffer->BeginCommandBuffer();
7192 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007193
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007194 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007195 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7196 // of PSO
7197 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7198 // cmd_pipeline.c
7199 // due to the fact that cmd_alloc_dset_data() has not been called in
7200 // cmd_bind_graphics_pipeline()
7201 // TODO : Want to cause various binding incompatibility issues here to test
7202 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007203 // First cause various verify_layout_compatibility() fails
7204 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007205 // verify_set_layout_compatibility fail cases:
7206 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007208 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7209 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007210 m_errorMonitor->VerifyFound();
7211
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007212 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7214 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7215 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007216 m_errorMonitor->VerifyFound();
7217
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007218 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007219 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7220 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7222 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7223 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007224 m_errorMonitor->VerifyFound();
7225
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007226 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7227 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7229 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7230 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007231 m_errorMonitor->VerifyFound();
7232
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007233 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7234 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7236 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7237 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7238 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007239 m_errorMonitor->VerifyFound();
7240
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007241 // Cause INFO messages due to disturbing previously bound Sets
7242 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007243 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7244 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007245 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7247 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7248 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007249 m_errorMonitor->VerifyFound();
7250
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007251 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7252 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007253 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7255 " newly bound as set #0 so set #1 and "
7256 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007257 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7258 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007259 m_errorMonitor->VerifyFound();
7260
Tobin Ehlis10fad692016-07-07 12:00:36 -06007261 // Now that we're done actively using the pipelineLayout that gfx pipeline
7262 // was created with, we should be able to delete it. Do that now to verify
7263 // that validation obeys pipelineLayout lifetime
7264 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7265
Tobin Ehlis88452832015-12-03 09:40:56 -07007266 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007267 // 1. Error due to not binding required set (we actually use same code as
7268 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007269 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7270 &descriptorSet[0], 0, NULL);
7271 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7272 &descriptorSet[1], 0, NULL);
7273 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 -07007274
7275 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7276 VkRect2D scissor = {{0, 0}, {16, 16}};
7277 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7278 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7279
Tobin Ehlis88452832015-12-03 09:40:56 -07007280 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007281 m_errorMonitor->VerifyFound();
7282
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007283 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007284 // 2. Error due to bound set not being compatible with PSO's
7285 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007286 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7287 &descriptorSet[0], 0, NULL);
7288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007289 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007290 m_errorMonitor->VerifyFound();
7291
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007292 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007293 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007294 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7295 }
7296 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007297 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7298 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7299}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007300
Karl Schultz6addd812016-02-02 17:17:23 -07007301TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7303 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007304
7305 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007306 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007307 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007308 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007309
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007310 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007311}
7312
Karl Schultz6addd812016-02-02 17:17:23 -07007313TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7314 VkResult err;
7315 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007316
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007318
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007319 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007320
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007321 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007322 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007323 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007324 cmd.commandPool = m_commandPool;
7325 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007326 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007327
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007328 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007329 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007330
7331 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007332 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007333 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7334
7335 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007336 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007337 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007338 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 -07007339 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007340
7341 // The error should be caught by validation of the BeginCommandBuffer call
7342 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7343
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007344 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007345 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007346}
7347
Karl Schultz6addd812016-02-02 17:17:23 -07007348TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007349 // Cause error due to Begin while recording CB
7350 // Then cause 2 errors for attempting to reset CB w/o having
7351 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7352 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007354
7355 ASSERT_NO_FATAL_FAILURE(InitState());
7356
7357 // Calls AllocateCommandBuffers
7358 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7359
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007360 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007361 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007362 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7363 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007364 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7365 cmd_buf_info.pNext = NULL;
7366 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007367 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007368
7369 // Begin CB to transition to recording state
7370 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7371 // Can't re-begin. This should trigger error
7372 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007373 m_errorMonitor->VerifyFound();
7374
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007376 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007377 // Reset attempt will trigger error due to incorrect CommandPool state
7378 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007379 m_errorMonitor->VerifyFound();
7380
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007382 // Transition CB to RECORDED state
7383 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7384 // Now attempting to Begin will implicitly reset, which triggers error
7385 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007386 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007387}
7388
Karl Schultz6addd812016-02-02 17:17:23 -07007389TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007390 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007391 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007392
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7394 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007395
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007396 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007397 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007398
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007399 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007400 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7401 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007402
7403 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007404 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7405 ds_pool_ci.pNext = NULL;
7406 ds_pool_ci.maxSets = 1;
7407 ds_pool_ci.poolSizeCount = 1;
7408 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007409
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007410 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007411 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007412 ASSERT_VK_SUCCESS(err);
7413
Tony Barboureb254902015-07-15 12:50:33 -06007414 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007415 dsl_binding.binding = 0;
7416 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7417 dsl_binding.descriptorCount = 1;
7418 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7419 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007420
Tony Barboureb254902015-07-15 12:50:33 -06007421 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007422 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7423 ds_layout_ci.pNext = NULL;
7424 ds_layout_ci.bindingCount = 1;
7425 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007426
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007427 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007428 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007429 ASSERT_VK_SUCCESS(err);
7430
7431 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007432 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007433 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007434 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007435 alloc_info.descriptorPool = ds_pool;
7436 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007437 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007438 ASSERT_VK_SUCCESS(err);
7439
Tony Barboureb254902015-07-15 12:50:33 -06007440 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007441 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7442 pipeline_layout_ci.setLayoutCount = 1;
7443 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007444
7445 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007446 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007447 ASSERT_VK_SUCCESS(err);
7448
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007449 VkViewport vp = {}; // Just need dummy vp to point to
7450 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007451
7452 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007453 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7454 vp_state_ci.scissorCount = 1;
7455 vp_state_ci.pScissors = &sc;
7456 vp_state_ci.viewportCount = 1;
7457 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007458
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007459 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7460 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7461 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7462 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7463 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7464 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007465 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007466 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007467 rs_state_ci.lineWidth = 1.0f;
7468
7469 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7470 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7471 vi_ci.pNext = nullptr;
7472 vi_ci.vertexBindingDescriptionCount = 0;
7473 vi_ci.pVertexBindingDescriptions = nullptr;
7474 vi_ci.vertexAttributeDescriptionCount = 0;
7475 vi_ci.pVertexAttributeDescriptions = nullptr;
7476
7477 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7478 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7479 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7480
7481 VkPipelineShaderStageCreateInfo shaderStages[2];
7482 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7483
7484 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7485 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7486 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
7487 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007488
Tony Barboureb254902015-07-15 12:50:33 -06007489 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007490 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7491 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007492 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007493 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7494 gp_ci.layout = pipeline_layout;
7495 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007496 gp_ci.pVertexInputState = &vi_ci;
7497 gp_ci.pInputAssemblyState = &ia_ci;
7498
7499 gp_ci.stageCount = 1;
7500 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007501
7502 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007503 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7504 pc_ci.initialDataSize = 0;
7505 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007506
7507 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007508 VkPipelineCache pipelineCache;
7509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007510 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007511 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007512 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007513 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007514
Chia-I Wuf7458c52015-10-26 21:10:41 +08007515 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7516 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7517 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7518 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007519}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007520
Tobin Ehlis912df022015-09-17 08:46:18 -06007521/*// TODO : This test should be good, but needs Tess support in compiler to run
7522TEST_F(VkLayerTest, InvalidPatchControlPoints)
7523{
7524 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007525 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007526
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007528 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7529primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007530
Tobin Ehlis912df022015-09-17 08:46:18 -06007531 ASSERT_NO_FATAL_FAILURE(InitState());
7532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007533
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007534 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007535 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007536 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007537
7538 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7539 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7540 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007541 ds_pool_ci.poolSizeCount = 1;
7542 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007543
7544 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007545 err = vkCreateDescriptorPool(m_device->device(),
7546VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007547 ASSERT_VK_SUCCESS(err);
7548
7549 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007550 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007551 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007552 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007553 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7554 dsl_binding.pImmutableSamplers = NULL;
7555
7556 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007557 ds_layout_ci.sType =
7558VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007559 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007560 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007561 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007562
7563 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007564 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7565&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007566 ASSERT_VK_SUCCESS(err);
7567
7568 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007569 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7570VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007571 ASSERT_VK_SUCCESS(err);
7572
7573 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007574 pipeline_layout_ci.sType =
7575VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007576 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007577 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007578 pipeline_layout_ci.pSetLayouts = &ds_layout;
7579
7580 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007581 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7582&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007583 ASSERT_VK_SUCCESS(err);
7584
7585 VkPipelineShaderStageCreateInfo shaderStages[3];
7586 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7587
Karl Schultz6addd812016-02-02 17:17:23 -07007588 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7589this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007590 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007591 VkShaderObj
7592tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7593this);
7594 VkShaderObj
7595te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7596this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007597
Karl Schultz6addd812016-02-02 17:17:23 -07007598 shaderStages[0].sType =
7599VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007600 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007601 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007602 shaderStages[1].sType =
7603VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007604 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007605 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007606 shaderStages[2].sType =
7607VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007608 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007609 shaderStages[2].shader = te.handle();
7610
7611 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007612 iaCI.sType =
7613VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007614 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007615
7616 VkPipelineTessellationStateCreateInfo tsCI = {};
7617 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7618 tsCI.patchControlPoints = 0; // This will cause an error
7619
7620 VkGraphicsPipelineCreateInfo gp_ci = {};
7621 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7622 gp_ci.pNext = NULL;
7623 gp_ci.stageCount = 3;
7624 gp_ci.pStages = shaderStages;
7625 gp_ci.pVertexInputState = NULL;
7626 gp_ci.pInputAssemblyState = &iaCI;
7627 gp_ci.pTessellationState = &tsCI;
7628 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007629 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007630 gp_ci.pMultisampleState = NULL;
7631 gp_ci.pDepthStencilState = NULL;
7632 gp_ci.pColorBlendState = NULL;
7633 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7634 gp_ci.layout = pipeline_layout;
7635 gp_ci.renderPass = renderPass();
7636
7637 VkPipelineCacheCreateInfo pc_ci = {};
7638 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7639 pc_ci.pNext = NULL;
7640 pc_ci.initialSize = 0;
7641 pc_ci.initialData = 0;
7642 pc_ci.maxSize = 0;
7643
7644 VkPipeline pipeline;
7645 VkPipelineCache pipelineCache;
7646
Karl Schultz6addd812016-02-02 17:17:23 -07007647 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7648&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007649 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007650 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7651&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007652
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007653 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007654
Chia-I Wuf7458c52015-10-26 21:10:41 +08007655 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7656 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7657 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7658 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007659}
7660*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007661
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007662TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007663 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007664
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007665 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007666
Tobin Ehlise68360f2015-10-01 11:15:13 -06007667 ASSERT_NO_FATAL_FAILURE(InitState());
7668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007669
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007670 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007671 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7672 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007673
7674 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007675 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7676 ds_pool_ci.maxSets = 1;
7677 ds_pool_ci.poolSizeCount = 1;
7678 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007679
7680 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007681 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007682 ASSERT_VK_SUCCESS(err);
7683
7684 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007685 dsl_binding.binding = 0;
7686 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7687 dsl_binding.descriptorCount = 1;
7688 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007689
7690 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007691 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7692 ds_layout_ci.bindingCount = 1;
7693 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007694
7695 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007696 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007697 ASSERT_VK_SUCCESS(err);
7698
7699 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007700 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007701 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007702 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007703 alloc_info.descriptorPool = ds_pool;
7704 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007705 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007706 ASSERT_VK_SUCCESS(err);
7707
7708 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007709 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7710 pipeline_layout_ci.setLayoutCount = 1;
7711 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007712
7713 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007714 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007715 ASSERT_VK_SUCCESS(err);
7716
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007717 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007718 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007719 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007720 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007721 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007722 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007723
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007724 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7725 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7726 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7727 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7728 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7729 rs_state_ci.depthClampEnable = VK_FALSE;
7730 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7731 rs_state_ci.depthBiasEnable = VK_FALSE;
7732
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007733 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7734 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7735 vi_ci.pNext = nullptr;
7736 vi_ci.vertexBindingDescriptionCount = 0;
7737 vi_ci.pVertexBindingDescriptions = nullptr;
7738 vi_ci.vertexAttributeDescriptionCount = 0;
7739 vi_ci.pVertexAttributeDescriptions = nullptr;
7740
7741 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7742 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7743 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7744
7745 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7746 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7747 pipe_ms_state_ci.pNext = NULL;
7748 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7749 pipe_ms_state_ci.sampleShadingEnable = 0;
7750 pipe_ms_state_ci.minSampleShading = 1.0;
7751 pipe_ms_state_ci.pSampleMask = NULL;
7752
Cody Northropeb3a6c12015-10-05 14:44:45 -06007753 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007754 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007755
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007756 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007757 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007758 shaderStages[0] = vs.GetStageCreateInfo();
7759 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007760
7761 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007762 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7763 gp_ci.stageCount = 2;
7764 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007765 gp_ci.pVertexInputState = &vi_ci;
7766 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007767 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007768 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007769 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007770 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7771 gp_ci.layout = pipeline_layout;
7772 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007773
7774 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007775 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007776
7777 VkPipeline pipeline;
7778 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007779 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007780 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007781
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007782 if (!m_device->phy().features().multiViewport) {
7783 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7784
7785 // Check case where multiViewport is disabled and viewport count is not 1
7786 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7789 vp_state_ci.scissorCount = 0;
7790 vp_state_ci.viewportCount = 0;
7791 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7792 m_errorMonitor->VerifyFound();
7793 } else {
7794 if (m_device->props.limits.maxViewports == 1) {
7795 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7796 } else {
7797 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7798
7799 // Check is that viewportcount and scissorcount match
7800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7801 vp_state_ci.scissorCount = 1;
7802 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7803 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7804 m_errorMonitor->VerifyFound();
7805
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007806 // Check case where multiViewport is enabled and viewport count is greater than max
7807 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7810 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7811 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7812 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7813 m_errorMonitor->VerifyFound();
7814 }
7815 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007816
Chia-I Wuf7458c52015-10-26 21:10:41 +08007817 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7818 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7819 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7820 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007821}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007822
7823// 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
7824// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007825TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007826 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007827
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007828 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7829
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007831
Tobin Ehlise68360f2015-10-01 11:15:13 -06007832 ASSERT_NO_FATAL_FAILURE(InitState());
7833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007834
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007835 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007836 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7837 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007838
7839 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007840 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7841 ds_pool_ci.maxSets = 1;
7842 ds_pool_ci.poolSizeCount = 1;
7843 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007844
7845 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007846 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007847 ASSERT_VK_SUCCESS(err);
7848
7849 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007850 dsl_binding.binding = 0;
7851 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7852 dsl_binding.descriptorCount = 1;
7853 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007854
7855 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007856 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7857 ds_layout_ci.bindingCount = 1;
7858 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007859
7860 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007862 ASSERT_VK_SUCCESS(err);
7863
7864 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007865 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007867 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007868 alloc_info.descriptorPool = ds_pool;
7869 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007871 ASSERT_VK_SUCCESS(err);
7872
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007873 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7874 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7875 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7876
7877 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7878 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7879 vi_ci.pNext = nullptr;
7880 vi_ci.vertexBindingDescriptionCount = 0;
7881 vi_ci.pVertexBindingDescriptions = nullptr;
7882 vi_ci.vertexAttributeDescriptionCount = 0;
7883 vi_ci.pVertexAttributeDescriptions = nullptr;
7884
7885 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7886 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7887 pipe_ms_state_ci.pNext = NULL;
7888 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7889 pipe_ms_state_ci.sampleShadingEnable = 0;
7890 pipe_ms_state_ci.minSampleShading = 1.0;
7891 pipe_ms_state_ci.pSampleMask = NULL;
7892
Tobin Ehlise68360f2015-10-01 11:15:13 -06007893 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007894 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7895 pipeline_layout_ci.setLayoutCount = 1;
7896 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007897
7898 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007899 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007900 ASSERT_VK_SUCCESS(err);
7901
7902 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7903 // Set scissor as dynamic to avoid second error
7904 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007905 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7906 dyn_state_ci.dynamicStateCount = 1;
7907 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007908
Cody Northropeb3a6c12015-10-05 14:44:45 -06007909 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007910 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007912 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007913 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7914 // 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 +08007915 shaderStages[0] = vs.GetStageCreateInfo();
7916 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007917
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007918 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7919 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7920 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7921 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7922 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7923 rs_state_ci.depthClampEnable = VK_FALSE;
7924 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7925 rs_state_ci.depthBiasEnable = VK_FALSE;
7926
Tobin Ehlise68360f2015-10-01 11:15:13 -06007927 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007928 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7929 gp_ci.stageCount = 2;
7930 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007931 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007932 // Not setting VP state w/o dynamic vp state should cause validation error
7933 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007934 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007935 gp_ci.pVertexInputState = &vi_ci;
7936 gp_ci.pInputAssemblyState = &ia_ci;
7937 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007938 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7939 gp_ci.layout = pipeline_layout;
7940 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007941
7942 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007943 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007944
7945 VkPipeline pipeline;
7946 VkPipelineCache pipelineCache;
7947
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007948 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007949 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007950 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007951
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007952 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007953
Chia-I Wuf7458c52015-10-26 21:10:41 +08007954 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7955 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7956 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7957 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007958}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007959
7960// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7961// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007962TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7963 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007964
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007966
Tobin Ehlise68360f2015-10-01 11:15:13 -06007967 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007968
7969 if (!m_device->phy().features().multiViewport) {
7970 printf("Device does not support multiple viewports/scissors; skipped.\n");
7971 return;
7972 }
7973
Tobin Ehlise68360f2015-10-01 11:15:13 -06007974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007975
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007976 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007977 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7978 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007979
7980 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007981 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7982 ds_pool_ci.maxSets = 1;
7983 ds_pool_ci.poolSizeCount = 1;
7984 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007985
7986 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007987 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007988 ASSERT_VK_SUCCESS(err);
7989
7990 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007991 dsl_binding.binding = 0;
7992 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7993 dsl_binding.descriptorCount = 1;
7994 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007995
7996 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007997 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7998 ds_layout_ci.bindingCount = 1;
7999 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008000
8001 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008002 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008003 ASSERT_VK_SUCCESS(err);
8004
8005 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008006 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008007 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008008 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008009 alloc_info.descriptorPool = ds_pool;
8010 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008011 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008012 ASSERT_VK_SUCCESS(err);
8013
8014 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008015 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8016 pipeline_layout_ci.setLayoutCount = 1;
8017 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008018
8019 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008020 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008021 ASSERT_VK_SUCCESS(err);
8022
8023 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008024 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8025 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008026 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008027 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008028 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008029
8030 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8031 // Set scissor as dynamic to avoid that error
8032 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008033 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8034 dyn_state_ci.dynamicStateCount = 1;
8035 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008036
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008037 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8038 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8039 pipe_ms_state_ci.pNext = NULL;
8040 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8041 pipe_ms_state_ci.sampleShadingEnable = 0;
8042 pipe_ms_state_ci.minSampleShading = 1.0;
8043 pipe_ms_state_ci.pSampleMask = NULL;
8044
Cody Northropeb3a6c12015-10-05 14:44:45 -06008045 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008046 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008047
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008048 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008049 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8050 // 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 +08008051 shaderStages[0] = vs.GetStageCreateInfo();
8052 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008053
Cody Northropf6622dc2015-10-06 10:33:21 -06008054 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8055 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8056 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008057 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008058 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008059 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008060 vi_ci.pVertexAttributeDescriptions = nullptr;
8061
8062 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8063 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8064 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8065
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008066 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008067 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008068 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008069 rs_ci.pNext = nullptr;
8070
Mark Youngc89c6312016-03-31 16:03:20 -06008071 VkPipelineColorBlendAttachmentState att = {};
8072 att.blendEnable = VK_FALSE;
8073 att.colorWriteMask = 0xf;
8074
Cody Northropf6622dc2015-10-06 10:33:21 -06008075 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8076 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8077 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008078 cb_ci.attachmentCount = 1;
8079 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008080
Tobin Ehlise68360f2015-10-01 11:15:13 -06008081 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008082 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8083 gp_ci.stageCount = 2;
8084 gp_ci.pStages = shaderStages;
8085 gp_ci.pVertexInputState = &vi_ci;
8086 gp_ci.pInputAssemblyState = &ia_ci;
8087 gp_ci.pViewportState = &vp_state_ci;
8088 gp_ci.pRasterizationState = &rs_ci;
8089 gp_ci.pColorBlendState = &cb_ci;
8090 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008091 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008092 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8093 gp_ci.layout = pipeline_layout;
8094 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008095
8096 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008097 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008098
8099 VkPipeline pipeline;
8100 VkPipelineCache pipelineCache;
8101
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008102 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008103 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008104 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008105
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008106 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008107
Tobin Ehlisd332f282015-10-02 11:00:56 -06008108 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008109 // First need to successfully create the PSO from above by setting
8110 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008111 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 -07008112
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008113 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008114 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008115 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008116 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008117 m_commandBuffer->BeginCommandBuffer();
8118 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008119 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008120 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008121 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008122 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008123 Draw(1, 0, 0, 0);
8124
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008125 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008126
8127 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8128 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8129 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8130 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008131 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008132}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008133
8134// 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 -07008135// viewportCount
8136TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8137 VkResult err;
8138
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008140
8141 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008142
8143 if (!m_device->phy().features().multiViewport) {
8144 printf("Device does not support multiple viewports/scissors; skipped.\n");
8145 return;
8146 }
8147
Karl Schultz6addd812016-02-02 17:17:23 -07008148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8149
8150 VkDescriptorPoolSize ds_type_count = {};
8151 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8152 ds_type_count.descriptorCount = 1;
8153
8154 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8155 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8156 ds_pool_ci.maxSets = 1;
8157 ds_pool_ci.poolSizeCount = 1;
8158 ds_pool_ci.pPoolSizes = &ds_type_count;
8159
8160 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008161 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008162 ASSERT_VK_SUCCESS(err);
8163
8164 VkDescriptorSetLayoutBinding dsl_binding = {};
8165 dsl_binding.binding = 0;
8166 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8167 dsl_binding.descriptorCount = 1;
8168 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8169
8170 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8171 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8172 ds_layout_ci.bindingCount = 1;
8173 ds_layout_ci.pBindings = &dsl_binding;
8174
8175 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008176 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008177 ASSERT_VK_SUCCESS(err);
8178
8179 VkDescriptorSet descriptorSet;
8180 VkDescriptorSetAllocateInfo alloc_info = {};
8181 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8182 alloc_info.descriptorSetCount = 1;
8183 alloc_info.descriptorPool = ds_pool;
8184 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008185 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008186 ASSERT_VK_SUCCESS(err);
8187
8188 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8189 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8190 pipeline_layout_ci.setLayoutCount = 1;
8191 pipeline_layout_ci.pSetLayouts = &ds_layout;
8192
8193 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008194 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008195 ASSERT_VK_SUCCESS(err);
8196
8197 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8198 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8199 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008200 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008201 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008202 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008203
8204 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8205 // Set scissor as dynamic to avoid that error
8206 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8207 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8208 dyn_state_ci.dynamicStateCount = 1;
8209 dyn_state_ci.pDynamicStates = &vp_state;
8210
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008211 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8212 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8213 pipe_ms_state_ci.pNext = NULL;
8214 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8215 pipe_ms_state_ci.sampleShadingEnable = 0;
8216 pipe_ms_state_ci.minSampleShading = 1.0;
8217 pipe_ms_state_ci.pSampleMask = NULL;
8218
Karl Schultz6addd812016-02-02 17:17:23 -07008219 VkPipelineShaderStageCreateInfo shaderStages[2];
8220 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8221
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008222 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008223 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8224 // 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 -07008225 shaderStages[0] = vs.GetStageCreateInfo();
8226 shaderStages[1] = fs.GetStageCreateInfo();
8227
8228 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8229 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8230 vi_ci.pNext = nullptr;
8231 vi_ci.vertexBindingDescriptionCount = 0;
8232 vi_ci.pVertexBindingDescriptions = nullptr;
8233 vi_ci.vertexAttributeDescriptionCount = 0;
8234 vi_ci.pVertexAttributeDescriptions = nullptr;
8235
8236 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8237 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8238 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8239
8240 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8241 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008242 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008243 rs_ci.pNext = nullptr;
8244
Mark Youngc89c6312016-03-31 16:03:20 -06008245 VkPipelineColorBlendAttachmentState att = {};
8246 att.blendEnable = VK_FALSE;
8247 att.colorWriteMask = 0xf;
8248
Karl Schultz6addd812016-02-02 17:17:23 -07008249 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8250 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8251 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008252 cb_ci.attachmentCount = 1;
8253 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008254
8255 VkGraphicsPipelineCreateInfo gp_ci = {};
8256 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8257 gp_ci.stageCount = 2;
8258 gp_ci.pStages = shaderStages;
8259 gp_ci.pVertexInputState = &vi_ci;
8260 gp_ci.pInputAssemblyState = &ia_ci;
8261 gp_ci.pViewportState = &vp_state_ci;
8262 gp_ci.pRasterizationState = &rs_ci;
8263 gp_ci.pColorBlendState = &cb_ci;
8264 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008265 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008266 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8267 gp_ci.layout = pipeline_layout;
8268 gp_ci.renderPass = renderPass();
8269
8270 VkPipelineCacheCreateInfo pc_ci = {};
8271 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8272
8273 VkPipeline pipeline;
8274 VkPipelineCache pipelineCache;
8275
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008276 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008277 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008278 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008279
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008280 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008281
8282 // Now hit second fail case where we set scissor w/ different count than PSO
8283 // First need to successfully create the PSO from above by setting
8284 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8286 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008287
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008288 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008289 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008290 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008291 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008292 m_commandBuffer->BeginCommandBuffer();
8293 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008294 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008295 VkViewport viewports[1] = {};
8296 viewports[0].width = 8;
8297 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008298 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008299 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008300 Draw(1, 0, 0, 0);
8301
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008302 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008303
Chia-I Wuf7458c52015-10-26 21:10:41 +08008304 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8305 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8306 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8307 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008308 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008309}
8310
Mark Young7394fdd2016-03-31 14:56:43 -06008311TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8312 VkResult err;
8313
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008315
8316 ASSERT_NO_FATAL_FAILURE(InitState());
8317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8318
8319 VkDescriptorPoolSize ds_type_count = {};
8320 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8321 ds_type_count.descriptorCount = 1;
8322
8323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8325 ds_pool_ci.maxSets = 1;
8326 ds_pool_ci.poolSizeCount = 1;
8327 ds_pool_ci.pPoolSizes = &ds_type_count;
8328
8329 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008330 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008331 ASSERT_VK_SUCCESS(err);
8332
8333 VkDescriptorSetLayoutBinding dsl_binding = {};
8334 dsl_binding.binding = 0;
8335 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8336 dsl_binding.descriptorCount = 1;
8337 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8338
8339 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8340 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8341 ds_layout_ci.bindingCount = 1;
8342 ds_layout_ci.pBindings = &dsl_binding;
8343
8344 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008345 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008346 ASSERT_VK_SUCCESS(err);
8347
8348 VkDescriptorSet descriptorSet;
8349 VkDescriptorSetAllocateInfo alloc_info = {};
8350 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8351 alloc_info.descriptorSetCount = 1;
8352 alloc_info.descriptorPool = ds_pool;
8353 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008354 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008355 ASSERT_VK_SUCCESS(err);
8356
8357 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8358 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8359 pipeline_layout_ci.setLayoutCount = 1;
8360 pipeline_layout_ci.pSetLayouts = &ds_layout;
8361
8362 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008363 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008364 ASSERT_VK_SUCCESS(err);
8365
8366 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8367 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8368 vp_state_ci.scissorCount = 1;
8369 vp_state_ci.pScissors = NULL;
8370 vp_state_ci.viewportCount = 1;
8371 vp_state_ci.pViewports = NULL;
8372
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008373 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008374 // Set scissor as dynamic to avoid that error
8375 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8376 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8377 dyn_state_ci.dynamicStateCount = 2;
8378 dyn_state_ci.pDynamicStates = dynamic_states;
8379
8380 VkPipelineShaderStageCreateInfo shaderStages[2];
8381 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8382
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008383 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8384 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008385 this); // TODO - We shouldn't need a fragment shader
8386 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008387 shaderStages[0] = vs.GetStageCreateInfo();
8388 shaderStages[1] = fs.GetStageCreateInfo();
8389
8390 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8391 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8392 vi_ci.pNext = nullptr;
8393 vi_ci.vertexBindingDescriptionCount = 0;
8394 vi_ci.pVertexBindingDescriptions = nullptr;
8395 vi_ci.vertexAttributeDescriptionCount = 0;
8396 vi_ci.pVertexAttributeDescriptions = nullptr;
8397
8398 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8399 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8400 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8401
8402 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8403 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8404 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008405 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008406
Mark Young47107952016-05-02 15:59:55 -06008407 // Check too low (line width of -1.0f).
8408 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008409
8410 VkPipelineColorBlendAttachmentState att = {};
8411 att.blendEnable = VK_FALSE;
8412 att.colorWriteMask = 0xf;
8413
8414 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8415 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8416 cb_ci.pNext = nullptr;
8417 cb_ci.attachmentCount = 1;
8418 cb_ci.pAttachments = &att;
8419
8420 VkGraphicsPipelineCreateInfo gp_ci = {};
8421 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8422 gp_ci.stageCount = 2;
8423 gp_ci.pStages = shaderStages;
8424 gp_ci.pVertexInputState = &vi_ci;
8425 gp_ci.pInputAssemblyState = &ia_ci;
8426 gp_ci.pViewportState = &vp_state_ci;
8427 gp_ci.pRasterizationState = &rs_ci;
8428 gp_ci.pColorBlendState = &cb_ci;
8429 gp_ci.pDynamicState = &dyn_state_ci;
8430 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8431 gp_ci.layout = pipeline_layout;
8432 gp_ci.renderPass = renderPass();
8433
8434 VkPipelineCacheCreateInfo pc_ci = {};
8435 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8436
8437 VkPipeline pipeline;
8438 VkPipelineCache pipelineCache;
8439
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008440 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008441 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008442 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008443
8444 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008445 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008446
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008448
8449 // Check too high (line width of 65536.0f).
8450 rs_ci.lineWidth = 65536.0f;
8451
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008452 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008453 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008454 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008455
8456 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008457 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008458
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008460
8461 dyn_state_ci.dynamicStateCount = 3;
8462
8463 rs_ci.lineWidth = 1.0f;
8464
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008465 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008466 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008467 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008468 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008469 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008470
8471 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008472 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008473 m_errorMonitor->VerifyFound();
8474
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008476
8477 // Check too high with dynamic setting.
8478 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8479 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008480 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008481
8482 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8483 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8484 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8485 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008486 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008487}
8488
Karl Schultz6addd812016-02-02 17:17:23 -07008489TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008490 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008492 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008493
8494 ASSERT_NO_FATAL_FAILURE(InitState());
8495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008496
Tony Barbour552f6c02016-12-21 14:34:07 -07008497 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008498 // Don't care about RenderPass handle b/c error should be flagged before
8499 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008500 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008501
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008502 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008503}
8504
Karl Schultz6addd812016-02-02 17:17:23 -07008505TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008506 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8508 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008509
8510 ASSERT_NO_FATAL_FAILURE(InitState());
8511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008512
Tony Barbour552f6c02016-12-21 14:34:07 -07008513 m_commandBuffer->BeginCommandBuffer();
8514 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008515 // Just create a dummy Renderpass that's non-NULL so we can get to the
8516 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008517 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008518
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008519 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008520}
8521
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008522TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008523 TEST_DESCRIPTION(
8524 "Begin a renderPass where clearValueCount is less than"
8525 "the number of renderPass attachments that use loadOp"
8526 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008527
8528 ASSERT_NO_FATAL_FAILURE(InitState());
8529 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8530
8531 // Create a renderPass with a single attachment that uses loadOp CLEAR
8532 VkAttachmentReference attach = {};
8533 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8534 VkSubpassDescription subpass = {};
8535 subpass.inputAttachmentCount = 1;
8536 subpass.pInputAttachments = &attach;
8537 VkRenderPassCreateInfo rpci = {};
8538 rpci.subpassCount = 1;
8539 rpci.pSubpasses = &subpass;
8540 rpci.attachmentCount = 1;
8541 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008542 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008543 // Set loadOp to CLEAR
8544 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8545 rpci.pAttachments = &attach_desc;
8546 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8547 VkRenderPass rp;
8548 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8549
8550 VkCommandBufferInheritanceInfo hinfo = {};
8551 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8552 hinfo.renderPass = VK_NULL_HANDLE;
8553 hinfo.subpass = 0;
8554 hinfo.framebuffer = VK_NULL_HANDLE;
8555 hinfo.occlusionQueryEnable = VK_FALSE;
8556 hinfo.queryFlags = 0;
8557 hinfo.pipelineStatistics = 0;
8558 VkCommandBufferBeginInfo info = {};
8559 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8560 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8561 info.pInheritanceInfo = &hinfo;
8562
8563 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8564 VkRenderPassBeginInfo rp_begin = {};
8565 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8566 rp_begin.pNext = NULL;
8567 rp_begin.renderPass = renderPass();
8568 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008569 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008570
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008572
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008573 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008574
8575 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008576
8577 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008578}
8579
Slawomir Cygan0808f392016-11-28 17:53:23 +01008580TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008581 TEST_DESCRIPTION(
8582 "Begin a renderPass where clearValueCount is greater than"
8583 "the number of renderPass attachments that use loadOp"
8584 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008585
8586 ASSERT_NO_FATAL_FAILURE(InitState());
8587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8588
8589 // Create a renderPass with a single attachment that uses loadOp CLEAR
8590 VkAttachmentReference attach = {};
8591 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8592 VkSubpassDescription subpass = {};
8593 subpass.inputAttachmentCount = 1;
8594 subpass.pInputAttachments = &attach;
8595 VkRenderPassCreateInfo rpci = {};
8596 rpci.subpassCount = 1;
8597 rpci.pSubpasses = &subpass;
8598 rpci.attachmentCount = 1;
8599 VkAttachmentDescription attach_desc = {};
8600 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8601 // Set loadOp to CLEAR
8602 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8603 rpci.pAttachments = &attach_desc;
8604 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8605 VkRenderPass rp;
8606 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8607
8608 VkCommandBufferBeginInfo info = {};
8609 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8610 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8611
8612 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8613 VkRenderPassBeginInfo rp_begin = {};
8614 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8615 rp_begin.pNext = NULL;
8616 rp_begin.renderPass = renderPass();
8617 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008618 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008619
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8621 " has a clearValueCount of"
8622 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008623
8624 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8625
8626 m_errorMonitor->VerifyFound();
8627
8628 vkDestroyRenderPass(m_device->device(), rp, NULL);
8629}
8630
Cody Northrop3bb4d962016-05-09 16:15:57 -06008631TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008632 TEST_DESCRIPTION("End a command buffer with an active render pass");
8633
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8635 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008636
8637 ASSERT_NO_FATAL_FAILURE(InitState());
8638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8639
Tony Barbour552f6c02016-12-21 14:34:07 -07008640 m_commandBuffer->BeginCommandBuffer();
8641 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8642 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008643
8644 m_errorMonitor->VerifyFound();
8645
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008646 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8647 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008648}
8649
Karl Schultz6addd812016-02-02 17:17:23 -07008650TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008651 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8653 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008654
8655 ASSERT_NO_FATAL_FAILURE(InitState());
8656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008657
Tony Barbour552f6c02016-12-21 14:34:07 -07008658 m_commandBuffer->BeginCommandBuffer();
8659 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008660
8661 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008662 vk_testing::Buffer dstBuffer;
8663 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008664
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008665 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008666
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008667 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008668}
8669
Karl Schultz6addd812016-02-02 17:17:23 -07008670TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008671 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8673 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008674
8675 ASSERT_NO_FATAL_FAILURE(InitState());
8676 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008677
Tony Barbour552f6c02016-12-21 14:34:07 -07008678 m_commandBuffer->BeginCommandBuffer();
8679 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008680
8681 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008682 vk_testing::Buffer dstBuffer;
8683 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008684
Karl Schultz6addd812016-02-02 17:17:23 -07008685 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008686 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8687 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8688 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008689
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008690 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008691}
8692
Karl Schultz6addd812016-02-02 17:17:23 -07008693TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008694 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8696 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008697
8698 ASSERT_NO_FATAL_FAILURE(InitState());
8699 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008700
Tony Barbour552f6c02016-12-21 14:34:07 -07008701 m_commandBuffer->BeginCommandBuffer();
8702 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008703
Michael Lentine0a369f62016-02-03 16:51:46 -06008704 VkClearColorValue clear_color;
8705 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008706 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8707 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8708 const int32_t tex_width = 32;
8709 const int32_t tex_height = 32;
8710 VkImageCreateInfo image_create_info = {};
8711 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8712 image_create_info.pNext = NULL;
8713 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8714 image_create_info.format = tex_format;
8715 image_create_info.extent.width = tex_width;
8716 image_create_info.extent.height = tex_height;
8717 image_create_info.extent.depth = 1;
8718 image_create_info.mipLevels = 1;
8719 image_create_info.arrayLayers = 1;
8720 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8721 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8722 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008723
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008724 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008725 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008726
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008727 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008728
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07008729 m_errorMonitor->SetUnexpectedError("image must have been created with VK_IMAGE_USAGE_TRANSFER_DST_BIT usage flag");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008730 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008731
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008732 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008733}
8734
Karl Schultz6addd812016-02-02 17:17:23 -07008735TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008736 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8738 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008739
8740 ASSERT_NO_FATAL_FAILURE(InitState());
8741 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008742
Tony Barbour552f6c02016-12-21 14:34:07 -07008743 m_commandBuffer->BeginCommandBuffer();
8744 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008745
8746 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008747 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008748 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8749 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8750 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8751 image_create_info.extent.width = 64;
8752 image_create_info.extent.height = 64;
8753 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8754 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008755
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008756 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008757 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008759 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008760
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008761 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8762 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008763
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008764 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008765}
8766
Karl Schultz6addd812016-02-02 17:17:23 -07008767TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008768 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008769 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008770
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8772 "vkCmdClearAttachments(): This call "
8773 "must be issued inside an active "
8774 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008775
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008776 ASSERT_NO_FATAL_FAILURE(InitState());
8777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008778
8779 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008780 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008781 ASSERT_VK_SUCCESS(err);
8782
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008783 VkClearAttachment color_attachment;
8784 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8785 color_attachment.clearValue.color.float32[0] = 0;
8786 color_attachment.clearValue.color.float32[1] = 0;
8787 color_attachment.clearValue.color.float32[2] = 0;
8788 color_attachment.clearValue.color.float32[3] = 0;
8789 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008790 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008791 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008792
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008793 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008794}
8795
Chris Forbes3b97e932016-09-07 11:29:24 +12008796TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008797 TEST_DESCRIPTION(
8798 "Test that an error is produced when CmdNextSubpass is "
8799 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008800
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8802 "vkCmdNextSubpass(): Attempted to advance "
8803 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008804
8805 ASSERT_NO_FATAL_FAILURE(InitState());
8806 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8807
Tony Barbour552f6c02016-12-21 14:34:07 -07008808 m_commandBuffer->BeginCommandBuffer();
8809 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008810
8811 // error here.
8812 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8813 m_errorMonitor->VerifyFound();
8814
Tony Barbour552f6c02016-12-21 14:34:07 -07008815 m_commandBuffer->EndRenderPass();
8816 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008817}
8818
Chris Forbes6d624702016-09-07 13:57:05 +12008819TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008820 TEST_DESCRIPTION(
8821 "Test that an error is produced when CmdEndRenderPass is "
8822 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008823
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8825 "vkCmdEndRenderPass(): Called before reaching "
8826 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008827
8828 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008829 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8830 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008831
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008832 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008833
8834 VkRenderPass rp;
8835 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8836 ASSERT_VK_SUCCESS(err);
8837
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008838 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008839
8840 VkFramebuffer fb;
8841 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8842 ASSERT_VK_SUCCESS(err);
8843
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008844 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008845
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008846 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 +12008847
8848 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8849
8850 // Error here.
8851 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8852 m_errorMonitor->VerifyFound();
8853
8854 // Clean up.
8855 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8856 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8857}
8858
Karl Schultz9e66a292016-04-21 15:57:51 -06008859TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8860 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8862 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008863
8864 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008865 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008866
8867 VkBufferMemoryBarrier buf_barrier = {};
8868 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8869 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8870 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8871 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8872 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8873 buf_barrier.buffer = VK_NULL_HANDLE;
8874 buf_barrier.offset = 0;
8875 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008876 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8877 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008878
8879 m_errorMonitor->VerifyFound();
8880}
8881
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008882TEST_F(VkLayerTest, InvalidBarriers) {
8883 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008886
8887 ASSERT_NO_FATAL_FAILURE(InitState());
8888 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8889
8890 VkMemoryBarrier mem_barrier = {};
8891 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8892 mem_barrier.pNext = NULL;
8893 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8894 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008895 m_commandBuffer->BeginCommandBuffer();
8896 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008897 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008898 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008899 &mem_barrier, 0, nullptr, 0, nullptr);
8900 m_errorMonitor->VerifyFound();
8901
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008903 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008904 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 -06008905 ASSERT_TRUE(image.initialized());
8906 VkImageMemoryBarrier img_barrier = {};
8907 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8908 img_barrier.pNext = NULL;
8909 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8910 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8911 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8912 // New layout can't be UNDEFINED
8913 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8914 img_barrier.image = image.handle();
8915 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8916 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8917 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8918 img_barrier.subresourceRange.baseArrayLayer = 0;
8919 img_barrier.subresourceRange.baseMipLevel = 0;
8920 img_barrier.subresourceRange.layerCount = 1;
8921 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008922 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8923 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008924 m_errorMonitor->VerifyFound();
8925 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8926
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8928 "Subresource must have the sum of the "
8929 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008930 // baseArrayLayer + layerCount must be <= image's arrayLayers
8931 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008932 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8933 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008934 m_errorMonitor->VerifyFound();
8935 img_barrier.subresourceRange.baseArrayLayer = 0;
8936
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008938 // baseMipLevel + levelCount must be <= image's mipLevels
8939 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008940 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8941 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008942 m_errorMonitor->VerifyFound();
8943 img_barrier.subresourceRange.baseMipLevel = 0;
8944
Mike Weiblen7053aa32017-01-25 15:21:10 -07008945 // levelCount must be non-zero.
8946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8947 img_barrier.subresourceRange.levelCount = 0;
8948 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8949 nullptr, 0, nullptr, 1, &img_barrier);
8950 m_errorMonitor->VerifyFound();
8951 img_barrier.subresourceRange.levelCount = 1;
8952
8953 // layerCount must be non-zero.
8954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8955 img_barrier.subresourceRange.layerCount = 0;
8956 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8957 nullptr, 0, nullptr, 1, &img_barrier);
8958 m_errorMonitor->VerifyFound();
8959 img_barrier.subresourceRange.layerCount = 1;
8960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008961 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 -06008962 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008963 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8964 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008965 VkBufferMemoryBarrier buf_barrier = {};
8966 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8967 buf_barrier.pNext = NULL;
8968 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8969 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8970 buf_barrier.buffer = buffer.handle();
8971 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8972 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8973 buf_barrier.offset = 0;
8974 buf_barrier.size = VK_WHOLE_SIZE;
8975 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008976 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8977 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008978 m_errorMonitor->VerifyFound();
8979 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8980
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008982 buf_barrier.offset = 257;
8983 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008984 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8985 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008986 m_errorMonitor->VerifyFound();
8987 buf_barrier.offset = 0;
8988
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008990 buf_barrier.size = 257;
8991 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008992 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8993 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008994 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008995
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008996 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008997 m_errorMonitor->SetDesiredFailureMsg(
8998 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008999 "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 -06009000 VkDepthStencilObj ds_image(m_device);
9001 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
9002 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009003 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9004 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009005 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009006
9007 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009008 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009009 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9010 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009011 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009012
9013 // Having anything other than DEPTH or STENCIL is an error
9014 m_errorMonitor->SetDesiredFailureMsg(
9015 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9016 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9017 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9018 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9019 nullptr, 0, nullptr, 1, &img_barrier);
9020 m_errorMonitor->VerifyFound();
9021
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009022 // Now test depth-only
9023 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009024 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9025 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009026 VkDepthStencilObj d_image(m_device);
9027 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9028 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009029 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009030 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009031 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009032
9033 // DEPTH bit must be set
9034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9035 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009036 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009037 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9038 0, nullptr, 0, nullptr, 1, &img_barrier);
9039 m_errorMonitor->VerifyFound();
9040
9041 // No bits other than DEPTH may be set
9042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9043 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9044 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009045 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9046 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009047 m_errorMonitor->VerifyFound();
9048 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009049
9050 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009051 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9052 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9054 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009055 VkDepthStencilObj s_image(m_device);
9056 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9057 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009058 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009059 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009060 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009061 // Use of COLOR aspect on depth image is error
9062 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009063 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9064 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009065 m_errorMonitor->VerifyFound();
9066 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009067
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009068 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009069 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009070 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 -06009071 ASSERT_TRUE(c_image.initialized());
9072 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9073 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9074 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009075
9076 // COLOR bit must be set
9077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9078 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009079 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009080 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9081 nullptr, 0, nullptr, 1, &img_barrier);
9082 m_errorMonitor->VerifyFound();
9083
9084 // No bits other than COLOR may be set
9085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9086 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9087 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009088 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9089 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009090 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009091
9092 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9093
9094 // Create command pool with incompatible queueflags
9095 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9096 uint32_t queue_family_index = UINT32_MAX;
9097 for (uint32_t i = 0; i < queue_props.size(); i++) {
9098 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9099 queue_family_index = i;
9100 break;
9101 }
9102 }
9103 if (queue_family_index == UINT32_MAX) {
9104 printf("No non-compute queue found; skipped.\n");
9105 return;
9106 }
9107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9108
9109 VkCommandPool command_pool;
9110 VkCommandPoolCreateInfo pool_create_info{};
9111 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9112 pool_create_info.queueFamilyIndex = queue_family_index;
9113 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9114 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9115
9116 // Allocate a command buffer
9117 VkCommandBuffer bad_command_buffer;
9118 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9119 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9120 command_buffer_allocate_info.commandPool = command_pool;
9121 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9122 command_buffer_allocate_info.commandBufferCount = 1;
9123 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9124
9125 VkCommandBufferBeginInfo cbbi = {};
9126 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9127 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9128 buf_barrier.offset = 0;
9129 buf_barrier.size = VK_WHOLE_SIZE;
9130 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9131 &buf_barrier, 0, nullptr);
9132 m_errorMonitor->VerifyFound();
9133
9134 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9135 vkEndCommandBuffer(bad_command_buffer);
9136 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
9137 printf("The non-compute queue does not support graphics; skipped.\n");
9138 return;
9139 }
9140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9141 VkEvent event;
9142 VkEventCreateInfo event_create_info{};
9143 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9144 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9145 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9146 nullptr, 0, nullptr);
9147 m_errorMonitor->VerifyFound();
9148
9149 vkEndCommandBuffer(bad_command_buffer);
9150 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009151}
9152
Tony Barbour18ba25c2016-09-29 13:42:40 -06009153TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9154 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9155
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009157 ASSERT_NO_FATAL_FAILURE(InitState());
9158 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06009159 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 -06009160 ASSERT_TRUE(image.initialized());
9161
9162 VkImageMemoryBarrier barrier = {};
9163 VkImageSubresourceRange range;
9164 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9165 barrier.srcAccessMask = 0;
9166 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9167 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9168 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9169 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9170 barrier.image = image.handle();
9171 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9172 range.baseMipLevel = 0;
9173 range.levelCount = 1;
9174 range.baseArrayLayer = 0;
9175 range.layerCount = 1;
9176 barrier.subresourceRange = range;
9177 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9178 cmdbuf.BeginCommandBuffer();
9179 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9180 &barrier);
9181 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9182 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9183 barrier.srcAccessMask = 0;
9184 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9185 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9186 &barrier);
9187
9188 m_errorMonitor->VerifyFound();
9189}
9190
Karl Schultz6addd812016-02-02 17:17:23 -07009191TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009192 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009193 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009194
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009196
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009197 ASSERT_NO_FATAL_FAILURE(InitState());
9198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009199 uint32_t qfi = 0;
9200 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009201 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9202 buffCI.size = 1024;
9203 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9204 buffCI.queueFamilyIndexCount = 1;
9205 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009206
9207 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009208 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009209 ASSERT_VK_SUCCESS(err);
9210
Tony Barbour552f6c02016-12-21 14:34:07 -07009211 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009212 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009213 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9214 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009215 // Should error before calling to driver so don't care about actual data
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009216 m_errorMonitor->SetUnexpectedError(
9217 "If buffer is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009218 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009219
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009220 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009221
Chia-I Wuf7458c52015-10-26 21:10:41 +08009222 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009223}
9224
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009225TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9226 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9228 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
9229 "of the indices specified when the device was created, via the "
9230 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009231
9232 ASSERT_NO_FATAL_FAILURE(InitState());
9233 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9234 VkBufferCreateInfo buffCI = {};
9235 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9236 buffCI.size = 1024;
9237 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9238 buffCI.queueFamilyIndexCount = 1;
9239 // Introduce failure by specifying invalid queue_family_index
9240 uint32_t qfi = 777;
9241 buffCI.pQueueFamilyIndices = &qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009242 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009243
9244 VkBuffer ib;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009245 m_errorMonitor->SetUnexpectedError(
9246 "If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009247 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9248
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009249 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06009250 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009251}
9252
Karl Schultz6addd812016-02-02 17:17:23 -07009253TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009254 TEST_DESCRIPTION(
9255 "Attempt vkCmdExecuteCommands with a primary command buffer"
9256 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009257
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009258 ASSERT_NO_FATAL_FAILURE(InitState());
9259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009260
Chris Forbesf29a84f2016-10-06 18:39:28 +13009261 // An empty primary command buffer
9262 VkCommandBufferObj cb(m_device, m_commandPool);
9263 cb.BeginCommandBuffer();
9264 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009265
Chris Forbesf29a84f2016-10-06 18:39:28 +13009266 m_commandBuffer->BeginCommandBuffer();
9267 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9268 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009269
Chris Forbesf29a84f2016-10-06 18:39:28 +13009270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9271 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009272 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009273
9274 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009275}
9276
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009277TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009278 TEST_DESCRIPTION(
9279 "Attempt to update descriptor sets for images and buffers "
9280 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009281 VkResult err;
9282
9283 ASSERT_NO_FATAL_FAILURE(InitState());
9284 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9285 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9286 ds_type_count[i].type = VkDescriptorType(i);
9287 ds_type_count[i].descriptorCount = 1;
9288 }
9289 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9290 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9291 ds_pool_ci.pNext = NULL;
9292 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9293 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9294 ds_pool_ci.pPoolSizes = ds_type_count;
9295
9296 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009297 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009298 ASSERT_VK_SUCCESS(err);
9299
9300 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009301 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009302 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9303 dsl_binding[i].binding = 0;
9304 dsl_binding[i].descriptorType = VkDescriptorType(i);
9305 dsl_binding[i].descriptorCount = 1;
9306 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9307 dsl_binding[i].pImmutableSamplers = NULL;
9308 }
9309
9310 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9311 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9312 ds_layout_ci.pNext = NULL;
9313 ds_layout_ci.bindingCount = 1;
9314 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9315 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9316 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009317 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009318 ASSERT_VK_SUCCESS(err);
9319 }
9320 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9321 VkDescriptorSetAllocateInfo alloc_info = {};
9322 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9323 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9324 alloc_info.descriptorPool = ds_pool;
9325 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009326 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009327 ASSERT_VK_SUCCESS(err);
9328
9329 // Create a buffer & bufferView to be used for invalid updates
9330 VkBufferCreateInfo buff_ci = {};
9331 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009332 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009333 buff_ci.size = 256;
9334 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009335 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009336 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9337 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009338
9339 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9340 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9341 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9342 ASSERT_VK_SUCCESS(err);
9343
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009344 VkMemoryRequirements mem_reqs;
9345 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9346 VkMemoryAllocateInfo mem_alloc_info = {};
9347 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9348 mem_alloc_info.pNext = NULL;
9349 mem_alloc_info.memoryTypeIndex = 0;
9350 mem_alloc_info.allocationSize = mem_reqs.size;
9351 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9352 if (!pass) {
9353 vkDestroyBuffer(m_device->device(), buffer, NULL);
9354 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9355 return;
9356 }
9357 VkDeviceMemory mem;
9358 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9359 ASSERT_VK_SUCCESS(err);
9360 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9361 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009362
9363 VkBufferViewCreateInfo buff_view_ci = {};
9364 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9365 buff_view_ci.buffer = buffer;
9366 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9367 buff_view_ci.range = VK_WHOLE_SIZE;
9368 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009369 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009370 ASSERT_VK_SUCCESS(err);
9371
Tony Barbour415497c2017-01-24 10:06:09 -07009372 // Now get resources / view for storage_texel_buffer
9373 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9374 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9375 if (!pass) {
9376 vkDestroyBuffer(m_device->device(), buffer, NULL);
9377 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9378 vkFreeMemory(m_device->device(), mem, NULL);
9379 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9380 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9381 return;
9382 }
9383 VkDeviceMemory storage_texel_buffer_mem;
9384 VkBufferView storage_texel_buffer_view;
9385 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9386 ASSERT_VK_SUCCESS(err);
9387 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9388 ASSERT_VK_SUCCESS(err);
9389 buff_view_ci.buffer = storage_texel_buffer;
9390 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9391 ASSERT_VK_SUCCESS(err);
9392
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009393 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009394 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009395 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009396 image_ci.format = VK_FORMAT_UNDEFINED;
9397 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9398 VkFormat format = static_cast<VkFormat>(f);
9399 VkFormatProperties fProps = m_device->format_properties(format);
9400 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9401 image_ci.format = format;
9402 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9403 break;
9404 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9405 image_ci.format = format;
9406 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9407 break;
9408 }
9409 }
9410 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9411 return;
9412 }
9413
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009414 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9415 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009416 image_ci.extent.width = 64;
9417 image_ci.extent.height = 64;
9418 image_ci.extent.depth = 1;
9419 image_ci.mipLevels = 1;
9420 image_ci.arrayLayers = 1;
9421 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009422 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009423 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009424 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9425 VkImage image;
9426 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9427 ASSERT_VK_SUCCESS(err);
9428 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009429 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009430
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009431 VkMemoryAllocateInfo mem_alloc = {};
9432 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9433 mem_alloc.pNext = NULL;
9434 mem_alloc.allocationSize = 0;
9435 mem_alloc.memoryTypeIndex = 0;
9436 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9437 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009438 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009439 ASSERT_TRUE(pass);
9440 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9441 ASSERT_VK_SUCCESS(err);
9442 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9443 ASSERT_VK_SUCCESS(err);
9444 // Now create view for image
9445 VkImageViewCreateInfo image_view_ci = {};
9446 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9447 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009448 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009449 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9450 image_view_ci.subresourceRange.layerCount = 1;
9451 image_view_ci.subresourceRange.baseArrayLayer = 0;
9452 image_view_ci.subresourceRange.levelCount = 1;
9453 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9454 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009455 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009456 ASSERT_VK_SUCCESS(err);
9457
9458 VkDescriptorBufferInfo buff_info = {};
9459 buff_info.buffer = buffer;
9460 VkDescriptorImageInfo img_info = {};
9461 img_info.imageView = image_view;
9462 VkWriteDescriptorSet descriptor_write = {};
9463 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9464 descriptor_write.dstBinding = 0;
9465 descriptor_write.descriptorCount = 1;
9466 descriptor_write.pTexelBufferView = &buff_view;
9467 descriptor_write.pBufferInfo = &buff_info;
9468 descriptor_write.pImageInfo = &img_info;
9469
9470 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009471 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009472 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9473 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9474 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9475 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9476 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9477 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9478 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9479 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9480 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9481 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9482 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009483 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009484 // Start loop at 1 as SAMPLER desc type has no usage bit error
9485 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009486 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9487 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9488 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9489 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009490 descriptor_write.descriptorType = VkDescriptorType(i);
9491 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009493
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009494 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009495
9496 m_errorMonitor->VerifyFound();
9497 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009498 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9499 descriptor_write.pTexelBufferView = &buff_view;
9500 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009501 }
Tony Barbour415497c2017-01-24 10:06:09 -07009502
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009503 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9504 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009505 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009506 vkDestroyImageView(m_device->device(), image_view, NULL);
9507 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009508 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009509 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009510 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009511 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009512 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009513 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9514}
9515
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009516TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009517 TEST_DESCRIPTION(
9518 "Attempt to update buffer descriptor set that has incorrect "
9519 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9520 "1. offset value greater than buffer size\n"
9521 "2. range value of 0\n"
9522 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009523 VkResult err;
9524
9525 ASSERT_NO_FATAL_FAILURE(InitState());
9526 VkDescriptorPoolSize ds_type_count = {};
9527 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9528 ds_type_count.descriptorCount = 1;
9529
9530 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9531 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9532 ds_pool_ci.pNext = NULL;
9533 ds_pool_ci.maxSets = 1;
9534 ds_pool_ci.poolSizeCount = 1;
9535 ds_pool_ci.pPoolSizes = &ds_type_count;
9536
9537 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009538 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009539 ASSERT_VK_SUCCESS(err);
9540
9541 // Create layout with single uniform buffer descriptor
9542 VkDescriptorSetLayoutBinding dsl_binding = {};
9543 dsl_binding.binding = 0;
9544 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9545 dsl_binding.descriptorCount = 1;
9546 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9547 dsl_binding.pImmutableSamplers = NULL;
9548
9549 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9550 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9551 ds_layout_ci.pNext = NULL;
9552 ds_layout_ci.bindingCount = 1;
9553 ds_layout_ci.pBindings = &dsl_binding;
9554 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009555 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009556 ASSERT_VK_SUCCESS(err);
9557
9558 VkDescriptorSet descriptor_set = {};
9559 VkDescriptorSetAllocateInfo alloc_info = {};
9560 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9561 alloc_info.descriptorSetCount = 1;
9562 alloc_info.descriptorPool = ds_pool;
9563 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009564 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009565 ASSERT_VK_SUCCESS(err);
9566
9567 // Create a buffer to be used for invalid updates
9568 VkBufferCreateInfo buff_ci = {};
9569 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9570 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9571 buff_ci.size = 256;
9572 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9573 VkBuffer buffer;
9574 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9575 ASSERT_VK_SUCCESS(err);
9576 // Have to bind memory to buffer before descriptor update
9577 VkMemoryAllocateInfo mem_alloc = {};
9578 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9579 mem_alloc.pNext = NULL;
9580 mem_alloc.allocationSize = 256;
9581 mem_alloc.memoryTypeIndex = 0;
9582
9583 VkMemoryRequirements mem_reqs;
9584 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009585 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009586 if (!pass) {
9587 vkDestroyBuffer(m_device->device(), buffer, NULL);
9588 return;
9589 }
9590
9591 VkDeviceMemory mem;
9592 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9593 ASSERT_VK_SUCCESS(err);
9594 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9595 ASSERT_VK_SUCCESS(err);
9596
9597 VkDescriptorBufferInfo buff_info = {};
9598 buff_info.buffer = buffer;
9599 // First make offset 1 larger than buffer size
9600 buff_info.offset = 257;
9601 buff_info.range = VK_WHOLE_SIZE;
9602 VkWriteDescriptorSet descriptor_write = {};
9603 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9604 descriptor_write.dstBinding = 0;
9605 descriptor_write.descriptorCount = 1;
9606 descriptor_write.pTexelBufferView = nullptr;
9607 descriptor_write.pBufferInfo = &buff_info;
9608 descriptor_write.pImageInfo = nullptr;
9609
9610 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9611 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009613
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009614 m_errorMonitor->SetUnexpectedError(
9615 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9616 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009617 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9618
9619 m_errorMonitor->VerifyFound();
9620 // Now cause error due to range of 0
9621 buff_info.offset = 0;
9622 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009624
9625 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9626
9627 m_errorMonitor->VerifyFound();
9628 // Now cause error due to range exceeding buffer size - offset
9629 buff_info.offset = 128;
9630 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009632
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009633 m_errorMonitor->SetUnexpectedError(
9634 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9635 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009636 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9637
9638 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009639 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009640 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9641 vkDestroyBuffer(m_device->device(), buffer, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009642 m_errorMonitor->SetUnexpectedError(
9643 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009644 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9645 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9646}
9647
Tobin Ehlis845887e2017-02-02 19:01:44 -07009648TEST_F(VkLayerTest, DSBufferLimitErrors) {
9649 TEST_DESCRIPTION(
9650 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9651 "Test cases include:\n"
9652 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9653 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9654 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9655 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9656 VkResult err;
9657
9658 ASSERT_NO_FATAL_FAILURE(InitState());
9659 VkDescriptorPoolSize ds_type_count[2] = {};
9660 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9661 ds_type_count[0].descriptorCount = 1;
9662 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9663 ds_type_count[1].descriptorCount = 1;
9664
9665 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9666 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9667 ds_pool_ci.pNext = NULL;
9668 ds_pool_ci.maxSets = 1;
9669 ds_pool_ci.poolSizeCount = 2;
9670 ds_pool_ci.pPoolSizes = ds_type_count;
9671
9672 VkDescriptorPool ds_pool;
9673 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9674 ASSERT_VK_SUCCESS(err);
9675
9676 // Create layout with single uniform buffer & single storage buffer descriptor
9677 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9678 dsl_binding[0].binding = 0;
9679 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9680 dsl_binding[0].descriptorCount = 1;
9681 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9682 dsl_binding[0].pImmutableSamplers = NULL;
9683 dsl_binding[1].binding = 1;
9684 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9685 dsl_binding[1].descriptorCount = 1;
9686 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9687 dsl_binding[1].pImmutableSamplers = NULL;
9688
9689 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9690 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9691 ds_layout_ci.pNext = NULL;
9692 ds_layout_ci.bindingCount = 2;
9693 ds_layout_ci.pBindings = dsl_binding;
9694 VkDescriptorSetLayout ds_layout;
9695 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9696 ASSERT_VK_SUCCESS(err);
9697
9698 VkDescriptorSet descriptor_set = {};
9699 VkDescriptorSetAllocateInfo alloc_info = {};
9700 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9701 alloc_info.descriptorSetCount = 1;
9702 alloc_info.descriptorPool = ds_pool;
9703 alloc_info.pSetLayouts = &ds_layout;
9704 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9705 ASSERT_VK_SUCCESS(err);
9706
9707 // Create a buffer to be used for invalid updates
9708 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9709 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9710 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9711 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9712 VkBufferCreateInfo ub_ci = {};
9713 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9714 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9715 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9716 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9717 VkBuffer uniform_buffer;
9718 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9719 ASSERT_VK_SUCCESS(err);
9720 VkBufferCreateInfo sb_ci = {};
9721 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9722 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9723 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9724 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9725 VkBuffer storage_buffer;
9726 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9727 ASSERT_VK_SUCCESS(err);
9728 // Have to bind memory to buffer before descriptor update
9729 VkMemoryAllocateInfo mem_alloc = {};
9730 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9731 mem_alloc.pNext = NULL;
9732 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9733 mem_alloc.memoryTypeIndex = 0;
9734
9735 VkMemoryRequirements mem_reqs;
9736 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &mem_reqs);
9737 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9738 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &mem_reqs);
9739 pass &= m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9740 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009741 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009742 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009743 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9744 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009745 return;
9746 }
9747
9748 VkDeviceMemory mem;
9749 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009750 if (VK_SUCCESS != err) {
9751 printf("Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
9752 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9753 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9754 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9755 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9756 return;
9757 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009758 ASSERT_VK_SUCCESS(err);
9759 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9760 ASSERT_VK_SUCCESS(err);
9761 auto sb_offset = ub_ci.size + 1024;
9762 // Verify offset alignment, I know there's a bit trick to do this but it escapes me
9763 sb_offset = (sb_offset % mem_reqs.alignment) ? sb_offset - (sb_offset % mem_reqs.alignment) : sb_offset;
9764 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9765 ASSERT_VK_SUCCESS(err);
9766
9767 VkDescriptorBufferInfo buff_info = {};
9768 buff_info.buffer = uniform_buffer;
9769 buff_info.range = ub_ci.size; // This will exceed limit
9770 VkWriteDescriptorSet descriptor_write = {};
9771 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9772 descriptor_write.dstBinding = 0;
9773 descriptor_write.descriptorCount = 1;
9774 descriptor_write.pTexelBufferView = nullptr;
9775 descriptor_write.pBufferInfo = &buff_info;
9776 descriptor_write.pImageInfo = nullptr;
9777
9778 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9779 descriptor_write.dstSet = descriptor_set;
9780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9781 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9782 m_errorMonitor->VerifyFound();
9783
9784 // Reduce size of range to acceptable limit & cause offset error
9785 buff_info.range = max_ub_range;
9786 buff_info.offset = min_ub_align - 1;
9787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9788 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9789 m_errorMonitor->VerifyFound();
9790
9791 // Now break storage updates
9792 buff_info.buffer = storage_buffer;
9793 buff_info.range = sb_ci.size; // This will exceed limit
9794 buff_info.offset = 0; // Reset offset for this update
9795
9796 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9797 descriptor_write.dstBinding = 1;
9798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9799 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9800 m_errorMonitor->VerifyFound();
9801
9802 // Reduce size of range to acceptable limit & cause offset error
9803 buff_info.range = max_sb_range;
9804 buff_info.offset = min_sb_align - 1;
9805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9806 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9807 m_errorMonitor->VerifyFound();
9808
9809 vkFreeMemory(m_device->device(), mem, NULL);
9810 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9811 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9812 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9813 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9814}
9815
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009816TEST_F(VkLayerTest, DSAspectBitsErrors) {
9817 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9818 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009819 TEST_DESCRIPTION(
9820 "Attempt to update descriptor sets for images "
9821 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009822 VkResult err;
9823
9824 ASSERT_NO_FATAL_FAILURE(InitState());
9825 VkDescriptorPoolSize ds_type_count = {};
9826 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9827 ds_type_count.descriptorCount = 1;
9828
9829 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9830 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9831 ds_pool_ci.pNext = NULL;
9832 ds_pool_ci.maxSets = 5;
9833 ds_pool_ci.poolSizeCount = 1;
9834 ds_pool_ci.pPoolSizes = &ds_type_count;
9835
9836 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009837 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009838 ASSERT_VK_SUCCESS(err);
9839
9840 VkDescriptorSetLayoutBinding dsl_binding = {};
9841 dsl_binding.binding = 0;
9842 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9843 dsl_binding.descriptorCount = 1;
9844 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9845 dsl_binding.pImmutableSamplers = NULL;
9846
9847 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9848 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9849 ds_layout_ci.pNext = NULL;
9850 ds_layout_ci.bindingCount = 1;
9851 ds_layout_ci.pBindings = &dsl_binding;
9852 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009853 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009854 ASSERT_VK_SUCCESS(err);
9855
9856 VkDescriptorSet descriptor_set = {};
9857 VkDescriptorSetAllocateInfo alloc_info = {};
9858 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9859 alloc_info.descriptorSetCount = 1;
9860 alloc_info.descriptorPool = ds_pool;
9861 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009862 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009863 ASSERT_VK_SUCCESS(err);
9864
9865 // Create an image to be used for invalid updates
9866 VkImageCreateInfo image_ci = {};
9867 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9868 image_ci.imageType = VK_IMAGE_TYPE_2D;
9869 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9870 image_ci.extent.width = 64;
9871 image_ci.extent.height = 64;
9872 image_ci.extent.depth = 1;
9873 image_ci.mipLevels = 1;
9874 image_ci.arrayLayers = 1;
9875 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9876 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9877 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9878 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9879 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9880 VkImage image;
9881 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9882 ASSERT_VK_SUCCESS(err);
9883 // Bind memory to image
9884 VkMemoryRequirements mem_reqs;
9885 VkDeviceMemory image_mem;
9886 bool pass;
9887 VkMemoryAllocateInfo mem_alloc = {};
9888 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9889 mem_alloc.pNext = NULL;
9890 mem_alloc.allocationSize = 0;
9891 mem_alloc.memoryTypeIndex = 0;
9892 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9893 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009894 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009895 ASSERT_TRUE(pass);
9896 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9897 ASSERT_VK_SUCCESS(err);
9898 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9899 ASSERT_VK_SUCCESS(err);
9900 // Now create view for image
9901 VkImageViewCreateInfo image_view_ci = {};
9902 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9903 image_view_ci.image = image;
9904 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9905 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9906 image_view_ci.subresourceRange.layerCount = 1;
9907 image_view_ci.subresourceRange.baseArrayLayer = 0;
9908 image_view_ci.subresourceRange.levelCount = 1;
9909 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009910 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009911
9912 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009913 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009914 ASSERT_VK_SUCCESS(err);
9915
9916 VkDescriptorImageInfo img_info = {};
9917 img_info.imageView = image_view;
9918 VkWriteDescriptorSet descriptor_write = {};
9919 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9920 descriptor_write.dstBinding = 0;
9921 descriptor_write.descriptorCount = 1;
9922 descriptor_write.pTexelBufferView = NULL;
9923 descriptor_write.pBufferInfo = NULL;
9924 descriptor_write.pImageInfo = &img_info;
9925 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9926 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009927 const char *error_msg =
9928 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9929 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009931
9932 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9933
9934 m_errorMonitor->VerifyFound();
9935 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9936 vkDestroyImage(m_device->device(), image, NULL);
9937 vkFreeMemory(m_device->device(), image_mem, NULL);
9938 vkDestroyImageView(m_device->device(), image_view, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009939 m_errorMonitor->SetUnexpectedError(
9940 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009941 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9942 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9943}
9944
Karl Schultz6addd812016-02-02 17:17:23 -07009945TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009946 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009947 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009948
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9950 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9951 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009952
Tobin Ehlis3b780662015-05-28 12:11:26 -06009953 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009954 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009955 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009956 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9957 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009958
9959 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009960 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9961 ds_pool_ci.pNext = NULL;
9962 ds_pool_ci.maxSets = 1;
9963 ds_pool_ci.poolSizeCount = 1;
9964 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009965
Tobin Ehlis3b780662015-05-28 12:11:26 -06009966 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009967 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009968 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009969 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009970 dsl_binding.binding = 0;
9971 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9972 dsl_binding.descriptorCount = 1;
9973 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9974 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009975
Tony Barboureb254902015-07-15 12:50:33 -06009976 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009977 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9978 ds_layout_ci.pNext = NULL;
9979 ds_layout_ci.bindingCount = 1;
9980 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009981
Tobin Ehlis3b780662015-05-28 12:11:26 -06009982 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009983 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009984 ASSERT_VK_SUCCESS(err);
9985
9986 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009987 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009988 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009989 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009990 alloc_info.descriptorPool = ds_pool;
9991 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009992 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009993 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009994
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009995 VkSamplerCreateInfo sampler_ci = {};
9996 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9997 sampler_ci.pNext = NULL;
9998 sampler_ci.magFilter = VK_FILTER_NEAREST;
9999 sampler_ci.minFilter = VK_FILTER_NEAREST;
10000 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10001 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10002 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10003 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10004 sampler_ci.mipLodBias = 1.0;
10005 sampler_ci.anisotropyEnable = VK_FALSE;
10006 sampler_ci.maxAnisotropy = 1;
10007 sampler_ci.compareEnable = VK_FALSE;
10008 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10009 sampler_ci.minLod = 1.0;
10010 sampler_ci.maxLod = 1.0;
10011 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10012 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10013 VkSampler sampler;
10014 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10015 ASSERT_VK_SUCCESS(err);
10016
10017 VkDescriptorImageInfo info = {};
10018 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010019
10020 VkWriteDescriptorSet descriptor_write;
10021 memset(&descriptor_write, 0, sizeof(descriptor_write));
10022 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010023 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010024 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010025 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010026 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010027 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010028
10029 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10030
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010031 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010032
Chia-I Wuf7458c52015-10-26 21:10:41 +080010033 vkDestroySampler(m_device->device(), sampler, NULL);
10034 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10035 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010036}
10037
Karl Schultz6addd812016-02-02 17:17:23 -070010038TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010039 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010040 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010041
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010043
Tobin Ehlis3b780662015-05-28 12:11:26 -060010044 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010045 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010046 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010047 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10048 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010049
10050 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010051 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10052 ds_pool_ci.pNext = NULL;
10053 ds_pool_ci.maxSets = 1;
10054 ds_pool_ci.poolSizeCount = 1;
10055 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010056
Tobin Ehlis3b780662015-05-28 12:11:26 -060010057 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010058 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010059 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010060
Tony Barboureb254902015-07-15 12:50:33 -060010061 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010062 dsl_binding.binding = 0;
10063 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10064 dsl_binding.descriptorCount = 1;
10065 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10066 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010067
10068 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010069 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10070 ds_layout_ci.pNext = NULL;
10071 ds_layout_ci.bindingCount = 1;
10072 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010073
Tobin Ehlis3b780662015-05-28 12:11:26 -060010074 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010075 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010076 ASSERT_VK_SUCCESS(err);
10077
10078 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010079 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010080 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010081 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010082 alloc_info.descriptorPool = ds_pool;
10083 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010084 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010085 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010086
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010087 // Correctly update descriptor to avoid "NOT_UPDATED" error
10088 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010089 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010090 buff_info.offset = 0;
10091 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010092
10093 VkWriteDescriptorSet descriptor_write;
10094 memset(&descriptor_write, 0, sizeof(descriptor_write));
10095 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010096 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010097 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010098 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010099 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10100 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010101
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010102 m_errorMonitor->SetUnexpectedError("required parameter pDescriptorWrites");
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010103 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10104
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010105 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010106
Chia-I Wuf7458c52015-10-26 21:10:41 +080010107 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10108 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010109}
10110
Karl Schultz6addd812016-02-02 17:17:23 -070010111TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010112 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010113 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010114
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010116
Tobin Ehlis3b780662015-05-28 12:11:26 -060010117 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010118 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010119 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010120 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10121 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010122
10123 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010124 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10125 ds_pool_ci.pNext = NULL;
10126 ds_pool_ci.maxSets = 1;
10127 ds_pool_ci.poolSizeCount = 1;
10128 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010129
Tobin Ehlis3b780662015-05-28 12:11:26 -060010130 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010131 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010132 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010133
Tony Barboureb254902015-07-15 12:50:33 -060010134 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010135 dsl_binding.binding = 0;
10136 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10137 dsl_binding.descriptorCount = 1;
10138 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10139 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010140
10141 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010142 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10143 ds_layout_ci.pNext = NULL;
10144 ds_layout_ci.bindingCount = 1;
10145 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010146 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010147 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010148 ASSERT_VK_SUCCESS(err);
10149
10150 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010151 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010152 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010153 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010154 alloc_info.descriptorPool = ds_pool;
10155 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010156 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010157 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010158
Tony Barboureb254902015-07-15 12:50:33 -060010159 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010160 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10161 sampler_ci.pNext = NULL;
10162 sampler_ci.magFilter = VK_FILTER_NEAREST;
10163 sampler_ci.minFilter = VK_FILTER_NEAREST;
10164 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10165 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10166 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10167 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10168 sampler_ci.mipLodBias = 1.0;
10169 sampler_ci.anisotropyEnable = VK_FALSE;
10170 sampler_ci.maxAnisotropy = 1;
10171 sampler_ci.compareEnable = VK_FALSE;
10172 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10173 sampler_ci.minLod = 1.0;
10174 sampler_ci.maxLod = 1.0;
10175 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10176 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010177
Tobin Ehlis3b780662015-05-28 12:11:26 -060010178 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010179 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010180 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010181
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010182 VkDescriptorImageInfo info = {};
10183 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010184
10185 VkWriteDescriptorSet descriptor_write;
10186 memset(&descriptor_write, 0, sizeof(descriptor_write));
10187 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010188 descriptor_write.dstSet = descriptorSet;
10189 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010190 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010191 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010192 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010193 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010194
10195 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10196
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010197 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010198
Chia-I Wuf7458c52015-10-26 21:10:41 +080010199 vkDestroySampler(m_device->device(), sampler, NULL);
10200 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10201 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010202}
10203
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010204TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10205 // Create layout w/ empty binding and attempt to update it
10206 VkResult err;
10207
10208 ASSERT_NO_FATAL_FAILURE(InitState());
10209
10210 VkDescriptorPoolSize ds_type_count = {};
10211 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10212 ds_type_count.descriptorCount = 1;
10213
10214 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10215 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10216 ds_pool_ci.pNext = NULL;
10217 ds_pool_ci.maxSets = 1;
10218 ds_pool_ci.poolSizeCount = 1;
10219 ds_pool_ci.pPoolSizes = &ds_type_count;
10220
10221 VkDescriptorPool ds_pool;
10222 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10223 ASSERT_VK_SUCCESS(err);
10224
10225 VkDescriptorSetLayoutBinding dsl_binding = {};
10226 dsl_binding.binding = 0;
10227 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10228 dsl_binding.descriptorCount = 0;
10229 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10230 dsl_binding.pImmutableSamplers = NULL;
10231
10232 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10233 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10234 ds_layout_ci.pNext = NULL;
10235 ds_layout_ci.bindingCount = 1;
10236 ds_layout_ci.pBindings = &dsl_binding;
10237 VkDescriptorSetLayout ds_layout;
10238 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10239 ASSERT_VK_SUCCESS(err);
10240
10241 VkDescriptorSet descriptor_set;
10242 VkDescriptorSetAllocateInfo alloc_info = {};
10243 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10244 alloc_info.descriptorSetCount = 1;
10245 alloc_info.descriptorPool = ds_pool;
10246 alloc_info.pSetLayouts = &ds_layout;
10247 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10248 ASSERT_VK_SUCCESS(err);
10249
10250 VkSamplerCreateInfo sampler_ci = {};
10251 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10252 sampler_ci.magFilter = VK_FILTER_NEAREST;
10253 sampler_ci.minFilter = VK_FILTER_NEAREST;
10254 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10255 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10256 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10257 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10258 sampler_ci.mipLodBias = 1.0;
10259 sampler_ci.maxAnisotropy = 1;
10260 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10261 sampler_ci.minLod = 1.0;
10262 sampler_ci.maxLod = 1.0;
10263 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10264
10265 VkSampler sampler;
10266 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10267 ASSERT_VK_SUCCESS(err);
10268
10269 VkDescriptorImageInfo info = {};
10270 info.sampler = sampler;
10271
10272 VkWriteDescriptorSet descriptor_write;
10273 memset(&descriptor_write, 0, sizeof(descriptor_write));
10274 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10275 descriptor_write.dstSet = descriptor_set;
10276 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010277 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010278 // This is the wrong type, but empty binding error will be flagged first
10279 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10280 descriptor_write.pImageInfo = &info;
10281
10282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10283 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10284 m_errorMonitor->VerifyFound();
10285
10286 vkDestroySampler(m_device->device(), sampler, NULL);
10287 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10288 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10289}
10290
Karl Schultz6addd812016-02-02 17:17:23 -070010291TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10292 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10293 // types
10294 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010296 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 -060010297
Tobin Ehlis3b780662015-05-28 12:11:26 -060010298 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010299
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010300 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010301 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10302 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010303
10304 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010305 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10306 ds_pool_ci.pNext = NULL;
10307 ds_pool_ci.maxSets = 1;
10308 ds_pool_ci.poolSizeCount = 1;
10309 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010310
Tobin Ehlis3b780662015-05-28 12:11:26 -060010311 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010312 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010313 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010314 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010315 dsl_binding.binding = 0;
10316 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10317 dsl_binding.descriptorCount = 1;
10318 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10319 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010320
Tony Barboureb254902015-07-15 12:50:33 -060010321 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010322 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10323 ds_layout_ci.pNext = NULL;
10324 ds_layout_ci.bindingCount = 1;
10325 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010326
Tobin Ehlis3b780662015-05-28 12:11:26 -060010327 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010328 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010329 ASSERT_VK_SUCCESS(err);
10330
10331 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010332 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010333 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010334 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010335 alloc_info.descriptorPool = ds_pool;
10336 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010337 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010338 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010339
Tony Barboureb254902015-07-15 12:50:33 -060010340 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010341 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10342 sampler_ci.pNext = NULL;
10343 sampler_ci.magFilter = VK_FILTER_NEAREST;
10344 sampler_ci.minFilter = VK_FILTER_NEAREST;
10345 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10346 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10347 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10348 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10349 sampler_ci.mipLodBias = 1.0;
10350 sampler_ci.anisotropyEnable = VK_FALSE;
10351 sampler_ci.maxAnisotropy = 1;
10352 sampler_ci.compareEnable = VK_FALSE;
10353 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10354 sampler_ci.minLod = 1.0;
10355 sampler_ci.maxLod = 1.0;
10356 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10357 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010358 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010359 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010360 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010361
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010362 VkDescriptorImageInfo info = {};
10363 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010364
10365 VkWriteDescriptorSet descriptor_write;
10366 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010367 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010368 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010369 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010370 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010371 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010372 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010373
10374 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10375
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010376 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010377
Chia-I Wuf7458c52015-10-26 21:10:41 +080010378 vkDestroySampler(m_device->device(), sampler, NULL);
10379 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10380 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010381}
10382
Karl Schultz6addd812016-02-02 17:17:23 -070010383TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010384 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010385 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010386
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010388
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010389 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010390 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10391 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010392 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010393 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10394 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010395
10396 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010397 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10398 ds_pool_ci.pNext = NULL;
10399 ds_pool_ci.maxSets = 1;
10400 ds_pool_ci.poolSizeCount = 1;
10401 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010402
10403 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010404 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010405 ASSERT_VK_SUCCESS(err);
10406
10407 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010408 dsl_binding.binding = 0;
10409 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10410 dsl_binding.descriptorCount = 1;
10411 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10412 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010413
10414 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010415 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10416 ds_layout_ci.pNext = NULL;
10417 ds_layout_ci.bindingCount = 1;
10418 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010419 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010420 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010421 ASSERT_VK_SUCCESS(err);
10422
10423 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010424 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010425 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010426 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010427 alloc_info.descriptorPool = ds_pool;
10428 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010429 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010430 ASSERT_VK_SUCCESS(err);
10431
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010432 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010433
10434 VkDescriptorImageInfo descriptor_info;
10435 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10436 descriptor_info.sampler = sampler;
10437
10438 VkWriteDescriptorSet descriptor_write;
10439 memset(&descriptor_write, 0, sizeof(descriptor_write));
10440 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010441 descriptor_write.dstSet = descriptorSet;
10442 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010443 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010444 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10445 descriptor_write.pImageInfo = &descriptor_info;
10446
10447 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10448
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010449 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010450
Chia-I Wuf7458c52015-10-26 21:10:41 +080010451 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10452 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010453}
10454
Karl Schultz6addd812016-02-02 17:17:23 -070010455TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10456 // Create a single combined Image/Sampler descriptor and send it an invalid
10457 // imageView
10458 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010459
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010461
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010462 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010463 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010464 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10465 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010466
10467 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010468 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10469 ds_pool_ci.pNext = NULL;
10470 ds_pool_ci.maxSets = 1;
10471 ds_pool_ci.poolSizeCount = 1;
10472 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010473
10474 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010475 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010476 ASSERT_VK_SUCCESS(err);
10477
10478 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010479 dsl_binding.binding = 0;
10480 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10481 dsl_binding.descriptorCount = 1;
10482 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10483 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010484
10485 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010486 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10487 ds_layout_ci.pNext = NULL;
10488 ds_layout_ci.bindingCount = 1;
10489 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010490 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010491 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010492 ASSERT_VK_SUCCESS(err);
10493
10494 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010495 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010496 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010497 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010498 alloc_info.descriptorPool = ds_pool;
10499 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010500 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010501 ASSERT_VK_SUCCESS(err);
10502
10503 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010504 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10505 sampler_ci.pNext = NULL;
10506 sampler_ci.magFilter = VK_FILTER_NEAREST;
10507 sampler_ci.minFilter = VK_FILTER_NEAREST;
10508 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10509 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10510 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10511 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10512 sampler_ci.mipLodBias = 1.0;
10513 sampler_ci.anisotropyEnable = VK_FALSE;
10514 sampler_ci.maxAnisotropy = 1;
10515 sampler_ci.compareEnable = VK_FALSE;
10516 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10517 sampler_ci.minLod = 1.0;
10518 sampler_ci.maxLod = 1.0;
10519 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10520 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010521
10522 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010523 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010524 ASSERT_VK_SUCCESS(err);
10525
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010526 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010527
10528 VkDescriptorImageInfo descriptor_info;
10529 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10530 descriptor_info.sampler = sampler;
10531 descriptor_info.imageView = view;
10532
10533 VkWriteDescriptorSet descriptor_write;
10534 memset(&descriptor_write, 0, sizeof(descriptor_write));
10535 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010536 descriptor_write.dstSet = descriptorSet;
10537 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010538 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010539 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10540 descriptor_write.pImageInfo = &descriptor_info;
10541
10542 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10543
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010544 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010545
Chia-I Wuf7458c52015-10-26 21:10:41 +080010546 vkDestroySampler(m_device->device(), sampler, NULL);
10547 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10548 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010549}
10550
Karl Schultz6addd812016-02-02 17:17:23 -070010551TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10552 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10553 // into the other
10554 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010555
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10557 " binding #1 with type "
10558 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10559 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010560
Tobin Ehlis04356f92015-10-27 16:35:27 -060010561 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010562 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010563 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010564 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10565 ds_type_count[0].descriptorCount = 1;
10566 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10567 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010568
10569 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010570 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10571 ds_pool_ci.pNext = NULL;
10572 ds_pool_ci.maxSets = 1;
10573 ds_pool_ci.poolSizeCount = 2;
10574 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010575
10576 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010577 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010578 ASSERT_VK_SUCCESS(err);
10579 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010580 dsl_binding[0].binding = 0;
10581 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10582 dsl_binding[0].descriptorCount = 1;
10583 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10584 dsl_binding[0].pImmutableSamplers = NULL;
10585 dsl_binding[1].binding = 1;
10586 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10587 dsl_binding[1].descriptorCount = 1;
10588 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10589 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010590
10591 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010592 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10593 ds_layout_ci.pNext = NULL;
10594 ds_layout_ci.bindingCount = 2;
10595 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010596
10597 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010598 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010599 ASSERT_VK_SUCCESS(err);
10600
10601 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010602 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010603 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010604 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010605 alloc_info.descriptorPool = ds_pool;
10606 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010607 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010608 ASSERT_VK_SUCCESS(err);
10609
10610 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010611 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10612 sampler_ci.pNext = NULL;
10613 sampler_ci.magFilter = VK_FILTER_NEAREST;
10614 sampler_ci.minFilter = VK_FILTER_NEAREST;
10615 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10616 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10617 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10618 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10619 sampler_ci.mipLodBias = 1.0;
10620 sampler_ci.anisotropyEnable = VK_FALSE;
10621 sampler_ci.maxAnisotropy = 1;
10622 sampler_ci.compareEnable = VK_FALSE;
10623 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10624 sampler_ci.minLod = 1.0;
10625 sampler_ci.maxLod = 1.0;
10626 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10627 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010628
10629 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010630 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010631 ASSERT_VK_SUCCESS(err);
10632
10633 VkDescriptorImageInfo info = {};
10634 info.sampler = sampler;
10635
10636 VkWriteDescriptorSet descriptor_write;
10637 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10638 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010639 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010640 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010641 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010642 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10643 descriptor_write.pImageInfo = &info;
10644 // This write update should succeed
10645 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10646 // Now perform a copy update that fails due to type mismatch
10647 VkCopyDescriptorSet copy_ds_update;
10648 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10649 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10650 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010651 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010652 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010653 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10654 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010655 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10656
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010657 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010658 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010659 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 -060010660 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10661 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10662 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010663 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010664 copy_ds_update.dstSet = descriptorSet;
10665 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010666 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010667 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10668
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010669 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010670
Tobin Ehlis04356f92015-10-27 16:35:27 -060010671 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10673 " binding#1 with offset index of 1 plus "
10674 "update array offset of 0 and update of "
10675 "5 descriptors oversteps total number "
10676 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010677
Tobin Ehlis04356f92015-10-27 16:35:27 -060010678 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10679 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10680 copy_ds_update.srcSet = descriptorSet;
10681 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010682 copy_ds_update.dstSet = descriptorSet;
10683 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010684 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010685 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10686
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010687 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010688
Chia-I Wuf7458c52015-10-26 21:10:41 +080010689 vkDestroySampler(m_device->device(), sampler, NULL);
10690 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10691 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010692}
10693
Karl Schultz6addd812016-02-02 17:17:23 -070010694TEST_F(VkLayerTest, NumSamplesMismatch) {
10695 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10696 // sampleCount
10697 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010698
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010700
Tobin Ehlis3b780662015-05-28 12:11:26 -060010701 ASSERT_NO_FATAL_FAILURE(InitState());
10702 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010703 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010704 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010705 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010706
10707 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010708 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10709 ds_pool_ci.pNext = NULL;
10710 ds_pool_ci.maxSets = 1;
10711 ds_pool_ci.poolSizeCount = 1;
10712 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010713
Tobin Ehlis3b780662015-05-28 12:11:26 -060010714 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010715 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010716 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010717
Tony Barboureb254902015-07-15 12:50:33 -060010718 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010719 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010720 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010721 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010722 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10723 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010724
Tony Barboureb254902015-07-15 12:50:33 -060010725 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10726 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10727 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010728 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010729 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010730
Tobin Ehlis3b780662015-05-28 12:11:26 -060010731 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010732 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010733 ASSERT_VK_SUCCESS(err);
10734
10735 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010736 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010737 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010738 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010739 alloc_info.descriptorPool = ds_pool;
10740 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010741 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010742 ASSERT_VK_SUCCESS(err);
10743
Tony Barboureb254902015-07-15 12:50:33 -060010744 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010745 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010746 pipe_ms_state_ci.pNext = NULL;
10747 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10748 pipe_ms_state_ci.sampleShadingEnable = 0;
10749 pipe_ms_state_ci.minSampleShading = 1.0;
10750 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010751
Tony Barboureb254902015-07-15 12:50:33 -060010752 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010753 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10754 pipeline_layout_ci.pNext = NULL;
10755 pipeline_layout_ci.setLayoutCount = 1;
10756 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010757
10758 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010759 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010760 ASSERT_VK_SUCCESS(err);
10761
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010762 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010763 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 -060010764 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010765 VkPipelineObj pipe(m_device);
10766 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010767 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010768 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010769 pipe.SetMSAA(&pipe_ms_state_ci);
10770 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010771
Tony Barbour552f6c02016-12-21 14:34:07 -070010772 m_commandBuffer->BeginCommandBuffer();
10773 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010774 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010775
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010776 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10777 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10778 VkRect2D scissor = {{0, 0}, {16, 16}};
10779 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10780
Mark Young29927482016-05-04 14:38:51 -060010781 // Render triangle (the error should trigger on the attempt to draw).
10782 Draw(3, 1, 0, 0);
10783
10784 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010785 m_commandBuffer->EndRenderPass();
10786 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010787
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010788 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010789
Chia-I Wuf7458c52015-10-26 21:10:41 +080010790 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10791 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10792 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010793}
Mark Young29927482016-05-04 14:38:51 -060010794
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010795TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010796 TEST_DESCRIPTION(
10797 "Hit RenderPass incompatible cases. "
10798 "Initial case is drawing with an active renderpass that's "
10799 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010800 VkResult err;
10801
10802 ASSERT_NO_FATAL_FAILURE(InitState());
10803 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10804
10805 VkDescriptorSetLayoutBinding dsl_binding = {};
10806 dsl_binding.binding = 0;
10807 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10808 dsl_binding.descriptorCount = 1;
10809 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10810 dsl_binding.pImmutableSamplers = NULL;
10811
10812 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10813 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10814 ds_layout_ci.pNext = NULL;
10815 ds_layout_ci.bindingCount = 1;
10816 ds_layout_ci.pBindings = &dsl_binding;
10817
10818 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010819 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010820 ASSERT_VK_SUCCESS(err);
10821
10822 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10823 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10824 pipeline_layout_ci.pNext = NULL;
10825 pipeline_layout_ci.setLayoutCount = 1;
10826 pipeline_layout_ci.pSetLayouts = &ds_layout;
10827
10828 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010829 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010830 ASSERT_VK_SUCCESS(err);
10831
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010832 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010833 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 -060010834 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010835 // Create a renderpass that will be incompatible with default renderpass
10836 VkAttachmentReference attach = {};
10837 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10838 VkAttachmentReference color_att = {};
10839 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10840 VkSubpassDescription subpass = {};
10841 subpass.inputAttachmentCount = 1;
10842 subpass.pInputAttachments = &attach;
10843 subpass.colorAttachmentCount = 1;
10844 subpass.pColorAttachments = &color_att;
10845 VkRenderPassCreateInfo rpci = {};
10846 rpci.subpassCount = 1;
10847 rpci.pSubpasses = &subpass;
10848 rpci.attachmentCount = 1;
10849 VkAttachmentDescription attach_desc = {};
10850 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010851 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10852 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010853 rpci.pAttachments = &attach_desc;
10854 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10855 VkRenderPass rp;
10856 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10857 VkPipelineObj pipe(m_device);
10858 pipe.AddShader(&vs);
10859 pipe.AddShader(&fs);
10860 pipe.AddColorAttachment();
10861 VkViewport view_port = {};
10862 m_viewports.push_back(view_port);
10863 pipe.SetViewport(m_viewports);
10864 VkRect2D rect = {};
10865 m_scissors.push_back(rect);
10866 pipe.SetScissor(m_scissors);
10867 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10868
10869 VkCommandBufferInheritanceInfo cbii = {};
10870 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10871 cbii.renderPass = rp;
10872 cbii.subpass = 0;
10873 VkCommandBufferBeginInfo cbbi = {};
10874 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10875 cbbi.pInheritanceInfo = &cbii;
10876 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10877 VkRenderPassBeginInfo rpbi = {};
10878 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10879 rpbi.framebuffer = m_framebuffer;
10880 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010881 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10882 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010883
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010885 // Render triangle (the error should trigger on the attempt to draw).
10886 Draw(3, 1, 0, 0);
10887
10888 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010889 m_commandBuffer->EndRenderPass();
10890 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010891
10892 m_errorMonitor->VerifyFound();
10893
10894 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10895 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10896 vkDestroyRenderPass(m_device->device(), rp, NULL);
10897}
10898
Mark Youngc89c6312016-03-31 16:03:20 -060010899TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10900 // Create Pipeline where the number of blend attachments doesn't match the
10901 // number of color attachments. In this case, we don't add any color
10902 // blend attachments even though we have a color attachment.
10903 VkResult err;
10904
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010906
10907 ASSERT_NO_FATAL_FAILURE(InitState());
10908 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10909 VkDescriptorPoolSize ds_type_count = {};
10910 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10911 ds_type_count.descriptorCount = 1;
10912
10913 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10914 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10915 ds_pool_ci.pNext = NULL;
10916 ds_pool_ci.maxSets = 1;
10917 ds_pool_ci.poolSizeCount = 1;
10918 ds_pool_ci.pPoolSizes = &ds_type_count;
10919
10920 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010921 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010922 ASSERT_VK_SUCCESS(err);
10923
10924 VkDescriptorSetLayoutBinding dsl_binding = {};
10925 dsl_binding.binding = 0;
10926 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10927 dsl_binding.descriptorCount = 1;
10928 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10929 dsl_binding.pImmutableSamplers = NULL;
10930
10931 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10932 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10933 ds_layout_ci.pNext = NULL;
10934 ds_layout_ci.bindingCount = 1;
10935 ds_layout_ci.pBindings = &dsl_binding;
10936
10937 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010938 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010939 ASSERT_VK_SUCCESS(err);
10940
10941 VkDescriptorSet descriptorSet;
10942 VkDescriptorSetAllocateInfo alloc_info = {};
10943 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10944 alloc_info.descriptorSetCount = 1;
10945 alloc_info.descriptorPool = ds_pool;
10946 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010947 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010948 ASSERT_VK_SUCCESS(err);
10949
10950 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010951 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010952 pipe_ms_state_ci.pNext = NULL;
10953 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10954 pipe_ms_state_ci.sampleShadingEnable = 0;
10955 pipe_ms_state_ci.minSampleShading = 1.0;
10956 pipe_ms_state_ci.pSampleMask = NULL;
10957
10958 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10959 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10960 pipeline_layout_ci.pNext = NULL;
10961 pipeline_layout_ci.setLayoutCount = 1;
10962 pipeline_layout_ci.pSetLayouts = &ds_layout;
10963
10964 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010965 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010966 ASSERT_VK_SUCCESS(err);
10967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010968 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010969 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 -060010970 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010971 VkPipelineObj pipe(m_device);
10972 pipe.AddShader(&vs);
10973 pipe.AddShader(&fs);
10974 pipe.SetMSAA(&pipe_ms_state_ci);
10975 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010976 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010977
10978 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10979 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10980 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10981}
Mark Young29927482016-05-04 14:38:51 -060010982
Mark Muellerd4914412016-06-13 17:52:06 -060010983TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010984 TEST_DESCRIPTION(
10985 "Points to a wrong colorAttachment index in a VkClearAttachment "
10986 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010987 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010989
10990 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10991 m_errorMonitor->VerifyFound();
10992}
10993
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010994TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010995 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10996 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010997
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010998 ASSERT_NO_FATAL_FAILURE(InitState());
10999 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011000
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011001 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011002 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11003 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011004
11005 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011006 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11007 ds_pool_ci.pNext = NULL;
11008 ds_pool_ci.maxSets = 1;
11009 ds_pool_ci.poolSizeCount = 1;
11010 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011011
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011012 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011013 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011014 ASSERT_VK_SUCCESS(err);
11015
Tony Barboureb254902015-07-15 12:50:33 -060011016 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011017 dsl_binding.binding = 0;
11018 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11019 dsl_binding.descriptorCount = 1;
11020 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11021 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011022
Tony Barboureb254902015-07-15 12:50:33 -060011023 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011024 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11025 ds_layout_ci.pNext = NULL;
11026 ds_layout_ci.bindingCount = 1;
11027 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011028
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011029 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011030 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011031 ASSERT_VK_SUCCESS(err);
11032
11033 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011034 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011035 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011036 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011037 alloc_info.descriptorPool = ds_pool;
11038 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011039 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011040 ASSERT_VK_SUCCESS(err);
11041
Tony Barboureb254902015-07-15 12:50:33 -060011042 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011043 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011044 pipe_ms_state_ci.pNext = NULL;
11045 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11046 pipe_ms_state_ci.sampleShadingEnable = 0;
11047 pipe_ms_state_ci.minSampleShading = 1.0;
11048 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011049
Tony Barboureb254902015-07-15 12:50:33 -060011050 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011051 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11052 pipeline_layout_ci.pNext = NULL;
11053 pipeline_layout_ci.setLayoutCount = 1;
11054 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011055
11056 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011057 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011058 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011060 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011061 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011062 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011063 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011064
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011065 VkPipelineObj pipe(m_device);
11066 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011067 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011068 pipe.SetMSAA(&pipe_ms_state_ci);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011069 m_errorMonitor->SetUnexpectedError(
11070 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
11071 "used to create subpass");
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011072 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011073
Tony Barbour552f6c02016-12-21 14:34:07 -070011074 m_commandBuffer->BeginCommandBuffer();
11075 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011076
Karl Schultz6addd812016-02-02 17:17:23 -070011077 // Main thing we care about for this test is that the VkImage obj we're
11078 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011079 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011080 VkClearAttachment color_attachment;
11081 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11082 color_attachment.clearValue.color.float32[0] = 1.0;
11083 color_attachment.clearValue.color.float32[1] = 1.0;
11084 color_attachment.clearValue.color.float32[2] = 1.0;
11085 color_attachment.clearValue.color.float32[3] = 1.0;
11086 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011087 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011088
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011089 // Call for full-sized FB Color attachment prior to issuing a Draw
11090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011091 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011092 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011093 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011094
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011095 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11096 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11098 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11099 m_errorMonitor->VerifyFound();
11100
11101 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11102 clear_rect.layerCount = 2;
11103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11104 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011105 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011106
Chia-I Wuf7458c52015-10-26 21:10:41 +080011107 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11108 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11109 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011110}
11111
Karl Schultz6addd812016-02-02 17:17:23 -070011112TEST_F(VkLayerTest, VtxBufferBadIndex) {
11113 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011114
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11116 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011117
Tobin Ehlis502480b2015-06-24 15:53:07 -060011118 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011119 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011121
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011122 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011123 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11124 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011125
11126 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011127 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11128 ds_pool_ci.pNext = NULL;
11129 ds_pool_ci.maxSets = 1;
11130 ds_pool_ci.poolSizeCount = 1;
11131 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011132
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011133 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011134 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011135 ASSERT_VK_SUCCESS(err);
11136
Tony Barboureb254902015-07-15 12:50:33 -060011137 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011138 dsl_binding.binding = 0;
11139 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11140 dsl_binding.descriptorCount = 1;
11141 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11142 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011143
Tony Barboureb254902015-07-15 12:50:33 -060011144 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011145 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11146 ds_layout_ci.pNext = NULL;
11147 ds_layout_ci.bindingCount = 1;
11148 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011149
Tobin Ehlis502480b2015-06-24 15:53:07 -060011150 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011151 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011152 ASSERT_VK_SUCCESS(err);
11153
11154 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011155 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011156 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011157 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011158 alloc_info.descriptorPool = ds_pool;
11159 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011160 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011161 ASSERT_VK_SUCCESS(err);
11162
Tony Barboureb254902015-07-15 12:50:33 -060011163 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011164 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011165 pipe_ms_state_ci.pNext = NULL;
11166 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11167 pipe_ms_state_ci.sampleShadingEnable = 0;
11168 pipe_ms_state_ci.minSampleShading = 1.0;
11169 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011170
Tony Barboureb254902015-07-15 12:50:33 -060011171 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011172 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11173 pipeline_layout_ci.pNext = NULL;
11174 pipeline_layout_ci.setLayoutCount = 1;
11175 pipeline_layout_ci.pSetLayouts = &ds_layout;
11176 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011177
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011178 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011179 ASSERT_VK_SUCCESS(err);
11180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011181 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011182 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 -060011183 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011184 VkPipelineObj pipe(m_device);
11185 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011186 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011187 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011188 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011189 pipe.SetViewport(m_viewports);
11190 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011191 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011192
Tony Barbour552f6c02016-12-21 14:34:07 -070011193 m_commandBuffer->BeginCommandBuffer();
11194 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011195 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011196 // Don't care about actual data, just need to get to draw to flag error
11197 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011198 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011199 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011200 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011201
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011202 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011203
Chia-I Wuf7458c52015-10-26 21:10:41 +080011204 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11205 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11206 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011207}
Mark Muellerdfe37552016-07-07 14:47:42 -060011208
Mark Mueller2ee294f2016-08-04 12:59:48 -060011209TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011210 TEST_DESCRIPTION(
11211 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11212 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011213 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011214
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011215 const char *invalid_queueFamilyIndex_message =
11216 "Invalid queue create request in vkCreateDevice(). Invalid "
11217 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011219 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011220
Mark Mueller880fce52016-08-17 15:23:23 -060011221 // The following test fails with recent NVidia drivers.
11222 // By the time core_validation is reached, the NVidia
11223 // driver has sanitized the invalid condition and core_validation
11224 // is not introduced to the failure condition. This is not the case
11225 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011226 // uint32_t count = static_cast<uint32_t>(~0);
11227 // VkPhysicalDevice physical_device;
11228 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11229 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011232 float queue_priority = 0.0;
11233
11234 VkDeviceQueueCreateInfo queue_create_info = {};
11235 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11236 queue_create_info.queueCount = 1;
11237 queue_create_info.pQueuePriorities = &queue_priority;
11238 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11239
11240 VkPhysicalDeviceFeatures features = m_device->phy().features();
11241 VkDevice testDevice;
11242 VkDeviceCreateInfo device_create_info = {};
11243 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11244 device_create_info.queueCreateInfoCount = 1;
11245 device_create_info.pQueueCreateInfos = &queue_create_info;
11246 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011247 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011248 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11249 m_errorMonitor->VerifyFound();
11250
11251 queue_create_info.queueFamilyIndex = 1;
11252
11253 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11254 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11255 for (unsigned i = 0; i < feature_count; i++) {
11256 if (VK_FALSE == feature_array[i]) {
11257 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011259 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011260 m_errorMonitor->SetUnexpectedError(
11261 "You requested features that are unavailable on this device. You should first query feature availability by "
11262 "calling vkGetPhysicalDeviceFeatures().");
11263 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011264 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11265 m_errorMonitor->VerifyFound();
11266 break;
11267 }
11268 }
11269}
11270
Tobin Ehlis16edf082016-11-21 12:33:49 -070011271TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11272 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11273
11274 ASSERT_NO_FATAL_FAILURE(InitState());
11275
11276 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11277 std::vector<VkDeviceQueueCreateInfo> queue_info;
11278 queue_info.reserve(queue_props.size());
11279 std::vector<std::vector<float>> queue_priorities;
11280 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11281 VkDeviceQueueCreateInfo qi{};
11282 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11283 qi.queueFamilyIndex = i;
11284 qi.queueCount = queue_props[i].queueCount;
11285 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11286 qi.pQueuePriorities = queue_priorities[i].data();
11287 queue_info.push_back(qi);
11288 }
11289
11290 std::vector<const char *> device_extension_names;
11291
11292 VkDevice local_device;
11293 VkDeviceCreateInfo device_create_info = {};
11294 auto features = m_device->phy().features();
11295 // Intentionally disable pipeline stats
11296 features.pipelineStatisticsQuery = VK_FALSE;
11297 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11298 device_create_info.pNext = NULL;
11299 device_create_info.queueCreateInfoCount = queue_info.size();
11300 device_create_info.pQueueCreateInfos = queue_info.data();
11301 device_create_info.enabledLayerCount = 0;
11302 device_create_info.ppEnabledLayerNames = NULL;
11303 device_create_info.pEnabledFeatures = &features;
11304 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11305 ASSERT_VK_SUCCESS(err);
11306
11307 VkQueryPoolCreateInfo qpci{};
11308 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11309 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11310 qpci.queryCount = 1;
11311 VkQueryPool query_pool;
11312
11313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11314 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11315 m_errorMonitor->VerifyFound();
11316
11317 vkDestroyDevice(local_device, nullptr);
11318}
11319
Mark Mueller2ee294f2016-08-04 12:59:48 -060011320TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011321 TEST_DESCRIPTION(
11322 "Use an invalid queue index in a vkCmdWaitEvents call."
11323 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011324
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011325 const char *invalid_queue_index =
11326 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11327 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11328 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011330 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011331
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011333
11334 ASSERT_NO_FATAL_FAILURE(InitState());
11335
11336 VkEvent event;
11337 VkEventCreateInfo event_create_info{};
11338 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11339 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11340
Mark Mueller2ee294f2016-08-04 12:59:48 -060011341 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011342 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011343
Tony Barbour552f6c02016-12-21 14:34:07 -070011344 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011345
11346 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011347 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 -060011348 ASSERT_TRUE(image.initialized());
11349 VkImageMemoryBarrier img_barrier = {};
11350 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11351 img_barrier.pNext = NULL;
11352 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11353 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11354 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11355 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11356 img_barrier.image = image.handle();
11357 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011358
11359 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11360 // that layer validation catches the case when it is not.
11361 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011362 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11363 img_barrier.subresourceRange.baseArrayLayer = 0;
11364 img_barrier.subresourceRange.baseMipLevel = 0;
11365 img_barrier.subresourceRange.layerCount = 1;
11366 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011367 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11368 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011369 m_errorMonitor->VerifyFound();
11370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011372
11373 VkQueryPool query_pool;
11374 VkQueryPoolCreateInfo query_pool_create_info = {};
11375 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11376 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11377 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011378 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011379
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011380 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011381 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11382
11383 vkEndCommandBuffer(m_commandBuffer->handle());
11384 m_errorMonitor->VerifyFound();
11385
11386 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11387 vkDestroyEvent(m_device->device(), event, nullptr);
11388}
11389
Mark Muellerdfe37552016-07-07 14:47:42 -060011390TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011391 TEST_DESCRIPTION(
11392 "Submit a command buffer using deleted vertex buffer, "
11393 "delete a buffer twice, use an invalid offset for each "
11394 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011395
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011396 const char *deleted_buffer_in_command_buffer =
11397 "Cannot submit cmd buffer "
11398 "using deleted buffer ";
11399 const char *invalid_offset_message =
11400 "vkBindBufferMemory(): "
11401 "memoryOffset is 0x";
11402 const char *invalid_storage_buffer_offset_message =
11403 "vkBindBufferMemory(): "
11404 "storage memoryOffset "
11405 "is 0x";
11406 const char *invalid_texel_buffer_offset_message =
11407 "vkBindBufferMemory(): "
11408 "texel memoryOffset "
11409 "is 0x";
11410 const char *invalid_uniform_buffer_offset_message =
11411 "vkBindBufferMemory(): "
11412 "uniform memoryOffset "
11413 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011414
11415 ASSERT_NO_FATAL_FAILURE(InitState());
11416 ASSERT_NO_FATAL_FAILURE(InitViewport());
11417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11418
11419 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011420 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011421 pipe_ms_state_ci.pNext = NULL;
11422 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11423 pipe_ms_state_ci.sampleShadingEnable = 0;
11424 pipe_ms_state_ci.minSampleShading = 1.0;
11425 pipe_ms_state_ci.pSampleMask = nullptr;
11426
11427 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11428 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11429 VkPipelineLayout pipeline_layout;
11430
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011431 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011432 ASSERT_VK_SUCCESS(err);
11433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011434 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11435 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011436 VkPipelineObj pipe(m_device);
11437 pipe.AddShader(&vs);
11438 pipe.AddShader(&fs);
11439 pipe.AddColorAttachment();
11440 pipe.SetMSAA(&pipe_ms_state_ci);
11441 pipe.SetViewport(m_viewports);
11442 pipe.SetScissor(m_scissors);
11443 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11444
Tony Barbour552f6c02016-12-21 14:34:07 -070011445 m_commandBuffer->BeginCommandBuffer();
11446 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011447 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011448
11449 {
11450 // Create and bind a vertex buffer in a reduced scope, which will cause
11451 // it to be deleted upon leaving this scope
11452 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011453 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011454 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11455 draw_verticies.AddVertexInputToPipe(pipe);
11456 }
11457
11458 Draw(1, 0, 0, 0);
11459
Tony Barbour552f6c02016-12-21 14:34:07 -070011460 m_commandBuffer->EndRenderPass();
11461 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011464 QueueCommandBuffer(false);
11465 m_errorMonitor->VerifyFound();
11466
11467 {
11468 // Create and bind a vertex buffer in a reduced scope, and delete it
11469 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011470 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011472 buffer_test.TestDoubleDestroy();
11473 }
11474 m_errorMonitor->VerifyFound();
11475
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011476 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011477 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011478 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011480 m_errorMonitor->SetUnexpectedError(
11481 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11482 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011483 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11484 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011485 m_errorMonitor->VerifyFound();
11486 }
11487
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011488 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11489 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011490 // Create and bind a memory buffer with an invalid offset again,
11491 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011493 m_errorMonitor->SetUnexpectedError(
11494 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11495 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011496 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11497 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011498 m_errorMonitor->VerifyFound();
11499 }
11500
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011501 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011502 // Create and bind a memory buffer with an invalid offset again, but
11503 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011505 m_errorMonitor->SetUnexpectedError(
11506 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11507 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011508 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11509 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011510 m_errorMonitor->VerifyFound();
11511 }
11512
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011513 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011514 // Create and bind a memory buffer with an invalid offset again, but
11515 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011517 m_errorMonitor->SetUnexpectedError(
11518 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11519 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011520 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11521 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011522 m_errorMonitor->VerifyFound();
11523 }
11524
11525 {
11526 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011528 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11529 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011530 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11531 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011532 m_errorMonitor->VerifyFound();
11533 }
11534
11535 {
11536 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011538 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11539 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011540 }
11541 m_errorMonitor->VerifyFound();
11542
11543 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11544}
11545
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011546// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11547TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011548 TEST_DESCRIPTION(
11549 "Hit all possible validation checks associated with the "
11550 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11551 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011552 // 3 in ValidateCmdBufImageLayouts
11553 // * -1 Attempt to submit cmd buf w/ deleted image
11554 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11555 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011556
11557 ASSERT_NO_FATAL_FAILURE(InitState());
11558 // Create src & dst images to use for copy operations
11559 VkImage src_image;
11560 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011561 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011562
11563 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11564 const int32_t tex_width = 32;
11565 const int32_t tex_height = 32;
11566
11567 VkImageCreateInfo image_create_info = {};
11568 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11569 image_create_info.pNext = NULL;
11570 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11571 image_create_info.format = tex_format;
11572 image_create_info.extent.width = tex_width;
11573 image_create_info.extent.height = tex_height;
11574 image_create_info.extent.depth = 1;
11575 image_create_info.mipLevels = 1;
11576 image_create_info.arrayLayers = 4;
11577 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11578 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11579 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011580 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011581 image_create_info.flags = 0;
11582
11583 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11584 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011585 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011586 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11587 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011588 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11589 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11590 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11591 ASSERT_VK_SUCCESS(err);
11592
11593 // Allocate memory
11594 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011595 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011596 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011597 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11598 mem_alloc.pNext = NULL;
11599 mem_alloc.allocationSize = 0;
11600 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011601
11602 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011603 mem_alloc.allocationSize = img_mem_reqs.size;
11604 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011605 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011606 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011607 ASSERT_VK_SUCCESS(err);
11608
11609 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011610 mem_alloc.allocationSize = img_mem_reqs.size;
11611 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011612 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011613 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011614 ASSERT_VK_SUCCESS(err);
11615
11616 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011617 mem_alloc.allocationSize = img_mem_reqs.size;
11618 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011619 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011620 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011621 ASSERT_VK_SUCCESS(err);
11622
11623 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11624 ASSERT_VK_SUCCESS(err);
11625 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11626 ASSERT_VK_SUCCESS(err);
11627 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11628 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011629
Tony Barbour552f6c02016-12-21 14:34:07 -070011630 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011631 VkImageCopy copy_region;
11632 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11633 copy_region.srcSubresource.mipLevel = 0;
11634 copy_region.srcSubresource.baseArrayLayer = 0;
11635 copy_region.srcSubresource.layerCount = 1;
11636 copy_region.srcOffset.x = 0;
11637 copy_region.srcOffset.y = 0;
11638 copy_region.srcOffset.z = 0;
11639 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11640 copy_region.dstSubresource.mipLevel = 0;
11641 copy_region.dstSubresource.baseArrayLayer = 0;
11642 copy_region.dstSubresource.layerCount = 1;
11643 copy_region.dstOffset.x = 0;
11644 copy_region.dstOffset.y = 0;
11645 copy_region.dstOffset.z = 0;
11646 copy_region.extent.width = 1;
11647 copy_region.extent.height = 1;
11648 copy_region.extent.depth = 1;
11649
11650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11651 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011652 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011653 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 -060011654 m_errorMonitor->VerifyFound();
11655 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11657 "Cannot copy from an image whose source layout is "
11658 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11659 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011660 m_errorMonitor->SetUnexpectedError(
11661 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011662 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 -060011663 m_errorMonitor->VerifyFound();
11664 // Final src error is due to bad layout type
11665 m_errorMonitor->SetDesiredFailureMsg(
11666 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11667 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011668 m_errorMonitor->SetUnexpectedError(
11669 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11670 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011671 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 -060011672 m_errorMonitor->VerifyFound();
11673 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11675 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011676 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011677 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 -060011678 m_errorMonitor->VerifyFound();
11679 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11681 "Cannot copy from an image whose dest layout is "
11682 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11683 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011684 m_errorMonitor->SetUnexpectedError(
11685 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011686 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 -060011687 m_errorMonitor->VerifyFound();
11688 m_errorMonitor->SetDesiredFailureMsg(
11689 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11690 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011691 m_errorMonitor->SetUnexpectedError(
11692 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11693 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011694 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 -060011695 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011696
Cort3b021012016-12-07 12:00:57 -080011697 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11698 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11699 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11700 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11701 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11702 transfer_dst_image_barrier[0].srcAccessMask = 0;
11703 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11704 transfer_dst_image_barrier[0].image = dst_image;
11705 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11706 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11707 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11708 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11709 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11710 transfer_dst_image_barrier[0].image = depth_image;
11711 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11712 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11713 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11714
11715 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011716 VkClearColorValue color_clear_value = {};
11717 VkImageSubresourceRange clear_range;
11718 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11719 clear_range.baseMipLevel = 0;
11720 clear_range.baseArrayLayer = 0;
11721 clear_range.layerCount = 1;
11722 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011723
Cort3b021012016-12-07 12:00:57 -080011724 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11725 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011728 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011729 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011730 // Fail due to provided layout not matching actual current layout for color clear.
11731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011732 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011733 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011734
Cort530cf382016-12-08 09:59:47 -080011735 VkClearDepthStencilValue depth_clear_value = {};
11736 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011737
11738 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11739 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011742 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011743 m_errorMonitor->VerifyFound();
11744 // Fail due to provided layout not matching actual current layout for depth clear.
11745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011746 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011747 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011748
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011749 // Now cause error due to bad image layout transition in PipelineBarrier
11750 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011751 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011752 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011753 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011754 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011755 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11756 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011757 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11759 "You cannot transition the layout of aspect 1 from "
11760 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11761 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011762 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11763 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011764 m_errorMonitor->VerifyFound();
11765
11766 // Finally some layout errors at RenderPass create time
11767 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11768 VkAttachmentReference attach = {};
11769 // perf warning for GENERAL layout w/ non-DS input attachment
11770 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11771 VkSubpassDescription subpass = {};
11772 subpass.inputAttachmentCount = 1;
11773 subpass.pInputAttachments = &attach;
11774 VkRenderPassCreateInfo rpci = {};
11775 rpci.subpassCount = 1;
11776 rpci.pSubpasses = &subpass;
11777 rpci.attachmentCount = 1;
11778 VkAttachmentDescription attach_desc = {};
11779 attach_desc.format = VK_FORMAT_UNDEFINED;
11780 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011781 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011782 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11784 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011785 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11786 m_errorMonitor->VerifyFound();
11787 // error w/ non-general layout
11788 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11789
11790 m_errorMonitor->SetDesiredFailureMsg(
11791 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11792 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11793 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11794 m_errorMonitor->VerifyFound();
11795 subpass.inputAttachmentCount = 0;
11796 subpass.colorAttachmentCount = 1;
11797 subpass.pColorAttachments = &attach;
11798 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11799 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11801 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011802 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11803 m_errorMonitor->VerifyFound();
11804 // error w/ non-color opt or GENERAL layout for color attachment
11805 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11806 m_errorMonitor->SetDesiredFailureMsg(
11807 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11808 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11809 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11810 m_errorMonitor->VerifyFound();
11811 subpass.colorAttachmentCount = 0;
11812 subpass.pDepthStencilAttachment = &attach;
11813 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11814 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11816 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011817 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11818 m_errorMonitor->VerifyFound();
11819 // error w/ non-ds opt or GENERAL layout for color attachment
11820 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11822 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11823 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011824 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11825 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011826 // For this error we need a valid renderpass so create default one
11827 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11828 attach.attachment = 0;
11829 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11830 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11831 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11832 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11833 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11834 // Can't do a CLEAR load on READ_ONLY initialLayout
11835 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11836 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11837 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11839 " with invalid first layout "
11840 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11841 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011842 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11843 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011844
Cort3b021012016-12-07 12:00:57 -080011845 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11846 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11847 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011848 vkDestroyImage(m_device->device(), src_image, NULL);
11849 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011850 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011851}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011852
Tobin Ehlise0936662016-10-11 08:10:51 -060011853TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11854 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11855 VkResult err;
11856
11857 ASSERT_NO_FATAL_FAILURE(InitState());
11858
11859 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11860 VkImageTiling tiling;
11861 VkFormatProperties format_properties;
11862 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11863 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11864 tiling = VK_IMAGE_TILING_LINEAR;
11865 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11866 tiling = VK_IMAGE_TILING_OPTIMAL;
11867 } else {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011868 printf(
11869 "Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11870 "skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011871 return;
11872 }
11873
11874 VkDescriptorPoolSize ds_type = {};
11875 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11876 ds_type.descriptorCount = 1;
11877
11878 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11879 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11880 ds_pool_ci.maxSets = 1;
11881 ds_pool_ci.poolSizeCount = 1;
11882 ds_pool_ci.pPoolSizes = &ds_type;
11883 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11884
11885 VkDescriptorPool ds_pool;
11886 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11887 ASSERT_VK_SUCCESS(err);
11888
11889 VkDescriptorSetLayoutBinding dsl_binding = {};
11890 dsl_binding.binding = 0;
11891 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11892 dsl_binding.descriptorCount = 1;
11893 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11894 dsl_binding.pImmutableSamplers = NULL;
11895
11896 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11897 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11898 ds_layout_ci.pNext = NULL;
11899 ds_layout_ci.bindingCount = 1;
11900 ds_layout_ci.pBindings = &dsl_binding;
11901
11902 VkDescriptorSetLayout ds_layout;
11903 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11904 ASSERT_VK_SUCCESS(err);
11905
11906 VkDescriptorSetAllocateInfo alloc_info = {};
11907 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11908 alloc_info.descriptorSetCount = 1;
11909 alloc_info.descriptorPool = ds_pool;
11910 alloc_info.pSetLayouts = &ds_layout;
11911 VkDescriptorSet descriptor_set;
11912 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11913 ASSERT_VK_SUCCESS(err);
11914
11915 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11916 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11917 pipeline_layout_ci.pNext = NULL;
11918 pipeline_layout_ci.setLayoutCount = 1;
11919 pipeline_layout_ci.pSetLayouts = &ds_layout;
11920 VkPipelineLayout pipeline_layout;
11921 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11922 ASSERT_VK_SUCCESS(err);
11923
11924 VkImageObj image(m_device);
11925 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11926 ASSERT_TRUE(image.initialized());
11927 VkImageView view = image.targetView(tex_format);
11928
11929 VkDescriptorImageInfo image_info = {};
11930 image_info.imageView = view;
11931 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11932
11933 VkWriteDescriptorSet descriptor_write = {};
11934 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11935 descriptor_write.dstSet = descriptor_set;
11936 descriptor_write.dstBinding = 0;
11937 descriptor_write.descriptorCount = 1;
11938 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11939 descriptor_write.pImageInfo = &image_info;
11940
11941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11942 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11943 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11944 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11945 m_errorMonitor->VerifyFound();
11946
11947 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11948 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11949 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11950 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11951}
11952
Mark Mueller93b938f2016-08-18 10:27:40 -060011953TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011954 TEST_DESCRIPTION(
11955 "Use vkCmdExecuteCommands with invalid state "
11956 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011957
11958 ASSERT_NO_FATAL_FAILURE(InitState());
11959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11960
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011961 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011962 const char *simultaneous_use_message2 =
11963 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11964 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011965
11966 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011967 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011968 command_buffer_allocate_info.commandPool = m_commandPool;
11969 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11970 command_buffer_allocate_info.commandBufferCount = 1;
11971
11972 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011973 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011974 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11975 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011976 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011977 command_buffer_inheritance_info.renderPass = m_renderPass;
11978 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011979
Mark Mueller93b938f2016-08-18 10:27:40 -060011980 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011981 command_buffer_begin_info.flags =
11982 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011983 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11984
11985 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11986 vkEndCommandBuffer(secondary_command_buffer);
11987
Mark Mueller93b938f2016-08-18 10:27:40 -060011988 VkSubmitInfo submit_info = {};
11989 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11990 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011991 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011992
Mark Mueller4042b652016-09-05 22:52:21 -060011993 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011994 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11996 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011997 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011998 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011999 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12000 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012001
Dave Houltonfbf52152017-01-06 12:55:29 -070012002 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012003 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012004 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012005
Mark Mueller4042b652016-09-05 22:52:21 -060012006 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012007 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12008 m_errorMonitor->SetUnexpectedError(
12009 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12010 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012011 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012012 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012013
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12015 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012016 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012017 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12018 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012019
12020 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012021
12022 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012023}
12024
Tony Barbour626994c2017-02-08 15:29:37 -070012025TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12026 TEST_DESCRIPTION(
12027 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12028 "errors");
12029 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12030 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12031 ASSERT_NO_FATAL_FAILURE(InitState());
12032
12033 VkCommandBuffer cmd_bufs[2];
12034 VkCommandBufferAllocateInfo alloc_info;
12035 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12036 alloc_info.pNext = NULL;
12037 alloc_info.commandBufferCount = 2;
12038 alloc_info.commandPool = m_commandPool;
12039 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12040 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12041
12042 VkCommandBufferBeginInfo cb_binfo;
12043 cb_binfo.pNext = NULL;
12044 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12045 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12046 cb_binfo.flags = 0;
12047 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12048 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12049 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12050 vkEndCommandBuffer(cmd_bufs[0]);
12051 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12052
12053 VkSubmitInfo submit_info = {};
12054 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12055 submit_info.commandBufferCount = 2;
12056 submit_info.pCommandBuffers = duplicates;
12057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12058 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12059 m_errorMonitor->VerifyFound();
12060 vkQueueWaitIdle(m_device->m_queue);
12061
12062 // Set one time use and now look for one time submit
12063 duplicates[0] = duplicates[1] = cmd_bufs[1];
12064 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12065 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12066 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12067 vkEndCommandBuffer(cmd_bufs[1]);
12068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12069 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12070 m_errorMonitor->VerifyFound();
12071 vkQueueWaitIdle(m_device->m_queue);
12072}
12073
Tobin Ehlisb093da82017-01-19 12:05:27 -070012074TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012075 TEST_DESCRIPTION(
12076 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12077 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012078
12079 ASSERT_NO_FATAL_FAILURE(InitState());
12080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12081
12082 std::vector<const char *> device_extension_names;
12083 auto features = m_device->phy().features();
12084 // Make sure gs & ts are disabled
12085 features.geometryShader = false;
12086 features.tessellationShader = false;
12087 // The sacrificial device object
12088 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12089
12090 VkCommandPoolCreateInfo pool_create_info{};
12091 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12092 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12093
12094 VkCommandPool command_pool;
12095 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12096
12097 VkCommandBufferAllocateInfo cmd = {};
12098 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12099 cmd.pNext = NULL;
12100 cmd.commandPool = command_pool;
12101 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12102 cmd.commandBufferCount = 1;
12103
12104 VkCommandBuffer cmd_buffer;
12105 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12106 ASSERT_VK_SUCCESS(err);
12107
12108 VkEvent event;
12109 VkEventCreateInfo evci = {};
12110 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12111 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12112 ASSERT_VK_SUCCESS(result);
12113
12114 VkCommandBufferBeginInfo cbbi = {};
12115 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12116 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12118 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12119 m_errorMonitor->VerifyFound();
12120
12121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12122 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12123 m_errorMonitor->VerifyFound();
12124
12125 vkDestroyEvent(test_device.handle(), event, NULL);
12126 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12127}
12128
Mark Mueller917f6bc2016-08-30 10:57:19 -060012129TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012130 TEST_DESCRIPTION(
12131 "Use vkCmdExecuteCommands with invalid state "
12132 "in primary and secondary command buffers. "
12133 "Delete objects that are inuse. Call VkQueueSubmit "
12134 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012135
12136 ASSERT_NO_FATAL_FAILURE(InitState());
12137 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12138
Tony Barbour552f6c02016-12-21 14:34:07 -070012139 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012140
12141 VkEvent event;
12142 VkEventCreateInfo event_create_info = {};
12143 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12144 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012145 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012146
Tony Barbour552f6c02016-12-21 14:34:07 -070012147 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012148 vkDestroyEvent(m_device->device(), event, nullptr);
12149
12150 VkSubmitInfo submit_info = {};
12151 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12152 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012153 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b082d72017-01-27 11:34:28 -070012154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted event 0x");
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012156 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12157 m_errorMonitor->VerifyFound();
12158
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012159 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012160 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12161
12162 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12163
Mark Mueller917f6bc2016-08-30 10:57:19 -060012164 VkSemaphoreCreateInfo semaphore_create_info = {};
12165 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12166 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012167 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012168 VkFenceCreateInfo fence_create_info = {};
12169 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12170 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012171 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012172
12173 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012174 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012175 descriptor_pool_type_count.descriptorCount = 1;
12176
12177 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12178 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12179 descriptor_pool_create_info.maxSets = 1;
12180 descriptor_pool_create_info.poolSizeCount = 1;
12181 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012182 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012183
12184 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012185 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012186
12187 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012188 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012189 descriptorset_layout_binding.descriptorCount = 1;
12190 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12191
12192 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012193 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012194 descriptorset_layout_create_info.bindingCount = 1;
12195 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12196
12197 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012198 ASSERT_VK_SUCCESS(
12199 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012200
12201 VkDescriptorSet descriptorset;
12202 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012203 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012204 descriptorset_allocate_info.descriptorSetCount = 1;
12205 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12206 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012207 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012208
Mark Mueller4042b652016-09-05 22:52:21 -060012209 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12210
12211 VkDescriptorBufferInfo buffer_info = {};
12212 buffer_info.buffer = buffer_test.GetBuffer();
12213 buffer_info.offset = 0;
12214 buffer_info.range = 1024;
12215
12216 VkWriteDescriptorSet write_descriptor_set = {};
12217 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12218 write_descriptor_set.dstSet = descriptorset;
12219 write_descriptor_set.descriptorCount = 1;
12220 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12221 write_descriptor_set.pBufferInfo = &buffer_info;
12222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012223 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012225 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12226 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012227
12228 VkPipelineObj pipe(m_device);
12229 pipe.AddColorAttachment();
12230 pipe.AddShader(&vs);
12231 pipe.AddShader(&fs);
12232
12233 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012234 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012235 pipeline_layout_create_info.setLayoutCount = 1;
12236 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12237
12238 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012239 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012240
12241 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12242
Tony Barbour552f6c02016-12-21 14:34:07 -070012243 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012244 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012246 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12247 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12248 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012249
Tony Barbour552f6c02016-12-21 14:34:07 -070012250 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012251
Mark Mueller917f6bc2016-08-30 10:57:19 -060012252 submit_info.signalSemaphoreCount = 1;
12253 submit_info.pSignalSemaphores = &semaphore;
12254 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012255 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012256
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012258 vkDestroyEvent(m_device->device(), event, nullptr);
12259 m_errorMonitor->VerifyFound();
12260
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012262 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12263 m_errorMonitor->VerifyFound();
12264
Jeremy Hayes08369882017-02-02 10:31:06 -070012265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012266 vkDestroyFence(m_device->device(), fence, nullptr);
12267 m_errorMonitor->VerifyFound();
12268
Tobin Ehlis122207b2016-09-01 08:50:06 -070012269 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012270 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12271 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012272 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012273 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12274 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012275 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012276 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12277 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012278 vkDestroyEvent(m_device->device(), event, nullptr);
12279 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012280 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012281 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12282}
12283
Tobin Ehlis2adda372016-09-01 08:51:06 -070012284TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12285 TEST_DESCRIPTION("Delete in-use query pool.");
12286
12287 ASSERT_NO_FATAL_FAILURE(InitState());
12288 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12289
12290 VkQueryPool query_pool;
12291 VkQueryPoolCreateInfo query_pool_ci{};
12292 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12293 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12294 query_pool_ci.queryCount = 1;
12295 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012296 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012297 // Reset query pool to create binding with cmd buffer
12298 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12299
Tony Barbour552f6c02016-12-21 14:34:07 -070012300 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012301
12302 VkSubmitInfo submit_info = {};
12303 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12304 submit_info.commandBufferCount = 1;
12305 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12306 // Submit cmd buffer and then destroy query pool while in-flight
12307 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12308
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012310 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12311 m_errorMonitor->VerifyFound();
12312
12313 vkQueueWaitIdle(m_device->m_queue);
12314 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012315 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12316 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012317 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12318}
12319
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012320TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12321 TEST_DESCRIPTION("Delete in-use pipeline.");
12322
12323 ASSERT_NO_FATAL_FAILURE(InitState());
12324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12325
12326 // Empty pipeline layout used for binding PSO
12327 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12328 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12329 pipeline_layout_ci.setLayoutCount = 0;
12330 pipeline_layout_ci.pSetLayouts = NULL;
12331
12332 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012333 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012334 ASSERT_VK_SUCCESS(err);
12335
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012337 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012338 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12339 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012340 // Store pipeline handle so we can actually delete it before test finishes
12341 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012342 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012343 VkPipelineObj pipe(m_device);
12344 pipe.AddShader(&vs);
12345 pipe.AddShader(&fs);
12346 pipe.AddColorAttachment();
12347 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12348 delete_this_pipeline = pipe.handle();
12349
Tony Barbour552f6c02016-12-21 14:34:07 -070012350 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012351 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012352 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012353
Tony Barbour552f6c02016-12-21 14:34:07 -070012354 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012355
12356 VkSubmitInfo submit_info = {};
12357 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12358 submit_info.commandBufferCount = 1;
12359 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12360 // Submit cmd buffer and then pipeline destroyed while in-flight
12361 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012362 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012363 m_errorMonitor->VerifyFound();
12364 // Make sure queue finished and then actually delete pipeline
12365 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012366 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12367 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012368 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12369 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12370}
12371
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012372TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12373 TEST_DESCRIPTION("Delete in-use imageView.");
12374
12375 ASSERT_NO_FATAL_FAILURE(InitState());
12376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12377
12378 VkDescriptorPoolSize ds_type_count;
12379 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12380 ds_type_count.descriptorCount = 1;
12381
12382 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12383 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12384 ds_pool_ci.maxSets = 1;
12385 ds_pool_ci.poolSizeCount = 1;
12386 ds_pool_ci.pPoolSizes = &ds_type_count;
12387
12388 VkDescriptorPool ds_pool;
12389 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12390 ASSERT_VK_SUCCESS(err);
12391
12392 VkSamplerCreateInfo sampler_ci = {};
12393 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12394 sampler_ci.pNext = NULL;
12395 sampler_ci.magFilter = VK_FILTER_NEAREST;
12396 sampler_ci.minFilter = VK_FILTER_NEAREST;
12397 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12398 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12399 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12400 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12401 sampler_ci.mipLodBias = 1.0;
12402 sampler_ci.anisotropyEnable = VK_FALSE;
12403 sampler_ci.maxAnisotropy = 1;
12404 sampler_ci.compareEnable = VK_FALSE;
12405 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12406 sampler_ci.minLod = 1.0;
12407 sampler_ci.maxLod = 1.0;
12408 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12409 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12410 VkSampler sampler;
12411
12412 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12413 ASSERT_VK_SUCCESS(err);
12414
12415 VkDescriptorSetLayoutBinding layout_binding;
12416 layout_binding.binding = 0;
12417 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12418 layout_binding.descriptorCount = 1;
12419 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12420 layout_binding.pImmutableSamplers = NULL;
12421
12422 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12423 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12424 ds_layout_ci.bindingCount = 1;
12425 ds_layout_ci.pBindings = &layout_binding;
12426 VkDescriptorSetLayout ds_layout;
12427 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12428 ASSERT_VK_SUCCESS(err);
12429
12430 VkDescriptorSetAllocateInfo alloc_info = {};
12431 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12432 alloc_info.descriptorSetCount = 1;
12433 alloc_info.descriptorPool = ds_pool;
12434 alloc_info.pSetLayouts = &ds_layout;
12435 VkDescriptorSet descriptor_set;
12436 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12437 ASSERT_VK_SUCCESS(err);
12438
12439 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12440 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12441 pipeline_layout_ci.pNext = NULL;
12442 pipeline_layout_ci.setLayoutCount = 1;
12443 pipeline_layout_ci.pSetLayouts = &ds_layout;
12444
12445 VkPipelineLayout pipeline_layout;
12446 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12447 ASSERT_VK_SUCCESS(err);
12448
12449 VkImageObj image(m_device);
12450 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12451 ASSERT_TRUE(image.initialized());
12452
12453 VkImageView view;
12454 VkImageViewCreateInfo ivci = {};
12455 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12456 ivci.image = image.handle();
12457 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12458 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12459 ivci.subresourceRange.layerCount = 1;
12460 ivci.subresourceRange.baseMipLevel = 0;
12461 ivci.subresourceRange.levelCount = 1;
12462 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12463
12464 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12465 ASSERT_VK_SUCCESS(err);
12466
12467 VkDescriptorImageInfo image_info{};
12468 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12469 image_info.imageView = view;
12470 image_info.sampler = sampler;
12471
12472 VkWriteDescriptorSet descriptor_write = {};
12473 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12474 descriptor_write.dstSet = descriptor_set;
12475 descriptor_write.dstBinding = 0;
12476 descriptor_write.descriptorCount = 1;
12477 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12478 descriptor_write.pImageInfo = &image_info;
12479
12480 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12481
12482 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012483 char const *vsSource =
12484 "#version 450\n"
12485 "\n"
12486 "out gl_PerVertex { \n"
12487 " vec4 gl_Position;\n"
12488 "};\n"
12489 "void main(){\n"
12490 " gl_Position = vec4(1);\n"
12491 "}\n";
12492 char const *fsSource =
12493 "#version 450\n"
12494 "\n"
12495 "layout(set=0, binding=0) uniform sampler2D s;\n"
12496 "layout(location=0) out vec4 x;\n"
12497 "void main(){\n"
12498 " x = texture(s, vec2(1));\n"
12499 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012500 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12501 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12502 VkPipelineObj pipe(m_device);
12503 pipe.AddShader(&vs);
12504 pipe.AddShader(&fs);
12505 pipe.AddColorAttachment();
12506 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12507
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012509
Tony Barbour552f6c02016-12-21 14:34:07 -070012510 m_commandBuffer->BeginCommandBuffer();
12511 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012512 // Bind pipeline to cmd buffer
12513 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12514 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12515 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012516
12517 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12518 VkRect2D scissor = {{0, 0}, {16, 16}};
12519 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12520 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12521
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012522 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012523 m_commandBuffer->EndRenderPass();
12524 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012525 // Submit cmd buffer then destroy sampler
12526 VkSubmitInfo submit_info = {};
12527 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12528 submit_info.commandBufferCount = 1;
12529 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12530 // Submit cmd buffer and then destroy imageView while in-flight
12531 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12532
12533 vkDestroyImageView(m_device->device(), view, nullptr);
12534 m_errorMonitor->VerifyFound();
12535 vkQueueWaitIdle(m_device->m_queue);
12536 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012537 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12538 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012539 vkDestroyImageView(m_device->device(), view, NULL);
12540 vkDestroySampler(m_device->device(), sampler, nullptr);
12541 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12542 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12543 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12544}
12545
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012546TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12547 TEST_DESCRIPTION("Delete in-use bufferView.");
12548
12549 ASSERT_NO_FATAL_FAILURE(InitState());
12550 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12551
12552 VkDescriptorPoolSize ds_type_count;
12553 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12554 ds_type_count.descriptorCount = 1;
12555
12556 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12557 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12558 ds_pool_ci.maxSets = 1;
12559 ds_pool_ci.poolSizeCount = 1;
12560 ds_pool_ci.pPoolSizes = &ds_type_count;
12561
12562 VkDescriptorPool ds_pool;
12563 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12564 ASSERT_VK_SUCCESS(err);
12565
12566 VkDescriptorSetLayoutBinding layout_binding;
12567 layout_binding.binding = 0;
12568 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12569 layout_binding.descriptorCount = 1;
12570 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12571 layout_binding.pImmutableSamplers = NULL;
12572
12573 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12574 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12575 ds_layout_ci.bindingCount = 1;
12576 ds_layout_ci.pBindings = &layout_binding;
12577 VkDescriptorSetLayout ds_layout;
12578 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12579 ASSERT_VK_SUCCESS(err);
12580
12581 VkDescriptorSetAllocateInfo alloc_info = {};
12582 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12583 alloc_info.descriptorSetCount = 1;
12584 alloc_info.descriptorPool = ds_pool;
12585 alloc_info.pSetLayouts = &ds_layout;
12586 VkDescriptorSet descriptor_set;
12587 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12588 ASSERT_VK_SUCCESS(err);
12589
12590 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12591 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12592 pipeline_layout_ci.pNext = NULL;
12593 pipeline_layout_ci.setLayoutCount = 1;
12594 pipeline_layout_ci.pSetLayouts = &ds_layout;
12595
12596 VkPipelineLayout pipeline_layout;
12597 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12598 ASSERT_VK_SUCCESS(err);
12599
12600 VkBuffer buffer;
12601 uint32_t queue_family_index = 0;
12602 VkBufferCreateInfo buffer_create_info = {};
12603 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12604 buffer_create_info.size = 1024;
12605 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12606 buffer_create_info.queueFamilyIndexCount = 1;
12607 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12608
12609 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12610 ASSERT_VK_SUCCESS(err);
12611
12612 VkMemoryRequirements memory_reqs;
12613 VkDeviceMemory buffer_memory;
12614
12615 VkMemoryAllocateInfo memory_info = {};
12616 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12617 memory_info.allocationSize = 0;
12618 memory_info.memoryTypeIndex = 0;
12619
12620 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12621 memory_info.allocationSize = memory_reqs.size;
12622 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12623 ASSERT_TRUE(pass);
12624
12625 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12626 ASSERT_VK_SUCCESS(err);
12627 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12628 ASSERT_VK_SUCCESS(err);
12629
12630 VkBufferView view;
12631 VkBufferViewCreateInfo bvci = {};
12632 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12633 bvci.buffer = buffer;
12634 bvci.format = VK_FORMAT_R8_UNORM;
12635 bvci.range = VK_WHOLE_SIZE;
12636
12637 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12638 ASSERT_VK_SUCCESS(err);
12639
12640 VkWriteDescriptorSet descriptor_write = {};
12641 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12642 descriptor_write.dstSet = descriptor_set;
12643 descriptor_write.dstBinding = 0;
12644 descriptor_write.descriptorCount = 1;
12645 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12646 descriptor_write.pTexelBufferView = &view;
12647
12648 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12649
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012650 char const *vsSource =
12651 "#version 450\n"
12652 "\n"
12653 "out gl_PerVertex { \n"
12654 " vec4 gl_Position;\n"
12655 "};\n"
12656 "void main(){\n"
12657 " gl_Position = vec4(1);\n"
12658 "}\n";
12659 char const *fsSource =
12660 "#version 450\n"
12661 "\n"
12662 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12663 "layout(location=0) out vec4 x;\n"
12664 "void main(){\n"
12665 " x = imageLoad(s, 0);\n"
12666 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012667 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12668 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12669 VkPipelineObj pipe(m_device);
12670 pipe.AddShader(&vs);
12671 pipe.AddShader(&fs);
12672 pipe.AddColorAttachment();
12673 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12674
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012676
Tony Barbour552f6c02016-12-21 14:34:07 -070012677 m_commandBuffer->BeginCommandBuffer();
12678 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012679 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12680 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12681 VkRect2D scissor = {{0, 0}, {16, 16}};
12682 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12683 // Bind pipeline to cmd buffer
12684 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12685 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12686 &descriptor_set, 0, nullptr);
12687 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012688 m_commandBuffer->EndRenderPass();
12689 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012690
12691 VkSubmitInfo submit_info = {};
12692 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12693 submit_info.commandBufferCount = 1;
12694 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12695 // Submit cmd buffer and then destroy bufferView while in-flight
12696 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12697
12698 vkDestroyBufferView(m_device->device(), view, nullptr);
12699 m_errorMonitor->VerifyFound();
12700 vkQueueWaitIdle(m_device->m_queue);
12701 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012702 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12703 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012704 vkDestroyBufferView(m_device->device(), view, NULL);
12705 vkDestroyBuffer(m_device->device(), buffer, NULL);
12706 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12707 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12708 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12709 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12710}
12711
Tobin Ehlis209532e2016-09-07 13:52:18 -060012712TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12713 TEST_DESCRIPTION("Delete in-use sampler.");
12714
12715 ASSERT_NO_FATAL_FAILURE(InitState());
12716 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12717
12718 VkDescriptorPoolSize ds_type_count;
12719 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12720 ds_type_count.descriptorCount = 1;
12721
12722 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12723 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12724 ds_pool_ci.maxSets = 1;
12725 ds_pool_ci.poolSizeCount = 1;
12726 ds_pool_ci.pPoolSizes = &ds_type_count;
12727
12728 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012729 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012730 ASSERT_VK_SUCCESS(err);
12731
12732 VkSamplerCreateInfo sampler_ci = {};
12733 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12734 sampler_ci.pNext = NULL;
12735 sampler_ci.magFilter = VK_FILTER_NEAREST;
12736 sampler_ci.minFilter = VK_FILTER_NEAREST;
12737 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12738 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12739 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12740 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12741 sampler_ci.mipLodBias = 1.0;
12742 sampler_ci.anisotropyEnable = VK_FALSE;
12743 sampler_ci.maxAnisotropy = 1;
12744 sampler_ci.compareEnable = VK_FALSE;
12745 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12746 sampler_ci.minLod = 1.0;
12747 sampler_ci.maxLod = 1.0;
12748 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12749 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12750 VkSampler sampler;
12751
12752 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12753 ASSERT_VK_SUCCESS(err);
12754
12755 VkDescriptorSetLayoutBinding layout_binding;
12756 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012757 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012758 layout_binding.descriptorCount = 1;
12759 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12760 layout_binding.pImmutableSamplers = NULL;
12761
12762 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12763 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12764 ds_layout_ci.bindingCount = 1;
12765 ds_layout_ci.pBindings = &layout_binding;
12766 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012767 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012768 ASSERT_VK_SUCCESS(err);
12769
12770 VkDescriptorSetAllocateInfo alloc_info = {};
12771 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12772 alloc_info.descriptorSetCount = 1;
12773 alloc_info.descriptorPool = ds_pool;
12774 alloc_info.pSetLayouts = &ds_layout;
12775 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012776 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012777 ASSERT_VK_SUCCESS(err);
12778
12779 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12780 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12781 pipeline_layout_ci.pNext = NULL;
12782 pipeline_layout_ci.setLayoutCount = 1;
12783 pipeline_layout_ci.pSetLayouts = &ds_layout;
12784
12785 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012786 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012787 ASSERT_VK_SUCCESS(err);
12788
12789 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012790 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 -060012791 ASSERT_TRUE(image.initialized());
12792
12793 VkImageView view;
12794 VkImageViewCreateInfo ivci = {};
12795 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12796 ivci.image = image.handle();
12797 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12798 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12799 ivci.subresourceRange.layerCount = 1;
12800 ivci.subresourceRange.baseMipLevel = 0;
12801 ivci.subresourceRange.levelCount = 1;
12802 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12803
12804 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12805 ASSERT_VK_SUCCESS(err);
12806
12807 VkDescriptorImageInfo image_info{};
12808 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12809 image_info.imageView = view;
12810 image_info.sampler = sampler;
12811
12812 VkWriteDescriptorSet descriptor_write = {};
12813 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12814 descriptor_write.dstSet = descriptor_set;
12815 descriptor_write.dstBinding = 0;
12816 descriptor_write.descriptorCount = 1;
12817 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12818 descriptor_write.pImageInfo = &image_info;
12819
12820 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12821
12822 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012823 char const *vsSource =
12824 "#version 450\n"
12825 "\n"
12826 "out gl_PerVertex { \n"
12827 " vec4 gl_Position;\n"
12828 "};\n"
12829 "void main(){\n"
12830 " gl_Position = vec4(1);\n"
12831 "}\n";
12832 char const *fsSource =
12833 "#version 450\n"
12834 "\n"
12835 "layout(set=0, binding=0) uniform sampler2D s;\n"
12836 "layout(location=0) out vec4 x;\n"
12837 "void main(){\n"
12838 " x = texture(s, vec2(1));\n"
12839 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012840 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12841 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12842 VkPipelineObj pipe(m_device);
12843 pipe.AddShader(&vs);
12844 pipe.AddShader(&fs);
12845 pipe.AddColorAttachment();
12846 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12847
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012849
Tony Barbour552f6c02016-12-21 14:34:07 -070012850 m_commandBuffer->BeginCommandBuffer();
12851 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012852 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012853 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12854 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12855 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012856
12857 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12858 VkRect2D scissor = {{0, 0}, {16, 16}};
12859 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12860 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12861
Tobin Ehlis209532e2016-09-07 13:52:18 -060012862 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012863 m_commandBuffer->EndRenderPass();
12864 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012865 // Submit cmd buffer then destroy sampler
12866 VkSubmitInfo submit_info = {};
12867 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12868 submit_info.commandBufferCount = 1;
12869 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12870 // Submit cmd buffer and then destroy sampler while in-flight
12871 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12872
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012873 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012874 m_errorMonitor->VerifyFound();
12875 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012876
Tobin Ehlis209532e2016-09-07 13:52:18 -060012877 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012878 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12879 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012880 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012881 vkDestroyImageView(m_device->device(), view, NULL);
12882 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12883 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12884 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12885}
12886
Mark Mueller1cd9f412016-08-25 13:23:52 -060012887TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012888 TEST_DESCRIPTION(
12889 "Call VkQueueSubmit with a semaphore that is already "
12890 "signaled but not waited on by the queue. Wait on a "
12891 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012892
12893 ASSERT_NO_FATAL_FAILURE(InitState());
12894 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12895
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012896 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 -070012897 const char *invalid_fence_wait_message =
12898 " which has not been submitted on a Queue or during "
12899 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012900
Tony Barbour552f6c02016-12-21 14:34:07 -070012901 m_commandBuffer->BeginCommandBuffer();
12902 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012903
12904 VkSemaphoreCreateInfo semaphore_create_info = {};
12905 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12906 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012907 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012908 VkSubmitInfo submit_info = {};
12909 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12910 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012911 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012912 submit_info.signalSemaphoreCount = 1;
12913 submit_info.pSignalSemaphores = &semaphore;
12914 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012915 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012916 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012917 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012918 m_commandBuffer->BeginCommandBuffer();
12919 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012921 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12922 m_errorMonitor->VerifyFound();
12923
Mark Mueller1cd9f412016-08-25 13:23:52 -060012924 VkFenceCreateInfo fence_create_info = {};
12925 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12926 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012927 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012928
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012930 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12931 m_errorMonitor->VerifyFound();
12932
Mark Mueller4042b652016-09-05 22:52:21 -060012933 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012934 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012935 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12936}
12937
Tobin Ehlis4af23302016-07-19 10:50:30 -060012938TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012939 TEST_DESCRIPTION(
12940 "Bind a secondary command buffer with with a framebuffer "
12941 "that does not match the framebuffer for the active "
12942 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012943 ASSERT_NO_FATAL_FAILURE(InitState());
12944 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12945
12946 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012947 VkAttachmentDescription attachment = {0,
12948 VK_FORMAT_B8G8R8A8_UNORM,
12949 VK_SAMPLE_COUNT_1_BIT,
12950 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12951 VK_ATTACHMENT_STORE_OP_STORE,
12952 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12953 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12954 VK_IMAGE_LAYOUT_UNDEFINED,
12955 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012956
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012957 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012959 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012961 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012962
12963 VkRenderPass rp;
12964 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12965 ASSERT_VK_SUCCESS(err);
12966
12967 // A compatible framebuffer.
12968 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012969 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 -060012970 ASSERT_TRUE(image.initialized());
12971
12972 VkImageViewCreateInfo ivci = {
12973 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12974 nullptr,
12975 0,
12976 image.handle(),
12977 VK_IMAGE_VIEW_TYPE_2D,
12978 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012979 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12980 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012981 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12982 };
12983 VkImageView view;
12984 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12985 ASSERT_VK_SUCCESS(err);
12986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012987 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012988 VkFramebuffer fb;
12989 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12990 ASSERT_VK_SUCCESS(err);
12991
12992 VkCommandBufferAllocateInfo cbai = {};
12993 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12994 cbai.commandPool = m_commandPool;
12995 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12996 cbai.commandBufferCount = 1;
12997
12998 VkCommandBuffer sec_cb;
12999 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13000 ASSERT_VK_SUCCESS(err);
13001 VkCommandBufferBeginInfo cbbi = {};
13002 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013003 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013004 cbii.renderPass = renderPass();
13005 cbii.framebuffer = fb;
13006 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13007 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013008 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 -060013009 cbbi.pInheritanceInfo = &cbii;
13010 vkBeginCommandBuffer(sec_cb, &cbbi);
13011 vkEndCommandBuffer(sec_cb);
13012
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013013 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013014 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13015 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013017 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013018 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013019 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13020 m_errorMonitor->VerifyFound();
13021 // Cleanup
13022 vkDestroyImageView(m_device->device(), view, NULL);
13023 vkDestroyRenderPass(m_device->device(), rp, NULL);
13024 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13025}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013026
13027TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013028 TEST_DESCRIPTION(
13029 "If logicOp is available on the device, set it to an "
13030 "invalid value. If logicOp is not available, attempt to "
13031 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013032 ASSERT_NO_FATAL_FAILURE(InitState());
13033 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13034
13035 auto features = m_device->phy().features();
13036 // Set the expected error depending on whether or not logicOp available
13037 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13039 "If logic operations feature not "
13040 "enabled, logicOpEnable must be "
13041 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013042 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013044 }
13045 // Create a pipeline using logicOp
13046 VkResult err;
13047
13048 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13049 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13050
13051 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013052 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013053 ASSERT_VK_SUCCESS(err);
13054
13055 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13056 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13057 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013058 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013059 vp_state_ci.pViewports = &vp;
13060 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013061 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013062 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013063
13064 VkPipelineShaderStageCreateInfo shaderStages[2];
13065 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13066
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013067 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13068 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013069 shaderStages[0] = vs.GetStageCreateInfo();
13070 shaderStages[1] = fs.GetStageCreateInfo();
13071
13072 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13073 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13074
13075 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13076 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13077 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13078
13079 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13080 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013081 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013082
13083 VkPipelineColorBlendAttachmentState att = {};
13084 att.blendEnable = VK_FALSE;
13085 att.colorWriteMask = 0xf;
13086
13087 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13088 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13089 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13090 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013091 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013092 cb_ci.attachmentCount = 1;
13093 cb_ci.pAttachments = &att;
13094
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013095 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13096 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13097 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13098
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013099 VkGraphicsPipelineCreateInfo gp_ci = {};
13100 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13101 gp_ci.stageCount = 2;
13102 gp_ci.pStages = shaderStages;
13103 gp_ci.pVertexInputState = &vi_ci;
13104 gp_ci.pInputAssemblyState = &ia_ci;
13105 gp_ci.pViewportState = &vp_state_ci;
13106 gp_ci.pRasterizationState = &rs_ci;
13107 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013108 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013109 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13110 gp_ci.layout = pipeline_layout;
13111 gp_ci.renderPass = renderPass();
13112
13113 VkPipelineCacheCreateInfo pc_ci = {};
13114 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13115
13116 VkPipeline pipeline;
13117 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013118 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013119 ASSERT_VK_SUCCESS(err);
13120
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013121 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013122 m_errorMonitor->VerifyFound();
13123 if (VK_SUCCESS == err) {
13124 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13125 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013126 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13127 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13128}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013129
Mike Stroyanaccf7692015-05-12 16:00:45 -060013130#if GTEST_IS_THREADSAFE
13131struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013132 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013133 VkEvent event;
13134 bool bailout;
13135};
13136
Karl Schultz6addd812016-02-02 17:17:23 -070013137extern "C" void *AddToCommandBuffer(void *arg) {
13138 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013139
Mike Stroyana6d14942016-07-13 15:10:05 -060013140 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013141 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013142 if (data->bailout) {
13143 break;
13144 }
13145 }
13146 return NULL;
13147}
13148
Karl Schultz6addd812016-02-02 17:17:23 -070013149TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013150 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013153
Mike Stroyanaccf7692015-05-12 16:00:45 -060013154 ASSERT_NO_FATAL_FAILURE(InitState());
13155 ASSERT_NO_FATAL_FAILURE(InitViewport());
13156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13157
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013158 // Calls AllocateCommandBuffers
13159 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013160
13161 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013162 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013163
13164 VkEventCreateInfo event_info;
13165 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013166 VkResult err;
13167
13168 memset(&event_info, 0, sizeof(event_info));
13169 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13170
Chia-I Wuf7458c52015-10-26 21:10:41 +080013171 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013172 ASSERT_VK_SUCCESS(err);
13173
Mike Stroyanaccf7692015-05-12 16:00:45 -060013174 err = vkResetEvent(device(), event);
13175 ASSERT_VK_SUCCESS(err);
13176
13177 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013178 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013179 data.event = event;
13180 data.bailout = false;
13181 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013182
13183 // First do some correct operations using multiple threads.
13184 // Add many entries to command buffer from another thread.
13185 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13186 // Make non-conflicting calls from this thread at the same time.
13187 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013188 uint32_t count;
13189 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013190 }
13191 test_platform_thread_join(thread, NULL);
13192
13193 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013194 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013195 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013196 // Add many entries to command buffer from this thread at the same time.
13197 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013198
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013199 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013200 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013201
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013202 m_errorMonitor->SetBailout(NULL);
13203
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013204 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013205
Chia-I Wuf7458c52015-10-26 21:10:41 +080013206 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013207}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013208#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013209
Karl Schultz6addd812016-02-02 17:17:23 -070013210TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013211 TEST_DESCRIPTION(
13212 "Test that an error is produced for a spirv module "
13213 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013216
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013217 ASSERT_NO_FATAL_FAILURE(InitState());
13218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13219
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013220 VkShaderModule module;
13221 VkShaderModuleCreateInfo moduleCreateInfo;
13222 struct icd_spv_header spv;
13223
13224 spv.magic = ICD_SPV_MAGIC;
13225 spv.version = ICD_SPV_VERSION;
13226 spv.gen_magic = 0;
13227
13228 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13229 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013230 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013231 moduleCreateInfo.codeSize = 4;
13232 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013233 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013234
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013235 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013236}
13237
Karl Schultz6addd812016-02-02 17:17:23 -070013238TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013239 TEST_DESCRIPTION(
13240 "Test that an error is produced for a spirv module "
13241 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013242
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013244
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013245 ASSERT_NO_FATAL_FAILURE(InitState());
13246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13247
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013248 VkShaderModule module;
13249 VkShaderModuleCreateInfo moduleCreateInfo;
13250 struct icd_spv_header spv;
13251
13252 spv.magic = ~ICD_SPV_MAGIC;
13253 spv.version = ICD_SPV_VERSION;
13254 spv.gen_magic = 0;
13255
13256 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13257 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013258 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013259 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13260 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013261 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013262
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013263 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013264}
13265
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013266#if 0
13267// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013268TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013270 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013271
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013272 ASSERT_NO_FATAL_FAILURE(InitState());
13273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13274
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013275 VkShaderModule module;
13276 VkShaderModuleCreateInfo moduleCreateInfo;
13277 struct icd_spv_header spv;
13278
13279 spv.magic = ICD_SPV_MAGIC;
13280 spv.version = ~ICD_SPV_VERSION;
13281 spv.gen_magic = 0;
13282
13283 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13284 moduleCreateInfo.pNext = NULL;
13285
Karl Schultz6addd812016-02-02 17:17:23 -070013286 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013287 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13288 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013289 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013290
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013291 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013292}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013293#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013294
Karl Schultz6addd812016-02-02 17:17:23 -070013295TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013296 TEST_DESCRIPTION(
13297 "Test that a warning is produced for a vertex output that "
13298 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013300
Chris Forbes9f7ff632015-05-25 11:13:08 +120013301 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013303
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013304 char const *vsSource =
13305 "#version 450\n"
13306 "\n"
13307 "layout(location=0) out float x;\n"
13308 "out gl_PerVertex {\n"
13309 " vec4 gl_Position;\n"
13310 "};\n"
13311 "void main(){\n"
13312 " gl_Position = vec4(1);\n"
13313 " x = 0;\n"
13314 "}\n";
13315 char const *fsSource =
13316 "#version 450\n"
13317 "\n"
13318 "layout(location=0) out vec4 color;\n"
13319 "void main(){\n"
13320 " color = vec4(1);\n"
13321 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013322
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013323 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13324 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013325
13326 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013327 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013328 pipe.AddShader(&vs);
13329 pipe.AddShader(&fs);
13330
Chris Forbes9f7ff632015-05-25 11:13:08 +120013331 VkDescriptorSetObj descriptorSet(m_device);
13332 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013333 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013334
Tony Barbour5781e8f2015-08-04 16:23:11 -060013335 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013336
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013337 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013338}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013339
Mark Mueller098c9cb2016-09-08 09:01:57 -060013340TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13341 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13342
13343 ASSERT_NO_FATAL_FAILURE(InitState());
13344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13345
13346 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013347 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013348
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013349 char const *vsSource =
13350 "#version 450\n"
13351 "\n"
13352 "out gl_PerVertex {\n"
13353 " vec4 gl_Position;\n"
13354 "};\n"
13355 "void main(){\n"
13356 " gl_Position = vec4(1);\n"
13357 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013358
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013359 char const *fsSource =
13360 "#version 450\n"
13361 "\n"
13362 "layout (constant_id = 0) const float r = 0.0f;\n"
13363 "layout(location = 0) out vec4 uFragColor;\n"
13364 "void main(){\n"
13365 " uFragColor = vec4(r,1,0,1);\n"
13366 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013367
13368 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13369 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13370
13371 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13372 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13373
13374 VkPipelineLayout pipeline_layout;
13375 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13376
13377 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13378 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13379 vp_state_create_info.viewportCount = 1;
13380 VkViewport viewport = {};
13381 vp_state_create_info.pViewports = &viewport;
13382 vp_state_create_info.scissorCount = 1;
13383 VkRect2D scissors = {};
13384 vp_state_create_info.pScissors = &scissors;
13385
13386 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13387
13388 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13389 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13390 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13391 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13392
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013393 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013394
13395 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13396 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13397
13398 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13399 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13400 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13401
13402 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13403 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13404 rasterization_state_create_info.pNext = nullptr;
13405 rasterization_state_create_info.lineWidth = 1.0f;
13406 rasterization_state_create_info.rasterizerDiscardEnable = true;
13407
13408 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13409 color_blend_attachment_state.blendEnable = VK_FALSE;
13410 color_blend_attachment_state.colorWriteMask = 0xf;
13411
13412 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13413 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13414 color_blend_state_create_info.attachmentCount = 1;
13415 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13416
13417 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13418 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13419 graphicspipe_create_info.stageCount = 2;
13420 graphicspipe_create_info.pStages = shader_stage_create_info;
13421 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13422 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13423 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13424 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13425 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13426 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13427 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13428 graphicspipe_create_info.layout = pipeline_layout;
13429 graphicspipe_create_info.renderPass = renderPass();
13430
13431 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13432 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13433
13434 VkPipelineCache pipelineCache;
13435 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13436
13437 // This structure maps constant ids to data locations.
13438 const VkSpecializationMapEntry entry =
13439 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013440 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013441
13442 uint32_t data = 1;
13443
13444 // Set up the info describing spec map and data
13445 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013446 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013447 };
13448 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13449
13450 VkPipeline pipeline;
13451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13452 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13453 m_errorMonitor->VerifyFound();
13454
13455 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13456 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13457}
13458
13459TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13460 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13461
13462 ASSERT_NO_FATAL_FAILURE(InitState());
13463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13464
13465 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13466
13467 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13468 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13469 descriptor_pool_type_count[0].descriptorCount = 1;
13470 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13471 descriptor_pool_type_count[1].descriptorCount = 1;
13472
13473 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13474 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13475 descriptor_pool_create_info.maxSets = 1;
13476 descriptor_pool_create_info.poolSizeCount = 2;
13477 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13478 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13479
13480 VkDescriptorPool descriptorset_pool;
13481 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13482
13483 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13484 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13485 descriptorset_layout_binding.descriptorCount = 1;
13486 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13487
13488 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13489 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13490 descriptorset_layout_create_info.bindingCount = 1;
13491 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13492
13493 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013494 ASSERT_VK_SUCCESS(
13495 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013496
13497 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13498 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13499 descriptorset_allocate_info.descriptorSetCount = 1;
13500 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13501 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13502 VkDescriptorSet descriptorset;
13503 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13504
13505 // Challenge core_validation with a non uniform buffer type.
13506 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13507
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013508 char const *vsSource =
13509 "#version 450\n"
13510 "\n"
13511 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13512 " mat4 mvp;\n"
13513 "} ubuf;\n"
13514 "out gl_PerVertex {\n"
13515 " vec4 gl_Position;\n"
13516 "};\n"
13517 "void main(){\n"
13518 " gl_Position = ubuf.mvp * vec4(1);\n"
13519 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013520
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013521 char const *fsSource =
13522 "#version 450\n"
13523 "\n"
13524 "layout(location = 0) out vec4 uFragColor;\n"
13525 "void main(){\n"
13526 " uFragColor = vec4(0,1,0,1);\n"
13527 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013528
13529 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13530 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13531
13532 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13533 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13534 pipeline_layout_create_info.setLayoutCount = 1;
13535 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13536
13537 VkPipelineLayout pipeline_layout;
13538 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13539
13540 VkPipelineObj pipe(m_device);
13541 pipe.AddColorAttachment();
13542 pipe.AddShader(&vs);
13543 pipe.AddShader(&fs);
13544
13545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13546 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13547 m_errorMonitor->VerifyFound();
13548
13549 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13550 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13551 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13552}
13553
13554TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13555 TEST_DESCRIPTION(
13556 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13557
13558 ASSERT_NO_FATAL_FAILURE(InitState());
13559 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13560
13561 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13562
13563 VkDescriptorPoolSize descriptor_pool_type_count = {};
13564 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13565 descriptor_pool_type_count.descriptorCount = 1;
13566
13567 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13568 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13569 descriptor_pool_create_info.maxSets = 1;
13570 descriptor_pool_create_info.poolSizeCount = 1;
13571 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13572 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13573
13574 VkDescriptorPool descriptorset_pool;
13575 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13576
13577 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13578 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13579 descriptorset_layout_binding.descriptorCount = 1;
13580 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13581 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13582
13583 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13584 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13585 descriptorset_layout_create_info.bindingCount = 1;
13586 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13587
13588 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013589 ASSERT_VK_SUCCESS(
13590 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013591
13592 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13593 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13594 descriptorset_allocate_info.descriptorSetCount = 1;
13595 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13596 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13597 VkDescriptorSet descriptorset;
13598 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13599
13600 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13601
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013602 char const *vsSource =
13603 "#version 450\n"
13604 "\n"
13605 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13606 " mat4 mvp;\n"
13607 "} ubuf;\n"
13608 "out gl_PerVertex {\n"
13609 " vec4 gl_Position;\n"
13610 "};\n"
13611 "void main(){\n"
13612 " gl_Position = ubuf.mvp * vec4(1);\n"
13613 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013614
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013615 char const *fsSource =
13616 "#version 450\n"
13617 "\n"
13618 "layout(location = 0) out vec4 uFragColor;\n"
13619 "void main(){\n"
13620 " uFragColor = vec4(0,1,0,1);\n"
13621 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013622
13623 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13624 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13625
13626 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13627 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13628 pipeline_layout_create_info.setLayoutCount = 1;
13629 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13630
13631 VkPipelineLayout pipeline_layout;
13632 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13633
13634 VkPipelineObj pipe(m_device);
13635 pipe.AddColorAttachment();
13636 pipe.AddShader(&vs);
13637 pipe.AddShader(&fs);
13638
13639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13640 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13641 m_errorMonitor->VerifyFound();
13642
13643 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13644 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13645 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13646}
13647
13648TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013649 TEST_DESCRIPTION(
13650 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13651 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013652
13653 ASSERT_NO_FATAL_FAILURE(InitState());
13654 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13655
13656 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013657 "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 -060013658
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013659 char const *vsSource =
13660 "#version 450\n"
13661 "\n"
13662 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13663 "out gl_PerVertex {\n"
13664 " vec4 gl_Position;\n"
13665 "};\n"
13666 "void main(){\n"
13667 " gl_Position = vec4(consts.x);\n"
13668 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013669
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013670 char const *fsSource =
13671 "#version 450\n"
13672 "\n"
13673 "layout(location = 0) out vec4 uFragColor;\n"
13674 "void main(){\n"
13675 " uFragColor = vec4(0,1,0,1);\n"
13676 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013677
13678 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13679 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13680
13681 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13682 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13683
13684 // Set up a push constant range
13685 VkPushConstantRange push_constant_ranges = {};
13686 // Set to the wrong stage to challenge core_validation
13687 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13688 push_constant_ranges.size = 4;
13689
13690 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13691 pipeline_layout_create_info.pushConstantRangeCount = 1;
13692
13693 VkPipelineLayout pipeline_layout;
13694 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13695
13696 VkPipelineObj pipe(m_device);
13697 pipe.AddColorAttachment();
13698 pipe.AddShader(&vs);
13699 pipe.AddShader(&fs);
13700
13701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13702 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13703 m_errorMonitor->VerifyFound();
13704
13705 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13706}
13707
13708TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13709 TEST_DESCRIPTION(
13710 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13711
13712 ASSERT_NO_FATAL_FAILURE(InitState());
13713 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13714
13715 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013716 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013717
13718 // Some awkward steps are required to test with custom device features.
13719 std::vector<const char *> device_extension_names;
13720 auto features = m_device->phy().features();
13721 // Disable support for 64 bit floats
13722 features.shaderFloat64 = false;
13723 // The sacrificial device object
13724 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13725
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013726 char const *vsSource =
13727 "#version 450\n"
13728 "\n"
13729 "out gl_PerVertex {\n"
13730 " vec4 gl_Position;\n"
13731 "};\n"
13732 "void main(){\n"
13733 " gl_Position = vec4(1);\n"
13734 "}\n";
13735 char const *fsSource =
13736 "#version 450\n"
13737 "\n"
13738 "layout(location=0) out vec4 color;\n"
13739 "void main(){\n"
13740 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13741 " color = vec4(green);\n"
13742 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013743
13744 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13745 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13746
13747 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013748
13749 VkPipelineObj pipe(&test_device);
13750 pipe.AddColorAttachment();
13751 pipe.AddShader(&vs);
13752 pipe.AddShader(&fs);
13753
13754 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13755 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13756 VkPipelineLayout pipeline_layout;
13757 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13758
13759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13760 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13761 m_errorMonitor->VerifyFound();
13762
13763 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13764}
13765
13766TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13767 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13768
13769 ASSERT_NO_FATAL_FAILURE(InitState());
13770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13771
13772 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13773
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013774 char const *vsSource =
13775 "#version 450\n"
13776 "\n"
13777 "out gl_PerVertex {\n"
13778 " vec4 gl_Position;\n"
13779 "};\n"
13780 "layout(xfb_buffer = 1) out;"
13781 "void main(){\n"
13782 " gl_Position = vec4(1);\n"
13783 "}\n";
13784 char const *fsSource =
13785 "#version 450\n"
13786 "\n"
13787 "layout(location=0) out vec4 color;\n"
13788 "void main(){\n"
13789 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13790 " color = vec4(green);\n"
13791 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013792
13793 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13794 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13795
13796 VkPipelineObj pipe(m_device);
13797 pipe.AddColorAttachment();
13798 pipe.AddShader(&vs);
13799 pipe.AddShader(&fs);
13800
13801 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13802 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13803 VkPipelineLayout pipeline_layout;
13804 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13805
13806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13807 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13808 m_errorMonitor->VerifyFound();
13809
13810 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13811}
13812
Karl Schultz6addd812016-02-02 17:17:23 -070013813TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013814 TEST_DESCRIPTION(
13815 "Test that an error is produced for a fragment shader input "
13816 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013817
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013819
Chris Forbes59cb88d2015-05-25 11:13:13 +120013820 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013821 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013822
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013823 char const *vsSource =
13824 "#version 450\n"
13825 "\n"
13826 "out gl_PerVertex {\n"
13827 " vec4 gl_Position;\n"
13828 "};\n"
13829 "void main(){\n"
13830 " gl_Position = vec4(1);\n"
13831 "}\n";
13832 char const *fsSource =
13833 "#version 450\n"
13834 "\n"
13835 "layout(location=0) in float x;\n"
13836 "layout(location=0) out vec4 color;\n"
13837 "void main(){\n"
13838 " color = vec4(x);\n"
13839 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013840
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013841 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13842 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013843
13844 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013845 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013846 pipe.AddShader(&vs);
13847 pipe.AddShader(&fs);
13848
Chris Forbes59cb88d2015-05-25 11:13:13 +120013849 VkDescriptorSetObj descriptorSet(m_device);
13850 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013851 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013852
Tony Barbour5781e8f2015-08-04 16:23:11 -060013853 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013854
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013855 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013856}
13857
Karl Schultz6addd812016-02-02 17:17:23 -070013858TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013859 TEST_DESCRIPTION(
13860 "Test that an error is produced for a fragment shader input "
13861 "within an interace block, which is not present in the outputs "
13862 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013864
13865 ASSERT_NO_FATAL_FAILURE(InitState());
13866 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13867
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013868 char const *vsSource =
13869 "#version 450\n"
13870 "\n"
13871 "out gl_PerVertex {\n"
13872 " vec4 gl_Position;\n"
13873 "};\n"
13874 "void main(){\n"
13875 " gl_Position = vec4(1);\n"
13876 "}\n";
13877 char const *fsSource =
13878 "#version 450\n"
13879 "\n"
13880 "in block { layout(location=0) float x; } ins;\n"
13881 "layout(location=0) out vec4 color;\n"
13882 "void main(){\n"
13883 " color = vec4(ins.x);\n"
13884 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013885
13886 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13887 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13888
13889 VkPipelineObj pipe(m_device);
13890 pipe.AddColorAttachment();
13891 pipe.AddShader(&vs);
13892 pipe.AddShader(&fs);
13893
13894 VkDescriptorSetObj descriptorSet(m_device);
13895 descriptorSet.AppendDummy();
13896 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13897
13898 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13899
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013900 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013901}
13902
Karl Schultz6addd812016-02-02 17:17:23 -070013903TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013904 TEST_DESCRIPTION(
13905 "Test that an error is produced for mismatched array sizes "
13906 "across the vertex->fragment shader interface");
13907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13908 "Type mismatch on location 0.0: 'ptr to "
13909 "output arr[2] of float32' vs 'ptr to "
13910 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013911
13912 ASSERT_NO_FATAL_FAILURE(InitState());
13913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13914
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013915 char const *vsSource =
13916 "#version 450\n"
13917 "\n"
13918 "layout(location=0) out float x[2];\n"
13919 "out gl_PerVertex {\n"
13920 " vec4 gl_Position;\n"
13921 "};\n"
13922 "void main(){\n"
13923 " x[0] = 0; x[1] = 0;\n"
13924 " gl_Position = vec4(1);\n"
13925 "}\n";
13926 char const *fsSource =
13927 "#version 450\n"
13928 "\n"
13929 "layout(location=0) in float x[1];\n"
13930 "layout(location=0) out vec4 color;\n"
13931 "void main(){\n"
13932 " color = vec4(x[0]);\n"
13933 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013934
13935 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13936 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13937
13938 VkPipelineObj pipe(m_device);
13939 pipe.AddColorAttachment();
13940 pipe.AddShader(&vs);
13941 pipe.AddShader(&fs);
13942
13943 VkDescriptorSetObj descriptorSet(m_device);
13944 descriptorSet.AppendDummy();
13945 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13946
13947 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13948
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013949 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013950}
13951
Karl Schultz6addd812016-02-02 17:17:23 -070013952TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013953 TEST_DESCRIPTION(
13954 "Test that an error is produced for mismatched types across "
13955 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013957
Chris Forbesb56af562015-05-25 11:13:17 +120013958 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013960
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013961 char const *vsSource =
13962 "#version 450\n"
13963 "\n"
13964 "layout(location=0) out int x;\n"
13965 "out gl_PerVertex {\n"
13966 " vec4 gl_Position;\n"
13967 "};\n"
13968 "void main(){\n"
13969 " x = 0;\n"
13970 " gl_Position = vec4(1);\n"
13971 "}\n";
13972 char const *fsSource =
13973 "#version 450\n"
13974 "\n"
13975 "layout(location=0) in float x;\n" /* VS writes int */
13976 "layout(location=0) out vec4 color;\n"
13977 "void main(){\n"
13978 " color = vec4(x);\n"
13979 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013980
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013981 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13982 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013983
13984 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013985 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013986 pipe.AddShader(&vs);
13987 pipe.AddShader(&fs);
13988
Chris Forbesb56af562015-05-25 11:13:17 +120013989 VkDescriptorSetObj descriptorSet(m_device);
13990 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013991 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013992
Tony Barbour5781e8f2015-08-04 16:23:11 -060013993 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013994
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013995 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013996}
13997
Karl Schultz6addd812016-02-02 17:17:23 -070013998TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013999 TEST_DESCRIPTION(
14000 "Test that an error is produced for mismatched types across "
14001 "the vertex->fragment shader interface, when the variable is contained within "
14002 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014004
14005 ASSERT_NO_FATAL_FAILURE(InitState());
14006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14007
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014008 char const *vsSource =
14009 "#version 450\n"
14010 "\n"
14011 "out block { layout(location=0) int x; } outs;\n"
14012 "out gl_PerVertex {\n"
14013 " vec4 gl_Position;\n"
14014 "};\n"
14015 "void main(){\n"
14016 " outs.x = 0;\n"
14017 " gl_Position = vec4(1);\n"
14018 "}\n";
14019 char const *fsSource =
14020 "#version 450\n"
14021 "\n"
14022 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14023 "layout(location=0) out vec4 color;\n"
14024 "void main(){\n"
14025 " color = vec4(ins.x);\n"
14026 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014027
14028 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14029 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14030
14031 VkPipelineObj pipe(m_device);
14032 pipe.AddColorAttachment();
14033 pipe.AddShader(&vs);
14034 pipe.AddShader(&fs);
14035
14036 VkDescriptorSetObj descriptorSet(m_device);
14037 descriptorSet.AppendDummy();
14038 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14039
14040 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14041
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014042 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014043}
14044
14045TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014046 TEST_DESCRIPTION(
14047 "Test that an error is produced for location mismatches across "
14048 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14049 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014050 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 +130014051
14052 ASSERT_NO_FATAL_FAILURE(InitState());
14053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14054
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014055 char const *vsSource =
14056 "#version 450\n"
14057 "\n"
14058 "out block { layout(location=1) float x; } outs;\n"
14059 "out gl_PerVertex {\n"
14060 " vec4 gl_Position;\n"
14061 "};\n"
14062 "void main(){\n"
14063 " outs.x = 0;\n"
14064 " gl_Position = vec4(1);\n"
14065 "}\n";
14066 char const *fsSource =
14067 "#version 450\n"
14068 "\n"
14069 "in block { layout(location=0) float x; } ins;\n"
14070 "layout(location=0) out vec4 color;\n"
14071 "void main(){\n"
14072 " color = vec4(ins.x);\n"
14073 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014074
14075 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14076 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14077
14078 VkPipelineObj pipe(m_device);
14079 pipe.AddColorAttachment();
14080 pipe.AddShader(&vs);
14081 pipe.AddShader(&fs);
14082
14083 VkDescriptorSetObj descriptorSet(m_device);
14084 descriptorSet.AppendDummy();
14085 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14086
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014087 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014088 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14089
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014090 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014091}
14092
14093TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014094 TEST_DESCRIPTION(
14095 "Test that an error is produced for component mismatches across the "
14096 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14097 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014098 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 +130014099
14100 ASSERT_NO_FATAL_FAILURE(InitState());
14101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14102
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014103 char const *vsSource =
14104 "#version 450\n"
14105 "\n"
14106 "out block { layout(location=0, component=0) float x; } outs;\n"
14107 "out gl_PerVertex {\n"
14108 " vec4 gl_Position;\n"
14109 "};\n"
14110 "void main(){\n"
14111 " outs.x = 0;\n"
14112 " gl_Position = vec4(1);\n"
14113 "}\n";
14114 char const *fsSource =
14115 "#version 450\n"
14116 "\n"
14117 "in block { layout(location=0, component=1) float x; } ins;\n"
14118 "layout(location=0) out vec4 color;\n"
14119 "void main(){\n"
14120 " color = vec4(ins.x);\n"
14121 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014122
14123 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14124 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14125
14126 VkPipelineObj pipe(m_device);
14127 pipe.AddColorAttachment();
14128 pipe.AddShader(&vs);
14129 pipe.AddShader(&fs);
14130
14131 VkDescriptorSetObj descriptorSet(m_device);
14132 descriptorSet.AppendDummy();
14133 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14134
14135 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14136
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014137 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014138}
14139
Chris Forbes1f3b0152016-11-30 12:48:40 +130014140TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14141 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14142
14143 ASSERT_NO_FATAL_FAILURE(InitState());
14144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14145
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014146 char const *vsSource =
14147 "#version 450\n"
14148 "layout(location=0) out mediump float x;\n"
14149 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14150 char const *fsSource =
14151 "#version 450\n"
14152 "layout(location=0) in highp float x;\n"
14153 "layout(location=0) out vec4 color;\n"
14154 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014155
14156 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14157 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14158
14159 VkPipelineObj pipe(m_device);
14160 pipe.AddColorAttachment();
14161 pipe.AddShader(&vs);
14162 pipe.AddShader(&fs);
14163
14164 VkDescriptorSetObj descriptorSet(m_device);
14165 descriptorSet.AppendDummy();
14166 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14167
14168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14169
14170 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14171
14172 m_errorMonitor->VerifyFound();
14173}
14174
Chris Forbes870a39e2016-11-30 12:55:56 +130014175TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14176 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14177
14178 ASSERT_NO_FATAL_FAILURE(InitState());
14179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14180
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014181 char const *vsSource =
14182 "#version 450\n"
14183 "out block { layout(location=0) mediump float x; };\n"
14184 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14185 char const *fsSource =
14186 "#version 450\n"
14187 "in block { layout(location=0) highp float x; };\n"
14188 "layout(location=0) out vec4 color;\n"
14189 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014190
14191 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14192 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14193
14194 VkPipelineObj pipe(m_device);
14195 pipe.AddColorAttachment();
14196 pipe.AddShader(&vs);
14197 pipe.AddShader(&fs);
14198
14199 VkDescriptorSetObj descriptorSet(m_device);
14200 descriptorSet.AppendDummy();
14201 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14202
14203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14204
14205 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14206
14207 m_errorMonitor->VerifyFound();
14208}
14209
Karl Schultz6addd812016-02-02 17:17:23 -070014210TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014211 TEST_DESCRIPTION(
14212 "Test that a warning is produced for a vertex attribute which is "
14213 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014215
Chris Forbesde136e02015-05-25 11:13:28 +120014216 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014218
14219 VkVertexInputBindingDescription input_binding;
14220 memset(&input_binding, 0, sizeof(input_binding));
14221
14222 VkVertexInputAttributeDescription input_attrib;
14223 memset(&input_attrib, 0, sizeof(input_attrib));
14224 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14225
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014226 char const *vsSource =
14227 "#version 450\n"
14228 "\n"
14229 "out gl_PerVertex {\n"
14230 " vec4 gl_Position;\n"
14231 "};\n"
14232 "void main(){\n"
14233 " gl_Position = vec4(1);\n"
14234 "}\n";
14235 char const *fsSource =
14236 "#version 450\n"
14237 "\n"
14238 "layout(location=0) out vec4 color;\n"
14239 "void main(){\n"
14240 " color = vec4(1);\n"
14241 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014242
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014243 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14244 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014245
14246 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014247 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014248 pipe.AddShader(&vs);
14249 pipe.AddShader(&fs);
14250
14251 pipe.AddVertexInputBindings(&input_binding, 1);
14252 pipe.AddVertexInputAttribs(&input_attrib, 1);
14253
Chris Forbesde136e02015-05-25 11:13:28 +120014254 VkDescriptorSetObj descriptorSet(m_device);
14255 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014256 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014257
Tony Barbour5781e8f2015-08-04 16:23:11 -060014258 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014259
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014260 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014261}
14262
Karl Schultz6addd812016-02-02 17:17:23 -070014263TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014264 TEST_DESCRIPTION(
14265 "Test that a warning is produced for a location mismatch on "
14266 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014268
14269 ASSERT_NO_FATAL_FAILURE(InitState());
14270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14271
14272 VkVertexInputBindingDescription input_binding;
14273 memset(&input_binding, 0, sizeof(input_binding));
14274
14275 VkVertexInputAttributeDescription input_attrib;
14276 memset(&input_attrib, 0, sizeof(input_attrib));
14277 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14278
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014279 char const *vsSource =
14280 "#version 450\n"
14281 "\n"
14282 "layout(location=1) in float x;\n"
14283 "out gl_PerVertex {\n"
14284 " vec4 gl_Position;\n"
14285 "};\n"
14286 "void main(){\n"
14287 " gl_Position = vec4(x);\n"
14288 "}\n";
14289 char const *fsSource =
14290 "#version 450\n"
14291 "\n"
14292 "layout(location=0) out vec4 color;\n"
14293 "void main(){\n"
14294 " color = vec4(1);\n"
14295 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014296
14297 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14298 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14299
14300 VkPipelineObj pipe(m_device);
14301 pipe.AddColorAttachment();
14302 pipe.AddShader(&vs);
14303 pipe.AddShader(&fs);
14304
14305 pipe.AddVertexInputBindings(&input_binding, 1);
14306 pipe.AddVertexInputAttribs(&input_attrib, 1);
14307
14308 VkDescriptorSetObj descriptorSet(m_device);
14309 descriptorSet.AppendDummy();
14310 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14311
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014312 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014313 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14314
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014315 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014316}
14317
Karl Schultz6addd812016-02-02 17:17:23 -070014318TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014319 TEST_DESCRIPTION(
14320 "Test that an error is produced for a vertex shader input which is not "
14321 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14323 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014324
Chris Forbes62e8e502015-05-25 11:13:29 +120014325 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014326 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014327
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014328 char const *vsSource =
14329 "#version 450\n"
14330 "\n"
14331 "layout(location=0) in vec4 x;\n" /* not provided */
14332 "out gl_PerVertex {\n"
14333 " vec4 gl_Position;\n"
14334 "};\n"
14335 "void main(){\n"
14336 " gl_Position = x;\n"
14337 "}\n";
14338 char const *fsSource =
14339 "#version 450\n"
14340 "\n"
14341 "layout(location=0) out vec4 color;\n"
14342 "void main(){\n"
14343 " color = vec4(1);\n"
14344 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014345
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014346 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14347 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014348
14349 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014350 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014351 pipe.AddShader(&vs);
14352 pipe.AddShader(&fs);
14353
Chris Forbes62e8e502015-05-25 11:13:29 +120014354 VkDescriptorSetObj descriptorSet(m_device);
14355 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014356 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014357
Tony Barbour5781e8f2015-08-04 16:23:11 -060014358 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014359
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014360 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014361}
14362
Karl Schultz6addd812016-02-02 17:17:23 -070014363TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014364 TEST_DESCRIPTION(
14365 "Test that an error is produced for a mismatch between the "
14366 "fundamental type (float/int/uint) of an attribute and the "
14367 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014368 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 -060014369
Chris Forbesc97d98e2015-05-25 11:13:31 +120014370 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014372
14373 VkVertexInputBindingDescription input_binding;
14374 memset(&input_binding, 0, sizeof(input_binding));
14375
14376 VkVertexInputAttributeDescription input_attrib;
14377 memset(&input_attrib, 0, sizeof(input_attrib));
14378 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14379
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014380 char const *vsSource =
14381 "#version 450\n"
14382 "\n"
14383 "layout(location=0) in int x;\n" /* attrib provided float */
14384 "out gl_PerVertex {\n"
14385 " vec4 gl_Position;\n"
14386 "};\n"
14387 "void main(){\n"
14388 " gl_Position = vec4(x);\n"
14389 "}\n";
14390 char const *fsSource =
14391 "#version 450\n"
14392 "\n"
14393 "layout(location=0) out vec4 color;\n"
14394 "void main(){\n"
14395 " color = vec4(1);\n"
14396 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014397
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014398 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14399 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014400
14401 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014402 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014403 pipe.AddShader(&vs);
14404 pipe.AddShader(&fs);
14405
14406 pipe.AddVertexInputBindings(&input_binding, 1);
14407 pipe.AddVertexInputAttribs(&input_attrib, 1);
14408
Chris Forbesc97d98e2015-05-25 11:13:31 +120014409 VkDescriptorSetObj descriptorSet(m_device);
14410 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014411 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014412
Tony Barbour5781e8f2015-08-04 16:23:11 -060014413 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014414
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014415 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014416}
14417
Chris Forbesc68b43c2016-04-06 11:18:47 +120014418TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014419 TEST_DESCRIPTION(
14420 "Test that an error is produced for a pipeline containing multiple "
14421 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14423 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014424
14425 ASSERT_NO_FATAL_FAILURE(InitState());
14426 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14427
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014428 char const *vsSource =
14429 "#version 450\n"
14430 "\n"
14431 "out gl_PerVertex {\n"
14432 " vec4 gl_Position;\n"
14433 "};\n"
14434 "void main(){\n"
14435 " gl_Position = vec4(1);\n"
14436 "}\n";
14437 char const *fsSource =
14438 "#version 450\n"
14439 "\n"
14440 "layout(location=0) out vec4 color;\n"
14441 "void main(){\n"
14442 " color = vec4(1);\n"
14443 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014444
14445 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14446 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14447
14448 VkPipelineObj pipe(m_device);
14449 pipe.AddColorAttachment();
14450 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014451 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014452 pipe.AddShader(&fs);
14453
14454 VkDescriptorSetObj descriptorSet(m_device);
14455 descriptorSet.AppendDummy();
14456 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14457
14458 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14459
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014460 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014461}
14462
Chris Forbes82ff92a2016-09-09 10:50:24 +120014463TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014465
14466 ASSERT_NO_FATAL_FAILURE(InitState());
14467 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14468
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014469 char const *vsSource =
14470 "#version 450\n"
14471 "out gl_PerVertex {\n"
14472 " vec4 gl_Position;\n"
14473 "};\n"
14474 "void main(){\n"
14475 " gl_Position = vec4(0);\n"
14476 "}\n";
14477 char const *fsSource =
14478 "#version 450\n"
14479 "\n"
14480 "layout(location=0) out vec4 color;\n"
14481 "void main(){\n"
14482 " color = vec4(1);\n"
14483 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014484
14485 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14486 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14487
14488 VkPipelineObj pipe(m_device);
14489 pipe.AddColorAttachment();
14490 pipe.AddShader(&vs);
14491 pipe.AddShader(&fs);
14492
14493 VkDescriptorSetObj descriptorSet(m_device);
14494 descriptorSet.AppendDummy();
14495 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14496
14497 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14498
14499 m_errorMonitor->VerifyFound();
14500}
14501
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014502TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14504 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14505 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014506
14507 ASSERT_NO_FATAL_FAILURE(InitState());
14508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14509
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014510 char const *vsSource =
14511 "#version 450\n"
14512 "void main(){ gl_Position = vec4(0); }\n";
14513 char const *fsSource =
14514 "#version 450\n"
14515 "\n"
14516 "layout(location=0) out vec4 color;\n"
14517 "void main(){\n"
14518 " color = vec4(1);\n"
14519 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014520
14521 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14522 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14523
14524 VkPipelineObj pipe(m_device);
14525 pipe.AddColorAttachment();
14526 pipe.AddShader(&vs);
14527 pipe.AddShader(&fs);
14528
14529 VkDescriptorSetObj descriptorSet(m_device);
14530 descriptorSet.AppendDummy();
14531 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14532
14533 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014534 {
14535 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14536 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14537 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014538 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014539 {
14540 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14541 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14542 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014543 },
14544 };
14545 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014546 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014547 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014548 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14549 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014550 VkRenderPass rp;
14551 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14552 ASSERT_VK_SUCCESS(err);
14553
14554 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14555
14556 m_errorMonitor->VerifyFound();
14557
14558 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14559}
14560
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014561TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014562 TEST_DESCRIPTION(
14563 "Test that an error is produced for a variable output from "
14564 "the TCS without the patch decoration, but consumed in the TES "
14565 "with the decoration.");
14566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14567 "is per-vertex in tessellation control shader stage "
14568 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014569
14570 ASSERT_NO_FATAL_FAILURE(InitState());
14571 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14572
Chris Forbesc1e852d2016-04-04 19:26:42 +120014573 if (!m_device->phy().features().tessellationShader) {
14574 printf("Device does not support tessellation shaders; skipped.\n");
14575 return;
14576 }
14577
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014578 char const *vsSource =
14579 "#version 450\n"
14580 "void main(){}\n";
14581 char const *tcsSource =
14582 "#version 450\n"
14583 "layout(location=0) out int x[];\n"
14584 "layout(vertices=3) out;\n"
14585 "void main(){\n"
14586 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14587 " gl_TessLevelInner[0] = 1;\n"
14588 " x[gl_InvocationID] = gl_InvocationID;\n"
14589 "}\n";
14590 char const *tesSource =
14591 "#version 450\n"
14592 "layout(triangles, equal_spacing, cw) in;\n"
14593 "layout(location=0) patch in int x;\n"
14594 "out gl_PerVertex { vec4 gl_Position; };\n"
14595 "void main(){\n"
14596 " gl_Position.xyz = gl_TessCoord;\n"
14597 " gl_Position.w = x;\n"
14598 "}\n";
14599 char const *fsSource =
14600 "#version 450\n"
14601 "layout(location=0) out vec4 color;\n"
14602 "void main(){\n"
14603 " color = vec4(1);\n"
14604 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014605
14606 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14607 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14608 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14609 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14610
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014611 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14612 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014613
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014614 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014615
14616 VkPipelineObj pipe(m_device);
14617 pipe.SetInputAssembly(&iasci);
14618 pipe.SetTessellation(&tsci);
14619 pipe.AddColorAttachment();
14620 pipe.AddShader(&vs);
14621 pipe.AddShader(&tcs);
14622 pipe.AddShader(&tes);
14623 pipe.AddShader(&fs);
14624
14625 VkDescriptorSetObj descriptorSet(m_device);
14626 descriptorSet.AppendDummy();
14627 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14628
14629 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14630
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014631 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014632}
14633
Karl Schultz6addd812016-02-02 17:17:23 -070014634TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014635 TEST_DESCRIPTION(
14636 "Test that an error is produced for a vertex attribute setup where multiple "
14637 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14639 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014640
Chris Forbes280ba2c2015-06-12 11:16:41 +120014641 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014642 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014643
14644 /* Two binding descriptions for binding 0 */
14645 VkVertexInputBindingDescription input_bindings[2];
14646 memset(input_bindings, 0, sizeof(input_bindings));
14647
14648 VkVertexInputAttributeDescription input_attrib;
14649 memset(&input_attrib, 0, sizeof(input_attrib));
14650 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14651
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014652 char const *vsSource =
14653 "#version 450\n"
14654 "\n"
14655 "layout(location=0) in float x;\n" /* attrib provided float */
14656 "out gl_PerVertex {\n"
14657 " vec4 gl_Position;\n"
14658 "};\n"
14659 "void main(){\n"
14660 " gl_Position = vec4(x);\n"
14661 "}\n";
14662 char const *fsSource =
14663 "#version 450\n"
14664 "\n"
14665 "layout(location=0) out vec4 color;\n"
14666 "void main(){\n"
14667 " color = vec4(1);\n"
14668 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014669
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014670 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14671 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014672
14673 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014674 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014675 pipe.AddShader(&vs);
14676 pipe.AddShader(&fs);
14677
14678 pipe.AddVertexInputBindings(input_bindings, 2);
14679 pipe.AddVertexInputAttribs(&input_attrib, 1);
14680
Chris Forbes280ba2c2015-06-12 11:16:41 +120014681 VkDescriptorSetObj descriptorSet(m_device);
14682 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014683 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014684
Tony Barbour5781e8f2015-08-04 16:23:11 -060014685 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014686
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014687 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014688}
Chris Forbes8f68b562015-05-25 11:13:32 +120014689
Karl Schultz6addd812016-02-02 17:17:23 -070014690TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014691 TEST_DESCRIPTION(
14692 "Test that an error is produced for a fragment shader which does not "
14693 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014695
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014696 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014697
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014698 char const *vsSource =
14699 "#version 450\n"
14700 "\n"
14701 "out gl_PerVertex {\n"
14702 " vec4 gl_Position;\n"
14703 "};\n"
14704 "void main(){\n"
14705 " gl_Position = vec4(1);\n"
14706 "}\n";
14707 char const *fsSource =
14708 "#version 450\n"
14709 "\n"
14710 "void main(){\n"
14711 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014712
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014713 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14714 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014715
14716 VkPipelineObj pipe(m_device);
14717 pipe.AddShader(&vs);
14718 pipe.AddShader(&fs);
14719
Chia-I Wu08accc62015-07-07 11:50:03 +080014720 /* set up CB 0, not written */
14721 pipe.AddColorAttachment();
14722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014723
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014724 VkDescriptorSetObj descriptorSet(m_device);
14725 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014726 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014727
Tony Barbour5781e8f2015-08-04 16:23:11 -060014728 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014729
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014730 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014731}
14732
Karl Schultz6addd812016-02-02 17:17:23 -070014733TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014734 TEST_DESCRIPTION(
14735 "Test that a warning is produced for a fragment shader which provides a spurious "
14736 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014738 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014739
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014740 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014741
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014742 char const *vsSource =
14743 "#version 450\n"
14744 "\n"
14745 "out gl_PerVertex {\n"
14746 " vec4 gl_Position;\n"
14747 "};\n"
14748 "void main(){\n"
14749 " gl_Position = vec4(1);\n"
14750 "}\n";
14751 char const *fsSource =
14752 "#version 450\n"
14753 "\n"
14754 "layout(location=0) out vec4 x;\n"
14755 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14756 "void main(){\n"
14757 " x = vec4(1);\n"
14758 " y = vec4(1);\n"
14759 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014760
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014761 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14762 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014763
14764 VkPipelineObj pipe(m_device);
14765 pipe.AddShader(&vs);
14766 pipe.AddShader(&fs);
14767
Chia-I Wu08accc62015-07-07 11:50:03 +080014768 /* set up CB 0, not written */
14769 pipe.AddColorAttachment();
14770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014771 /* FS writes CB 1, but we don't configure it */
14772
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014773 VkDescriptorSetObj descriptorSet(m_device);
14774 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014775 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014776
Tony Barbour5781e8f2015-08-04 16:23:11 -060014777 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014778
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014779 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014780}
14781
Karl Schultz6addd812016-02-02 17:17:23 -070014782TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014783 TEST_DESCRIPTION(
14784 "Test that an error is produced for a mismatch between the fundamental "
14785 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014787
Chris Forbesa36d69e2015-05-25 11:13:44 +120014788 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014789
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014790 char const *vsSource =
14791 "#version 450\n"
14792 "\n"
14793 "out gl_PerVertex {\n"
14794 " vec4 gl_Position;\n"
14795 "};\n"
14796 "void main(){\n"
14797 " gl_Position = vec4(1);\n"
14798 "}\n";
14799 char const *fsSource =
14800 "#version 450\n"
14801 "\n"
14802 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14803 "void main(){\n"
14804 " x = ivec4(1);\n"
14805 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014806
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014807 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14808 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014809
14810 VkPipelineObj pipe(m_device);
14811 pipe.AddShader(&vs);
14812 pipe.AddShader(&fs);
14813
Chia-I Wu08accc62015-07-07 11:50:03 +080014814 /* set up CB 0; type is UNORM by default */
14815 pipe.AddColorAttachment();
14816 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014817
Chris Forbesa36d69e2015-05-25 11:13:44 +120014818 VkDescriptorSetObj descriptorSet(m_device);
14819 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014820 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014821
Tony Barbour5781e8f2015-08-04 16:23:11 -060014822 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014823
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014824 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014825}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014826
Karl Schultz6addd812016-02-02 17:17:23 -070014827TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014828 TEST_DESCRIPTION(
14829 "Test that an error is produced for a shader consuming a uniform "
14830 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014832
Chris Forbes556c76c2015-08-14 12:04:59 +120014833 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014834
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014835 char const *vsSource =
14836 "#version 450\n"
14837 "\n"
14838 "out gl_PerVertex {\n"
14839 " vec4 gl_Position;\n"
14840 "};\n"
14841 "void main(){\n"
14842 " gl_Position = vec4(1);\n"
14843 "}\n";
14844 char const *fsSource =
14845 "#version 450\n"
14846 "\n"
14847 "layout(location=0) out vec4 x;\n"
14848 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14849 "void main(){\n"
14850 " x = vec4(bar.y);\n"
14851 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014852
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014853 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14854 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014855
Chris Forbes556c76c2015-08-14 12:04:59 +120014856 VkPipelineObj pipe(m_device);
14857 pipe.AddShader(&vs);
14858 pipe.AddShader(&fs);
14859
14860 /* set up CB 0; type is UNORM by default */
14861 pipe.AddColorAttachment();
14862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14863
14864 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014865 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014866
14867 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14868
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014869 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014870}
14871
Chris Forbes5c59e902016-02-26 16:56:09 +130014872TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014873 TEST_DESCRIPTION(
14874 "Test that an error is produced for a shader consuming push constants "
14875 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014877
14878 ASSERT_NO_FATAL_FAILURE(InitState());
14879
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014880 char const *vsSource =
14881 "#version 450\n"
14882 "\n"
14883 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14884 "out gl_PerVertex {\n"
14885 " vec4 gl_Position;\n"
14886 "};\n"
14887 "void main(){\n"
14888 " gl_Position = vec4(consts.x);\n"
14889 "}\n";
14890 char const *fsSource =
14891 "#version 450\n"
14892 "\n"
14893 "layout(location=0) out vec4 x;\n"
14894 "void main(){\n"
14895 " x = vec4(1);\n"
14896 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014897
14898 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14899 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14900
14901 VkPipelineObj pipe(m_device);
14902 pipe.AddShader(&vs);
14903 pipe.AddShader(&fs);
14904
14905 /* set up CB 0; type is UNORM by default */
14906 pipe.AddColorAttachment();
14907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14908
14909 VkDescriptorSetObj descriptorSet(m_device);
14910 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14911
14912 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14913
14914 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014915 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014916}
14917
Chris Forbes3fb17902016-08-22 14:57:55 +120014918TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014919 TEST_DESCRIPTION(
14920 "Test that an error is produced for a shader consuming an input attachment "
14921 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14923 "consumes input attachment index 0 but not provided in subpass");
14924
14925 ASSERT_NO_FATAL_FAILURE(InitState());
14926
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014927 char const *vsSource =
14928 "#version 450\n"
14929 "\n"
14930 "out gl_PerVertex {\n"
14931 " vec4 gl_Position;\n"
14932 "};\n"
14933 "void main(){\n"
14934 " gl_Position = vec4(1);\n"
14935 "}\n";
14936 char const *fsSource =
14937 "#version 450\n"
14938 "\n"
14939 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14940 "layout(location=0) out vec4 color;\n"
14941 "void main() {\n"
14942 " color = subpassLoad(x);\n"
14943 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014944
14945 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14946 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14947
14948 VkPipelineObj pipe(m_device);
14949 pipe.AddShader(&vs);
14950 pipe.AddShader(&fs);
14951 pipe.AddColorAttachment();
14952 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14953
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014954 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14955 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014956 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014957 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014958 ASSERT_VK_SUCCESS(err);
14959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014960 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014961 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014962 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014963 ASSERT_VK_SUCCESS(err);
14964
14965 // error here.
14966 pipe.CreateVKPipeline(pl, renderPass());
14967
14968 m_errorMonitor->VerifyFound();
14969
14970 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14971 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14972}
14973
Chris Forbes5a9a0472016-08-22 16:02:09 +120014974TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014975 TEST_DESCRIPTION(
14976 "Test that an error is produced for a shader consuming an input attachment "
14977 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120014978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14979 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14980
14981 ASSERT_NO_FATAL_FAILURE(InitState());
14982
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014983 char const *vsSource =
14984 "#version 450\n"
14985 "\n"
14986 "out gl_PerVertex {\n"
14987 " vec4 gl_Position;\n"
14988 "};\n"
14989 "void main(){\n"
14990 " gl_Position = vec4(1);\n"
14991 "}\n";
14992 char const *fsSource =
14993 "#version 450\n"
14994 "\n"
14995 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14996 "layout(location=0) out vec4 color;\n"
14997 "void main() {\n"
14998 " color = subpassLoad(x);\n"
14999 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015000
15001 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15002 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15003
15004 VkPipelineObj pipe(m_device);
15005 pipe.AddShader(&vs);
15006 pipe.AddShader(&fs);
15007 pipe.AddColorAttachment();
15008 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15009
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015010 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15011 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015012 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015013 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015014 ASSERT_VK_SUCCESS(err);
15015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015016 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015017 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015018 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015019 ASSERT_VK_SUCCESS(err);
15020
15021 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015022 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15023 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15024 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15025 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15026 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 +120015027 };
15028 VkAttachmentReference color = {
15029 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15030 };
15031 VkAttachmentReference input = {
15032 1, VK_IMAGE_LAYOUT_GENERAL,
15033 };
15034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015035 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015036
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015037 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015038 VkRenderPass rp;
15039 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15040 ASSERT_VK_SUCCESS(err);
15041
15042 // error here.
15043 pipe.CreateVKPipeline(pl, rp);
15044
15045 m_errorMonitor->VerifyFound();
15046
15047 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15048 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15049 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15050}
15051
Chris Forbes541f7b02016-08-22 15:30:27 +120015052TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015053 TEST_DESCRIPTION(
15054 "Test that an error is produced for a shader consuming an input attachment "
15055 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015057 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015058
15059 ASSERT_NO_FATAL_FAILURE(InitState());
15060
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015061 char const *vsSource =
15062 "#version 450\n"
15063 "\n"
15064 "out gl_PerVertex {\n"
15065 " vec4 gl_Position;\n"
15066 "};\n"
15067 "void main(){\n"
15068 " gl_Position = vec4(1);\n"
15069 "}\n";
15070 char const *fsSource =
15071 "#version 450\n"
15072 "\n"
15073 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15074 "layout(location=0) out vec4 color;\n"
15075 "void main() {\n"
15076 " color = subpassLoad(xs[0]);\n"
15077 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015078
15079 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15080 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15081
15082 VkPipelineObj pipe(m_device);
15083 pipe.AddShader(&vs);
15084 pipe.AddShader(&fs);
15085 pipe.AddColorAttachment();
15086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15087
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015088 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15089 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015090 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015091 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015092 ASSERT_VK_SUCCESS(err);
15093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015094 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015095 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015096 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015097 ASSERT_VK_SUCCESS(err);
15098
15099 // error here.
15100 pipe.CreateVKPipeline(pl, renderPass());
15101
15102 m_errorMonitor->VerifyFound();
15103
15104 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15105 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15106}
15107
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015108TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015109 TEST_DESCRIPTION(
15110 "Test that an error is produced for a compute pipeline consuming a "
15111 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015113
15114 ASSERT_NO_FATAL_FAILURE(InitState());
15115
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015116 char const *csSource =
15117 "#version 450\n"
15118 "\n"
15119 "layout(local_size_x=1) in;\n"
15120 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15121 "void main(){\n"
15122 " x = vec4(1);\n"
15123 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015124
15125 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15126
15127 VkDescriptorSetObj descriptorSet(m_device);
15128 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15129
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015130 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15131 nullptr,
15132 0,
15133 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15134 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15135 descriptorSet.GetPipelineLayout(),
15136 VK_NULL_HANDLE,
15137 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015138
15139 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015140 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015141
15142 m_errorMonitor->VerifyFound();
15143
15144 if (err == VK_SUCCESS) {
15145 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15146 }
15147}
15148
Chris Forbes22a9b092016-07-19 14:34:05 +120015149TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015150 TEST_DESCRIPTION(
15151 "Test that an error is produced for a pipeline consuming a "
15152 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15154 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015155
15156 ASSERT_NO_FATAL_FAILURE(InitState());
15157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015158 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15159 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015160 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015161 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015162 ASSERT_VK_SUCCESS(err);
15163
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015164 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015165 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015166 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015167 ASSERT_VK_SUCCESS(err);
15168
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015169 char const *csSource =
15170 "#version 450\n"
15171 "\n"
15172 "layout(local_size_x=1) in;\n"
15173 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15174 "void main() {\n"
15175 " x.x = 1.0f;\n"
15176 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015177 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015179 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15180 nullptr,
15181 0,
15182 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15183 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15184 pl,
15185 VK_NULL_HANDLE,
15186 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015187
15188 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015189 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015190
15191 m_errorMonitor->VerifyFound();
15192
15193 if (err == VK_SUCCESS) {
15194 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15195 }
15196
15197 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15198 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15199}
15200
Chris Forbes50020592016-07-27 13:52:41 +120015201TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015202 TEST_DESCRIPTION(
15203 "Test that an error is produced when an image view type "
15204 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015205
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015206 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 +120015207
15208 ASSERT_NO_FATAL_FAILURE(InitState());
15209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15210
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015211 char const *vsSource =
15212 "#version 450\n"
15213 "\n"
15214 "out gl_PerVertex { vec4 gl_Position; };\n"
15215 "void main() { gl_Position = vec4(0); }\n";
15216 char const *fsSource =
15217 "#version 450\n"
15218 "\n"
15219 "layout(set=0, binding=0) uniform sampler3D s;\n"
15220 "layout(location=0) out vec4 color;\n"
15221 "void main() {\n"
15222 " color = texture(s, vec3(0));\n"
15223 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015224 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15225 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15226
15227 VkPipelineObj pipe(m_device);
15228 pipe.AddShader(&vs);
15229 pipe.AddShader(&fs);
15230 pipe.AddColorAttachment();
15231
15232 VkTextureObj texture(m_device, nullptr);
15233 VkSamplerObj sampler(m_device);
15234
15235 VkDescriptorSetObj descriptorSet(m_device);
15236 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15237 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15238
15239 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15240 ASSERT_VK_SUCCESS(err);
15241
Tony Barbour552f6c02016-12-21 14:34:07 -070015242 m_commandBuffer->BeginCommandBuffer();
15243 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015244
15245 m_commandBuffer->BindPipeline(pipe);
15246 m_commandBuffer->BindDescriptorSet(descriptorSet);
15247
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015248 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015249 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015250 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015251 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15252
15253 // error produced here.
15254 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15255
15256 m_errorMonitor->VerifyFound();
15257
Tony Barbour552f6c02016-12-21 14:34:07 -070015258 m_commandBuffer->EndRenderPass();
15259 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015260}
15261
Chris Forbes5533bfc2016-07-27 14:12:34 +120015262TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015263 TEST_DESCRIPTION(
15264 "Test that an error is produced when a multisampled images "
15265 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015268
15269 ASSERT_NO_FATAL_FAILURE(InitState());
15270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15271
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015272 char const *vsSource =
15273 "#version 450\n"
15274 "\n"
15275 "out gl_PerVertex { vec4 gl_Position; };\n"
15276 "void main() { gl_Position = vec4(0); }\n";
15277 char const *fsSource =
15278 "#version 450\n"
15279 "\n"
15280 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15281 "layout(location=0) out vec4 color;\n"
15282 "void main() {\n"
15283 " color = texelFetch(s, ivec2(0), 0);\n"
15284 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015285 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15286 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15287
15288 VkPipelineObj pipe(m_device);
15289 pipe.AddShader(&vs);
15290 pipe.AddShader(&fs);
15291 pipe.AddColorAttachment();
15292
15293 VkTextureObj texture(m_device, nullptr);
15294 VkSamplerObj sampler(m_device);
15295
15296 VkDescriptorSetObj descriptorSet(m_device);
15297 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15298 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15299
15300 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15301 ASSERT_VK_SUCCESS(err);
15302
Tony Barbour552f6c02016-12-21 14:34:07 -070015303 m_commandBuffer->BeginCommandBuffer();
15304 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015305
15306 m_commandBuffer->BindPipeline(pipe);
15307 m_commandBuffer->BindDescriptorSet(descriptorSet);
15308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015309 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015310 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015311 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015312 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15313
15314 // error produced here.
15315 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15316
15317 m_errorMonitor->VerifyFound();
15318
Tony Barbour552f6c02016-12-21 14:34:07 -070015319 m_commandBuffer->EndRenderPass();
15320 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015321}
15322
Mark Youngc48c4c12016-04-11 14:26:49 -060015323TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015325
15326 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015327
15328 // Create an image
15329 VkImage image;
15330
Karl Schultz6addd812016-02-02 17:17:23 -070015331 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15332 const int32_t tex_width = 32;
15333 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015334
15335 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015336 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15337 image_create_info.pNext = NULL;
15338 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15339 image_create_info.format = tex_format;
15340 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015341 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015342 image_create_info.extent.depth = 1;
15343 image_create_info.mipLevels = 1;
15344 image_create_info.arrayLayers = 1;
15345 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15346 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15347 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15348 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015349
15350 // Introduce error by sending down a bogus width extent
15351 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015352 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015353
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015354 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015355}
15356
Mark Youngc48c4c12016-04-11 14:26:49 -060015357TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015359
15360 ASSERT_NO_FATAL_FAILURE(InitState());
15361
15362 // Create an image
15363 VkImage image;
15364
15365 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15366 const int32_t tex_width = 32;
15367 const int32_t tex_height = 32;
15368
15369 VkImageCreateInfo image_create_info = {};
15370 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15371 image_create_info.pNext = NULL;
15372 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15373 image_create_info.format = tex_format;
15374 image_create_info.extent.width = tex_width;
15375 image_create_info.extent.height = tex_height;
15376 image_create_info.extent.depth = 1;
15377 image_create_info.mipLevels = 1;
15378 image_create_info.arrayLayers = 1;
15379 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15380 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15381 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15382 image_create_info.flags = 0;
15383
15384 // Introduce error by sending down a bogus width extent
15385 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015386 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015387 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15388
15389 m_errorMonitor->VerifyFound();
15390}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015391
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015392TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015393 TEST_DESCRIPTION(
15394 "Create a render pass with an attachment description "
15395 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015396
15397 ASSERT_NO_FATAL_FAILURE(InitState());
15398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15399
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015401
15402 VkAttachmentReference color_attach = {};
15403 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15404 color_attach.attachment = 0;
15405 VkSubpassDescription subpass = {};
15406 subpass.colorAttachmentCount = 1;
15407 subpass.pColorAttachments = &color_attach;
15408
15409 VkRenderPassCreateInfo rpci = {};
15410 rpci.subpassCount = 1;
15411 rpci.pSubpasses = &subpass;
15412 rpci.attachmentCount = 1;
15413 VkAttachmentDescription attach_desc = {};
15414 attach_desc.format = VK_FORMAT_UNDEFINED;
15415 rpci.pAttachments = &attach_desc;
15416 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15417 VkRenderPass rp;
15418 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15419
15420 m_errorMonitor->VerifyFound();
15421
15422 if (result == VK_SUCCESS) {
15423 vkDestroyRenderPass(m_device->device(), rp, NULL);
15424 }
15425}
15426
Karl Schultz6addd812016-02-02 17:17:23 -070015427TEST_F(VkLayerTest, InvalidImageView) {
15428 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015429
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015431
Tobin Ehliscde08892015-09-22 10:11:37 -060015432 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015433
Mike Stroyana3082432015-09-25 13:39:21 -060015434 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015435 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015436
Karl Schultz6addd812016-02-02 17:17:23 -070015437 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15438 const int32_t tex_width = 32;
15439 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015440
15441 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015442 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15443 image_create_info.pNext = NULL;
15444 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15445 image_create_info.format = tex_format;
15446 image_create_info.extent.width = tex_width;
15447 image_create_info.extent.height = tex_height;
15448 image_create_info.extent.depth = 1;
15449 image_create_info.mipLevels = 1;
15450 image_create_info.arrayLayers = 1;
15451 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15452 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15453 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15454 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015455
Chia-I Wuf7458c52015-10-26 21:10:41 +080015456 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015457 ASSERT_VK_SUCCESS(err);
15458
15459 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015460 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015461 image_view_create_info.image = image;
15462 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15463 image_view_create_info.format = tex_format;
15464 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015465 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015466 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015467 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015468
15469 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015470 m_errorMonitor->SetUnexpectedError(
15471 "If image is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015472 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015473
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015474 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015475 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015476}
Mike Stroyana3082432015-09-25 13:39:21 -060015477
Mark Youngd339ba32016-05-30 13:28:35 -060015478TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15479 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015481 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015482
15483 ASSERT_NO_FATAL_FAILURE(InitState());
15484
15485 // Create an image and try to create a view with no memory backing the image
15486 VkImage image;
15487
15488 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15489 const int32_t tex_width = 32;
15490 const int32_t tex_height = 32;
15491
15492 VkImageCreateInfo image_create_info = {};
15493 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15494 image_create_info.pNext = NULL;
15495 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15496 image_create_info.format = tex_format;
15497 image_create_info.extent.width = tex_width;
15498 image_create_info.extent.height = tex_height;
15499 image_create_info.extent.depth = 1;
15500 image_create_info.mipLevels = 1;
15501 image_create_info.arrayLayers = 1;
15502 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15503 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15504 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15505 image_create_info.flags = 0;
15506
15507 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15508 ASSERT_VK_SUCCESS(err);
15509
15510 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015511 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015512 image_view_create_info.image = image;
15513 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15514 image_view_create_info.format = tex_format;
15515 image_view_create_info.subresourceRange.layerCount = 1;
15516 image_view_create_info.subresourceRange.baseMipLevel = 0;
15517 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015518 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015519
15520 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015521 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015522
15523 m_errorMonitor->VerifyFound();
15524 vkDestroyImage(m_device->device(), image, NULL);
15525 // If last error is success, it still created the view, so delete it.
15526 if (err == VK_SUCCESS) {
15527 vkDestroyImageView(m_device->device(), view, NULL);
15528 }
Mark Youngd339ba32016-05-30 13:28:35 -060015529}
15530
Karl Schultz6addd812016-02-02 17:17:23 -070015531TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015532 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015534
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015535 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015536
Karl Schultz6addd812016-02-02 17:17:23 -070015537 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015538 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015539 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015540 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015541
15542 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015543 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015544 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015545 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15546 image_view_create_info.format = tex_format;
15547 image_view_create_info.subresourceRange.baseMipLevel = 0;
15548 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015549 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015550 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015551 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015552
15553 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015554 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015555
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015556 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015557}
15558
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015559TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015560 VkResult err;
15561 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015562
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015564
Mike Stroyana3082432015-09-25 13:39:21 -060015565 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015566
15567 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015568 VkImage srcImage;
15569 VkImage dstImage;
15570 VkDeviceMemory srcMem;
15571 VkDeviceMemory destMem;
15572 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015573
15574 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015575 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15576 image_create_info.pNext = NULL;
15577 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15578 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15579 image_create_info.extent.width = 32;
15580 image_create_info.extent.height = 32;
15581 image_create_info.extent.depth = 1;
15582 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015583 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015584 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15585 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15586 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15587 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015589 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015590 ASSERT_VK_SUCCESS(err);
15591
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015592 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015593 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015594 ASSERT_VK_SUCCESS(err);
15595
15596 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015597 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015598 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15599 memAlloc.pNext = NULL;
15600 memAlloc.allocationSize = 0;
15601 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015602
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015603 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015604 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015605 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015606 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015607 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015608 ASSERT_VK_SUCCESS(err);
15609
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015610 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015611 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015612 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015613 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015614 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015615 ASSERT_VK_SUCCESS(err);
15616
15617 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15618 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015619 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015620 ASSERT_VK_SUCCESS(err);
15621
Tony Barbour552f6c02016-12-21 14:34:07 -070015622 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015623 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015624 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015625 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015626 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015627 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015628 copyRegion.srcOffset.x = 0;
15629 copyRegion.srcOffset.y = 0;
15630 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015631 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015632 copyRegion.dstSubresource.mipLevel = 0;
15633 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015634 // Introduce failure by forcing the dst layerCount to differ from src
15635 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015636 copyRegion.dstOffset.x = 0;
15637 copyRegion.dstOffset.y = 0;
15638 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015639 copyRegion.extent.width = 1;
15640 copyRegion.extent.height = 1;
15641 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015642 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015643 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015644
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015645 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015646
Chia-I Wuf7458c52015-10-26 21:10:41 +080015647 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015648 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015649 vkFreeMemory(m_device->device(), srcMem, NULL);
15650 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015651}
15652
Tony Barbourd6673642016-05-05 14:46:39 -060015653TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015654 TEST_DESCRIPTION("Creating images with unsuported formats ");
15655
15656 ASSERT_NO_FATAL_FAILURE(InitState());
15657 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15658 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015659 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 -060015660 VK_IMAGE_TILING_OPTIMAL, 0);
15661 ASSERT_TRUE(image.initialized());
15662
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015663 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015664 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015665 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015666 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15667 image_create_info.format = VK_FORMAT_UNDEFINED;
15668 image_create_info.extent.width = 32;
15669 image_create_info.extent.height = 32;
15670 image_create_info.extent.depth = 1;
15671 image_create_info.mipLevels = 1;
15672 image_create_info.arrayLayers = 1;
15673 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15674 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15675 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015676
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15678 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015679
15680 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015681 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15682 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15683 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15684 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015685 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15686 m_errorMonitor->VerifyFound();
15687
Tony Barbourd6673642016-05-05 14:46:39 -060015688 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015689 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015690 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15691 VkFormat format = static_cast<VkFormat>(f);
15692 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015693 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015694 unsupported = format;
15695 break;
15696 }
15697 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015698
Tony Barbourd6673642016-05-05 14:46:39 -060015699 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015700 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015702
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015703 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15704 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15705 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15706 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15707 m_errorMonitor->SetUnexpectedError(
15708 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15709 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15710 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015711 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015712 m_errorMonitor->VerifyFound();
15713 }
15714}
15715
15716TEST_F(VkLayerTest, ImageLayerViewTests) {
15717 VkResult ret;
15718 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15719
15720 ASSERT_NO_FATAL_FAILURE(InitState());
15721
15722 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015723 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 -060015724 VK_IMAGE_TILING_OPTIMAL, 0);
15725 ASSERT_TRUE(image.initialized());
15726
15727 VkImageView imgView;
15728 VkImageViewCreateInfo imgViewInfo = {};
15729 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15730 imgViewInfo.image = image.handle();
15731 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15732 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15733 imgViewInfo.subresourceRange.layerCount = 1;
15734 imgViewInfo.subresourceRange.baseMipLevel = 0;
15735 imgViewInfo.subresourceRange.levelCount = 1;
15736 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15737
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015739 // View can't have baseMipLevel >= image's mipLevels - Expect
15740 // VIEW_CREATE_ERROR
15741 imgViewInfo.subresourceRange.baseMipLevel = 1;
15742 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15743 m_errorMonitor->VerifyFound();
15744 imgViewInfo.subresourceRange.baseMipLevel = 0;
15745
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015747 // View can't have baseArrayLayer >= image's arraySize - Expect
15748 // VIEW_CREATE_ERROR
15749 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15750 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15751 m_errorMonitor->VerifyFound();
15752 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15753
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015755 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15756 imgViewInfo.subresourceRange.levelCount = 0;
15757 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15758 m_errorMonitor->VerifyFound();
15759 imgViewInfo.subresourceRange.levelCount = 1;
15760
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015761 m_errorMonitor->SetDesiredFailureMsg(
15762 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15763 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015764 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15765 imgViewInfo.subresourceRange.layerCount = 0;
15766 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15767 m_errorMonitor->VerifyFound();
15768 imgViewInfo.subresourceRange.layerCount = 1;
15769
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15771 "Formats MUST be IDENTICAL unless "
15772 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15773 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015774 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15775 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15776 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15777 m_errorMonitor->VerifyFound();
15778 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15779
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015781 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15782 // VIEW_CREATE_ERROR
15783 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15784 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15785 m_errorMonitor->VerifyFound();
15786 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15787
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015789 // TODO: Update framework to easily passing mutable flag into ImageObj init
15790 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015791 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15792 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15793 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015794 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15795 // VIEW_CREATE_ERROR
15796 VkImageCreateInfo mutImgInfo = image.create_info();
15797 VkImage mutImage;
15798 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015799 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015800 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15801 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15802 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15803 ASSERT_VK_SUCCESS(ret);
15804 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015805 m_errorMonitor->SetUnexpectedError(
15806 "If image is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object");
Tony Barbourd6673642016-05-05 14:46:39 -060015807 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15808 m_errorMonitor->VerifyFound();
15809 imgViewInfo.image = image.handle();
15810 vkDestroyImage(m_device->handle(), mutImage, NULL);
15811}
15812
15813TEST_F(VkLayerTest, MiscImageLayerTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060015814 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15815
15816 ASSERT_NO_FATAL_FAILURE(InitState());
15817
Rene Lindsay135204f2016-12-22 17:11:09 -070015818 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060015819 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070015820 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 -070015821 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060015822 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060015823 vk_testing::Buffer buffer;
15824 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070015825 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060015826 VkBufferImageCopy region = {};
15827 region.bufferRowLength = 128;
15828 region.bufferImageHeight = 128;
15829 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15830 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070015831 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015832 region.imageExtent.height = 4;
15833 region.imageExtent.width = 4;
15834 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070015835
15836 VkImageObj image2(m_device);
15837 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 -070015838 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070015839 ASSERT_TRUE(image2.initialized());
15840 vk_testing::Buffer buffer2;
15841 VkMemoryPropertyFlags reqs2 = 0;
15842 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
15843 VkBufferImageCopy region2 = {};
15844 region2.bufferRowLength = 128;
15845 region2.bufferImageHeight = 128;
15846 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15847 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15848 region2.imageSubresource.layerCount = 1;
15849 region2.imageExtent.height = 4;
15850 region2.imageExtent.width = 4;
15851 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015852 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060015853
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015854 // Image must have offset.z of 0 and extent.depth of 1
15855 // Introduce failure by setting imageExtent.depth to 0
15856 region.imageExtent.depth = 0;
15857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15858 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015859 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015860 m_errorMonitor->VerifyFound();
15861
15862 region.imageExtent.depth = 1;
15863
15864 // Image must have offset.z of 0 and extent.depth of 1
15865 // Introduce failure by setting imageOffset.z to 4
15866 region.imageOffset.z = 4;
15867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15868 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015869 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015870 m_errorMonitor->VerifyFound();
15871
15872 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015873 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15874 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070015875 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015877 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15878 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015879 m_errorMonitor->VerifyFound();
15880
15881 // BufferOffset must be a multiple of 4
15882 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070015883 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070015885 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
15886 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015887 m_errorMonitor->VerifyFound();
15888
15889 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15890 region.bufferOffset = 0;
15891 region.imageExtent.height = 128;
15892 region.imageExtent.width = 128;
15893 // Introduce failure by setting bufferRowLength > 0 but less than width
15894 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015896 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15897 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015898 m_errorMonitor->VerifyFound();
15899
15900 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15901 region.bufferRowLength = 128;
15902 // Introduce failure by setting bufferRowHeight > 0 but less than height
15903 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015905 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15906 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015907 m_errorMonitor->VerifyFound();
15908
15909 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060015910 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015911 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
15912 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015913 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015914 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15915 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015916 VkImageBlit blitRegion = {};
15917 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15918 blitRegion.srcSubresource.baseArrayLayer = 0;
15919 blitRegion.srcSubresource.layerCount = 1;
15920 blitRegion.srcSubresource.mipLevel = 0;
15921 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15922 blitRegion.dstSubresource.baseArrayLayer = 0;
15923 blitRegion.dstSubresource.layerCount = 1;
15924 blitRegion.dstSubresource.mipLevel = 0;
15925
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015926 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015928 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015929 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15930 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015931 m_errorMonitor->VerifyFound();
15932
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070015933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015934 VkImageMemoryBarrier img_barrier;
15935 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15936 img_barrier.pNext = NULL;
15937 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15938 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15939 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15940 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15941 img_barrier.image = image.handle();
15942 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15943 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15944 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15945 img_barrier.subresourceRange.baseArrayLayer = 0;
15946 img_barrier.subresourceRange.baseMipLevel = 0;
15947 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
15948 img_barrier.subresourceRange.layerCount = 0;
15949 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015950 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
15951 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060015952 m_errorMonitor->VerifyFound();
15953 img_barrier.subresourceRange.layerCount = 1;
15954}
15955
15956TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060015957 TEST_DESCRIPTION("Exceed the limits of image format ");
15958
Cody Northropc31a84f2016-08-22 10:41:47 -060015959 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060015961 VkImageCreateInfo image_create_info = {};
15962 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15963 image_create_info.pNext = NULL;
15964 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15965 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15966 image_create_info.extent.width = 32;
15967 image_create_info.extent.height = 32;
15968 image_create_info.extent.depth = 1;
15969 image_create_info.mipLevels = 1;
15970 image_create_info.arrayLayers = 1;
15971 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15972 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15973 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15974 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15975 image_create_info.flags = 0;
15976
15977 VkImage nullImg;
15978 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015979 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15980 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070015981 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015982 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15983 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15984 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070015985 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015988 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15989 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15990 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15991 m_errorMonitor->VerifyFound();
15992 image_create_info.mipLevels = 1;
15993
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015995 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15996 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15997 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15998 m_errorMonitor->VerifyFound();
15999 image_create_info.arrayLayers = 1;
16000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016002 int samples = imgFmtProps.sampleCounts >> 1;
16003 image_create_info.samples = (VkSampleCountFlagBits)samples;
16004 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16005 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16006 m_errorMonitor->VerifyFound();
16007 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16008
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16010 "pCreateInfo->initialLayout, must be "
16011 "VK_IMAGE_LAYOUT_UNDEFINED or "
16012 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016013 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16014 // Expect INVALID_LAYOUT
16015 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16016 m_errorMonitor->VerifyFound();
16017 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16018}
16019
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016020TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016021 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016023
16024 ASSERT_NO_FATAL_FAILURE(InitState());
16025
16026 VkImageObj src_image(m_device);
16027 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16028 VkImageObj dst_image(m_device);
16029 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16030
Tony Barbour552f6c02016-12-21 14:34:07 -070016031 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016032 VkImageCopy copy_region;
16033 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16034 copy_region.srcSubresource.mipLevel = 0;
16035 copy_region.srcSubresource.baseArrayLayer = 0;
16036 copy_region.srcSubresource.layerCount = 0;
16037 copy_region.srcOffset.x = 0;
16038 copy_region.srcOffset.y = 0;
16039 copy_region.srcOffset.z = 0;
16040 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16041 copy_region.dstSubresource.mipLevel = 0;
16042 copy_region.dstSubresource.baseArrayLayer = 0;
16043 copy_region.dstSubresource.layerCount = 0;
16044 copy_region.dstOffset.x = 0;
16045 copy_region.dstOffset.y = 0;
16046 copy_region.dstOffset.z = 0;
16047 copy_region.extent.width = 64;
16048 copy_region.extent.height = 64;
16049 copy_region.extent.depth = 1;
16050 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16051 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016052 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016053
16054 m_errorMonitor->VerifyFound();
16055}
16056
16057TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016058 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016060
16061 ASSERT_NO_FATAL_FAILURE(InitState());
16062
16063 VkImageObj src_image(m_device);
16064 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16065 VkImageObj dst_image(m_device);
16066 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16067
Tony Barbour552f6c02016-12-21 14:34:07 -070016068 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016069 VkImageCopy copy_region;
16070 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16071 copy_region.srcSubresource.mipLevel = 0;
16072 copy_region.srcSubresource.baseArrayLayer = 0;
16073 copy_region.srcSubresource.layerCount = 0;
16074 copy_region.srcOffset.x = 0;
16075 copy_region.srcOffset.y = 0;
16076 copy_region.srcOffset.z = 0;
16077 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16078 copy_region.dstSubresource.mipLevel = 0;
16079 copy_region.dstSubresource.baseArrayLayer = 0;
16080 copy_region.dstSubresource.layerCount = 0;
16081 copy_region.dstOffset.x = 0;
16082 copy_region.dstOffset.y = 0;
16083 copy_region.dstOffset.z = 0;
16084 copy_region.extent.width = 64;
16085 copy_region.extent.height = 64;
16086 copy_region.extent.depth = 1;
16087 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16088 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016089 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016090
16091 m_errorMonitor->VerifyFound();
16092}
16093
Karl Schultz6addd812016-02-02 17:17:23 -070016094TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016095 VkResult err;
16096 bool pass;
16097
16098 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016100
16101 ASSERT_NO_FATAL_FAILURE(InitState());
16102
16103 // Create two images of different types and try to copy between them
16104 VkImage srcImage;
16105 VkImage dstImage;
16106 VkDeviceMemory srcMem;
16107 VkDeviceMemory destMem;
16108 VkMemoryRequirements memReqs;
16109
16110 VkImageCreateInfo image_create_info = {};
16111 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16112 image_create_info.pNext = NULL;
16113 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16114 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16115 image_create_info.extent.width = 32;
16116 image_create_info.extent.height = 32;
16117 image_create_info.extent.depth = 1;
16118 image_create_info.mipLevels = 1;
16119 image_create_info.arrayLayers = 1;
16120 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16121 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16122 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16123 image_create_info.flags = 0;
16124
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016125 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016126 ASSERT_VK_SUCCESS(err);
16127
16128 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16129 // Introduce failure by creating second image with a different-sized format.
16130 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016132 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016133 ASSERT_VK_SUCCESS(err);
16134
16135 // Allocate memory
16136 VkMemoryAllocateInfo memAlloc = {};
16137 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16138 memAlloc.pNext = NULL;
16139 memAlloc.allocationSize = 0;
16140 memAlloc.memoryTypeIndex = 0;
16141
16142 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16143 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016144 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016145 ASSERT_TRUE(pass);
16146 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16147 ASSERT_VK_SUCCESS(err);
16148
16149 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16150 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016151 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016152 ASSERT_TRUE(pass);
16153 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16154 ASSERT_VK_SUCCESS(err);
16155
16156 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16157 ASSERT_VK_SUCCESS(err);
16158 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16159 ASSERT_VK_SUCCESS(err);
16160
Tony Barbour552f6c02016-12-21 14:34:07 -070016161 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016162 VkImageCopy copyRegion;
16163 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16164 copyRegion.srcSubresource.mipLevel = 0;
16165 copyRegion.srcSubresource.baseArrayLayer = 0;
16166 copyRegion.srcSubresource.layerCount = 0;
16167 copyRegion.srcOffset.x = 0;
16168 copyRegion.srcOffset.y = 0;
16169 copyRegion.srcOffset.z = 0;
16170 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16171 copyRegion.dstSubresource.mipLevel = 0;
16172 copyRegion.dstSubresource.baseArrayLayer = 0;
16173 copyRegion.dstSubresource.layerCount = 0;
16174 copyRegion.dstOffset.x = 0;
16175 copyRegion.dstOffset.y = 0;
16176 copyRegion.dstOffset.z = 0;
16177 copyRegion.extent.width = 1;
16178 copyRegion.extent.height = 1;
16179 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016180 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016181 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016182
16183 m_errorMonitor->VerifyFound();
16184
16185 vkDestroyImage(m_device->device(), srcImage, NULL);
16186 vkDestroyImage(m_device->device(), dstImage, NULL);
16187 vkFreeMemory(m_device->device(), srcMem, NULL);
16188 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016189}
16190
Karl Schultz6addd812016-02-02 17:17:23 -070016191TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16192 VkResult err;
16193 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016194
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016195 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16197 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016198
Mike Stroyana3082432015-09-25 13:39:21 -060016199 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016200
16201 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016202 VkImage srcImage;
16203 VkImage dstImage;
16204 VkDeviceMemory srcMem;
16205 VkDeviceMemory destMem;
16206 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016207
16208 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016209 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16210 image_create_info.pNext = NULL;
16211 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16212 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16213 image_create_info.extent.width = 32;
16214 image_create_info.extent.height = 32;
16215 image_create_info.extent.depth = 1;
16216 image_create_info.mipLevels = 1;
16217 image_create_info.arrayLayers = 1;
16218 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16219 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16220 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16221 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016223 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016224 ASSERT_VK_SUCCESS(err);
16225
Karl Schultzbdb75952016-04-19 11:36:49 -060016226 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16227
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016228 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016229 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016230 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016231 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016232
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016233 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016234 ASSERT_VK_SUCCESS(err);
16235
16236 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016237 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016238 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16239 memAlloc.pNext = NULL;
16240 memAlloc.allocationSize = 0;
16241 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016242
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016243 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016244 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016245 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016246 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016247 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016248 ASSERT_VK_SUCCESS(err);
16249
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016250 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016251 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016252 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016253 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016254 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016255 ASSERT_VK_SUCCESS(err);
16256
16257 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16258 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016259 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016260 ASSERT_VK_SUCCESS(err);
16261
Tony Barbour552f6c02016-12-21 14:34:07 -070016262 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016263 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016264 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016265 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016266 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016267 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016268 copyRegion.srcOffset.x = 0;
16269 copyRegion.srcOffset.y = 0;
16270 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016271 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016272 copyRegion.dstSubresource.mipLevel = 0;
16273 copyRegion.dstSubresource.baseArrayLayer = 0;
16274 copyRegion.dstSubresource.layerCount = 0;
16275 copyRegion.dstOffset.x = 0;
16276 copyRegion.dstOffset.y = 0;
16277 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016278 copyRegion.extent.width = 1;
16279 copyRegion.extent.height = 1;
16280 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016281 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016282 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016283
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016284 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016285
Chia-I Wuf7458c52015-10-26 21:10:41 +080016286 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016287 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016288 vkFreeMemory(m_device->device(), srcMem, NULL);
16289 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016290}
16291
Karl Schultz6addd812016-02-02 17:17:23 -070016292TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16293 VkResult err;
16294 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16297 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016298
Mike Stroyana3082432015-09-25 13:39:21 -060016299 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016300
16301 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016302 VkImage srcImage;
16303 VkImage dstImage;
16304 VkDeviceMemory srcMem;
16305 VkDeviceMemory destMem;
16306 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016307
16308 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016309 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16310 image_create_info.pNext = NULL;
16311 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16312 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16313 image_create_info.extent.width = 32;
16314 image_create_info.extent.height = 1;
16315 image_create_info.extent.depth = 1;
16316 image_create_info.mipLevels = 1;
16317 image_create_info.arrayLayers = 1;
16318 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16319 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16320 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16321 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016323 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016324 ASSERT_VK_SUCCESS(err);
16325
Karl Schultz6addd812016-02-02 17:17:23 -070016326 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016328 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016329 ASSERT_VK_SUCCESS(err);
16330
16331 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016332 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016333 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16334 memAlloc.pNext = NULL;
16335 memAlloc.allocationSize = 0;
16336 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016337
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016338 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016339 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016340 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016341 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016342 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016343 ASSERT_VK_SUCCESS(err);
16344
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016345 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016346 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016347 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016348 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016349 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016350 ASSERT_VK_SUCCESS(err);
16351
16352 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16353 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016354 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016355 ASSERT_VK_SUCCESS(err);
16356
Tony Barbour552f6c02016-12-21 14:34:07 -070016357 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016358 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016359 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16360 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016361 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016362 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016363 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016364 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016365 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016366 resolveRegion.srcOffset.x = 0;
16367 resolveRegion.srcOffset.y = 0;
16368 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016369 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016370 resolveRegion.dstSubresource.mipLevel = 0;
16371 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016372 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016373 resolveRegion.dstOffset.x = 0;
16374 resolveRegion.dstOffset.y = 0;
16375 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016376 resolveRegion.extent.width = 1;
16377 resolveRegion.extent.height = 1;
16378 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016379 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016380 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016381
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016382 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016383
Chia-I Wuf7458c52015-10-26 21:10:41 +080016384 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016385 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016386 vkFreeMemory(m_device->device(), srcMem, NULL);
16387 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016388}
16389
Karl Schultz6addd812016-02-02 17:17:23 -070016390TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16391 VkResult err;
16392 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016393
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16395 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016396
Mike Stroyana3082432015-09-25 13:39:21 -060016397 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016398
Chris Forbesa7530692016-05-08 12:35:39 +120016399 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016400 VkImage srcImage;
16401 VkImage dstImage;
16402 VkDeviceMemory srcMem;
16403 VkDeviceMemory destMem;
16404 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016405
16406 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016407 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16408 image_create_info.pNext = NULL;
16409 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16410 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16411 image_create_info.extent.width = 32;
16412 image_create_info.extent.height = 1;
16413 image_create_info.extent.depth = 1;
16414 image_create_info.mipLevels = 1;
16415 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016416 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016417 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16418 // Note: Some implementations expect color attachment usage for any
16419 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016420 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016421 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016423 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016424 ASSERT_VK_SUCCESS(err);
16425
Karl Schultz6addd812016-02-02 17:17:23 -070016426 // Note: Some implementations expect color attachment usage for any
16427 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016428 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016429
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016430 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016431 ASSERT_VK_SUCCESS(err);
16432
16433 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016434 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016435 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16436 memAlloc.pNext = NULL;
16437 memAlloc.allocationSize = 0;
16438 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016439
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016440 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016441 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016442 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016443 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016444 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016445 ASSERT_VK_SUCCESS(err);
16446
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016447 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016448 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016449 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016450 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016451 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016452 ASSERT_VK_SUCCESS(err);
16453
16454 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16455 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016456 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016457 ASSERT_VK_SUCCESS(err);
16458
Tony Barbour552f6c02016-12-21 14:34:07 -070016459 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016460 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016461 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16462 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016463 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016464 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016465 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016466 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016467 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016468 resolveRegion.srcOffset.x = 0;
16469 resolveRegion.srcOffset.y = 0;
16470 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016471 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016472 resolveRegion.dstSubresource.mipLevel = 0;
16473 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016474 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016475 resolveRegion.dstOffset.x = 0;
16476 resolveRegion.dstOffset.y = 0;
16477 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016478 resolveRegion.extent.width = 1;
16479 resolveRegion.extent.height = 1;
16480 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016481 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016482 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016483
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016484 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016485
Chia-I Wuf7458c52015-10-26 21:10:41 +080016486 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016487 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016488 vkFreeMemory(m_device->device(), srcMem, NULL);
16489 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016490}
16491
Karl Schultz6addd812016-02-02 17:17:23 -070016492TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16493 VkResult err;
16494 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016495
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016497 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016498
Mike Stroyana3082432015-09-25 13:39:21 -060016499 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016500
16501 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016502 VkImage srcImage;
16503 VkImage dstImage;
16504 VkDeviceMemory srcMem;
16505 VkDeviceMemory destMem;
16506 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016507
16508 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016509 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16510 image_create_info.pNext = NULL;
16511 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16512 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16513 image_create_info.extent.width = 32;
16514 image_create_info.extent.height = 1;
16515 image_create_info.extent.depth = 1;
16516 image_create_info.mipLevels = 1;
16517 image_create_info.arrayLayers = 1;
16518 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16519 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16520 // Note: Some implementations expect color attachment usage for any
16521 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016522 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016523 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016524
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016525 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016526 ASSERT_VK_SUCCESS(err);
16527
Karl Schultz6addd812016-02-02 17:17:23 -070016528 // Set format to something other than source image
16529 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16530 // Note: Some implementations expect color attachment usage for any
16531 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016532 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016533 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016535 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016536 ASSERT_VK_SUCCESS(err);
16537
16538 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016539 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016540 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16541 memAlloc.pNext = NULL;
16542 memAlloc.allocationSize = 0;
16543 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016544
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016545 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016546 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016547 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016548 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016549 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016550 ASSERT_VK_SUCCESS(err);
16551
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016552 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016553 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016554 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016555 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016556 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016557 ASSERT_VK_SUCCESS(err);
16558
16559 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16560 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016561 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016562 ASSERT_VK_SUCCESS(err);
16563
Tony Barbour552f6c02016-12-21 14:34:07 -070016564 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016565 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016566 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16567 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016568 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016569 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016570 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016571 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016572 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016573 resolveRegion.srcOffset.x = 0;
16574 resolveRegion.srcOffset.y = 0;
16575 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016576 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016577 resolveRegion.dstSubresource.mipLevel = 0;
16578 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016579 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016580 resolveRegion.dstOffset.x = 0;
16581 resolveRegion.dstOffset.y = 0;
16582 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016583 resolveRegion.extent.width = 1;
16584 resolveRegion.extent.height = 1;
16585 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016586 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016587 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016588
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016589 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016590
Chia-I Wuf7458c52015-10-26 21:10:41 +080016591 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016592 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016593 vkFreeMemory(m_device->device(), srcMem, NULL);
16594 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016595}
16596
Karl Schultz6addd812016-02-02 17:17:23 -070016597TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16598 VkResult err;
16599 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016600
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016602 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016603
Mike Stroyana3082432015-09-25 13:39:21 -060016604 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016605
16606 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016607 VkImage srcImage;
16608 VkImage dstImage;
16609 VkDeviceMemory srcMem;
16610 VkDeviceMemory destMem;
16611 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016612
16613 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016614 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16615 image_create_info.pNext = NULL;
16616 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16617 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16618 image_create_info.extent.width = 32;
16619 image_create_info.extent.height = 1;
16620 image_create_info.extent.depth = 1;
16621 image_create_info.mipLevels = 1;
16622 image_create_info.arrayLayers = 1;
16623 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16624 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16625 // Note: Some implementations expect color attachment usage for any
16626 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016627 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016628 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016629
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016630 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016631 ASSERT_VK_SUCCESS(err);
16632
Karl Schultz6addd812016-02-02 17:17:23 -070016633 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16634 // Note: Some implementations expect color attachment usage for any
16635 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016636 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016637 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016638
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016639 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016640 ASSERT_VK_SUCCESS(err);
16641
16642 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016643 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016644 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16645 memAlloc.pNext = NULL;
16646 memAlloc.allocationSize = 0;
16647 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016648
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016649 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016650 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016651 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016652 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016653 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016654 ASSERT_VK_SUCCESS(err);
16655
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016656 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016657 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016658 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016659 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016660 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016661 ASSERT_VK_SUCCESS(err);
16662
16663 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16664 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016665 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016666 ASSERT_VK_SUCCESS(err);
16667
Tony Barbour552f6c02016-12-21 14:34:07 -070016668 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016669 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016670 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16671 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016672 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016673 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016674 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016675 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016676 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016677 resolveRegion.srcOffset.x = 0;
16678 resolveRegion.srcOffset.y = 0;
16679 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016680 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016681 resolveRegion.dstSubresource.mipLevel = 0;
16682 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016683 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016684 resolveRegion.dstOffset.x = 0;
16685 resolveRegion.dstOffset.y = 0;
16686 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016687 resolveRegion.extent.width = 1;
16688 resolveRegion.extent.height = 1;
16689 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016690 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016691 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016692
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016693 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016694
Chia-I Wuf7458c52015-10-26 21:10:41 +080016695 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016696 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016697 vkFreeMemory(m_device->device(), srcMem, NULL);
16698 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016699}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016700
Karl Schultz6addd812016-02-02 17:17:23 -070016701TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016702 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016703 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16704 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016705 // The image format check comes 2nd in validation so we trigger it first,
16706 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016707 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16710 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016711
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016712 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016713
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016714 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016715 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16716 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016717
16718 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016719 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16720 ds_pool_ci.pNext = NULL;
16721 ds_pool_ci.maxSets = 1;
16722 ds_pool_ci.poolSizeCount = 1;
16723 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016724
16725 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016726 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016727 ASSERT_VK_SUCCESS(err);
16728
16729 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016730 dsl_binding.binding = 0;
16731 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16732 dsl_binding.descriptorCount = 1;
16733 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16734 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016735
16736 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016737 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16738 ds_layout_ci.pNext = NULL;
16739 ds_layout_ci.bindingCount = 1;
16740 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016741 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016742 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016743 ASSERT_VK_SUCCESS(err);
16744
16745 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016746 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016747 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016748 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016749 alloc_info.descriptorPool = ds_pool;
16750 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016751 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016752 ASSERT_VK_SUCCESS(err);
16753
Karl Schultz6addd812016-02-02 17:17:23 -070016754 VkImage image_bad;
16755 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016756 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016757 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016758 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016759 const int32_t tex_width = 32;
16760 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016761
16762 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016763 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16764 image_create_info.pNext = NULL;
16765 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16766 image_create_info.format = tex_format_bad;
16767 image_create_info.extent.width = tex_width;
16768 image_create_info.extent.height = tex_height;
16769 image_create_info.extent.depth = 1;
16770 image_create_info.mipLevels = 1;
16771 image_create_info.arrayLayers = 1;
16772 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16773 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016774 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016775 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016776
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016777 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016778 ASSERT_VK_SUCCESS(err);
16779 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016780 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16781 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016782 ASSERT_VK_SUCCESS(err);
16783
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016784 // ---Bind image memory---
16785 VkMemoryRequirements img_mem_reqs;
16786 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
16787 VkMemoryAllocateInfo image_alloc_info = {};
16788 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16789 image_alloc_info.pNext = NULL;
16790 image_alloc_info.memoryTypeIndex = 0;
16791 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016792 bool pass =
16793 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 -070016794 ASSERT_TRUE(pass);
16795 VkDeviceMemory mem;
16796 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
16797 ASSERT_VK_SUCCESS(err);
16798 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
16799 ASSERT_VK_SUCCESS(err);
16800 // -----------------------
16801
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016802 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016803 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016804 image_view_create_info.image = image_bad;
16805 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16806 image_view_create_info.format = tex_format_bad;
16807 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16808 image_view_create_info.subresourceRange.baseMipLevel = 0;
16809 image_view_create_info.subresourceRange.layerCount = 1;
16810 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016811 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016812
16813 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016814 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016815
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016816 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016817
Chia-I Wuf7458c52015-10-26 21:10:41 +080016818 vkDestroyImage(m_device->device(), image_bad, NULL);
16819 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016820 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16821 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016822
16823 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016824}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016825
16826TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016827 TEST_DESCRIPTION(
16828 "Call ClearColorImage w/ a depth|stencil image and "
16829 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016830
16831 ASSERT_NO_FATAL_FAILURE(InitState());
16832 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16833
Tony Barbour552f6c02016-12-21 14:34:07 -070016834 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016835
16836 // Color image
16837 VkClearColorValue clear_color;
16838 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16839 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16840 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16841 const int32_t img_width = 32;
16842 const int32_t img_height = 32;
16843 VkImageCreateInfo image_create_info = {};
16844 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16845 image_create_info.pNext = NULL;
16846 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16847 image_create_info.format = color_format;
16848 image_create_info.extent.width = img_width;
16849 image_create_info.extent.height = img_height;
16850 image_create_info.extent.depth = 1;
16851 image_create_info.mipLevels = 1;
16852 image_create_info.arrayLayers = 1;
16853 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16854 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16855 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16856
16857 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016858 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016859
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016860 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016861
16862 // Depth/Stencil image
16863 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016864 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016865 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16866 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16867 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16868 ds_image_create_info.extent.width = 64;
16869 ds_image_create_info.extent.height = 64;
16870 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016871 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 -060016872
16873 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016874 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016875
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016876 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 -060016877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016879
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016880 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016881 &color_range);
16882
16883 m_errorMonitor->VerifyFound();
16884
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16886 "vkCmdClearColorImage called with "
16887 "image created without "
16888 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016889
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016890 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016891 &color_range);
16892
16893 m_errorMonitor->VerifyFound();
16894
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016895 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16897 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016898
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016899 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
16900 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016901
16902 m_errorMonitor->VerifyFound();
16903}
Tobin Ehliscde08892015-09-22 10:11:37 -060016904
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016905// WSI Enabled Tests
16906//
Chris Forbes09368e42016-10-13 11:59:22 +130016907#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016908TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
16909
16910#if defined(VK_USE_PLATFORM_XCB_KHR)
16911 VkSurfaceKHR surface = VK_NULL_HANDLE;
16912
16913 VkResult err;
16914 bool pass;
16915 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
16916 VkSwapchainCreateInfoKHR swapchain_create_info = {};
16917 // uint32_t swapchain_image_count = 0;
16918 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
16919 // uint32_t image_index = 0;
16920 // VkPresentInfoKHR present_info = {};
16921
16922 ASSERT_NO_FATAL_FAILURE(InitState());
16923
16924 // Use the create function from one of the VK_KHR_*_surface extension in
16925 // order to create a surface, testing all known errors in the process,
16926 // before successfully creating a surface:
16927 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
16928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
16929 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
16930 pass = (err != VK_SUCCESS);
16931 ASSERT_TRUE(pass);
16932 m_errorMonitor->VerifyFound();
16933
16934 // Next, try to create a surface with the wrong
16935 // VkXcbSurfaceCreateInfoKHR::sType:
16936 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
16937 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16939 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16940 pass = (err != VK_SUCCESS);
16941 ASSERT_TRUE(pass);
16942 m_errorMonitor->VerifyFound();
16943
16944 // Create a native window, and then correctly create a surface:
16945 xcb_connection_t *connection;
16946 xcb_screen_t *screen;
16947 xcb_window_t xcb_window;
16948 xcb_intern_atom_reply_t *atom_wm_delete_window;
16949
16950 const xcb_setup_t *setup;
16951 xcb_screen_iterator_t iter;
16952 int scr;
16953 uint32_t value_mask, value_list[32];
16954 int width = 1;
16955 int height = 1;
16956
16957 connection = xcb_connect(NULL, &scr);
16958 ASSERT_TRUE(connection != NULL);
16959 setup = xcb_get_setup(connection);
16960 iter = xcb_setup_roots_iterator(setup);
16961 while (scr-- > 0)
16962 xcb_screen_next(&iter);
16963 screen = iter.data;
16964
16965 xcb_window = xcb_generate_id(connection);
16966
16967 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
16968 value_list[0] = screen->black_pixel;
16969 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
16970
16971 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
16972 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
16973
16974 /* Magic code that will send notification when window is destroyed */
16975 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
16976 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
16977
16978 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
16979 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
16980 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
16981 free(reply);
16982
16983 xcb_map_window(connection, xcb_window);
16984
16985 // Force the x/y coordinates to 100,100 results are identical in consecutive
16986 // runs
16987 const uint32_t coords[] = { 100, 100 };
16988 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
16989
16990 // Finally, try to correctly create a surface:
16991 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
16992 xcb_create_info.pNext = NULL;
16993 xcb_create_info.flags = 0;
16994 xcb_create_info.connection = connection;
16995 xcb_create_info.window = xcb_window;
16996 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16997 pass = (err == VK_SUCCESS);
16998 ASSERT_TRUE(pass);
16999
17000 // Check if surface supports presentation:
17001
17002 // 1st, do so without having queried the queue families:
17003 VkBool32 supported = false;
17004 // TODO: Get the following error to come out:
17005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17006 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17007 "function");
17008 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17009 pass = (err != VK_SUCCESS);
17010 // ASSERT_TRUE(pass);
17011 // m_errorMonitor->VerifyFound();
17012
17013 // Next, query a queue family index that's too large:
17014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17015 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17016 pass = (err != VK_SUCCESS);
17017 ASSERT_TRUE(pass);
17018 m_errorMonitor->VerifyFound();
17019
17020 // Finally, do so correctly:
17021 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17022 // SUPPORTED
17023 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17024 pass = (err == VK_SUCCESS);
17025 ASSERT_TRUE(pass);
17026
17027 // Before proceeding, try to create a swapchain without having called
17028 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17029 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17030 swapchain_create_info.pNext = NULL;
17031 swapchain_create_info.flags = 0;
17032 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17033 swapchain_create_info.surface = surface;
17034 swapchain_create_info.imageArrayLayers = 1;
17035 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17036 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17038 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17039 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17040 pass = (err != VK_SUCCESS);
17041 ASSERT_TRUE(pass);
17042 m_errorMonitor->VerifyFound();
17043
17044 // Get the surface capabilities:
17045 VkSurfaceCapabilitiesKHR surface_capabilities;
17046
17047 // Do so correctly (only error logged by this entrypoint is if the
17048 // extension isn't enabled):
17049 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17050 pass = (err == VK_SUCCESS);
17051 ASSERT_TRUE(pass);
17052
17053 // Get the surface formats:
17054 uint32_t surface_format_count;
17055
17056 // First, try without a pointer to surface_format_count:
17057 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17058 "specified as NULL");
17059 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17060 pass = (err == VK_SUCCESS);
17061 ASSERT_TRUE(pass);
17062 m_errorMonitor->VerifyFound();
17063
17064 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17065 // correctly done a 1st try (to get the count):
17066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17067 surface_format_count = 0;
17068 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17069 pass = (err == VK_SUCCESS);
17070 ASSERT_TRUE(pass);
17071 m_errorMonitor->VerifyFound();
17072
17073 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17074 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17075 pass = (err == VK_SUCCESS);
17076 ASSERT_TRUE(pass);
17077
17078 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17079 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17080
17081 // Next, do a 2nd try with surface_format_count being set too high:
17082 surface_format_count += 5;
17083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17084 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17085 pass = (err == VK_SUCCESS);
17086 ASSERT_TRUE(pass);
17087 m_errorMonitor->VerifyFound();
17088
17089 // Finally, do a correct 1st and 2nd try:
17090 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17091 pass = (err == VK_SUCCESS);
17092 ASSERT_TRUE(pass);
17093 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17094 pass = (err == VK_SUCCESS);
17095 ASSERT_TRUE(pass);
17096
17097 // Get the surface present modes:
17098 uint32_t surface_present_mode_count;
17099
17100 // First, try without a pointer to surface_format_count:
17101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17102 "specified as NULL");
17103
17104 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17105 pass = (err == VK_SUCCESS);
17106 ASSERT_TRUE(pass);
17107 m_errorMonitor->VerifyFound();
17108
17109 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17110 // correctly done a 1st try (to get the count):
17111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17112 surface_present_mode_count = 0;
17113 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17114 (VkPresentModeKHR *)&surface_present_mode_count);
17115 pass = (err == VK_SUCCESS);
17116 ASSERT_TRUE(pass);
17117 m_errorMonitor->VerifyFound();
17118
17119 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17120 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17121 pass = (err == VK_SUCCESS);
17122 ASSERT_TRUE(pass);
17123
17124 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17125 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17126
17127 // Next, do a 2nd try with surface_format_count being set too high:
17128 surface_present_mode_count += 5;
17129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17130 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17131 pass = (err == VK_SUCCESS);
17132 ASSERT_TRUE(pass);
17133 m_errorMonitor->VerifyFound();
17134
17135 // Finally, do a correct 1st and 2nd try:
17136 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17137 pass = (err == VK_SUCCESS);
17138 ASSERT_TRUE(pass);
17139 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17140 pass = (err == VK_SUCCESS);
17141 ASSERT_TRUE(pass);
17142
17143 // Create a swapchain:
17144
17145 // First, try without a pointer to swapchain_create_info:
17146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17147 "specified as NULL");
17148
17149 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17150 pass = (err != VK_SUCCESS);
17151 ASSERT_TRUE(pass);
17152 m_errorMonitor->VerifyFound();
17153
17154 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17155 // sType:
17156 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17158
17159 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17160 pass = (err != VK_SUCCESS);
17161 ASSERT_TRUE(pass);
17162 m_errorMonitor->VerifyFound();
17163
17164 // Next, call with a NULL swapchain pointer:
17165 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17166 swapchain_create_info.pNext = NULL;
17167 swapchain_create_info.flags = 0;
17168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17169 "specified as NULL");
17170
17171 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17172 pass = (err != VK_SUCCESS);
17173 ASSERT_TRUE(pass);
17174 m_errorMonitor->VerifyFound();
17175
17176 // TODO: Enhance swapchain layer so that
17177 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17178
17179 // Next, call with a queue family index that's too large:
17180 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17181 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17182 swapchain_create_info.queueFamilyIndexCount = 2;
17183 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17185 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17186 pass = (err != VK_SUCCESS);
17187 ASSERT_TRUE(pass);
17188 m_errorMonitor->VerifyFound();
17189
17190 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17191 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17192 swapchain_create_info.queueFamilyIndexCount = 1;
17193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17194 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17195 "pCreateInfo->pQueueFamilyIndices).");
17196 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17197 pass = (err != VK_SUCCESS);
17198 ASSERT_TRUE(pass);
17199 m_errorMonitor->VerifyFound();
17200
17201 // Next, call with an invalid imageSharingMode:
17202 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17203 swapchain_create_info.queueFamilyIndexCount = 1;
17204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17205 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17206 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17207 pass = (err != VK_SUCCESS);
17208 ASSERT_TRUE(pass);
17209 m_errorMonitor->VerifyFound();
17210 // Fix for the future:
17211 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17212 // SUPPORTED
17213 swapchain_create_info.queueFamilyIndexCount = 0;
17214 queueFamilyIndex[0] = 0;
17215 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17216
17217 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17218 // Get the images from a swapchain:
17219 // Acquire an image from a swapchain:
17220 // Present an image to a swapchain:
17221 // Destroy the swapchain:
17222
17223 // TODOs:
17224 //
17225 // - Try destroying the device without first destroying the swapchain
17226 //
17227 // - Try destroying the device without first destroying the surface
17228 //
17229 // - Try destroying the surface without first destroying the swapchain
17230
17231 // Destroy the surface:
17232 vkDestroySurfaceKHR(instance(), surface, NULL);
17233
17234 // Tear down the window:
17235 xcb_destroy_window(connection, xcb_window);
17236 xcb_disconnect(connection);
17237
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017238#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017239 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017240#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017241}
Chris Forbes09368e42016-10-13 11:59:22 +130017242#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017243
17244//
17245// POSITIVE VALIDATION TESTS
17246//
17247// These tests do not expect to encounter ANY validation errors pass only if this is true
17248
Tobin Ehlise0006882016-11-03 10:14:28 -060017249TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017250 TEST_DESCRIPTION(
17251 "Perform an image layout transition in a secondary command buffer followed "
17252 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060017253 VkResult err;
17254 m_errorMonitor->ExpectSuccess();
17255 ASSERT_NO_FATAL_FAILURE(InitState());
17256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17257 // Allocate a secondary and primary cmd buffer
17258 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17259 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17260 command_buffer_allocate_info.commandPool = m_commandPool;
17261 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17262 command_buffer_allocate_info.commandBufferCount = 1;
17263
17264 VkCommandBuffer secondary_command_buffer;
17265 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17266 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17267 VkCommandBuffer primary_command_buffer;
17268 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
17269 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17270 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17271 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17272 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17273 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
17274 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17275
17276 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17277 ASSERT_VK_SUCCESS(err);
17278 VkImageObj image(m_device);
17279 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17280 ASSERT_TRUE(image.initialized());
17281 VkImageMemoryBarrier img_barrier = {};
17282 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17283 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17284 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17285 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17286 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17287 img_barrier.image = image.handle();
17288 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17289 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17290 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17291 img_barrier.subresourceRange.baseArrayLayer = 0;
17292 img_barrier.subresourceRange.baseMipLevel = 0;
17293 img_barrier.subresourceRange.layerCount = 1;
17294 img_barrier.subresourceRange.levelCount = 1;
17295 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
17296 0, nullptr, 1, &img_barrier);
17297 err = vkEndCommandBuffer(secondary_command_buffer);
17298 ASSERT_VK_SUCCESS(err);
17299
17300 // Now update primary cmd buffer to execute secondary and transitions image
17301 command_buffer_begin_info.pInheritanceInfo = nullptr;
17302 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
17303 ASSERT_VK_SUCCESS(err);
17304 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
17305 VkImageMemoryBarrier img_barrier2 = {};
17306 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17307 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17308 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17309 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17310 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17311 img_barrier2.image = image.handle();
17312 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17313 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17314 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17315 img_barrier2.subresourceRange.baseArrayLayer = 0;
17316 img_barrier2.subresourceRange.baseMipLevel = 0;
17317 img_barrier2.subresourceRange.layerCount = 1;
17318 img_barrier2.subresourceRange.levelCount = 1;
17319 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
17320 nullptr, 1, &img_barrier2);
17321 err = vkEndCommandBuffer(primary_command_buffer);
17322 ASSERT_VK_SUCCESS(err);
17323 VkSubmitInfo submit_info = {};
17324 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17325 submit_info.commandBufferCount = 1;
17326 submit_info.pCommandBuffers = &primary_command_buffer;
17327 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17328 ASSERT_VK_SUCCESS(err);
17329 m_errorMonitor->VerifyNotFound();
17330 err = vkDeviceWaitIdle(m_device->device());
17331 ASSERT_VK_SUCCESS(err);
17332 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
17333 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
17334}
17335
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017336// This is a positive test. No failures are expected.
17337TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017338 TEST_DESCRIPTION(
17339 "Ensure that the vkUpdateDescriptorSets validation code "
17340 "is ignoring VkWriteDescriptorSet members that are not "
17341 "related to the descriptor type specified by "
17342 "VkWriteDescriptorSet::descriptorType. Correct "
17343 "validation behavior will result in the test running to "
17344 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017345
17346 const uintptr_t invalid_ptr = 0xcdcdcdcd;
17347
17348 ASSERT_NO_FATAL_FAILURE(InitState());
17349
17350 // Image Case
17351 {
17352 m_errorMonitor->ExpectSuccess();
17353
17354 VkImage image;
17355 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
17356 const int32_t tex_width = 32;
17357 const int32_t tex_height = 32;
17358 VkImageCreateInfo image_create_info = {};
17359 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17360 image_create_info.pNext = NULL;
17361 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17362 image_create_info.format = tex_format;
17363 image_create_info.extent.width = tex_width;
17364 image_create_info.extent.height = tex_height;
17365 image_create_info.extent.depth = 1;
17366 image_create_info.mipLevels = 1;
17367 image_create_info.arrayLayers = 1;
17368 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17369 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17370 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17371 image_create_info.flags = 0;
17372 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17373 ASSERT_VK_SUCCESS(err);
17374
17375 VkMemoryRequirements memory_reqs;
17376 VkDeviceMemory image_memory;
17377 bool pass;
17378 VkMemoryAllocateInfo memory_info = {};
17379 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17380 memory_info.pNext = NULL;
17381 memory_info.allocationSize = 0;
17382 memory_info.memoryTypeIndex = 0;
17383 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17384 memory_info.allocationSize = memory_reqs.size;
17385 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17386 ASSERT_TRUE(pass);
17387 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
17388 ASSERT_VK_SUCCESS(err);
17389 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
17390 ASSERT_VK_SUCCESS(err);
17391
17392 VkImageViewCreateInfo image_view_create_info = {};
17393 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17394 image_view_create_info.image = image;
17395 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17396 image_view_create_info.format = tex_format;
17397 image_view_create_info.subresourceRange.layerCount = 1;
17398 image_view_create_info.subresourceRange.baseMipLevel = 0;
17399 image_view_create_info.subresourceRange.levelCount = 1;
17400 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17401
17402 VkImageView view;
17403 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
17404 ASSERT_VK_SUCCESS(err);
17405
17406 VkDescriptorPoolSize ds_type_count = {};
17407 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17408 ds_type_count.descriptorCount = 1;
17409
17410 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17411 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17412 ds_pool_ci.pNext = NULL;
17413 ds_pool_ci.maxSets = 1;
17414 ds_pool_ci.poolSizeCount = 1;
17415 ds_pool_ci.pPoolSizes = &ds_type_count;
17416
17417 VkDescriptorPool ds_pool;
17418 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17419 ASSERT_VK_SUCCESS(err);
17420
17421 VkDescriptorSetLayoutBinding dsl_binding = {};
17422 dsl_binding.binding = 0;
17423 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17424 dsl_binding.descriptorCount = 1;
17425 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17426 dsl_binding.pImmutableSamplers = NULL;
17427
17428 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17429 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17430 ds_layout_ci.pNext = NULL;
17431 ds_layout_ci.bindingCount = 1;
17432 ds_layout_ci.pBindings = &dsl_binding;
17433 VkDescriptorSetLayout ds_layout;
17434 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17435 ASSERT_VK_SUCCESS(err);
17436
17437 VkDescriptorSet descriptor_set;
17438 VkDescriptorSetAllocateInfo alloc_info = {};
17439 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17440 alloc_info.descriptorSetCount = 1;
17441 alloc_info.descriptorPool = ds_pool;
17442 alloc_info.pSetLayouts = &ds_layout;
17443 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17444 ASSERT_VK_SUCCESS(err);
17445
17446 VkDescriptorImageInfo image_info = {};
17447 image_info.imageView = view;
17448 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17449
17450 VkWriteDescriptorSet descriptor_write;
17451 memset(&descriptor_write, 0, sizeof(descriptor_write));
17452 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17453 descriptor_write.dstSet = descriptor_set;
17454 descriptor_write.dstBinding = 0;
17455 descriptor_write.descriptorCount = 1;
17456 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17457 descriptor_write.pImageInfo = &image_info;
17458
17459 // Set pBufferInfo and pTexelBufferView to invalid values, which should
17460 // be
17461 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
17462 // This will most likely produce a crash if the parameter_validation
17463 // layer
17464 // does not correctly ignore pBufferInfo.
17465 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17466 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17467
17468 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17469
17470 m_errorMonitor->VerifyNotFound();
17471
17472 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17473 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17474 vkDestroyImageView(m_device->device(), view, NULL);
17475 vkDestroyImage(m_device->device(), image, NULL);
17476 vkFreeMemory(m_device->device(), image_memory, NULL);
17477 }
17478
17479 // Buffer Case
17480 {
17481 m_errorMonitor->ExpectSuccess();
17482
17483 VkBuffer buffer;
17484 uint32_t queue_family_index = 0;
17485 VkBufferCreateInfo buffer_create_info = {};
17486 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17487 buffer_create_info.size = 1024;
17488 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17489 buffer_create_info.queueFamilyIndexCount = 1;
17490 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17491
17492 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17493 ASSERT_VK_SUCCESS(err);
17494
17495 VkMemoryRequirements memory_reqs;
17496 VkDeviceMemory buffer_memory;
17497 bool pass;
17498 VkMemoryAllocateInfo memory_info = {};
17499 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17500 memory_info.pNext = NULL;
17501 memory_info.allocationSize = 0;
17502 memory_info.memoryTypeIndex = 0;
17503
17504 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
17505 memory_info.allocationSize = memory_reqs.size;
17506 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17507 ASSERT_TRUE(pass);
17508
17509 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17510 ASSERT_VK_SUCCESS(err);
17511 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17512 ASSERT_VK_SUCCESS(err);
17513
17514 VkDescriptorPoolSize ds_type_count = {};
17515 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17516 ds_type_count.descriptorCount = 1;
17517
17518 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17519 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17520 ds_pool_ci.pNext = NULL;
17521 ds_pool_ci.maxSets = 1;
17522 ds_pool_ci.poolSizeCount = 1;
17523 ds_pool_ci.pPoolSizes = &ds_type_count;
17524
17525 VkDescriptorPool ds_pool;
17526 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17527 ASSERT_VK_SUCCESS(err);
17528
17529 VkDescriptorSetLayoutBinding dsl_binding = {};
17530 dsl_binding.binding = 0;
17531 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17532 dsl_binding.descriptorCount = 1;
17533 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17534 dsl_binding.pImmutableSamplers = NULL;
17535
17536 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17537 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17538 ds_layout_ci.pNext = NULL;
17539 ds_layout_ci.bindingCount = 1;
17540 ds_layout_ci.pBindings = &dsl_binding;
17541 VkDescriptorSetLayout ds_layout;
17542 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17543 ASSERT_VK_SUCCESS(err);
17544
17545 VkDescriptorSet descriptor_set;
17546 VkDescriptorSetAllocateInfo alloc_info = {};
17547 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17548 alloc_info.descriptorSetCount = 1;
17549 alloc_info.descriptorPool = ds_pool;
17550 alloc_info.pSetLayouts = &ds_layout;
17551 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17552 ASSERT_VK_SUCCESS(err);
17553
17554 VkDescriptorBufferInfo buffer_info = {};
17555 buffer_info.buffer = buffer;
17556 buffer_info.offset = 0;
17557 buffer_info.range = 1024;
17558
17559 VkWriteDescriptorSet descriptor_write;
17560 memset(&descriptor_write, 0, sizeof(descriptor_write));
17561 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17562 descriptor_write.dstSet = descriptor_set;
17563 descriptor_write.dstBinding = 0;
17564 descriptor_write.descriptorCount = 1;
17565 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17566 descriptor_write.pBufferInfo = &buffer_info;
17567
17568 // Set pImageInfo and pTexelBufferView to invalid values, which should
17569 // be
17570 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
17571 // This will most likely produce a crash if the parameter_validation
17572 // layer
17573 // does not correctly ignore pImageInfo.
17574 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17575 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17576
17577 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17578
17579 m_errorMonitor->VerifyNotFound();
17580
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017581 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17582 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17583 vkDestroyBuffer(m_device->device(), buffer, NULL);
17584 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17585 }
17586
17587 // Texel Buffer Case
17588 {
17589 m_errorMonitor->ExpectSuccess();
17590
17591 VkBuffer buffer;
17592 uint32_t queue_family_index = 0;
17593 VkBufferCreateInfo buffer_create_info = {};
17594 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17595 buffer_create_info.size = 1024;
17596 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
17597 buffer_create_info.queueFamilyIndexCount = 1;
17598 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17599
17600 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17601 ASSERT_VK_SUCCESS(err);
17602
17603 VkMemoryRequirements memory_reqs;
17604 VkDeviceMemory buffer_memory;
17605 bool pass;
17606 VkMemoryAllocateInfo memory_info = {};
17607 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17608 memory_info.pNext = NULL;
17609 memory_info.allocationSize = 0;
17610 memory_info.memoryTypeIndex = 0;
17611
17612 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
17613 memory_info.allocationSize = memory_reqs.size;
17614 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17615 ASSERT_TRUE(pass);
17616
17617 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17618 ASSERT_VK_SUCCESS(err);
17619 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17620 ASSERT_VK_SUCCESS(err);
17621
17622 VkBufferViewCreateInfo buff_view_ci = {};
17623 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
17624 buff_view_ci.buffer = buffer;
17625 buff_view_ci.format = VK_FORMAT_R8_UNORM;
17626 buff_view_ci.range = VK_WHOLE_SIZE;
17627 VkBufferView buffer_view;
17628 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
17629
17630 VkDescriptorPoolSize ds_type_count = {};
17631 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17632 ds_type_count.descriptorCount = 1;
17633
17634 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17635 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17636 ds_pool_ci.pNext = NULL;
17637 ds_pool_ci.maxSets = 1;
17638 ds_pool_ci.poolSizeCount = 1;
17639 ds_pool_ci.pPoolSizes = &ds_type_count;
17640
17641 VkDescriptorPool ds_pool;
17642 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17643 ASSERT_VK_SUCCESS(err);
17644
17645 VkDescriptorSetLayoutBinding dsl_binding = {};
17646 dsl_binding.binding = 0;
17647 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17648 dsl_binding.descriptorCount = 1;
17649 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17650 dsl_binding.pImmutableSamplers = NULL;
17651
17652 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17653 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17654 ds_layout_ci.pNext = NULL;
17655 ds_layout_ci.bindingCount = 1;
17656 ds_layout_ci.pBindings = &dsl_binding;
17657 VkDescriptorSetLayout ds_layout;
17658 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17659 ASSERT_VK_SUCCESS(err);
17660
17661 VkDescriptorSet descriptor_set;
17662 VkDescriptorSetAllocateInfo alloc_info = {};
17663 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17664 alloc_info.descriptorSetCount = 1;
17665 alloc_info.descriptorPool = ds_pool;
17666 alloc_info.pSetLayouts = &ds_layout;
17667 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17668 ASSERT_VK_SUCCESS(err);
17669
17670 VkWriteDescriptorSet descriptor_write;
17671 memset(&descriptor_write, 0, sizeof(descriptor_write));
17672 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17673 descriptor_write.dstSet = descriptor_set;
17674 descriptor_write.dstBinding = 0;
17675 descriptor_write.descriptorCount = 1;
17676 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17677 descriptor_write.pTexelBufferView = &buffer_view;
17678
17679 // Set pImageInfo and pBufferInfo to invalid values, which should be
17680 // ignored for descriptorType ==
17681 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
17682 // This will most likely produce a crash if the parameter_validation
17683 // layer
17684 // does not correctly ignore pImageInfo and pBufferInfo.
17685 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17686 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17687
17688 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17689
17690 m_errorMonitor->VerifyNotFound();
17691
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017692 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17693 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17694 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
17695 vkDestroyBuffer(m_device->device(), buffer, NULL);
17696 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17697 }
17698}
17699
Tobin Ehlisf7428442016-10-25 07:58:24 -060017700TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
17701 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
17702
17703 ASSERT_NO_FATAL_FAILURE(InitState());
17704 // Create layout where two binding #s are "1"
17705 static const uint32_t NUM_BINDINGS = 3;
17706 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17707 dsl_binding[0].binding = 1;
17708 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17709 dsl_binding[0].descriptorCount = 1;
17710 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17711 dsl_binding[0].pImmutableSamplers = NULL;
17712 dsl_binding[1].binding = 0;
17713 dsl_binding[1].descriptorCount = 1;
17714 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17715 dsl_binding[1].descriptorCount = 1;
17716 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17717 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017718 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060017719 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17720 dsl_binding[2].descriptorCount = 1;
17721 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17722 dsl_binding[2].pImmutableSamplers = NULL;
17723
17724 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17725 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17726 ds_layout_ci.pNext = NULL;
17727 ds_layout_ci.bindingCount = NUM_BINDINGS;
17728 ds_layout_ci.pBindings = dsl_binding;
17729 VkDescriptorSetLayout ds_layout;
17730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
17731 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17732 m_errorMonitor->VerifyFound();
17733}
17734
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017735TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017736 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
17737
17738 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017739
Tony Barbour552f6c02016-12-21 14:34:07 -070017740 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017741
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017742 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
17743
17744 {
17745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
17746 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
17747 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17748 m_errorMonitor->VerifyFound();
17749 }
17750
17751 {
17752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
17753 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
17754 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17755 m_errorMonitor->VerifyFound();
17756 }
17757
17758 {
17759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17760 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
17761 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17762 m_errorMonitor->VerifyFound();
17763 }
17764
17765 {
17766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17767 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
17768 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17769 m_errorMonitor->VerifyFound();
17770 }
17771
17772 {
17773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
17774 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
17775 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17776 m_errorMonitor->VerifyFound();
17777 }
17778
17779 {
17780 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
17781 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
17782 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17783 m_errorMonitor->VerifyFound();
17784 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017785
17786 {
17787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17788 VkRect2D scissor = {{-1, 0}, {16, 16}};
17789 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17790 m_errorMonitor->VerifyFound();
17791 }
17792
17793 {
17794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17795 VkRect2D scissor = {{0, -2}, {16, 16}};
17796 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17797 m_errorMonitor->VerifyFound();
17798 }
17799
17800 {
17801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
17802 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
17803 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17804 m_errorMonitor->VerifyFound();
17805 }
17806
17807 {
17808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
17809 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
17810 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17811 m_errorMonitor->VerifyFound();
17812 }
17813
Tony Barbour552f6c02016-12-21 14:34:07 -070017814 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017815}
17816
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017817// This is a positive test. No failures are expected.
17818TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
17819 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
17820 VkResult err;
17821
17822 ASSERT_NO_FATAL_FAILURE(InitState());
17823 m_errorMonitor->ExpectSuccess();
17824 VkDescriptorPoolSize ds_type_count = {};
17825 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17826 ds_type_count.descriptorCount = 2;
17827
17828 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17829 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17830 ds_pool_ci.pNext = NULL;
17831 ds_pool_ci.maxSets = 1;
17832 ds_pool_ci.poolSizeCount = 1;
17833 ds_pool_ci.pPoolSizes = &ds_type_count;
17834
17835 VkDescriptorPool ds_pool;
17836 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17837 ASSERT_VK_SUCCESS(err);
17838
17839 // Create layout with two uniform buffer descriptors w/ empty binding between them
17840 static const uint32_t NUM_BINDINGS = 3;
17841 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17842 dsl_binding[0].binding = 0;
17843 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17844 dsl_binding[0].descriptorCount = 1;
17845 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
17846 dsl_binding[0].pImmutableSamplers = NULL;
17847 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017848 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017849 dsl_binding[2].binding = 2;
17850 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17851 dsl_binding[2].descriptorCount = 1;
17852 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
17853 dsl_binding[2].pImmutableSamplers = NULL;
17854
17855 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17856 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17857 ds_layout_ci.pNext = NULL;
17858 ds_layout_ci.bindingCount = NUM_BINDINGS;
17859 ds_layout_ci.pBindings = dsl_binding;
17860 VkDescriptorSetLayout ds_layout;
17861 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17862 ASSERT_VK_SUCCESS(err);
17863
17864 VkDescriptorSet descriptor_set = {};
17865 VkDescriptorSetAllocateInfo alloc_info = {};
17866 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17867 alloc_info.descriptorSetCount = 1;
17868 alloc_info.descriptorPool = ds_pool;
17869 alloc_info.pSetLayouts = &ds_layout;
17870 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17871 ASSERT_VK_SUCCESS(err);
17872
17873 // Create a buffer to be used for update
17874 VkBufferCreateInfo buff_ci = {};
17875 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17876 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17877 buff_ci.size = 256;
17878 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17879 VkBuffer buffer;
17880 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
17881 ASSERT_VK_SUCCESS(err);
17882 // Have to bind memory to buffer before descriptor update
17883 VkMemoryAllocateInfo mem_alloc = {};
17884 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17885 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017886 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017887 mem_alloc.memoryTypeIndex = 0;
17888
17889 VkMemoryRequirements mem_reqs;
17890 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17891 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
17892 if (!pass) {
17893 vkDestroyBuffer(m_device->device(), buffer, NULL);
17894 return;
17895 }
17896
17897 VkDeviceMemory mem;
17898 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17899 ASSERT_VK_SUCCESS(err);
17900 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17901 ASSERT_VK_SUCCESS(err);
17902
17903 // Only update the descriptor at binding 2
17904 VkDescriptorBufferInfo buff_info = {};
17905 buff_info.buffer = buffer;
17906 buff_info.offset = 0;
17907 buff_info.range = VK_WHOLE_SIZE;
17908 VkWriteDescriptorSet descriptor_write = {};
17909 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17910 descriptor_write.dstBinding = 2;
17911 descriptor_write.descriptorCount = 1;
17912 descriptor_write.pTexelBufferView = nullptr;
17913 descriptor_write.pBufferInfo = &buff_info;
17914 descriptor_write.pImageInfo = nullptr;
17915 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17916 descriptor_write.dstSet = descriptor_set;
17917
17918 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17919
17920 m_errorMonitor->VerifyNotFound();
17921 // Cleanup
17922 vkFreeMemory(m_device->device(), mem, NULL);
17923 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17924 vkDestroyBuffer(m_device->device(), buffer, NULL);
17925 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17926}
17927
17928// This is a positive test. No failures are expected.
17929TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
17930 VkResult err;
17931 bool pass;
17932
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017933 TEST_DESCRIPTION(
17934 "Create a buffer, allocate memory, bind memory, destroy "
17935 "the buffer, create an image, and bind the same memory to "
17936 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017937
17938 m_errorMonitor->ExpectSuccess();
17939
17940 ASSERT_NO_FATAL_FAILURE(InitState());
17941
17942 VkBuffer buffer;
17943 VkImage image;
17944 VkDeviceMemory mem;
17945 VkMemoryRequirements mem_reqs;
17946
17947 VkBufferCreateInfo buf_info = {};
17948 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17949 buf_info.pNext = NULL;
17950 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17951 buf_info.size = 256;
17952 buf_info.queueFamilyIndexCount = 0;
17953 buf_info.pQueueFamilyIndices = NULL;
17954 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17955 buf_info.flags = 0;
17956 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
17957 ASSERT_VK_SUCCESS(err);
17958
17959 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17960
17961 VkMemoryAllocateInfo alloc_info = {};
17962 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17963 alloc_info.pNext = NULL;
17964 alloc_info.memoryTypeIndex = 0;
17965
17966 // Ensure memory is big enough for both bindings
17967 alloc_info.allocationSize = 0x10000;
17968
17969 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17970 if (!pass) {
17971 vkDestroyBuffer(m_device->device(), buffer, NULL);
17972 return;
17973 }
17974
17975 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17976 ASSERT_VK_SUCCESS(err);
17977
17978 uint8_t *pData;
17979 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
17980 ASSERT_VK_SUCCESS(err);
17981
17982 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
17983
17984 vkUnmapMemory(m_device->device(), mem);
17985
17986 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17987 ASSERT_VK_SUCCESS(err);
17988
17989 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
17990 // memory. In fact, it was never used by the GPU.
17991 // Just be be sure, wait for idle.
17992 vkDestroyBuffer(m_device->device(), buffer, NULL);
17993 vkDeviceWaitIdle(m_device->device());
17994
Tobin Ehlis6a005702016-12-28 15:25:56 -070017995 // Use optimal as some platforms report linear support but then fail image creation
17996 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
17997 VkImageFormatProperties image_format_properties;
17998 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
17999 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18000 if (image_format_properties.maxExtent.width == 0) {
18001 printf("Image format not supported; skipped.\n");
18002 vkFreeMemory(m_device->device(), mem, NULL);
18003 return;
18004 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018005 VkImageCreateInfo image_create_info = {};
18006 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18007 image_create_info.pNext = NULL;
18008 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18009 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18010 image_create_info.extent.width = 64;
18011 image_create_info.extent.height = 64;
18012 image_create_info.extent.depth = 1;
18013 image_create_info.mipLevels = 1;
18014 image_create_info.arrayLayers = 1;
18015 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018016 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018017 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18018 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18019 image_create_info.queueFamilyIndexCount = 0;
18020 image_create_info.pQueueFamilyIndices = NULL;
18021 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18022 image_create_info.flags = 0;
18023
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018024 /* Create a mappable image. It will be the texture if linear images are ok
18025 * to be textures or it will be the staging image if they are not.
18026 */
18027 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18028 ASSERT_VK_SUCCESS(err);
18029
18030 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18031
Tobin Ehlis6a005702016-12-28 15:25:56 -070018032 VkMemoryAllocateInfo mem_alloc = {};
18033 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18034 mem_alloc.pNext = NULL;
18035 mem_alloc.allocationSize = 0;
18036 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018037 mem_alloc.allocationSize = mem_reqs.size;
18038
18039 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18040 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018041 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018042 vkDestroyImage(m_device->device(), image, NULL);
18043 return;
18044 }
18045
18046 // VALIDATION FAILURE:
18047 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18048 ASSERT_VK_SUCCESS(err);
18049
18050 m_errorMonitor->VerifyNotFound();
18051
18052 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018053 vkDestroyImage(m_device->device(), image, NULL);
18054}
18055
Tony Barbourab713912017-02-02 14:17:35 -070018056// This is a positive test. No failures are expected.
18057TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18058 VkResult err;
18059
18060 TEST_DESCRIPTION(
18061 "Call all applicable destroy and free routines with NULL"
18062 "handles, expecting no validation errors");
18063
18064 m_errorMonitor->ExpectSuccess();
18065
18066 ASSERT_NO_FATAL_FAILURE(InitState());
18067 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18068 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18069 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18070 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18071 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18072 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18073 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18074 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18075 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18076 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18077 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18078 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18079 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18080 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18081 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18082 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18083 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18084 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18085 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18086 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18087
18088 VkCommandPool command_pool;
18089 VkCommandPoolCreateInfo pool_create_info{};
18090 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18091 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18092 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18093 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18094 VkCommandBuffer command_buffers[3] = {};
18095 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18096 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18097 command_buffer_allocate_info.commandPool = command_pool;
18098 command_buffer_allocate_info.commandBufferCount = 1;
18099 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18100 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18101 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18102 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18103
18104 VkDescriptorPoolSize ds_type_count = {};
18105 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18106 ds_type_count.descriptorCount = 1;
18107
18108 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18109 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18110 ds_pool_ci.pNext = NULL;
18111 ds_pool_ci.maxSets = 1;
18112 ds_pool_ci.poolSizeCount = 1;
18113 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18114 ds_pool_ci.pPoolSizes = &ds_type_count;
18115
18116 VkDescriptorPool ds_pool;
18117 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18118 ASSERT_VK_SUCCESS(err);
18119
18120 VkDescriptorSetLayoutBinding dsl_binding = {};
18121 dsl_binding.binding = 2;
18122 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18123 dsl_binding.descriptorCount = 1;
18124 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18125 dsl_binding.pImmutableSamplers = NULL;
18126 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18127 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18128 ds_layout_ci.pNext = NULL;
18129 ds_layout_ci.bindingCount = 1;
18130 ds_layout_ci.pBindings = &dsl_binding;
18131 VkDescriptorSetLayout ds_layout;
18132 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18133 ASSERT_VK_SUCCESS(err);
18134
18135 VkDescriptorSet descriptor_sets[3] = {};
18136 VkDescriptorSetAllocateInfo alloc_info = {};
18137 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18138 alloc_info.descriptorSetCount = 1;
18139 alloc_info.descriptorPool = ds_pool;
18140 alloc_info.pSetLayouts = &ds_layout;
18141 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18142 ASSERT_VK_SUCCESS(err);
18143 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18144 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18145 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18146
18147 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18148
18149 m_errorMonitor->VerifyNotFound();
18150}
18151
Tony Barbour626994c2017-02-08 15:29:37 -070018152TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018153 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018154
18155 m_errorMonitor->ExpectSuccess();
18156
18157 ASSERT_NO_FATAL_FAILURE(InitState());
18158 VkCommandBuffer cmd_bufs[4];
18159 VkCommandBufferAllocateInfo alloc_info;
18160 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18161 alloc_info.pNext = NULL;
18162 alloc_info.commandBufferCount = 4;
18163 alloc_info.commandPool = m_commandPool;
18164 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18165 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18166 VkImageObj image(m_device);
18167 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18168 ASSERT_TRUE(image.initialized());
18169 VkCommandBufferBeginInfo cb_binfo;
18170 cb_binfo.pNext = NULL;
18171 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18172 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18173 cb_binfo.flags = 0;
18174 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18175 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18176 VkImageMemoryBarrier img_barrier = {};
18177 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18178 img_barrier.pNext = NULL;
18179 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18180 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18181 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18182 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18183 img_barrier.image = image.handle();
18184 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18185 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18186 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18187 img_barrier.subresourceRange.baseArrayLayer = 0;
18188 img_barrier.subresourceRange.baseMipLevel = 0;
18189 img_barrier.subresourceRange.layerCount = 1;
18190 img_barrier.subresourceRange.levelCount = 1;
18191 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18192 &img_barrier);
18193 vkEndCommandBuffer(cmd_bufs[0]);
18194 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18195 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18196 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18197 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18198 &img_barrier);
18199 vkEndCommandBuffer(cmd_bufs[1]);
18200 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
18201 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18202 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18203 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18204 &img_barrier);
18205 vkEndCommandBuffer(cmd_bufs[2]);
18206 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
18207 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18208 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18209 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18210 &img_barrier);
18211 vkEndCommandBuffer(cmd_bufs[3]);
18212
18213 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
18214 VkSemaphore semaphore1, semaphore2;
18215 VkSemaphoreCreateInfo semaphore_create_info{};
18216 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18217 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
18218 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
18219 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
18220 VkSubmitInfo submit_info[3];
18221 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18222 submit_info[0].pNext = nullptr;
18223 submit_info[0].commandBufferCount = 1;
18224 submit_info[0].pCommandBuffers = &cmd_bufs[0];
18225 submit_info[0].signalSemaphoreCount = 1;
18226 submit_info[0].pSignalSemaphores = &semaphore1;
18227 submit_info[0].waitSemaphoreCount = 0;
18228 submit_info[0].pWaitDstStageMask = nullptr;
18229 submit_info[0].pWaitDstStageMask = flags;
18230 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18231 submit_info[1].pNext = nullptr;
18232 submit_info[1].commandBufferCount = 1;
18233 submit_info[1].pCommandBuffers = &cmd_bufs[1];
18234 submit_info[1].waitSemaphoreCount = 1;
18235 submit_info[1].pWaitSemaphores = &semaphore1;
18236 submit_info[1].signalSemaphoreCount = 1;
18237 submit_info[1].pSignalSemaphores = &semaphore2;
18238 submit_info[1].pWaitDstStageMask = flags;
18239 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18240 submit_info[2].pNext = nullptr;
18241 submit_info[2].commandBufferCount = 2;
18242 submit_info[2].pCommandBuffers = &cmd_bufs[2];
18243 submit_info[2].waitSemaphoreCount = 1;
18244 submit_info[2].pWaitSemaphores = &semaphore2;
18245 submit_info[2].signalSemaphoreCount = 0;
18246 submit_info[2].pSignalSemaphores = nullptr;
18247 submit_info[2].pWaitDstStageMask = flags;
18248 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
18249 vkQueueWaitIdle(m_device->m_queue);
18250
18251 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
18252 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
18253 m_errorMonitor->VerifyNotFound();
18254}
18255
Tobin Ehlis953e8392016-11-17 10:54:13 -070018256TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
18257 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
18258 // We previously had a bug where dynamic offset of inactive bindings was still being used
18259 VkResult err;
18260 m_errorMonitor->ExpectSuccess();
18261
18262 ASSERT_NO_FATAL_FAILURE(InitState());
18263 ASSERT_NO_FATAL_FAILURE(InitViewport());
18264 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18265
18266 VkDescriptorPoolSize ds_type_count = {};
18267 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18268 ds_type_count.descriptorCount = 3;
18269
18270 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18271 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18272 ds_pool_ci.pNext = NULL;
18273 ds_pool_ci.maxSets = 1;
18274 ds_pool_ci.poolSizeCount = 1;
18275 ds_pool_ci.pPoolSizes = &ds_type_count;
18276
18277 VkDescriptorPool ds_pool;
18278 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18279 ASSERT_VK_SUCCESS(err);
18280
18281 const uint32_t BINDING_COUNT = 3;
18282 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018283 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018284 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18285 dsl_binding[0].descriptorCount = 1;
18286 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18287 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018288 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018289 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18290 dsl_binding[1].descriptorCount = 1;
18291 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18292 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018293 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018294 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18295 dsl_binding[2].descriptorCount = 1;
18296 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18297 dsl_binding[2].pImmutableSamplers = NULL;
18298
18299 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18300 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18301 ds_layout_ci.pNext = NULL;
18302 ds_layout_ci.bindingCount = BINDING_COUNT;
18303 ds_layout_ci.pBindings = dsl_binding;
18304 VkDescriptorSetLayout ds_layout;
18305 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18306 ASSERT_VK_SUCCESS(err);
18307
18308 VkDescriptorSet descriptor_set;
18309 VkDescriptorSetAllocateInfo alloc_info = {};
18310 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18311 alloc_info.descriptorSetCount = 1;
18312 alloc_info.descriptorPool = ds_pool;
18313 alloc_info.pSetLayouts = &ds_layout;
18314 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18315 ASSERT_VK_SUCCESS(err);
18316
18317 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18318 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18319 pipeline_layout_ci.pNext = NULL;
18320 pipeline_layout_ci.setLayoutCount = 1;
18321 pipeline_layout_ci.pSetLayouts = &ds_layout;
18322
18323 VkPipelineLayout pipeline_layout;
18324 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18325 ASSERT_VK_SUCCESS(err);
18326
18327 // Create two buffers to update the descriptors with
18328 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
18329 uint32_t qfi = 0;
18330 VkBufferCreateInfo buffCI = {};
18331 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18332 buffCI.size = 2048;
18333 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18334 buffCI.queueFamilyIndexCount = 1;
18335 buffCI.pQueueFamilyIndices = &qfi;
18336
18337 VkBuffer dyub1;
18338 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
18339 ASSERT_VK_SUCCESS(err);
18340 // buffer2
18341 buffCI.size = 1024;
18342 VkBuffer dyub2;
18343 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
18344 ASSERT_VK_SUCCESS(err);
18345 // Allocate memory and bind to buffers
18346 VkMemoryAllocateInfo mem_alloc[2] = {};
18347 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18348 mem_alloc[0].pNext = NULL;
18349 mem_alloc[0].memoryTypeIndex = 0;
18350 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18351 mem_alloc[1].pNext = NULL;
18352 mem_alloc[1].memoryTypeIndex = 0;
18353
18354 VkMemoryRequirements mem_reqs1;
18355 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
18356 VkMemoryRequirements mem_reqs2;
18357 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
18358 mem_alloc[0].allocationSize = mem_reqs1.size;
18359 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
18360 mem_alloc[1].allocationSize = mem_reqs2.size;
18361 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
18362 if (!pass) {
18363 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18364 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18365 return;
18366 }
18367
18368 VkDeviceMemory mem1;
18369 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
18370 ASSERT_VK_SUCCESS(err);
18371 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
18372 ASSERT_VK_SUCCESS(err);
18373 VkDeviceMemory mem2;
18374 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
18375 ASSERT_VK_SUCCESS(err);
18376 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
18377 ASSERT_VK_SUCCESS(err);
18378 // Update descriptors
18379 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
18380 buff_info[0].buffer = dyub1;
18381 buff_info[0].offset = 0;
18382 buff_info[0].range = 256;
18383 buff_info[1].buffer = dyub1;
18384 buff_info[1].offset = 256;
18385 buff_info[1].range = 512;
18386 buff_info[2].buffer = dyub2;
18387 buff_info[2].offset = 0;
18388 buff_info[2].range = 512;
18389
18390 VkWriteDescriptorSet descriptor_write;
18391 memset(&descriptor_write, 0, sizeof(descriptor_write));
18392 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18393 descriptor_write.dstSet = descriptor_set;
18394 descriptor_write.dstBinding = 0;
18395 descriptor_write.descriptorCount = BINDING_COUNT;
18396 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18397 descriptor_write.pBufferInfo = buff_info;
18398
18399 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18400
Tony Barbour552f6c02016-12-21 14:34:07 -070018401 m_commandBuffer->BeginCommandBuffer();
18402 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070018403
18404 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018405 char const *vsSource =
18406 "#version 450\n"
18407 "\n"
18408 "out gl_PerVertex { \n"
18409 " vec4 gl_Position;\n"
18410 "};\n"
18411 "void main(){\n"
18412 " gl_Position = vec4(1);\n"
18413 "}\n";
18414 char const *fsSource =
18415 "#version 450\n"
18416 "\n"
18417 "layout(location=0) out vec4 x;\n"
18418 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
18419 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
18420 "void main(){\n"
18421 " x = vec4(bar1.y) + vec4(bar2.y);\n"
18422 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070018423 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18424 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18425 VkPipelineObj pipe(m_device);
18426 pipe.SetViewport(m_viewports);
18427 pipe.SetScissor(m_scissors);
18428 pipe.AddShader(&vs);
18429 pipe.AddShader(&fs);
18430 pipe.AddColorAttachment();
18431 pipe.CreateVKPipeline(pipeline_layout, renderPass());
18432
18433 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
18434 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
18435 // we used to have a bug in this case.
18436 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
18437 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
18438 &descriptor_set, BINDING_COUNT, dyn_off);
18439 Draw(1, 0, 0, 0);
18440 m_errorMonitor->VerifyNotFound();
18441
18442 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18443 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18444 vkFreeMemory(m_device->device(), mem1, NULL);
18445 vkFreeMemory(m_device->device(), mem2, NULL);
18446
18447 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
18448 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18449 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18450}
18451
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018452TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018453 TEST_DESCRIPTION(
18454 "Ensure that validations handling of non-coherent memory "
18455 "mapping while using VK_WHOLE_SIZE does not cause access "
18456 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018457 VkResult err;
18458 uint8_t *pData;
18459 ASSERT_NO_FATAL_FAILURE(InitState());
18460
18461 VkDeviceMemory mem;
18462 VkMemoryRequirements mem_reqs;
18463 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018464 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018465 VkMemoryAllocateInfo alloc_info = {};
18466 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18467 alloc_info.pNext = NULL;
18468 alloc_info.memoryTypeIndex = 0;
18469
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018470 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018471 alloc_info.allocationSize = allocation_size;
18472
18473 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
18474 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 -070018475 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018476 if (!pass) {
18477 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018478 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
18479 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018480 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018481 pass = m_device->phy().set_memory_type(
18482 mem_reqs.memoryTypeBits, &alloc_info,
18483 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
18484 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018485 if (!pass) {
18486 return;
18487 }
18488 }
18489 }
18490
18491 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18492 ASSERT_VK_SUCCESS(err);
18493
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018494 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018495 m_errorMonitor->ExpectSuccess();
18496 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
18497 ASSERT_VK_SUCCESS(err);
18498 VkMappedMemoryRange mmr = {};
18499 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18500 mmr.memory = mem;
18501 mmr.offset = 0;
18502 mmr.size = VK_WHOLE_SIZE;
18503 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18504 ASSERT_VK_SUCCESS(err);
18505 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
18506 ASSERT_VK_SUCCESS(err);
18507 m_errorMonitor->VerifyNotFound();
18508 vkUnmapMemory(m_device->device(), mem);
18509
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018510 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018511 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018512 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018513 ASSERT_VK_SUCCESS(err);
18514 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18515 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018516 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018517 mmr.size = VK_WHOLE_SIZE;
18518 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18519 ASSERT_VK_SUCCESS(err);
18520 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
18521 ASSERT_VK_SUCCESS(err);
18522 m_errorMonitor->VerifyNotFound();
18523 vkUnmapMemory(m_device->device(), mem);
18524
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018525 // Map with offset and size
18526 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018527 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018528 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018529 ASSERT_VK_SUCCESS(err);
18530 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18531 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018532 mmr.offset = 4 * atom_size;
18533 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018534 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18535 ASSERT_VK_SUCCESS(err);
18536 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
18537 ASSERT_VK_SUCCESS(err);
18538 m_errorMonitor->VerifyNotFound();
18539 vkUnmapMemory(m_device->device(), mem);
18540
18541 // Map without offset and flush WHOLE_SIZE with two separate offsets
18542 m_errorMonitor->ExpectSuccess();
18543 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
18544 ASSERT_VK_SUCCESS(err);
18545 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
18546 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018547 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018548 mmr.size = VK_WHOLE_SIZE;
18549 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18550 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018551 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018552 mmr.size = VK_WHOLE_SIZE;
18553 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
18554 ASSERT_VK_SUCCESS(err);
18555 m_errorMonitor->VerifyNotFound();
18556 vkUnmapMemory(m_device->device(), mem);
18557
18558 vkFreeMemory(m_device->device(), mem, NULL);
18559}
18560
18561// This is a positive test. We used to expect error in this case but spec now allows it
18562TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
18563 m_errorMonitor->ExpectSuccess();
18564 vk_testing::Fence testFence;
18565 VkFenceCreateInfo fenceInfo = {};
18566 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18567 fenceInfo.pNext = NULL;
18568
18569 ASSERT_NO_FATAL_FAILURE(InitState());
18570 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018571 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018572 VkResult result = vkResetFences(m_device->device(), 1, fences);
18573 ASSERT_VK_SUCCESS(result);
18574
18575 m_errorMonitor->VerifyNotFound();
18576}
18577
18578TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
18579 m_errorMonitor->ExpectSuccess();
18580
18581 ASSERT_NO_FATAL_FAILURE(InitState());
18582 VkResult err;
18583
18584 // Record (empty!) command buffer that can be submitted multiple times
18585 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018586 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
18587 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018588 m_commandBuffer->BeginCommandBuffer(&cbbi);
18589 m_commandBuffer->EndCommandBuffer();
18590
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018591 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018592 VkFence fence;
18593 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
18594 ASSERT_VK_SUCCESS(err);
18595
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018596 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018597 VkSemaphore s1, s2;
18598 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
18599 ASSERT_VK_SUCCESS(err);
18600 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
18601 ASSERT_VK_SUCCESS(err);
18602
18603 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018604 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018605 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
18606 ASSERT_VK_SUCCESS(err);
18607
18608 // Submit CB again, signaling s2.
18609 si.pSignalSemaphores = &s2;
18610 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
18611 ASSERT_VK_SUCCESS(err);
18612
18613 // Wait for fence.
18614 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18615 ASSERT_VK_SUCCESS(err);
18616
18617 // CB is still in flight from second submission, but semaphore s1 is no
18618 // longer in flight. delete it.
18619 vkDestroySemaphore(m_device->device(), s1, nullptr);
18620
18621 m_errorMonitor->VerifyNotFound();
18622
18623 // Force device idle and clean up remaining objects
18624 vkDeviceWaitIdle(m_device->device());
18625 vkDestroySemaphore(m_device->device(), s2, nullptr);
18626 vkDestroyFence(m_device->device(), fence, nullptr);
18627}
18628
18629TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
18630 m_errorMonitor->ExpectSuccess();
18631
18632 ASSERT_NO_FATAL_FAILURE(InitState());
18633 VkResult err;
18634
18635 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018636 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018637 VkFence f1;
18638 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
18639 ASSERT_VK_SUCCESS(err);
18640
18641 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018642 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018643 VkFence f2;
18644 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
18645 ASSERT_VK_SUCCESS(err);
18646
18647 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018648 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018649 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
18650
18651 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018652 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018653 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
18654
18655 // Should have both retired!
18656 vkDestroyFence(m_device->device(), f1, nullptr);
18657 vkDestroyFence(m_device->device(), f2, nullptr);
18658
18659 m_errorMonitor->VerifyNotFound();
18660}
18661
18662TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018663 TEST_DESCRIPTION(
18664 "Verify that creating an image view from an image with valid usage "
18665 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018666
18667 ASSERT_NO_FATAL_FAILURE(InitState());
18668
18669 m_errorMonitor->ExpectSuccess();
18670 // Verify that we can create a view with usage INPUT_ATTACHMENT
18671 VkImageObj image(m_device);
18672 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18673 ASSERT_TRUE(image.initialized());
18674 VkImageView imageView;
18675 VkImageViewCreateInfo ivci = {};
18676 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18677 ivci.image = image.handle();
18678 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
18679 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
18680 ivci.subresourceRange.layerCount = 1;
18681 ivci.subresourceRange.baseMipLevel = 0;
18682 ivci.subresourceRange.levelCount = 1;
18683 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18684
18685 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
18686 m_errorMonitor->VerifyNotFound();
18687 vkDestroyImageView(m_device->device(), imageView, NULL);
18688}
18689
18690// This is a positive test. No failures are expected.
18691TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018692 TEST_DESCRIPTION(
18693 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
18694 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018695
18696 ASSERT_NO_FATAL_FAILURE(InitState());
18697
18698 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018699 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018700
18701 m_errorMonitor->ExpectSuccess();
18702
18703 VkImage image;
18704 VkImageCreateInfo image_create_info = {};
18705 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18706 image_create_info.pNext = NULL;
18707 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18708 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18709 image_create_info.extent.width = 64;
18710 image_create_info.extent.height = 64;
18711 image_create_info.extent.depth = 1;
18712 image_create_info.mipLevels = 1;
18713 image_create_info.arrayLayers = 1;
18714 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18715 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18716 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
18717 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
18718 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18719 ASSERT_VK_SUCCESS(err);
18720
18721 VkMemoryRequirements memory_reqs;
18722 VkDeviceMemory memory_one, memory_two;
18723 bool pass;
18724 VkMemoryAllocateInfo memory_info = {};
18725 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18726 memory_info.pNext = NULL;
18727 memory_info.allocationSize = 0;
18728 memory_info.memoryTypeIndex = 0;
18729 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18730 // Find an image big enough to allow sparse mapping of 2 memory regions
18731 // Increase the image size until it is at least twice the
18732 // size of the required alignment, to ensure we can bind both
18733 // allocated memory blocks to the image on aligned offsets.
18734 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
18735 vkDestroyImage(m_device->device(), image, nullptr);
18736 image_create_info.extent.width *= 2;
18737 image_create_info.extent.height *= 2;
18738 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
18739 ASSERT_VK_SUCCESS(err);
18740 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18741 }
18742 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
18743 // at the end of the first
18744 memory_info.allocationSize = memory_reqs.alignment;
18745 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18746 ASSERT_TRUE(pass);
18747 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
18748 ASSERT_VK_SUCCESS(err);
18749 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
18750 ASSERT_VK_SUCCESS(err);
18751 VkSparseMemoryBind binds[2];
18752 binds[0].flags = 0;
18753 binds[0].memory = memory_one;
18754 binds[0].memoryOffset = 0;
18755 binds[0].resourceOffset = 0;
18756 binds[0].size = memory_info.allocationSize;
18757 binds[1].flags = 0;
18758 binds[1].memory = memory_two;
18759 binds[1].memoryOffset = 0;
18760 binds[1].resourceOffset = memory_info.allocationSize;
18761 binds[1].size = memory_info.allocationSize;
18762
18763 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
18764 opaqueBindInfo.image = image;
18765 opaqueBindInfo.bindCount = 2;
18766 opaqueBindInfo.pBinds = binds;
18767
18768 VkFence fence = VK_NULL_HANDLE;
18769 VkBindSparseInfo bindSparseInfo = {};
18770 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
18771 bindSparseInfo.imageOpaqueBindCount = 1;
18772 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
18773
18774 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
18775 vkQueueWaitIdle(m_device->m_queue);
18776 vkDestroyImage(m_device->device(), image, NULL);
18777 vkFreeMemory(m_device->device(), memory_one, NULL);
18778 vkFreeMemory(m_device->device(), memory_two, NULL);
18779 m_errorMonitor->VerifyNotFound();
18780}
18781
18782TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018783 TEST_DESCRIPTION(
18784 "Ensure that CmdBeginRenderPass with an attachment's "
18785 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
18786 "the command buffer has prior knowledge of that "
18787 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018788
18789 m_errorMonitor->ExpectSuccess();
18790
18791 ASSERT_NO_FATAL_FAILURE(InitState());
18792
18793 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018794 VkAttachmentDescription attachment = {0,
18795 VK_FORMAT_R8G8B8A8_UNORM,
18796 VK_SAMPLE_COUNT_1_BIT,
18797 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18798 VK_ATTACHMENT_STORE_OP_STORE,
18799 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18800 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18801 VK_IMAGE_LAYOUT_UNDEFINED,
18802 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018803
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018804 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018805
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018806 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018807
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018808 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018809
18810 VkRenderPass rp;
18811 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18812 ASSERT_VK_SUCCESS(err);
18813
18814 // A compatible framebuffer.
18815 VkImageObj image(m_device);
18816 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18817 ASSERT_TRUE(image.initialized());
18818
18819 VkImageViewCreateInfo ivci = {
18820 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18821 nullptr,
18822 0,
18823 image.handle(),
18824 VK_IMAGE_VIEW_TYPE_2D,
18825 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018826 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18827 VK_COMPONENT_SWIZZLE_IDENTITY},
18828 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018829 };
18830 VkImageView view;
18831 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18832 ASSERT_VK_SUCCESS(err);
18833
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018834 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018835 VkFramebuffer fb;
18836 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18837 ASSERT_VK_SUCCESS(err);
18838
18839 // Record a single command buffer which uses this renderpass twice. The
18840 // bug is triggered at the beginning of the second renderpass, when the
18841 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018842 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 -070018843 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018844 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18845 vkCmdEndRenderPass(m_commandBuffer->handle());
18846 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18847
18848 m_errorMonitor->VerifyNotFound();
18849
18850 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018851 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018852
18853 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18854 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18855 vkDestroyImageView(m_device->device(), view, nullptr);
18856}
18857
18858TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018859 TEST_DESCRIPTION(
18860 "This test should pass. Create a Framebuffer and "
18861 "command buffer, bind them together, then destroy "
18862 "command pool and framebuffer and verify there are no "
18863 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018864
18865 m_errorMonitor->ExpectSuccess();
18866
18867 ASSERT_NO_FATAL_FAILURE(InitState());
18868
18869 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018870 VkAttachmentDescription attachment = {0,
18871 VK_FORMAT_R8G8B8A8_UNORM,
18872 VK_SAMPLE_COUNT_1_BIT,
18873 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18874 VK_ATTACHMENT_STORE_OP_STORE,
18875 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18876 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18877 VK_IMAGE_LAYOUT_UNDEFINED,
18878 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018879
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018880 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018881
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018882 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018883
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018884 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018885
18886 VkRenderPass rp;
18887 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18888 ASSERT_VK_SUCCESS(err);
18889
18890 // A compatible framebuffer.
18891 VkImageObj image(m_device);
18892 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18893 ASSERT_TRUE(image.initialized());
18894
18895 VkImageViewCreateInfo ivci = {
18896 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18897 nullptr,
18898 0,
18899 image.handle(),
18900 VK_IMAGE_VIEW_TYPE_2D,
18901 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018902 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18903 VK_COMPONENT_SWIZZLE_IDENTITY},
18904 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018905 };
18906 VkImageView view;
18907 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18908 ASSERT_VK_SUCCESS(err);
18909
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018910 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018911 VkFramebuffer fb;
18912 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18913 ASSERT_VK_SUCCESS(err);
18914
18915 // Explicitly create a command buffer to bind the FB to so that we can then
18916 // destroy the command pool in order to implicitly free command buffer
18917 VkCommandPool command_pool;
18918 VkCommandPoolCreateInfo pool_create_info{};
18919 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18920 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18921 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18922 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18923
18924 VkCommandBuffer command_buffer;
18925 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18926 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18927 command_buffer_allocate_info.commandPool = command_pool;
18928 command_buffer_allocate_info.commandBufferCount = 1;
18929 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18930 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18931
18932 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018933 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 -060018934 VkCommandBufferBeginInfo begin_info{};
18935 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18936 vkBeginCommandBuffer(command_buffer, &begin_info);
18937
18938 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18939 vkCmdEndRenderPass(command_buffer);
18940 vkEndCommandBuffer(command_buffer);
18941 vkDestroyImageView(m_device->device(), view, nullptr);
18942 // Destroy command pool to implicitly free command buffer
18943 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18944 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18945 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18946 m_errorMonitor->VerifyNotFound();
18947}
18948
18949TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018950 TEST_DESCRIPTION(
18951 "Ensure that CmdBeginRenderPass applies the layout "
18952 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018953
18954 m_errorMonitor->ExpectSuccess();
18955
18956 ASSERT_NO_FATAL_FAILURE(InitState());
18957
18958 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018959 VkAttachmentDescription attachment = {0,
18960 VK_FORMAT_R8G8B8A8_UNORM,
18961 VK_SAMPLE_COUNT_1_BIT,
18962 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18963 VK_ATTACHMENT_STORE_OP_STORE,
18964 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18965 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18966 VK_IMAGE_LAYOUT_UNDEFINED,
18967 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018968
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018969 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018970
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018971 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018972
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018973 VkSubpassDependency dep = {0,
18974 0,
18975 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18976 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18977 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18978 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18979 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018980
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018981 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018982
18983 VkResult err;
18984 VkRenderPass rp;
18985 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18986 ASSERT_VK_SUCCESS(err);
18987
18988 // A compatible framebuffer.
18989 VkImageObj image(m_device);
18990 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18991 ASSERT_TRUE(image.initialized());
18992
18993 VkImageViewCreateInfo ivci = {
18994 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18995 nullptr,
18996 0,
18997 image.handle(),
18998 VK_IMAGE_VIEW_TYPE_2D,
18999 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019000 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19001 VK_COMPONENT_SWIZZLE_IDENTITY},
19002 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019003 };
19004 VkImageView view;
19005 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19006 ASSERT_VK_SUCCESS(err);
19007
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019008 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019009 VkFramebuffer fb;
19010 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19011 ASSERT_VK_SUCCESS(err);
19012
19013 // Record a single command buffer which issues a pipeline barrier w/
19014 // image memory barrier for the attachment. This detects the previously
19015 // missing tracking of the subpass layout by throwing a validation error
19016 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019017 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 -070019018 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019019 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19020
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019021 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19022 nullptr,
19023 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19024 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19025 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19026 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19027 VK_QUEUE_FAMILY_IGNORED,
19028 VK_QUEUE_FAMILY_IGNORED,
19029 image.handle(),
19030 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019031 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019032 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19033 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019034
19035 vkCmdEndRenderPass(m_commandBuffer->handle());
19036 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019037 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019038
19039 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19040 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19041 vkDestroyImageView(m_device->device(), view, nullptr);
19042}
19043
19044TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019045 TEST_DESCRIPTION(
19046 "Validate that when an imageView of a depth/stencil image "
19047 "is used as a depth/stencil framebuffer attachment, the "
19048 "aspectMask is ignored and both depth and stencil image "
19049 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019050
19051 VkFormatProperties format_properties;
19052 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19053 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19054 return;
19055 }
19056
19057 m_errorMonitor->ExpectSuccess();
19058
19059 ASSERT_NO_FATAL_FAILURE(InitState());
19060
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019061 VkAttachmentDescription attachment = {0,
19062 VK_FORMAT_D32_SFLOAT_S8_UINT,
19063 VK_SAMPLE_COUNT_1_BIT,
19064 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19065 VK_ATTACHMENT_STORE_OP_STORE,
19066 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19067 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19068 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19069 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019070
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019071 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019072
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019073 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019074
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019075 VkSubpassDependency dep = {0,
19076 0,
19077 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19078 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19079 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19080 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19081 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019082
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019083 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019084
19085 VkResult err;
19086 VkRenderPass rp;
19087 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19088 ASSERT_VK_SUCCESS(err);
19089
19090 VkImageObj image(m_device);
19091 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019092 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019093 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019094 ASSERT_TRUE(image.initialized());
19095 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19096
19097 VkImageViewCreateInfo ivci = {
19098 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19099 nullptr,
19100 0,
19101 image.handle(),
19102 VK_IMAGE_VIEW_TYPE_2D,
19103 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019104 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19105 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019106 };
19107 VkImageView view;
19108 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19109 ASSERT_VK_SUCCESS(err);
19110
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019111 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019112 VkFramebuffer fb;
19113 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19114 ASSERT_VK_SUCCESS(err);
19115
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019116 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 -070019117 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019118 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19119
19120 VkImageMemoryBarrier imb = {};
19121 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19122 imb.pNext = nullptr;
19123 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19124 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19125 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19126 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19127 imb.srcQueueFamilyIndex = 0;
19128 imb.dstQueueFamilyIndex = 0;
19129 imb.image = image.handle();
19130 imb.subresourceRange.aspectMask = 0x6;
19131 imb.subresourceRange.baseMipLevel = 0;
19132 imb.subresourceRange.levelCount = 0x1;
19133 imb.subresourceRange.baseArrayLayer = 0;
19134 imb.subresourceRange.layerCount = 0x1;
19135
19136 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019137 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19138 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019139
19140 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019141 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019142 QueueCommandBuffer(false);
19143 m_errorMonitor->VerifyNotFound();
19144
19145 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19146 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19147 vkDestroyImageView(m_device->device(), view, nullptr);
19148}
19149
19150TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019151 TEST_DESCRIPTION(
19152 "Ensure that layout transitions work correctly without "
19153 "errors, when an attachment reference is "
19154 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019155
19156 m_errorMonitor->ExpectSuccess();
19157
19158 ASSERT_NO_FATAL_FAILURE(InitState());
19159
19160 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019161 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019162
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019163 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019164
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019165 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019166
19167 VkRenderPass rp;
19168 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19169 ASSERT_VK_SUCCESS(err);
19170
19171 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019172 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019173 VkFramebuffer fb;
19174 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19175 ASSERT_VK_SUCCESS(err);
19176
19177 // Record a command buffer which just begins and ends the renderpass. The
19178 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019179 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 -070019180 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019181 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19182 vkCmdEndRenderPass(m_commandBuffer->handle());
19183 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019184 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019185
19186 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19187 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19188}
19189
19190// This is a positive test. No errors are expected.
19191TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019192 TEST_DESCRIPTION(
19193 "Create a stencil-only attachment with a LOAD_OP set to "
19194 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019195 VkResult result = VK_SUCCESS;
19196 VkImageFormatProperties formatProps;
19197 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019198 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
19199 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019200 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
19201 return;
19202 }
19203
19204 ASSERT_NO_FATAL_FAILURE(InitState());
19205 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
19206 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019207 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019208 VkAttachmentDescription att = {};
19209 VkAttachmentReference ref = {};
19210 att.format = depth_stencil_fmt;
19211 att.samples = VK_SAMPLE_COUNT_1_BIT;
19212 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
19213 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19214 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19215 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
19216 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19217 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19218
19219 VkClearValue clear;
19220 clear.depthStencil.depth = 1.0;
19221 clear.depthStencil.stencil = 0;
19222 ref.attachment = 0;
19223 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19224
19225 VkSubpassDescription subpass = {};
19226 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
19227 subpass.flags = 0;
19228 subpass.inputAttachmentCount = 0;
19229 subpass.pInputAttachments = NULL;
19230 subpass.colorAttachmentCount = 0;
19231 subpass.pColorAttachments = NULL;
19232 subpass.pResolveAttachments = NULL;
19233 subpass.pDepthStencilAttachment = &ref;
19234 subpass.preserveAttachmentCount = 0;
19235 subpass.pPreserveAttachments = NULL;
19236
19237 VkRenderPass rp;
19238 VkRenderPassCreateInfo rp_info = {};
19239 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19240 rp_info.attachmentCount = 1;
19241 rp_info.pAttachments = &att;
19242 rp_info.subpassCount = 1;
19243 rp_info.pSubpasses = &subpass;
19244 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
19245 ASSERT_VK_SUCCESS(result);
19246
19247 VkImageView *depthView = m_depthStencil->BindInfo();
19248 VkFramebufferCreateInfo fb_info = {};
19249 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
19250 fb_info.pNext = NULL;
19251 fb_info.renderPass = rp;
19252 fb_info.attachmentCount = 1;
19253 fb_info.pAttachments = depthView;
19254 fb_info.width = 100;
19255 fb_info.height = 100;
19256 fb_info.layers = 1;
19257 VkFramebuffer fb;
19258 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
19259 ASSERT_VK_SUCCESS(result);
19260
19261 VkRenderPassBeginInfo rpbinfo = {};
19262 rpbinfo.clearValueCount = 1;
19263 rpbinfo.pClearValues = &clear;
19264 rpbinfo.pNext = NULL;
19265 rpbinfo.renderPass = rp;
19266 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
19267 rpbinfo.renderArea.extent.width = 100;
19268 rpbinfo.renderArea.extent.height = 100;
19269 rpbinfo.renderArea.offset.x = 0;
19270 rpbinfo.renderArea.offset.y = 0;
19271 rpbinfo.framebuffer = fb;
19272
19273 VkFence fence = {};
19274 VkFenceCreateInfo fence_ci = {};
19275 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19276 fence_ci.pNext = nullptr;
19277 fence_ci.flags = 0;
19278 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
19279 ASSERT_VK_SUCCESS(result);
19280
19281 m_commandBuffer->BeginCommandBuffer();
19282 m_commandBuffer->BeginRenderPass(rpbinfo);
19283 m_commandBuffer->EndRenderPass();
19284 m_commandBuffer->EndCommandBuffer();
19285 m_commandBuffer->QueueCommandBuffer(fence);
19286
19287 VkImageObj destImage(m_device);
19288 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 -070019289 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019290 VkImageMemoryBarrier barrier = {};
19291 VkImageSubresourceRange range;
19292 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19293 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19294 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
19295 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19296 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19297 barrier.image = m_depthStencil->handle();
19298 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19299 range.baseMipLevel = 0;
19300 range.levelCount = 1;
19301 range.baseArrayLayer = 0;
19302 range.layerCount = 1;
19303 barrier.subresourceRange = range;
19304 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19305 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
19306 cmdbuf.BeginCommandBuffer();
19307 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 -070019308 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019309 barrier.srcAccessMask = 0;
19310 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19311 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19312 barrier.image = destImage.handle();
19313 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19314 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 -070019315 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019316 VkImageCopy cregion;
19317 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19318 cregion.srcSubresource.mipLevel = 0;
19319 cregion.srcSubresource.baseArrayLayer = 0;
19320 cregion.srcSubresource.layerCount = 1;
19321 cregion.srcOffset.x = 0;
19322 cregion.srcOffset.y = 0;
19323 cregion.srcOffset.z = 0;
19324 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19325 cregion.dstSubresource.mipLevel = 0;
19326 cregion.dstSubresource.baseArrayLayer = 0;
19327 cregion.dstSubresource.layerCount = 1;
19328 cregion.dstOffset.x = 0;
19329 cregion.dstOffset.y = 0;
19330 cregion.dstOffset.z = 0;
19331 cregion.extent.width = 100;
19332 cregion.extent.height = 100;
19333 cregion.extent.depth = 1;
19334 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019335 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019336 cmdbuf.EndCommandBuffer();
19337
19338 VkSubmitInfo submit_info;
19339 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19340 submit_info.pNext = NULL;
19341 submit_info.waitSemaphoreCount = 0;
19342 submit_info.pWaitSemaphores = NULL;
19343 submit_info.pWaitDstStageMask = NULL;
19344 submit_info.commandBufferCount = 1;
19345 submit_info.pCommandBuffers = &cmdbuf.handle();
19346 submit_info.signalSemaphoreCount = 0;
19347 submit_info.pSignalSemaphores = NULL;
19348
19349 m_errorMonitor->ExpectSuccess();
19350 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19351 m_errorMonitor->VerifyNotFound();
19352
19353 vkQueueWaitIdle(m_device->m_queue);
19354 vkDestroyFence(m_device->device(), fence, nullptr);
19355 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19356 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19357}
19358
19359// This is a positive test. No errors should be generated.
19360TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
19361 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
19362
19363 m_errorMonitor->ExpectSuccess();
19364 ASSERT_NO_FATAL_FAILURE(InitState());
19365
19366 VkEvent event;
19367 VkEventCreateInfo event_create_info{};
19368 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19369 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19370
19371 VkCommandPool command_pool;
19372 VkCommandPoolCreateInfo pool_create_info{};
19373 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19374 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19375 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19376 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19377
19378 VkCommandBuffer command_buffer;
19379 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19380 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19381 command_buffer_allocate_info.commandPool = command_pool;
19382 command_buffer_allocate_info.commandBufferCount = 1;
19383 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19384 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19385
19386 VkQueue queue = VK_NULL_HANDLE;
19387 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19388
19389 {
19390 VkCommandBufferBeginInfo begin_info{};
19391 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19392 vkBeginCommandBuffer(command_buffer, &begin_info);
19393
19394 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 -070019395 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019396 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
19397 vkEndCommandBuffer(command_buffer);
19398 }
19399 {
19400 VkSubmitInfo submit_info{};
19401 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19402 submit_info.commandBufferCount = 1;
19403 submit_info.pCommandBuffers = &command_buffer;
19404 submit_info.signalSemaphoreCount = 0;
19405 submit_info.pSignalSemaphores = nullptr;
19406 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19407 }
19408 { vkSetEvent(m_device->device(), event); }
19409
19410 vkQueueWaitIdle(queue);
19411
19412 vkDestroyEvent(m_device->device(), event, nullptr);
19413 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19414 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19415
19416 m_errorMonitor->VerifyNotFound();
19417}
19418// This is a positive test. No errors should be generated.
19419TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
19420 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
19421
19422 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019423 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019424
19425 m_errorMonitor->ExpectSuccess();
19426
19427 VkQueryPool query_pool;
19428 VkQueryPoolCreateInfo query_pool_create_info{};
19429 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
19430 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
19431 query_pool_create_info.queryCount = 1;
19432 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
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;
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 = 1;
19446 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19447 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19448
19449 VkCommandBuffer secondary_command_buffer;
19450 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19451 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
19452
19453 VkQueue queue = VK_NULL_HANDLE;
19454 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19455
19456 uint32_t qfi = 0;
19457 VkBufferCreateInfo buff_create_info = {};
19458 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19459 buff_create_info.size = 1024;
19460 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
19461 buff_create_info.queueFamilyIndexCount = 1;
19462 buff_create_info.pQueueFamilyIndices = &qfi;
19463
19464 VkResult err;
19465 VkBuffer buffer;
19466 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
19467 ASSERT_VK_SUCCESS(err);
19468 VkMemoryAllocateInfo mem_alloc = {};
19469 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19470 mem_alloc.pNext = NULL;
19471 mem_alloc.allocationSize = 1024;
19472 mem_alloc.memoryTypeIndex = 0;
19473
19474 VkMemoryRequirements memReqs;
19475 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
19476 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
19477 if (!pass) {
19478 vkDestroyBuffer(m_device->device(), buffer, NULL);
19479 return;
19480 }
19481
19482 VkDeviceMemory mem;
19483 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19484 ASSERT_VK_SUCCESS(err);
19485 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19486 ASSERT_VK_SUCCESS(err);
19487
19488 VkCommandBufferInheritanceInfo hinfo = {};
19489 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
19490 hinfo.renderPass = VK_NULL_HANDLE;
19491 hinfo.subpass = 0;
19492 hinfo.framebuffer = VK_NULL_HANDLE;
19493 hinfo.occlusionQueryEnable = VK_FALSE;
19494 hinfo.queryFlags = 0;
19495 hinfo.pipelineStatistics = 0;
19496
19497 {
19498 VkCommandBufferBeginInfo begin_info{};
19499 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19500 begin_info.pInheritanceInfo = &hinfo;
19501 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
19502
19503 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
19504 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
19505
19506 vkEndCommandBuffer(secondary_command_buffer);
19507
19508 begin_info.pInheritanceInfo = nullptr;
19509 vkBeginCommandBuffer(command_buffer, &begin_info);
19510
19511 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
19512 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
19513
19514 vkEndCommandBuffer(command_buffer);
19515 }
19516 {
19517 VkSubmitInfo submit_info{};
19518 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19519 submit_info.commandBufferCount = 1;
19520 submit_info.pCommandBuffers = &command_buffer;
19521 submit_info.signalSemaphoreCount = 0;
19522 submit_info.pSignalSemaphores = nullptr;
19523 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19524 }
19525
19526 vkQueueWaitIdle(queue);
19527
19528 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
19529 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19530 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
19531 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19532 vkDestroyBuffer(m_device->device(), buffer, NULL);
19533 vkFreeMemory(m_device->device(), mem, NULL);
19534
19535 m_errorMonitor->VerifyNotFound();
19536}
19537
19538// This is a positive test. No errors should be generated.
19539TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
19540 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
19541
19542 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019543 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019544
19545 m_errorMonitor->ExpectSuccess();
19546
19547 VkQueryPool query_pool;
19548 VkQueryPoolCreateInfo query_pool_create_info{};
19549 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
19550 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
19551 query_pool_create_info.queryCount = 1;
19552 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
19553
19554 VkCommandPool command_pool;
19555 VkCommandPoolCreateInfo pool_create_info{};
19556 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19557 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19558 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19559 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19560
19561 VkCommandBuffer command_buffer[2];
19562 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19563 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19564 command_buffer_allocate_info.commandPool = command_pool;
19565 command_buffer_allocate_info.commandBufferCount = 2;
19566 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19567 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19568
19569 VkQueue queue = VK_NULL_HANDLE;
19570 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19571
19572 uint32_t qfi = 0;
19573 VkBufferCreateInfo buff_create_info = {};
19574 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19575 buff_create_info.size = 1024;
19576 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
19577 buff_create_info.queueFamilyIndexCount = 1;
19578 buff_create_info.pQueueFamilyIndices = &qfi;
19579
19580 VkResult err;
19581 VkBuffer buffer;
19582 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
19583 ASSERT_VK_SUCCESS(err);
19584 VkMemoryAllocateInfo mem_alloc = {};
19585 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19586 mem_alloc.pNext = NULL;
19587 mem_alloc.allocationSize = 1024;
19588 mem_alloc.memoryTypeIndex = 0;
19589
19590 VkMemoryRequirements memReqs;
19591 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
19592 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
19593 if (!pass) {
19594 vkDestroyBuffer(m_device->device(), buffer, NULL);
19595 return;
19596 }
19597
19598 VkDeviceMemory mem;
19599 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19600 ASSERT_VK_SUCCESS(err);
19601 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19602 ASSERT_VK_SUCCESS(err);
19603
19604 {
19605 VkCommandBufferBeginInfo begin_info{};
19606 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19607 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19608
19609 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
19610 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
19611
19612 vkEndCommandBuffer(command_buffer[0]);
19613
19614 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19615
19616 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
19617
19618 vkEndCommandBuffer(command_buffer[1]);
19619 }
19620 {
19621 VkSubmitInfo submit_info{};
19622 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19623 submit_info.commandBufferCount = 2;
19624 submit_info.pCommandBuffers = command_buffer;
19625 submit_info.signalSemaphoreCount = 0;
19626 submit_info.pSignalSemaphores = nullptr;
19627 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19628 }
19629
19630 vkQueueWaitIdle(queue);
19631
19632 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
19633 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
19634 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19635 vkDestroyBuffer(m_device->device(), buffer, NULL);
19636 vkFreeMemory(m_device->device(), mem, NULL);
19637
19638 m_errorMonitor->VerifyNotFound();
19639}
19640
Tony Barbourc46924f2016-11-04 11:49:52 -060019641TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019642 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
19643
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019644 ASSERT_NO_FATAL_FAILURE(InitState());
19645 VkEvent event;
19646 VkEventCreateInfo event_create_info{};
19647 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19648 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19649
19650 VkCommandPool command_pool;
19651 VkCommandPoolCreateInfo pool_create_info{};
19652 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19653 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19654 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19655 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19656
19657 VkCommandBuffer command_buffer;
19658 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19659 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19660 command_buffer_allocate_info.commandPool = command_pool;
19661 command_buffer_allocate_info.commandBufferCount = 1;
19662 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19663 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19664
19665 VkQueue queue = VK_NULL_HANDLE;
19666 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19667
19668 {
19669 VkCommandBufferBeginInfo begin_info{};
19670 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19671 vkBeginCommandBuffer(command_buffer, &begin_info);
19672
19673 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019674 vkEndCommandBuffer(command_buffer);
19675 }
19676 {
19677 VkSubmitInfo submit_info{};
19678 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19679 submit_info.commandBufferCount = 1;
19680 submit_info.pCommandBuffers = &command_buffer;
19681 submit_info.signalSemaphoreCount = 0;
19682 submit_info.pSignalSemaphores = nullptr;
19683 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19684 }
19685 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19687 "that is already in use by a "
19688 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019689 vkSetEvent(m_device->device(), event);
19690 m_errorMonitor->VerifyFound();
19691 }
19692
19693 vkQueueWaitIdle(queue);
19694
19695 vkDestroyEvent(m_device->device(), event, nullptr);
19696 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19697 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19698}
19699
19700// This is a positive test. No errors should be generated.
19701TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019702 TEST_DESCRIPTION(
19703 "Two command buffers with two separate fences are each "
19704 "run through a Submit & WaitForFences cycle 3 times. This "
19705 "previously revealed a bug so running this positive test "
19706 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019707 m_errorMonitor->ExpectSuccess();
19708
19709 ASSERT_NO_FATAL_FAILURE(InitState());
19710 VkQueue queue = VK_NULL_HANDLE;
19711 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19712
19713 static const uint32_t NUM_OBJECTS = 2;
19714 static const uint32_t NUM_FRAMES = 3;
19715 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
19716 VkFence fences[NUM_OBJECTS] = {};
19717
19718 VkCommandPool cmd_pool;
19719 VkCommandPoolCreateInfo cmd_pool_ci = {};
19720 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19721 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
19722 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19723 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
19724 ASSERT_VK_SUCCESS(err);
19725
19726 VkCommandBufferAllocateInfo cmd_buf_info = {};
19727 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19728 cmd_buf_info.commandPool = cmd_pool;
19729 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19730 cmd_buf_info.commandBufferCount = 1;
19731
19732 VkFenceCreateInfo fence_ci = {};
19733 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19734 fence_ci.pNext = nullptr;
19735 fence_ci.flags = 0;
19736
19737 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19738 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
19739 ASSERT_VK_SUCCESS(err);
19740 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
19741 ASSERT_VK_SUCCESS(err);
19742 }
19743
19744 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
19745 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
19746 // Create empty cmd buffer
19747 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
19748 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19749
19750 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
19751 ASSERT_VK_SUCCESS(err);
19752 err = vkEndCommandBuffer(cmd_buffers[obj]);
19753 ASSERT_VK_SUCCESS(err);
19754
19755 VkSubmitInfo submit_info = {};
19756 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19757 submit_info.commandBufferCount = 1;
19758 submit_info.pCommandBuffers = &cmd_buffers[obj];
19759 // Submit cmd buffer and wait for fence
19760 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
19761 ASSERT_VK_SUCCESS(err);
19762 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
19763 ASSERT_VK_SUCCESS(err);
19764 err = vkResetFences(m_device->device(), 1, &fences[obj]);
19765 ASSERT_VK_SUCCESS(err);
19766 }
19767 }
19768 m_errorMonitor->VerifyNotFound();
19769 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
19770 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19771 vkDestroyFence(m_device->device(), fences[i], nullptr);
19772 }
19773}
19774// This is a positive test. No errors should be generated.
19775TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019776 TEST_DESCRIPTION(
19777 "Two command buffers, each in a separate QueueSubmit call "
19778 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019779
19780 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019781 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019782
19783 m_errorMonitor->ExpectSuccess();
19784
19785 VkSemaphore semaphore;
19786 VkSemaphoreCreateInfo semaphore_create_info{};
19787 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19788 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19789
19790 VkCommandPool command_pool;
19791 VkCommandPoolCreateInfo pool_create_info{};
19792 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19793 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19794 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19795 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19796
19797 VkCommandBuffer command_buffer[2];
19798 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19799 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19800 command_buffer_allocate_info.commandPool = command_pool;
19801 command_buffer_allocate_info.commandBufferCount = 2;
19802 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19803 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19804
19805 VkQueue queue = VK_NULL_HANDLE;
19806 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19807
19808 {
19809 VkCommandBufferBeginInfo begin_info{};
19810 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19811 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19812
19813 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 -070019814 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019815
19816 VkViewport viewport{};
19817 viewport.maxDepth = 1.0f;
19818 viewport.minDepth = 0.0f;
19819 viewport.width = 512;
19820 viewport.height = 512;
19821 viewport.x = 0;
19822 viewport.y = 0;
19823 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19824 vkEndCommandBuffer(command_buffer[0]);
19825 }
19826 {
19827 VkCommandBufferBeginInfo begin_info{};
19828 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19829 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19830
19831 VkViewport viewport{};
19832 viewport.maxDepth = 1.0f;
19833 viewport.minDepth = 0.0f;
19834 viewport.width = 512;
19835 viewport.height = 512;
19836 viewport.x = 0;
19837 viewport.y = 0;
19838 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19839 vkEndCommandBuffer(command_buffer[1]);
19840 }
19841 {
19842 VkSubmitInfo submit_info{};
19843 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19844 submit_info.commandBufferCount = 1;
19845 submit_info.pCommandBuffers = &command_buffer[0];
19846 submit_info.signalSemaphoreCount = 1;
19847 submit_info.pSignalSemaphores = &semaphore;
19848 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19849 }
19850 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019851 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019852 VkSubmitInfo submit_info{};
19853 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19854 submit_info.commandBufferCount = 1;
19855 submit_info.pCommandBuffers = &command_buffer[1];
19856 submit_info.waitSemaphoreCount = 1;
19857 submit_info.pWaitSemaphores = &semaphore;
19858 submit_info.pWaitDstStageMask = flags;
19859 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19860 }
19861
19862 vkQueueWaitIdle(m_device->m_queue);
19863
19864 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19865 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19866 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19867
19868 m_errorMonitor->VerifyNotFound();
19869}
19870
19871// This is a positive test. No errors should be generated.
19872TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019873 TEST_DESCRIPTION(
19874 "Two command buffers, each in a separate QueueSubmit call "
19875 "submitted on separate queues, the second having a fence"
19876 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019877
19878 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019879 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019880
19881 m_errorMonitor->ExpectSuccess();
19882
19883 VkFence fence;
19884 VkFenceCreateInfo fence_create_info{};
19885 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19886 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19887
19888 VkSemaphore semaphore;
19889 VkSemaphoreCreateInfo semaphore_create_info{};
19890 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19891 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19892
19893 VkCommandPool command_pool;
19894 VkCommandPoolCreateInfo pool_create_info{};
19895 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19896 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19897 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19898 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19899
19900 VkCommandBuffer command_buffer[2];
19901 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19902 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19903 command_buffer_allocate_info.commandPool = command_pool;
19904 command_buffer_allocate_info.commandBufferCount = 2;
19905 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19906 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19907
19908 VkQueue queue = VK_NULL_HANDLE;
19909 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19910
19911 {
19912 VkCommandBufferBeginInfo begin_info{};
19913 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19914 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19915
19916 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 -070019917 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019918
19919 VkViewport viewport{};
19920 viewport.maxDepth = 1.0f;
19921 viewport.minDepth = 0.0f;
19922 viewport.width = 512;
19923 viewport.height = 512;
19924 viewport.x = 0;
19925 viewport.y = 0;
19926 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19927 vkEndCommandBuffer(command_buffer[0]);
19928 }
19929 {
19930 VkCommandBufferBeginInfo begin_info{};
19931 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19932 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19933
19934 VkViewport viewport{};
19935 viewport.maxDepth = 1.0f;
19936 viewport.minDepth = 0.0f;
19937 viewport.width = 512;
19938 viewport.height = 512;
19939 viewport.x = 0;
19940 viewport.y = 0;
19941 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19942 vkEndCommandBuffer(command_buffer[1]);
19943 }
19944 {
19945 VkSubmitInfo submit_info{};
19946 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19947 submit_info.commandBufferCount = 1;
19948 submit_info.pCommandBuffers = &command_buffer[0];
19949 submit_info.signalSemaphoreCount = 1;
19950 submit_info.pSignalSemaphores = &semaphore;
19951 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19952 }
19953 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019954 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019955 VkSubmitInfo submit_info{};
19956 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19957 submit_info.commandBufferCount = 1;
19958 submit_info.pCommandBuffers = &command_buffer[1];
19959 submit_info.waitSemaphoreCount = 1;
19960 submit_info.pWaitSemaphores = &semaphore;
19961 submit_info.pWaitDstStageMask = flags;
19962 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19963 }
19964
19965 vkQueueWaitIdle(m_device->m_queue);
19966
19967 vkDestroyFence(m_device->device(), fence, nullptr);
19968 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19969 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19970 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19971
19972 m_errorMonitor->VerifyNotFound();
19973}
19974
19975// This is a positive test. No errors should be generated.
19976TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019977 TEST_DESCRIPTION(
19978 "Two command buffers, each in a separate QueueSubmit call "
19979 "submitted on separate queues, the second having a fence"
19980 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019981
19982 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019983 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019984
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 VkQueue queue = VK_NULL_HANDLE;
20013 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20014
20015 {
20016 VkCommandBufferBeginInfo begin_info{};
20017 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20018 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20019
20020 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 -070020021 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020022
20023 VkViewport viewport{};
20024 viewport.maxDepth = 1.0f;
20025 viewport.minDepth = 0.0f;
20026 viewport.width = 512;
20027 viewport.height = 512;
20028 viewport.x = 0;
20029 viewport.y = 0;
20030 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20031 vkEndCommandBuffer(command_buffer[0]);
20032 }
20033 {
20034 VkCommandBufferBeginInfo begin_info{};
20035 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20036 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20037
20038 VkViewport viewport{};
20039 viewport.maxDepth = 1.0f;
20040 viewport.minDepth = 0.0f;
20041 viewport.width = 512;
20042 viewport.height = 512;
20043 viewport.x = 0;
20044 viewport.y = 0;
20045 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20046 vkEndCommandBuffer(command_buffer[1]);
20047 }
20048 {
20049 VkSubmitInfo submit_info{};
20050 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20051 submit_info.commandBufferCount = 1;
20052 submit_info.pCommandBuffers = &command_buffer[0];
20053 submit_info.signalSemaphoreCount = 1;
20054 submit_info.pSignalSemaphores = &semaphore;
20055 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20056 }
20057 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020058 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020059 VkSubmitInfo submit_info{};
20060 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20061 submit_info.commandBufferCount = 1;
20062 submit_info.pCommandBuffers = &command_buffer[1];
20063 submit_info.waitSemaphoreCount = 1;
20064 submit_info.pWaitSemaphores = &semaphore;
20065 submit_info.pWaitDstStageMask = flags;
20066 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20067 }
20068
20069 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20070 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20071
20072 vkDestroyFence(m_device->device(), fence, nullptr);
20073 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20074 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20075 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20076
20077 m_errorMonitor->VerifyNotFound();
20078}
20079
20080TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020081 ASSERT_NO_FATAL_FAILURE(InitState());
20082 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
20083 printf("Test requires two queues, skipping\n");
20084 return;
20085 }
20086
20087 VkResult err;
20088
20089 m_errorMonitor->ExpectSuccess();
20090
20091 VkQueue q0 = m_device->m_queue;
20092 VkQueue q1 = nullptr;
20093 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20094 ASSERT_NE(q1, nullptr);
20095
20096 // An (empty) command buffer. We must have work in the first submission --
20097 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020098 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020099 VkCommandPool pool;
20100 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20101 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020102 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20103 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020104 VkCommandBuffer cb;
20105 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20106 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020107 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020108 err = vkBeginCommandBuffer(cb, &cbbi);
20109 ASSERT_VK_SUCCESS(err);
20110 err = vkEndCommandBuffer(cb);
20111 ASSERT_VK_SUCCESS(err);
20112
20113 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020114 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020115 VkSemaphore s;
20116 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20117 ASSERT_VK_SUCCESS(err);
20118
20119 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020120 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020121
20122 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20123 ASSERT_VK_SUCCESS(err);
20124
20125 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020126 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020127 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020128
20129 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20130 ASSERT_VK_SUCCESS(err);
20131
20132 // Wait for q0 idle
20133 err = vkQueueWaitIdle(q0);
20134 ASSERT_VK_SUCCESS(err);
20135
20136 // Command buffer should have been completed (it was on q0); reset the pool.
20137 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20138
20139 m_errorMonitor->VerifyNotFound();
20140
20141 // Force device completely idle and clean up resources
20142 vkDeviceWaitIdle(m_device->device());
20143 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20144 vkDestroySemaphore(m_device->device(), s, nullptr);
20145}
20146
20147// This is a positive test. No errors should be generated.
20148TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020149 TEST_DESCRIPTION(
20150 "Two command buffers, each in a separate QueueSubmit call "
20151 "submitted on separate queues, the second having a fence, "
20152 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020153
20154 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020155 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020156
20157 m_errorMonitor->ExpectSuccess();
20158
20159 ASSERT_NO_FATAL_FAILURE(InitState());
20160 VkFence fence;
20161 VkFenceCreateInfo fence_create_info{};
20162 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20163 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20164
20165 VkSemaphore semaphore;
20166 VkSemaphoreCreateInfo semaphore_create_info{};
20167 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20168 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20169
20170 VkCommandPool command_pool;
20171 VkCommandPoolCreateInfo pool_create_info{};
20172 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20173 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20174 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20175 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20176
20177 VkCommandBuffer command_buffer[2];
20178 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20179 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20180 command_buffer_allocate_info.commandPool = command_pool;
20181 command_buffer_allocate_info.commandBufferCount = 2;
20182 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20183 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20184
20185 VkQueue queue = VK_NULL_HANDLE;
20186 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20187
20188 {
20189 VkCommandBufferBeginInfo begin_info{};
20190 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20191 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20192
20193 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 -070020194 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020195
20196 VkViewport viewport{};
20197 viewport.maxDepth = 1.0f;
20198 viewport.minDepth = 0.0f;
20199 viewport.width = 512;
20200 viewport.height = 512;
20201 viewport.x = 0;
20202 viewport.y = 0;
20203 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20204 vkEndCommandBuffer(command_buffer[0]);
20205 }
20206 {
20207 VkCommandBufferBeginInfo begin_info{};
20208 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20209 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20210
20211 VkViewport viewport{};
20212 viewport.maxDepth = 1.0f;
20213 viewport.minDepth = 0.0f;
20214 viewport.width = 512;
20215 viewport.height = 512;
20216 viewport.x = 0;
20217 viewport.y = 0;
20218 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20219 vkEndCommandBuffer(command_buffer[1]);
20220 }
20221 {
20222 VkSubmitInfo submit_info{};
20223 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20224 submit_info.commandBufferCount = 1;
20225 submit_info.pCommandBuffers = &command_buffer[0];
20226 submit_info.signalSemaphoreCount = 1;
20227 submit_info.pSignalSemaphores = &semaphore;
20228 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20229 }
20230 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020231 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020232 VkSubmitInfo submit_info{};
20233 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20234 submit_info.commandBufferCount = 1;
20235 submit_info.pCommandBuffers = &command_buffer[1];
20236 submit_info.waitSemaphoreCount = 1;
20237 submit_info.pWaitSemaphores = &semaphore;
20238 submit_info.pWaitDstStageMask = flags;
20239 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20240 }
20241
20242 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20243
20244 vkDestroyFence(m_device->device(), fence, nullptr);
20245 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20246 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20247 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20248
20249 m_errorMonitor->VerifyNotFound();
20250}
20251
20252// This is a positive test. No errors should be generated.
20253TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020254 TEST_DESCRIPTION(
20255 "Two command buffers, each in a separate QueueSubmit call "
20256 "on the same queue, sharing a signal/wait semaphore, the "
20257 "second having a fence, "
20258 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020259
20260 m_errorMonitor->ExpectSuccess();
20261
20262 ASSERT_NO_FATAL_FAILURE(InitState());
20263 VkFence fence;
20264 VkFenceCreateInfo fence_create_info{};
20265 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20266 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20267
20268 VkSemaphore semaphore;
20269 VkSemaphoreCreateInfo semaphore_create_info{};
20270 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20271 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20272
20273 VkCommandPool command_pool;
20274 VkCommandPoolCreateInfo pool_create_info{};
20275 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20276 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20277 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20278 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20279
20280 VkCommandBuffer command_buffer[2];
20281 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20282 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20283 command_buffer_allocate_info.commandPool = command_pool;
20284 command_buffer_allocate_info.commandBufferCount = 2;
20285 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20286 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20287
20288 {
20289 VkCommandBufferBeginInfo begin_info{};
20290 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20291 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20292
20293 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 -070020294 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020295
20296 VkViewport viewport{};
20297 viewport.maxDepth = 1.0f;
20298 viewport.minDepth = 0.0f;
20299 viewport.width = 512;
20300 viewport.height = 512;
20301 viewport.x = 0;
20302 viewport.y = 0;
20303 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20304 vkEndCommandBuffer(command_buffer[0]);
20305 }
20306 {
20307 VkCommandBufferBeginInfo begin_info{};
20308 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20309 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20310
20311 VkViewport viewport{};
20312 viewport.maxDepth = 1.0f;
20313 viewport.minDepth = 0.0f;
20314 viewport.width = 512;
20315 viewport.height = 512;
20316 viewport.x = 0;
20317 viewport.y = 0;
20318 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20319 vkEndCommandBuffer(command_buffer[1]);
20320 }
20321 {
20322 VkSubmitInfo submit_info{};
20323 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20324 submit_info.commandBufferCount = 1;
20325 submit_info.pCommandBuffers = &command_buffer[0];
20326 submit_info.signalSemaphoreCount = 1;
20327 submit_info.pSignalSemaphores = &semaphore;
20328 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20329 }
20330 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020331 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020332 VkSubmitInfo submit_info{};
20333 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20334 submit_info.commandBufferCount = 1;
20335 submit_info.pCommandBuffers = &command_buffer[1];
20336 submit_info.waitSemaphoreCount = 1;
20337 submit_info.pWaitSemaphores = &semaphore;
20338 submit_info.pWaitDstStageMask = flags;
20339 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20340 }
20341
20342 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20343
20344 vkDestroyFence(m_device->device(), fence, nullptr);
20345 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20346 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20347 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20348
20349 m_errorMonitor->VerifyNotFound();
20350}
20351
20352// This is a positive test. No errors should be generated.
20353TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020354 TEST_DESCRIPTION(
20355 "Two command buffers, each in a separate QueueSubmit call "
20356 "on the same queue, no fences, followed by a third QueueSubmit with NO "
20357 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020358
20359 m_errorMonitor->ExpectSuccess();
20360
20361 ASSERT_NO_FATAL_FAILURE(InitState());
20362 VkFence fence;
20363 VkFenceCreateInfo fence_create_info{};
20364 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20365 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20366
20367 VkCommandPool command_pool;
20368 VkCommandPoolCreateInfo pool_create_info{};
20369 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20370 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20371 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20372 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20373
20374 VkCommandBuffer command_buffer[2];
20375 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20376 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20377 command_buffer_allocate_info.commandPool = command_pool;
20378 command_buffer_allocate_info.commandBufferCount = 2;
20379 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20380 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20381
20382 {
20383 VkCommandBufferBeginInfo begin_info{};
20384 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20385 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20386
20387 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 -070020388 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020389
20390 VkViewport viewport{};
20391 viewport.maxDepth = 1.0f;
20392 viewport.minDepth = 0.0f;
20393 viewport.width = 512;
20394 viewport.height = 512;
20395 viewport.x = 0;
20396 viewport.y = 0;
20397 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20398 vkEndCommandBuffer(command_buffer[0]);
20399 }
20400 {
20401 VkCommandBufferBeginInfo begin_info{};
20402 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20403 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20404
20405 VkViewport viewport{};
20406 viewport.maxDepth = 1.0f;
20407 viewport.minDepth = 0.0f;
20408 viewport.width = 512;
20409 viewport.height = 512;
20410 viewport.x = 0;
20411 viewport.y = 0;
20412 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20413 vkEndCommandBuffer(command_buffer[1]);
20414 }
20415 {
20416 VkSubmitInfo submit_info{};
20417 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20418 submit_info.commandBufferCount = 1;
20419 submit_info.pCommandBuffers = &command_buffer[0];
20420 submit_info.signalSemaphoreCount = 0;
20421 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20422 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20423 }
20424 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020425 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020426 VkSubmitInfo submit_info{};
20427 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20428 submit_info.commandBufferCount = 1;
20429 submit_info.pCommandBuffers = &command_buffer[1];
20430 submit_info.waitSemaphoreCount = 0;
20431 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20432 submit_info.pWaitDstStageMask = flags;
20433 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20434 }
20435
20436 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
20437
20438 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20439 ASSERT_VK_SUCCESS(err);
20440
20441 vkDestroyFence(m_device->device(), fence, nullptr);
20442 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20443 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20444
20445 m_errorMonitor->VerifyNotFound();
20446}
20447
20448// This is a positive test. No errors should be generated.
20449TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020450 TEST_DESCRIPTION(
20451 "Two command buffers, each in a separate QueueSubmit call "
20452 "on the same queue, the second having a fence, followed "
20453 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020454
20455 m_errorMonitor->ExpectSuccess();
20456
20457 ASSERT_NO_FATAL_FAILURE(InitState());
20458 VkFence fence;
20459 VkFenceCreateInfo fence_create_info{};
20460 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20461 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20462
20463 VkCommandPool command_pool;
20464 VkCommandPoolCreateInfo pool_create_info{};
20465 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20466 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20467 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20468 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20469
20470 VkCommandBuffer command_buffer[2];
20471 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20472 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20473 command_buffer_allocate_info.commandPool = command_pool;
20474 command_buffer_allocate_info.commandBufferCount = 2;
20475 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20476 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20477
20478 {
20479 VkCommandBufferBeginInfo begin_info{};
20480 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20481 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20482
20483 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 -070020484 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020485
20486 VkViewport viewport{};
20487 viewport.maxDepth = 1.0f;
20488 viewport.minDepth = 0.0f;
20489 viewport.width = 512;
20490 viewport.height = 512;
20491 viewport.x = 0;
20492 viewport.y = 0;
20493 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20494 vkEndCommandBuffer(command_buffer[0]);
20495 }
20496 {
20497 VkCommandBufferBeginInfo begin_info{};
20498 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20499 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20500
20501 VkViewport viewport{};
20502 viewport.maxDepth = 1.0f;
20503 viewport.minDepth = 0.0f;
20504 viewport.width = 512;
20505 viewport.height = 512;
20506 viewport.x = 0;
20507 viewport.y = 0;
20508 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20509 vkEndCommandBuffer(command_buffer[1]);
20510 }
20511 {
20512 VkSubmitInfo submit_info{};
20513 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20514 submit_info.commandBufferCount = 1;
20515 submit_info.pCommandBuffers = &command_buffer[0];
20516 submit_info.signalSemaphoreCount = 0;
20517 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20518 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20519 }
20520 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020521 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020522 VkSubmitInfo submit_info{};
20523 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20524 submit_info.commandBufferCount = 1;
20525 submit_info.pCommandBuffers = &command_buffer[1];
20526 submit_info.waitSemaphoreCount = 0;
20527 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20528 submit_info.pWaitDstStageMask = flags;
20529 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20530 }
20531
20532 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20533
20534 vkDestroyFence(m_device->device(), fence, nullptr);
20535 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20536 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20537
20538 m_errorMonitor->VerifyNotFound();
20539}
20540
20541// This is a positive test. No errors should be generated.
20542TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020543 TEST_DESCRIPTION(
20544 "Two command buffers each in a separate SubmitInfo sent in a single "
20545 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020546 ASSERT_NO_FATAL_FAILURE(InitState());
20547
20548 m_errorMonitor->ExpectSuccess();
20549
20550 VkFence fence;
20551 VkFenceCreateInfo fence_create_info{};
20552 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20553 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20554
20555 VkSemaphore semaphore;
20556 VkSemaphoreCreateInfo semaphore_create_info{};
20557 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20558 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20559
20560 VkCommandPool command_pool;
20561 VkCommandPoolCreateInfo pool_create_info{};
20562 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20563 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20564 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20565 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20566
20567 VkCommandBuffer command_buffer[2];
20568 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20569 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20570 command_buffer_allocate_info.commandPool = command_pool;
20571 command_buffer_allocate_info.commandBufferCount = 2;
20572 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20573 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20574
20575 {
20576 VkCommandBufferBeginInfo begin_info{};
20577 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20578 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20579
20580 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 -070020581 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020582
20583 VkViewport viewport{};
20584 viewport.maxDepth = 1.0f;
20585 viewport.minDepth = 0.0f;
20586 viewport.width = 512;
20587 viewport.height = 512;
20588 viewport.x = 0;
20589 viewport.y = 0;
20590 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20591 vkEndCommandBuffer(command_buffer[0]);
20592 }
20593 {
20594 VkCommandBufferBeginInfo begin_info{};
20595 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20596 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20597
20598 VkViewport viewport{};
20599 viewport.maxDepth = 1.0f;
20600 viewport.minDepth = 0.0f;
20601 viewport.width = 512;
20602 viewport.height = 512;
20603 viewport.x = 0;
20604 viewport.y = 0;
20605 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20606 vkEndCommandBuffer(command_buffer[1]);
20607 }
20608 {
20609 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020610 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020611
20612 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20613 submit_info[0].pNext = NULL;
20614 submit_info[0].commandBufferCount = 1;
20615 submit_info[0].pCommandBuffers = &command_buffer[0];
20616 submit_info[0].signalSemaphoreCount = 1;
20617 submit_info[0].pSignalSemaphores = &semaphore;
20618 submit_info[0].waitSemaphoreCount = 0;
20619 submit_info[0].pWaitSemaphores = NULL;
20620 submit_info[0].pWaitDstStageMask = 0;
20621
20622 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20623 submit_info[1].pNext = NULL;
20624 submit_info[1].commandBufferCount = 1;
20625 submit_info[1].pCommandBuffers = &command_buffer[1];
20626 submit_info[1].waitSemaphoreCount = 1;
20627 submit_info[1].pWaitSemaphores = &semaphore;
20628 submit_info[1].pWaitDstStageMask = flags;
20629 submit_info[1].signalSemaphoreCount = 0;
20630 submit_info[1].pSignalSemaphores = NULL;
20631 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
20632 }
20633
20634 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20635
20636 vkDestroyFence(m_device->device(), fence, nullptr);
20637 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20638 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20639 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20640
20641 m_errorMonitor->VerifyNotFound();
20642}
20643
20644TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
20645 m_errorMonitor->ExpectSuccess();
20646
20647 ASSERT_NO_FATAL_FAILURE(InitState());
20648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20649
Tony Barbour552f6c02016-12-21 14:34:07 -070020650 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020651
20652 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
20653 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
20654 m_errorMonitor->VerifyNotFound();
20655 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
20656 m_errorMonitor->VerifyNotFound();
20657 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
20658 m_errorMonitor->VerifyNotFound();
20659
20660 m_commandBuffer->EndCommandBuffer();
20661 m_errorMonitor->VerifyNotFound();
20662}
20663
20664TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020665 TEST_DESCRIPTION(
20666 "Positive test where we create a renderpass with an "
20667 "attachment that uses LOAD_OP_CLEAR, the first subpass "
20668 "has a valid layout, and a second subpass then uses a "
20669 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020670 m_errorMonitor->ExpectSuccess();
20671 ASSERT_NO_FATAL_FAILURE(InitState());
20672
20673 VkAttachmentReference attach[2] = {};
20674 attach[0].attachment = 0;
20675 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20676 attach[1].attachment = 0;
20677 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
20678 VkSubpassDescription subpasses[2] = {};
20679 // First subpass clears DS attach on load
20680 subpasses[0].pDepthStencilAttachment = &attach[0];
20681 // 2nd subpass reads in DS as input attachment
20682 subpasses[1].inputAttachmentCount = 1;
20683 subpasses[1].pInputAttachments = &attach[1];
20684 VkAttachmentDescription attach_desc = {};
20685 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
20686 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
20687 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
20688 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
20689 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20690 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20691 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20692 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
20693 VkRenderPassCreateInfo rpci = {};
20694 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20695 rpci.attachmentCount = 1;
20696 rpci.pAttachments = &attach_desc;
20697 rpci.subpassCount = 2;
20698 rpci.pSubpasses = subpasses;
20699
20700 // Now create RenderPass and verify no errors
20701 VkRenderPass rp;
20702 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
20703 m_errorMonitor->VerifyNotFound();
20704
20705 vkDestroyRenderPass(m_device->device(), rp, NULL);
20706}
20707
20708TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020709 TEST_DESCRIPTION(
20710 "Test that pipeline validation accepts matrices passed "
20711 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020712 m_errorMonitor->ExpectSuccess();
20713
20714 ASSERT_NO_FATAL_FAILURE(InitState());
20715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20716
20717 VkVertexInputBindingDescription input_binding;
20718 memset(&input_binding, 0, sizeof(input_binding));
20719
20720 VkVertexInputAttributeDescription input_attribs[2];
20721 memset(input_attribs, 0, sizeof(input_attribs));
20722
20723 for (int i = 0; i < 2; i++) {
20724 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20725 input_attribs[i].location = i;
20726 }
20727
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020728 char const *vsSource =
20729 "#version 450\n"
20730 "\n"
20731 "layout(location=0) in mat2x4 x;\n"
20732 "out gl_PerVertex {\n"
20733 " vec4 gl_Position;\n"
20734 "};\n"
20735 "void main(){\n"
20736 " gl_Position = x[0] + x[1];\n"
20737 "}\n";
20738 char const *fsSource =
20739 "#version 450\n"
20740 "\n"
20741 "layout(location=0) out vec4 color;\n"
20742 "void main(){\n"
20743 " color = vec4(1);\n"
20744 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020745
20746 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20747 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20748
20749 VkPipelineObj pipe(m_device);
20750 pipe.AddColorAttachment();
20751 pipe.AddShader(&vs);
20752 pipe.AddShader(&fs);
20753
20754 pipe.AddVertexInputBindings(&input_binding, 1);
20755 pipe.AddVertexInputAttribs(input_attribs, 2);
20756
20757 VkDescriptorSetObj descriptorSet(m_device);
20758 descriptorSet.AppendDummy();
20759 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20760
20761 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20762
20763 /* expect success */
20764 m_errorMonitor->VerifyNotFound();
20765}
20766
20767TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
20768 m_errorMonitor->ExpectSuccess();
20769
20770 ASSERT_NO_FATAL_FAILURE(InitState());
20771 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20772
20773 VkVertexInputBindingDescription input_binding;
20774 memset(&input_binding, 0, sizeof(input_binding));
20775
20776 VkVertexInputAttributeDescription input_attribs[2];
20777 memset(input_attribs, 0, sizeof(input_attribs));
20778
20779 for (int i = 0; i < 2; i++) {
20780 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20781 input_attribs[i].location = i;
20782 }
20783
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020784 char const *vsSource =
20785 "#version 450\n"
20786 "\n"
20787 "layout(location=0) in vec4 x[2];\n"
20788 "out gl_PerVertex {\n"
20789 " vec4 gl_Position;\n"
20790 "};\n"
20791 "void main(){\n"
20792 " gl_Position = x[0] + x[1];\n"
20793 "}\n";
20794 char const *fsSource =
20795 "#version 450\n"
20796 "\n"
20797 "layout(location=0) out vec4 color;\n"
20798 "void main(){\n"
20799 " color = vec4(1);\n"
20800 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020801
20802 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20803 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20804
20805 VkPipelineObj pipe(m_device);
20806 pipe.AddColorAttachment();
20807 pipe.AddShader(&vs);
20808 pipe.AddShader(&fs);
20809
20810 pipe.AddVertexInputBindings(&input_binding, 1);
20811 pipe.AddVertexInputAttribs(input_attribs, 2);
20812
20813 VkDescriptorSetObj descriptorSet(m_device);
20814 descriptorSet.AppendDummy();
20815 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20816
20817 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20818
20819 m_errorMonitor->VerifyNotFound();
20820}
20821
20822TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020823 TEST_DESCRIPTION(
20824 "Test that pipeline validation accepts consuming a vertex attribute "
20825 "through multiple vertex shader inputs, each consuming a different "
20826 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020827 m_errorMonitor->ExpectSuccess();
20828
20829 ASSERT_NO_FATAL_FAILURE(InitState());
20830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20831
20832 VkVertexInputBindingDescription input_binding;
20833 memset(&input_binding, 0, sizeof(input_binding));
20834
20835 VkVertexInputAttributeDescription input_attribs[3];
20836 memset(input_attribs, 0, sizeof(input_attribs));
20837
20838 for (int i = 0; i < 3; i++) {
20839 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20840 input_attribs[i].location = i;
20841 }
20842
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020843 char const *vsSource =
20844 "#version 450\n"
20845 "\n"
20846 "layout(location=0) in vec4 x;\n"
20847 "layout(location=1) in vec3 y1;\n"
20848 "layout(location=1, component=3) in float y2;\n"
20849 "layout(location=2) in vec4 z;\n"
20850 "out gl_PerVertex {\n"
20851 " vec4 gl_Position;\n"
20852 "};\n"
20853 "void main(){\n"
20854 " gl_Position = x + vec4(y1, y2) + z;\n"
20855 "}\n";
20856 char const *fsSource =
20857 "#version 450\n"
20858 "\n"
20859 "layout(location=0) out vec4 color;\n"
20860 "void main(){\n"
20861 " color = vec4(1);\n"
20862 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020863
20864 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20865 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20866
20867 VkPipelineObj pipe(m_device);
20868 pipe.AddColorAttachment();
20869 pipe.AddShader(&vs);
20870 pipe.AddShader(&fs);
20871
20872 pipe.AddVertexInputBindings(&input_binding, 1);
20873 pipe.AddVertexInputAttribs(input_attribs, 3);
20874
20875 VkDescriptorSetObj descriptorSet(m_device);
20876 descriptorSet.AppendDummy();
20877 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20878
20879 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20880
20881 m_errorMonitor->VerifyNotFound();
20882}
20883
20884TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
20885 m_errorMonitor->ExpectSuccess();
20886
20887 ASSERT_NO_FATAL_FAILURE(InitState());
20888 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20889
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020890 char const *vsSource =
20891 "#version 450\n"
20892 "out gl_PerVertex {\n"
20893 " vec4 gl_Position;\n"
20894 "};\n"
20895 "void main(){\n"
20896 " gl_Position = vec4(0);\n"
20897 "}\n";
20898 char const *fsSource =
20899 "#version 450\n"
20900 "\n"
20901 "layout(location=0) out vec4 color;\n"
20902 "void main(){\n"
20903 " color = vec4(1);\n"
20904 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020905
20906 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20907 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20908
20909 VkPipelineObj pipe(m_device);
20910 pipe.AddColorAttachment();
20911 pipe.AddShader(&vs);
20912 pipe.AddShader(&fs);
20913
20914 VkDescriptorSetObj descriptorSet(m_device);
20915 descriptorSet.AppendDummy();
20916 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20917
20918 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20919
20920 m_errorMonitor->VerifyNotFound();
20921}
20922
20923TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020924 TEST_DESCRIPTION(
20925 "Test that pipeline validation accepts the relaxed type matching rules "
20926 "set out in 14.1.3: fundamental type must match, and producer side must "
20927 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020928 m_errorMonitor->ExpectSuccess();
20929
20930 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
20931
20932 ASSERT_NO_FATAL_FAILURE(InitState());
20933 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20934
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020935 char const *vsSource =
20936 "#version 450\n"
20937 "out gl_PerVertex {\n"
20938 " vec4 gl_Position;\n"
20939 "};\n"
20940 "layout(location=0) out vec3 x;\n"
20941 "layout(location=1) out ivec3 y;\n"
20942 "layout(location=2) out vec3 z;\n"
20943 "void main(){\n"
20944 " gl_Position = vec4(0);\n"
20945 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
20946 "}\n";
20947 char const *fsSource =
20948 "#version 450\n"
20949 "\n"
20950 "layout(location=0) out vec4 color;\n"
20951 "layout(location=0) in float x;\n"
20952 "layout(location=1) flat in int y;\n"
20953 "layout(location=2) in vec2 z;\n"
20954 "void main(){\n"
20955 " color = vec4(1 + x + y + z.x);\n"
20956 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020957
20958 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20959 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20960
20961 VkPipelineObj pipe(m_device);
20962 pipe.AddColorAttachment();
20963 pipe.AddShader(&vs);
20964 pipe.AddShader(&fs);
20965
20966 VkDescriptorSetObj descriptorSet(m_device);
20967 descriptorSet.AppendDummy();
20968 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20969
20970 VkResult err = VK_SUCCESS;
20971 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20972 ASSERT_VK_SUCCESS(err);
20973
20974 m_errorMonitor->VerifyNotFound();
20975}
20976
20977TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020978 TEST_DESCRIPTION(
20979 "Test that pipeline validation accepts per-vertex variables "
20980 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020981 m_errorMonitor->ExpectSuccess();
20982
20983 ASSERT_NO_FATAL_FAILURE(InitState());
20984 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20985
20986 if (!m_device->phy().features().tessellationShader) {
20987 printf("Device does not support tessellation shaders; skipped.\n");
20988 return;
20989 }
20990
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020991 char const *vsSource =
20992 "#version 450\n"
20993 "void main(){}\n";
20994 char const *tcsSource =
20995 "#version 450\n"
20996 "layout(location=0) out int x[];\n"
20997 "layout(vertices=3) out;\n"
20998 "void main(){\n"
20999 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21000 " gl_TessLevelInner[0] = 1;\n"
21001 " x[gl_InvocationID] = gl_InvocationID;\n"
21002 "}\n";
21003 char const *tesSource =
21004 "#version 450\n"
21005 "layout(triangles, equal_spacing, cw) in;\n"
21006 "layout(location=0) in int x[];\n"
21007 "out gl_PerVertex { vec4 gl_Position; };\n"
21008 "void main(){\n"
21009 " gl_Position.xyz = gl_TessCoord;\n"
21010 " gl_Position.w = x[0] + x[1] + x[2];\n"
21011 "}\n";
21012 char const *fsSource =
21013 "#version 450\n"
21014 "layout(location=0) out vec4 color;\n"
21015 "void main(){\n"
21016 " color = vec4(1);\n"
21017 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021018
21019 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21020 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21021 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21022 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21023
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021024 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21025 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021026
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021027 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021028
21029 VkPipelineObj pipe(m_device);
21030 pipe.SetInputAssembly(&iasci);
21031 pipe.SetTessellation(&tsci);
21032 pipe.AddColorAttachment();
21033 pipe.AddShader(&vs);
21034 pipe.AddShader(&tcs);
21035 pipe.AddShader(&tes);
21036 pipe.AddShader(&fs);
21037
21038 VkDescriptorSetObj descriptorSet(m_device);
21039 descriptorSet.AppendDummy();
21040 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21041
21042 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21043
21044 m_errorMonitor->VerifyNotFound();
21045}
21046
21047TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021048 TEST_DESCRIPTION(
21049 "Test that pipeline validation accepts a user-defined "
21050 "interface block passed into the geometry shader. This "
21051 "is interesting because the 'extra' array level is not "
21052 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021053 m_errorMonitor->ExpectSuccess();
21054
21055 ASSERT_NO_FATAL_FAILURE(InitState());
21056 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21057
21058 if (!m_device->phy().features().geometryShader) {
21059 printf("Device does not support geometry shaders; skipped.\n");
21060 return;
21061 }
21062
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021063 char const *vsSource =
21064 "#version 450\n"
21065 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21066 "void main(){\n"
21067 " vs_out.x = vec4(1);\n"
21068 "}\n";
21069 char const *gsSource =
21070 "#version 450\n"
21071 "layout(triangles) in;\n"
21072 "layout(triangle_strip, max_vertices=3) out;\n"
21073 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21074 "out gl_PerVertex { vec4 gl_Position; };\n"
21075 "void main() {\n"
21076 " gl_Position = gs_in[0].x;\n"
21077 " EmitVertex();\n"
21078 "}\n";
21079 char const *fsSource =
21080 "#version 450\n"
21081 "layout(location=0) out vec4 color;\n"
21082 "void main(){\n"
21083 " color = vec4(1);\n"
21084 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021085
21086 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21087 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21088 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21089
21090 VkPipelineObj pipe(m_device);
21091 pipe.AddColorAttachment();
21092 pipe.AddShader(&vs);
21093 pipe.AddShader(&gs);
21094 pipe.AddShader(&fs);
21095
21096 VkDescriptorSetObj descriptorSet(m_device);
21097 descriptorSet.AppendDummy();
21098 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21099
21100 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21101
21102 m_errorMonitor->VerifyNotFound();
21103}
21104
21105TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021106 TEST_DESCRIPTION(
21107 "Test that pipeline validation accepts basic use of 64bit vertex "
21108 "attributes. This is interesting because they consume multiple "
21109 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021110 m_errorMonitor->ExpectSuccess();
21111
21112 ASSERT_NO_FATAL_FAILURE(InitState());
21113 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21114
21115 if (!m_device->phy().features().shaderFloat64) {
21116 printf("Device does not support 64bit vertex attributes; skipped.\n");
21117 return;
21118 }
21119
21120 VkVertexInputBindingDescription input_bindings[1];
21121 memset(input_bindings, 0, sizeof(input_bindings));
21122
21123 VkVertexInputAttributeDescription input_attribs[4];
21124 memset(input_attribs, 0, sizeof(input_attribs));
21125 input_attribs[0].location = 0;
21126 input_attribs[0].offset = 0;
21127 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21128 input_attribs[1].location = 2;
21129 input_attribs[1].offset = 32;
21130 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21131 input_attribs[2].location = 4;
21132 input_attribs[2].offset = 64;
21133 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21134 input_attribs[3].location = 6;
21135 input_attribs[3].offset = 96;
21136 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21137
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021138 char const *vsSource =
21139 "#version 450\n"
21140 "\n"
21141 "layout(location=0) in dmat4 x;\n"
21142 "out gl_PerVertex {\n"
21143 " vec4 gl_Position;\n"
21144 "};\n"
21145 "void main(){\n"
21146 " gl_Position = vec4(x[0][0]);\n"
21147 "}\n";
21148 char const *fsSource =
21149 "#version 450\n"
21150 "\n"
21151 "layout(location=0) out vec4 color;\n"
21152 "void main(){\n"
21153 " color = vec4(1);\n"
21154 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021155
21156 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21157 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21158
21159 VkPipelineObj pipe(m_device);
21160 pipe.AddColorAttachment();
21161 pipe.AddShader(&vs);
21162 pipe.AddShader(&fs);
21163
21164 pipe.AddVertexInputBindings(input_bindings, 1);
21165 pipe.AddVertexInputAttribs(input_attribs, 4);
21166
21167 VkDescriptorSetObj descriptorSet(m_device);
21168 descriptorSet.AppendDummy();
21169 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21170
21171 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21172
21173 m_errorMonitor->VerifyNotFound();
21174}
21175
21176TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
21177 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
21178 m_errorMonitor->ExpectSuccess();
21179
21180 ASSERT_NO_FATAL_FAILURE(InitState());
21181
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021182 char const *vsSource =
21183 "#version 450\n"
21184 "\n"
21185 "out gl_PerVertex {\n"
21186 " vec4 gl_Position;\n"
21187 "};\n"
21188 "void main(){\n"
21189 " gl_Position = vec4(1);\n"
21190 "}\n";
21191 char const *fsSource =
21192 "#version 450\n"
21193 "\n"
21194 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
21195 "layout(location=0) out vec4 color;\n"
21196 "void main() {\n"
21197 " color = subpassLoad(x);\n"
21198 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021199
21200 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21201 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21202
21203 VkPipelineObj pipe(m_device);
21204 pipe.AddShader(&vs);
21205 pipe.AddShader(&fs);
21206 pipe.AddColorAttachment();
21207 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21208
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021209 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
21210 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021211 VkDescriptorSetLayout dsl;
21212 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21213 ASSERT_VK_SUCCESS(err);
21214
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021215 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021216 VkPipelineLayout pl;
21217 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21218 ASSERT_VK_SUCCESS(err);
21219
21220 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021221 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21222 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21223 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
21224 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21225 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 -060021226 };
21227 VkAttachmentReference color = {
21228 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21229 };
21230 VkAttachmentReference input = {
21231 1, VK_IMAGE_LAYOUT_GENERAL,
21232 };
21233
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021234 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021235
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021236 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021237 VkRenderPass rp;
21238 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21239 ASSERT_VK_SUCCESS(err);
21240
21241 // should be OK. would go wrong here if it's going to...
21242 pipe.CreateVKPipeline(pl, rp);
21243
21244 m_errorMonitor->VerifyNotFound();
21245
21246 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21247 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21248 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21249}
21250
21251TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021252 TEST_DESCRIPTION(
21253 "Test that pipeline validation accepts a compute pipeline which declares a "
21254 "descriptor-backed resource which is not provided, but the shader does not "
21255 "statically use it. This is interesting because it requires compute pipelines "
21256 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021257 m_errorMonitor->ExpectSuccess();
21258
21259 ASSERT_NO_FATAL_FAILURE(InitState());
21260
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021261 char const *csSource =
21262 "#version 450\n"
21263 "\n"
21264 "layout(local_size_x=1) in;\n"
21265 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
21266 "void main(){\n"
21267 " // x is not used.\n"
21268 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021269
21270 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21271
21272 VkDescriptorSetObj descriptorSet(m_device);
21273 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21274
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021275 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21276 nullptr,
21277 0,
21278 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21279 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21280 descriptorSet.GetPipelineLayout(),
21281 VK_NULL_HANDLE,
21282 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021283
21284 VkPipeline pipe;
21285 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21286
21287 m_errorMonitor->VerifyNotFound();
21288
21289 if (err == VK_SUCCESS) {
21290 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21291 }
21292}
21293
21294TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021295 TEST_DESCRIPTION(
21296 "Test that pipeline validation accepts a shader consuming only the "
21297 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021298 m_errorMonitor->ExpectSuccess();
21299
21300 ASSERT_NO_FATAL_FAILURE(InitState());
21301
21302 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021303 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21304 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21305 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021306 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021307 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021308 VkDescriptorSetLayout dsl;
21309 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21310 ASSERT_VK_SUCCESS(err);
21311
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021312 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021313 VkPipelineLayout pl;
21314 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21315 ASSERT_VK_SUCCESS(err);
21316
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021317 char const *csSource =
21318 "#version 450\n"
21319 "\n"
21320 "layout(local_size_x=1) in;\n"
21321 "layout(set=0, binding=0) uniform sampler s;\n"
21322 "layout(set=0, binding=1) uniform texture2D t;\n"
21323 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21324 "void main() {\n"
21325 " x = texture(sampler2D(t, s), vec2(0));\n"
21326 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021327 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21328
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021329 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21330 nullptr,
21331 0,
21332 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21333 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21334 pl,
21335 VK_NULL_HANDLE,
21336 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021337
21338 VkPipeline pipe;
21339 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21340
21341 m_errorMonitor->VerifyNotFound();
21342
21343 if (err == VK_SUCCESS) {
21344 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21345 }
21346
21347 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21348 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21349}
21350
21351TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021352 TEST_DESCRIPTION(
21353 "Test that pipeline validation accepts a shader consuming only the "
21354 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021355 m_errorMonitor->ExpectSuccess();
21356
21357 ASSERT_NO_FATAL_FAILURE(InitState());
21358
21359 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021360 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21361 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21362 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021363 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021364 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021365 VkDescriptorSetLayout dsl;
21366 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21367 ASSERT_VK_SUCCESS(err);
21368
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021369 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021370 VkPipelineLayout pl;
21371 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21372 ASSERT_VK_SUCCESS(err);
21373
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021374 char const *csSource =
21375 "#version 450\n"
21376 "\n"
21377 "layout(local_size_x=1) in;\n"
21378 "layout(set=0, binding=0) uniform texture2D t;\n"
21379 "layout(set=0, binding=1) uniform sampler s;\n"
21380 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21381 "void main() {\n"
21382 " x = texture(sampler2D(t, s), vec2(0));\n"
21383 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021384 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21385
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021386 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21387 nullptr,
21388 0,
21389 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21390 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21391 pl,
21392 VK_NULL_HANDLE,
21393 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021394
21395 VkPipeline pipe;
21396 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21397
21398 m_errorMonitor->VerifyNotFound();
21399
21400 if (err == VK_SUCCESS) {
21401 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21402 }
21403
21404 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21405 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21406}
21407
21408TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021409 TEST_DESCRIPTION(
21410 "Test that pipeline validation accepts a shader consuming "
21411 "both the sampler and the image of a combined image+sampler "
21412 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021413 m_errorMonitor->ExpectSuccess();
21414
21415 ASSERT_NO_FATAL_FAILURE(InitState());
21416
21417 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021418 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21419 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021420 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021421 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021422 VkDescriptorSetLayout dsl;
21423 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21424 ASSERT_VK_SUCCESS(err);
21425
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021426 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021427 VkPipelineLayout pl;
21428 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21429 ASSERT_VK_SUCCESS(err);
21430
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021431 char const *csSource =
21432 "#version 450\n"
21433 "\n"
21434 "layout(local_size_x=1) in;\n"
21435 "layout(set=0, binding=0) uniform texture2D t;\n"
21436 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
21437 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
21438 "void main() {\n"
21439 " x = texture(sampler2D(t, s), vec2(0));\n"
21440 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021441 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21442
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021443 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21444 nullptr,
21445 0,
21446 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21447 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21448 pl,
21449 VK_NULL_HANDLE,
21450 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021451
21452 VkPipeline pipe;
21453 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21454
21455 m_errorMonitor->VerifyNotFound();
21456
21457 if (err == VK_SUCCESS) {
21458 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21459 }
21460
21461 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21462 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21463}
21464
21465TEST_F(VkPositiveLayerTest, ValidStructPNext) {
21466 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
21467
21468 ASSERT_NO_FATAL_FAILURE(InitState());
21469
21470 // Positive test to check parameter_validation and unique_objects support
21471 // for NV_dedicated_allocation
21472 uint32_t extension_count = 0;
21473 bool supports_nv_dedicated_allocation = false;
21474 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
21475 ASSERT_VK_SUCCESS(err);
21476
21477 if (extension_count > 0) {
21478 std::vector<VkExtensionProperties> available_extensions(extension_count);
21479
21480 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
21481 ASSERT_VK_SUCCESS(err);
21482
21483 for (const auto &extension_props : available_extensions) {
21484 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
21485 supports_nv_dedicated_allocation = true;
21486 }
21487 }
21488 }
21489
21490 if (supports_nv_dedicated_allocation) {
21491 m_errorMonitor->ExpectSuccess();
21492
21493 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
21494 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
21495 dedicated_buffer_create_info.pNext = nullptr;
21496 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
21497
21498 uint32_t queue_family_index = 0;
21499 VkBufferCreateInfo buffer_create_info = {};
21500 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
21501 buffer_create_info.pNext = &dedicated_buffer_create_info;
21502 buffer_create_info.size = 1024;
21503 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
21504 buffer_create_info.queueFamilyIndexCount = 1;
21505 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
21506
21507 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070021508 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021509 ASSERT_VK_SUCCESS(err);
21510
21511 VkMemoryRequirements memory_reqs;
21512 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
21513
21514 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
21515 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
21516 dedicated_memory_info.pNext = nullptr;
21517 dedicated_memory_info.buffer = buffer;
21518 dedicated_memory_info.image = VK_NULL_HANDLE;
21519
21520 VkMemoryAllocateInfo memory_info = {};
21521 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
21522 memory_info.pNext = &dedicated_memory_info;
21523 memory_info.allocationSize = memory_reqs.size;
21524
21525 bool pass;
21526 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
21527 ASSERT_TRUE(pass);
21528
21529 VkDeviceMemory buffer_memory;
21530 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
21531 ASSERT_VK_SUCCESS(err);
21532
21533 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
21534 ASSERT_VK_SUCCESS(err);
21535
21536 vkDestroyBuffer(m_device->device(), buffer, NULL);
21537 vkFreeMemory(m_device->device(), buffer_memory, NULL);
21538
21539 m_errorMonitor->VerifyNotFound();
21540 }
21541}
21542
21543TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
21544 VkResult err;
21545
21546 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
21547
21548 ASSERT_NO_FATAL_FAILURE(InitState());
21549 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21550
21551 std::vector<const char *> device_extension_names;
21552 auto features = m_device->phy().features();
21553 // Artificially disable support for non-solid fill modes
21554 features.fillModeNonSolid = false;
21555 // The sacrificial device object
21556 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
21557
21558 VkRenderpassObj render_pass(&test_device);
21559
21560 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
21561 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
21562 pipeline_layout_ci.setLayoutCount = 0;
21563 pipeline_layout_ci.pSetLayouts = NULL;
21564
21565 VkPipelineLayout pipeline_layout;
21566 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21567 ASSERT_VK_SUCCESS(err);
21568
21569 VkPipelineRasterizationStateCreateInfo rs_ci = {};
21570 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
21571 rs_ci.pNext = nullptr;
21572 rs_ci.lineWidth = 1.0f;
21573 rs_ci.rasterizerDiscardEnable = true;
21574
21575 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
21576 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21577
21578 // Set polygonMode=FILL. No error is expected
21579 m_errorMonitor->ExpectSuccess();
21580 {
21581 VkPipelineObj pipe(&test_device);
21582 pipe.AddShader(&vs);
21583 pipe.AddShader(&fs);
21584 pipe.AddColorAttachment();
21585 // Set polygonMode to a good value
21586 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
21587 pipe.SetRasterization(&rs_ci);
21588 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
21589 }
21590 m_errorMonitor->VerifyNotFound();
21591
21592 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
21593}
21594
21595TEST_F(VkPositiveLayerTest, ValidPushConstants) {
21596 VkResult err;
21597 ASSERT_NO_FATAL_FAILURE(InitState());
21598 ASSERT_NO_FATAL_FAILURE(InitViewport());
21599 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21600
21601 VkPipelineLayout pipeline_layout;
21602 VkPushConstantRange pc_range = {};
21603 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
21604 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
21605 pipeline_layout_ci.pushConstantRangeCount = 1;
21606 pipeline_layout_ci.pPushConstantRanges = &pc_range;
21607
21608 //
21609 // Check for invalid push constant ranges in pipeline layouts.
21610 //
21611 struct PipelineLayoutTestCase {
21612 VkPushConstantRange const range;
21613 char const *msg;
21614 };
21615
21616 // Check for overlapping ranges
21617 const uint32_t ranges_per_test = 5;
21618 struct OverlappingRangeTestCase {
21619 VkPushConstantRange const ranges[ranges_per_test];
21620 char const *msg;
21621 };
21622
21623 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021624 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
21625 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
21626 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
21627 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
21628 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
21629 ""},
21630 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
21631 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
21632 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
21633 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
21634 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
21635 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021636 for (const auto &iter : overlapping_range_tests_pos) {
21637 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
21638 m_errorMonitor->ExpectSuccess();
21639 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21640 m_errorMonitor->VerifyNotFound();
21641 if (VK_SUCCESS == err) {
21642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
21643 }
21644 }
21645
21646 //
21647 // CmdPushConstants tests
21648 //
21649 const uint8_t dummy_values[100] = {};
21650
Tony Barbour552f6c02016-12-21 14:34:07 -070021651 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021652
21653 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021654 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
21655 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
21656 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
21657 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
21658 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
21659 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021660
21661 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
21662 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021663 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
21664 {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 -060021665 };
21666
21667 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
21668 pipeline_layout_ci.pPushConstantRanges = pc_range4;
21669 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21670 ASSERT_VK_SUCCESS(err);
21671 for (const auto &iter : cmd_overlap_tests_pos) {
21672 m_errorMonitor->ExpectSuccess();
21673 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021674 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021675 m_errorMonitor->VerifyNotFound();
21676 }
21677 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
21678
Tony Barbour552f6c02016-12-21 14:34:07 -070021679 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021680}
21681
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021682#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021683TEST_F(VkPositiveLayerTest, LongFenceChain)
21684{
21685 m_errorMonitor->ExpectSuccess();
21686
21687 ASSERT_NO_FATAL_FAILURE(InitState());
21688 VkResult err;
21689
21690 std::vector<VkFence> fences;
21691
21692 const int chainLength = 32768;
21693
21694 for (int i = 0; i < chainLength; i++) {
21695 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
21696 VkFence fence;
21697 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
21698 ASSERT_VK_SUCCESS(err);
21699
21700 fences.push_back(fence);
21701
21702 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
21703 0, nullptr, 0, nullptr };
21704 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
21705 ASSERT_VK_SUCCESS(err);
21706
21707 }
21708
21709 // BOOM, stack overflow.
21710 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
21711
21712 for (auto fence : fences)
21713 vkDestroyFence(m_device->device(), fence, nullptr);
21714
21715 m_errorMonitor->VerifyNotFound();
21716}
21717#endif
21718
Cody Northrop1242dfd2016-07-13 17:24:59 -060021719#if defined(ANDROID) && defined(VALIDATION_APK)
21720static bool initialized = false;
21721static bool active = false;
21722
21723// Convert Intents to argv
21724// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021725std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021726 std::vector<std::string> args;
21727 JavaVM &vm = *app.activity->vm;
21728 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021729 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021730
21731 JNIEnv &env = *p_env;
21732 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021733 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021734 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021735 jmethodID get_string_extra_method =
21736 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021737 jvalue get_string_extra_args;
21738 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021739 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060021740
21741 std::string args_str;
21742 if (extra_str) {
21743 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
21744 args_str = extra_utf;
21745 env.ReleaseStringUTFChars(extra_str, extra_utf);
21746 env.DeleteLocalRef(extra_str);
21747 }
21748
21749 env.DeleteLocalRef(get_string_extra_args.l);
21750 env.DeleteLocalRef(intent);
21751 vm.DetachCurrentThread();
21752
21753 // split args_str
21754 std::stringstream ss(args_str);
21755 std::string arg;
21756 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021757 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021758 }
21759
21760 return args;
21761}
21762
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021763static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021764
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021765static void processCommand(struct android_app *app, int32_t cmd) {
21766 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021767 case APP_CMD_INIT_WINDOW: {
21768 if (app->window) {
21769 initialized = true;
21770 }
21771 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021772 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021773 case APP_CMD_GAINED_FOCUS: {
21774 active = true;
21775 break;
21776 }
21777 case APP_CMD_LOST_FOCUS: {
21778 active = false;
21779 break;
21780 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021781 }
21782}
21783
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021784void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021785 app_dummy();
21786
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021787 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060021788
21789 int vulkanSupport = InitVulkan();
21790 if (vulkanSupport == 0) {
21791 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
21792 return;
21793 }
21794
21795 app->onAppCmd = processCommand;
21796 app->onInputEvent = processInput;
21797
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021798 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021799 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021800 struct android_poll_source *source;
21801 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021802 if (source) {
21803 source->process(app, source);
21804 }
21805
21806 if (app->destroyRequested != 0) {
21807 VkTestFramework::Finish();
21808 return;
21809 }
21810 }
21811
21812 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021813 // Use the following key to send arguments to gtest, i.e.
21814 // --es args "--gtest_filter=-VkLayerTest.foo"
21815 const char key[] = "args";
21816 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021817
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021818 std::string filter = "";
21819 if (args.size() > 0) {
21820 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
21821 filter += args[0];
21822 } else {
21823 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
21824 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021825
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021826 int argc = 2;
21827 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
21828 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021829
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021830 // Route output to files until we can override the gtest output
21831 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
21832 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021833
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021834 ::testing::InitGoogleTest(&argc, argv);
21835 VkTestFramework::InitArgs(&argc, argv);
21836 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021838 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060021839
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021840 if (result != 0) {
21841 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
21842 } else {
21843 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
21844 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021845
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021846 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060021847
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021848 fclose(stdout);
21849 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021850
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021851 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021853 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021854 }
21855 }
21856}
21857#endif
21858
Tony Barbour300a6082015-04-07 13:44:53 -060021859int main(int argc, char **argv) {
21860 int result;
21861
Cody Northrop8e54a402016-03-08 22:25:52 -070021862#ifdef ANDROID
21863 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021864 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070021865#endif
21866
Tony Barbour300a6082015-04-07 13:44:53 -060021867 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060021868 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060021869
21870 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
21871
21872 result = RUN_ALL_TESTS();
21873
Tony Barbour6918cd52015-04-09 12:58:51 -060021874 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060021875 return result;
21876}