blob: d349b94063e40796d3795a99492213f7ae6b8cf1 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
Michael Lentine0a369f62016-02-03 16:51:46 -06005 * Copyright (c) 2015-2016 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Karl Schultz6addd812016-02-02 17:17:23 -070021 */
Tony Barbour65c48b32015-11-17 10:02:56 -070022
Cody Northrop8e54a402016-03-08 22:25:52 -070023#ifdef ANDROID
24#include "vulkan_wrapper.h"
25#else
David Pinedo9316d3b2015-11-06 12:54:48 -070026#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070027#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060028
29#if defined(ANDROID) && defined(VALIDATION_APK)
30#include <android/log.h>
31#include <android_native_app_glue.h>
32#endif
33
Jon Ashburn7fa7e222016-02-02 12:08:10 -070034#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060035#include "test_common.h"
36#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060037#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060038#include "vkrenderframework.h"
39#include <limits.h>
40#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060041
Mark Lobodzinski3780e142015-05-14 15:08:13 -050042#define GLM_FORCE_RADIANS
43#include "glm/glm.hpp"
44#include <glm/gtc/matrix_transform.hpp>
45
Dustin Gravesffa90fa2016-05-06 11:20:38 -060046#define PARAMETER_VALIDATION_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060047#define MEM_TRACKER_TESTS 1
48#define OBJ_TRACKER_TESTS 1
49#define DRAW_STATE_TESTS 1
50#define THREADING_TESTS 1
Chris Forbes9f7ff632015-05-25 11:13:08 +120051#define SHADER_CHECKER_TESTS 1
Mark Lobodzinski209b5292015-09-17 09:44:05 -060052#define DEVICE_LIMITS_TESTS 1
Tobin Ehliscde08892015-09-22 10:11:37 -060053#define IMAGE_TESTS 1
Tobin Ehlis0788f522015-05-26 16:11:58 -060054
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055//--------------------------------------------------------------------------------------
56// Mesh and VertexFormat Data
57//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070058struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070059 float posX, posY, posZ, posW; // Position data
60 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050061};
62
Karl Schultz6addd812016-02-02 17:17:23 -070063#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050064
65typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070066 BsoFailNone = 0x00000000,
67 BsoFailLineWidth = 0x00000001,
68 BsoFailDepthBias = 0x00000002,
69 BsoFailViewport = 0x00000004,
70 BsoFailScissor = 0x00000008,
71 BsoFailBlend = 0x00000010,
72 BsoFailDepthBounds = 0x00000020,
73 BsoFailStencilReadMask = 0x00000040,
74 BsoFailStencilWriteMask = 0x00000080,
75 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060076 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060077 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050078} BsoFailSelect;
79
80struct vktriangle_vs_uniform {
81 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070082 float mvp[4][4];
83 float position[3][4];
84 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050085};
86
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070087static const char bindStateVertShaderText[] =
88 "#version 450\n"
89 "vec2 vertices[3];\n"
90 "out gl_PerVertex {\n"
91 " vec4 gl_Position;\n"
92 "};\n"
93 "void main() {\n"
94 " vertices[0] = vec2(-1.0, -1.0);\n"
95 " vertices[1] = vec2( 1.0, -1.0);\n"
96 " vertices[2] = vec2( 0.0, 1.0);\n"
97 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
98 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050099
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700100static const char bindStateFragShaderText[] =
101 "#version 450\n"
102 "\n"
103 "layout(location = 0) out vec4 uFragColor;\n"
104 "void main(){\n"
105 " uFragColor = vec4(0,1,0,1);\n"
106 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500107
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600108static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
109 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
110 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600111
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600112// ErrorMonitor Usage:
113//
Dave Houltonfbf52152017-01-06 12:55:29 -0700114// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600115// encountered log messages, or a validation error enum identifying
116// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
117// will match all log messages. logMsg will return true for skipCall
118// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600119//
Dave Houltonfbf52152017-01-06 12:55:29 -0700120// Call VerifyFound to determine if all desired failure messages
121// were encountered. Call VerifyNotFound to determine if any unexpected
122// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600123class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700124 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700125 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700126 test_platform_thread_create_mutex(&mutex_);
127 test_platform_thread_lock_mutex(&mutex_);
128 Reset();
129 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600130 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600131
Dave Houltonfbf52152017-01-06 12:55:29 -0700132 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600133
Dave Houltonfbf52152017-01-06 12:55:29 -0700134 // Set monitor to pristine state
135 void Reset() {
136 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
137 bailout_ = NULL;
138 message_found_ = VK_FALSE;
139 failure_message_strings_.clear();
140 desired_message_strings_.clear();
141 desired_message_ids_.clear();
142 other_messages_.clear();
143 message_outstanding_count_ = 0;
144 }
145
146 // ErrorMonitor will look for an error message containing the specified string(s)
Karl Schultz6addd812016-02-02 17:17:23 -0700147 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700148 test_platform_thread_lock_mutex(&mutex_);
149 desired_message_strings_.insert(msgString);
150 message_flags_ |= msgFlags;
151 message_outstanding_count_++;
152 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600153 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600154
Dave Houltonfbf52152017-01-06 12:55:29 -0700155 // ErrorMonitor will look for a message ID matching the specified one(s)
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600156 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700157 test_platform_thread_lock_mutex(&mutex_);
158 desired_message_ids_.insert(msg_id);
159 message_flags_ |= msgFlags;
160 message_outstanding_count_++;
161 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600162 }
163
164 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600165 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700166 test_platform_thread_lock_mutex(&mutex_);
167 if (bailout_ != NULL) {
168 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600169 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600170 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600171 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600172
Dave Houltonfbf52152017-01-06 12:55:29 -0700173 for (auto desired_msg : desired_message_strings_) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600174 if (desired_msg.length() == 0) {
175 // An empty desired_msg string "" indicates a positive test - not expecting an error.
176 // Return true to avoid calling layers/driver with this error.
177 // And don't erase the "" string, so it remains if another error is found.
178 result = VK_TRUE;
Tony Barbourae58dba2016-12-13 16:30:36 -0700179 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700180 message_found_ = VK_TRUE;
181 failure_message_strings_.insert(errorString);
Karl Schultz05cc4e32016-10-12 13:25:23 -0600182 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600183 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700184 message_outstanding_count_--;
185 failure_message_strings_.insert(errorString);
186 message_found_ = VK_TRUE;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600187 result = VK_TRUE;
188 // We only want one match for each expected error so remove from set here
189 // Since we're about the break the loop it's ok to remove from set we're iterating over
Dave Houltonfbf52152017-01-06 12:55:29 -0700190 desired_message_strings_.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600191 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600192 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600193 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700194 for (auto desired_id : desired_message_ids_) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600195 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
196 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
197 // Return true to avoid calling layers/driver with this error.
198 result = VK_TRUE;
199 } else if (desired_id == message_code) {
200 // Double-check that the string matches the error enum
201 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
202 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700203 message_outstanding_count_--;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600204 result = VK_TRUE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700205 message_found_ = VK_TRUE;
206 desired_message_ids_.erase(desired_id);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600207 break;
208 } else {
209 // Treat this message as a regular unexpected error, but print a warning jic
210 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
211 errorString.c_str(), desired_id, validation_error_map[desired_id]);
212 }
213 }
214 }
215
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600216 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200217 printf("Unexpected: %s\n", msgString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700218 other_messages_.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600219 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700220 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600221 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600222 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600223
Dave Houltonfbf52152017-01-06 12:55:29 -0700224 vector<string> GetOtherFailureMsgs(void) { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600225
Dave Houltonfbf52152017-01-06 12:55:29 -0700226 VkDebugReportFlagsEXT GetMessageFlags(void) { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600227
Dave Houltonfbf52152017-01-06 12:55:29 -0700228 VkBool32 AnyDesiredMsgFound(void) { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600229
Dave Houltonfbf52152017-01-06 12:55:29 -0700230 VkBool32 AllDesiredMsgsFound(void) { return (0 == message_outstanding_count_); }
231
232 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600233
Karl Schultz6addd812016-02-02 17:17:23 -0700234 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600235 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600236 if (otherMsgs.size()) {
237 cout << "Other error messages logged for this test were:" << endl;
238 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
239 cout << " " << *iter << endl;
240 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600241 }
242 }
243
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600244 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200245
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600246 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
247 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600248 // Match ANY message matching specified type
249 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700250 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200251 }
252
253 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600254 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700255 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200256 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700257 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700258 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600259 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700260 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700261 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600262 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200263 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700264 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200265 }
266
267 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600268 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700269 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200270 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700271 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700272 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600273 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200274 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700275 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200276 }
277
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700278 private:
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700279 VkFlags message_flags_;
280 std::unordered_set<uint32_t> desired_message_ids_;
281 std::unordered_set<string> desired_message_strings_;
282 std::unordered_set<string> failure_message_strings_;
283 vector<string> other_messages_;
284 test_platform_thread_mutex mutex_;
285 bool *bailout_;
286 VkBool32 message_found_;
287 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600288};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500289
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600290static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
291 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
292 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600293 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
294 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600295 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600296 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600297 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600298}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500299
Karl Schultz6addd812016-02-02 17:17:23 -0700300class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700301 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600302 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
303 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700304 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600305 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
306 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700307 }
Tony Barbour300a6082015-04-07 13:44:53 -0600308
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600309 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
310 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700311 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600312 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700313 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600314 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700315 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600316 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
317 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
318 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700319 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
320 }
321 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
322 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
323 }
324
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700325 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700326 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600327 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600328
329 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600330 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600331 std::vector<const char *> instance_extension_names;
332 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600333
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700334 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600335 /*
336 * Since CreateDbgMsgCallback is an instance level extension call
337 * any extension / layer that utilizes that feature also needs
338 * to be enabled at create instance time.
339 */
Karl Schultz6addd812016-02-02 17:17:23 -0700340 // Use Threading layer first to protect others from
341 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700342 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600343 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800344 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700345 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800346 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600347 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700348 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600349
Ian Elliott2c1daf52016-05-12 09:41:46 -0600350 if (m_enableWSI) {
351 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
352 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
353#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
354#if defined(VK_USE_PLATFORM_ANDROID_KHR)
355 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700356#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600357#if defined(VK_USE_PLATFORM_MIR_KHR)
358 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700359#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600360#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
361 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700362#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600363#if defined(VK_USE_PLATFORM_WIN32_KHR)
364 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700365#endif // VK_USE_PLATFORM_WIN32_KHR
366#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600367#if defined(VK_USE_PLATFORM_XCB_KHR)
368 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
369#elif defined(VK_USE_PLATFORM_XLIB_KHR)
370 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700371#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600372 }
373
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600374 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600375 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800376 this->app_info.pApplicationName = "layer_tests";
377 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600378 this->app_info.pEngineName = "unittest";
379 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600380 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600381
Tony Barbour15524c32015-04-29 17:34:29 -0600382 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600383 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600384 }
385
386 virtual void TearDown() {
387 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600388 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600389 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600390 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600391
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600392 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600393};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500394
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600395void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500396 // Create identity matrix
397 int i;
398 struct vktriangle_vs_uniform data;
399
400 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700401 glm::mat4 View = glm::mat4(1.0f);
402 glm::mat4 Model = glm::mat4(1.0f);
403 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500404 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700405 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500406
407 memcpy(&data.mvp, &MVP[0][0], matrixSize);
408
Karl Schultz6addd812016-02-02 17:17:23 -0700409 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600410 {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 -0500411 };
412
Karl Schultz6addd812016-02-02 17:17:23 -0700413 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500414 data.position[i][0] = tri_data[i].posX;
415 data.position[i][1] = tri_data[i].posY;
416 data.position[i][2] = tri_data[i].posZ;
417 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700418 data.color[i][0] = tri_data[i].r;
419 data.color[i][1] = tri_data[i].g;
420 data.color[i][2] = tri_data[i].b;
421 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500422 }
423
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500424 ASSERT_NO_FATAL_FAILURE(InitViewport());
425
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200426 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
427 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500428
Karl Schultz6addd812016-02-02 17:17:23 -0700429 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600430 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500431
432 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800433 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500434 pipelineobj.AddShader(&vs);
435 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600436 if (failMask & BsoFailLineWidth) {
437 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600438 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600439 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600440 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
441 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600442 }
443 if (failMask & BsoFailDepthBias) {
444 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600445 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600446 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600447 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600448 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600449 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600450 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700451 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700452 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600453 if (failMask & BsoFailViewport) {
454 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
455 }
456 if (failMask & BsoFailScissor) {
457 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
458 }
459 if (failMask & BsoFailBlend) {
460 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600461 VkPipelineColorBlendAttachmentState att_state = {};
462 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
463 att_state.blendEnable = VK_TRUE;
464 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600465 }
466 if (failMask & BsoFailDepthBounds) {
467 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
468 }
469 if (failMask & BsoFailStencilReadMask) {
470 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
471 }
472 if (failMask & BsoFailStencilWriteMask) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
474 }
475 if (failMask & BsoFailStencilReference) {
476 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
477 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500478
479 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600480 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500481
482 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700483 m_commandBuffer->BeginCommandBuffer();
484 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500485
Tony Barbourfe3351b2015-07-28 10:17:20 -0600486 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500487
488 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600489 if (failMask & BsoFailIndexBuffer) {
490 // Use DrawIndexed w/o an index buffer bound
491 DrawIndexed(3, 1, 0, 0, 0);
492 } else {
493 Draw(3, 1, 0, 0);
494 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500495
Mark Muellerd4914412016-06-13 17:52:06 -0600496 if (failMask & BsoFailCmdClearAttachments) {
497 VkClearAttachment color_attachment = {};
498 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700499 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600500 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
501
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600502 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600503 }
504
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500505 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700506 m_commandBuffer->EndRenderPass();
507 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600508 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500509}
510
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600511void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
512 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600514 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500515 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600516 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500517 }
518
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800519 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700520 // Make sure depthWriteEnable is set so that Depth fail test will work
521 // correctly
522 // Make sure stencilTestEnable is set so that Stencil fail test will work
523 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600524 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800525 stencil.failOp = VK_STENCIL_OP_KEEP;
526 stencil.passOp = VK_STENCIL_OP_KEEP;
527 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
528 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600529
530 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
531 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600532 ds_ci.pNext = NULL;
533 ds_ci.depthTestEnable = VK_FALSE;
534 ds_ci.depthWriteEnable = VK_TRUE;
535 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
536 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600537 if (failMask & BsoFailDepthBounds) {
538 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600539 ds_ci.maxDepthBounds = 0.0f;
540 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600541 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600542 ds_ci.stencilTestEnable = VK_TRUE;
543 ds_ci.front = stencil;
544 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600545
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600546 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600547 pipelineobj.SetViewport(m_viewports);
548 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800549 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600550 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600551 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800552 commandBuffer->BindPipeline(pipelineobj);
553 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500554}
555
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600556class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700557 public:
558 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600559};
560
Ian Elliott2c1daf52016-05-12 09:41:46 -0600561class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700562 public:
563 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600564 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600565};
566
Mark Muellerdfe37552016-07-07 14:47:42 -0600567class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700568 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600569 enum eTestEnFlags {
570 eDoubleDelete,
571 eInvalidDeviceOffset,
572 eInvalidMemoryOffset,
573 eBindNullBuffer,
574 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600575 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600576 };
577
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600578 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600579
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600580 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
581 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600582 return true;
583 }
584 VkDeviceSize offset_limit = 0;
585 if (eInvalidMemoryOffset == aTestFlag) {
586 VkBuffer vulkanBuffer;
587 VkBufferCreateInfo buffer_create_info = {};
588 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
589 buffer_create_info.size = 32;
590 buffer_create_info.usage = aBufferUsage;
591
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600592 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600593 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600594
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600595 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600596 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
597 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600598 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
599 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600602 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600603 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600604 }
605 if (eOffsetAlignment < offset_limit) {
606 return true;
607 }
608 return false;
609 }
610
611 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600612 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
613 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600614 if (eBindNullBuffer == aTestFlag) {
615 VulkanMemory = 0;
616 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
617 } else {
618 VkBufferCreateInfo buffer_create_info = {};
619 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
620 buffer_create_info.size = 32;
621 buffer_create_info.usage = aBufferUsage;
622
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600623 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600624
625 CreateCurrent = true;
626
627 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600628 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600629
630 VkMemoryAllocateInfo memory_allocate_info = {};
631 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
632 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600633 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
634 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600635 if (!pass) {
636 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
637 return;
638 }
639
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600640 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600641 AllocateCurrent = true;
642 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600643 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
644 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600645 BoundCurrent = true;
646
647 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
648 }
649 }
650
651 ~VkBufferTest() {
652 if (CreateCurrent) {
653 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
654 }
655 if (AllocateCurrent) {
656 if (InvalidDeleteEn) {
657 union {
658 VkDeviceMemory device_memory;
659 unsigned long long index_access;
660 } bad_index;
661
662 bad_index.device_memory = VulkanMemory;
663 bad_index.index_access++;
664
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600665 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600666 }
667 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
668 }
669 }
670
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600671 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600672
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600673 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600674
675 void TestDoubleDestroy() {
676 // Destroy the buffer but leave the flag set, which will cause
677 // the buffer to be destroyed again in the destructor.
678 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
679 }
680
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700681 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600682 bool AllocateCurrent;
683 bool BoundCurrent;
684 bool CreateCurrent;
685 bool InvalidDeleteEn;
686
687 VkBuffer VulkanBuffer;
688 VkDevice VulkanDevice;
689 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600690};
691
692class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700693 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600694 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600695 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700696 : BoundCurrent(false),
697 AttributeCount(aAttributeCount),
698 BindingCount(aBindingCount),
699 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600700 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600701 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
702 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700703 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600704
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600705 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
706 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600707
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600708 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
709 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
710 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
711 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
712 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600713
714 unsigned i = 0;
715 do {
716 VertexInputAttributeDescription[i].binding = BindId;
717 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600718 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
719 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600720 i++;
721 } while (AttributeCount < i);
722
723 i = 0;
724 do {
725 VertexInputBindingDescription[i].binding = BindId;
726 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600727 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600728 i++;
729 } while (BindingCount < i);
730 }
731
732 ~VkVerticesObj() {
733 if (VertexInputAttributeDescription) {
734 delete[] VertexInputAttributeDescription;
735 }
736 if (VertexInputBindingDescription) {
737 delete[] VertexInputBindingDescription;
738 }
739 }
740
741 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600742 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
743 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600744 return true;
745 }
746
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600748 VkDeviceSize *offsetList;
749 unsigned offsetCount;
750
751 if (aOffsetCount) {
752 offsetList = aOffsetList;
753 offsetCount = aOffsetCount;
754 } else {
755 offsetList = new VkDeviceSize[1]();
756 offsetCount = 1;
757 }
758
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600759 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600760 BoundCurrent = true;
761
762 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600763 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600764 }
765 }
766
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700767 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600768 static uint32_t BindIdGenerator;
769
770 bool BoundCurrent;
771 unsigned AttributeCount;
772 unsigned BindingCount;
773 uint32_t BindId;
774
775 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
776 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
777 VkVertexInputBindingDescription *VertexInputBindingDescription;
778 VkConstantBufferObj VulkanMemoryBuffer;
779};
780
781uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500782// ********************************************************************************************************************
783// ********************************************************************************************************************
784// ********************************************************************************************************************
785// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600786#if PARAMETER_VALIDATION_TESTS
787TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700788 TEST_DESCRIPTION(
789 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
790 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600791
792 ASSERT_NO_FATAL_FAILURE(InitState());
793
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600795 // Specify NULL for a pointer to a handle
796 // Expected to trigger an error with
797 // parameter_validation::validate_required_pointer
798 vkGetPhysicalDeviceFeatures(gpu(), NULL);
799 m_errorMonitor->VerifyFound();
800
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
802 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600803 // Specify NULL for pointer to array count
804 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600805 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600806 m_errorMonitor->VerifyFound();
807
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600809 // Specify 0 for a required array count
810 // Expected to trigger an error with parameter_validation::validate_array
811 VkViewport view_port = {};
812 m_commandBuffer->SetViewport(0, 0, &view_port);
813 m_errorMonitor->VerifyFound();
814
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600816 // Specify NULL for a required array
817 // Expected to trigger an error with parameter_validation::validate_array
818 m_commandBuffer->SetViewport(0, 1, NULL);
819 m_errorMonitor->VerifyFound();
820
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600822 // Specify VK_NULL_HANDLE for a required handle
823 // Expected to trigger an error with
824 // parameter_validation::validate_required_handle
825 vkUnmapMemory(device(), VK_NULL_HANDLE);
826 m_errorMonitor->VerifyFound();
827
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
829 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600830 // Specify VK_NULL_HANDLE for a required handle array entry
831 // Expected to trigger an error with
832 // parameter_validation::validate_required_handle_array
833 VkFence fence = VK_NULL_HANDLE;
834 vkResetFences(device(), 1, &fence);
835 m_errorMonitor->VerifyFound();
836
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600838 // Specify NULL for a required struct pointer
839 // Expected to trigger an error with
840 // parameter_validation::validate_struct_type
841 VkDeviceMemory memory = VK_NULL_HANDLE;
842 vkAllocateMemory(device(), NULL, NULL, &memory);
843 m_errorMonitor->VerifyFound();
844
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600846 // Specify 0 for a required VkFlags parameter
847 // Expected to trigger an error with parameter_validation::validate_flags
848 m_commandBuffer->SetStencilReference(0, 0);
849 m_errorMonitor->VerifyFound();
850
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600851 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 -0600852 // Specify 0 for a required VkFlags array entry
853 // Expected to trigger an error with
854 // parameter_validation::validate_flags_array
855 VkSemaphore semaphore = VK_NULL_HANDLE;
856 VkPipelineStageFlags stageFlags = 0;
857 VkSubmitInfo submitInfo = {};
858 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
859 submitInfo.waitSemaphoreCount = 1;
860 submitInfo.pWaitSemaphores = &semaphore;
861 submitInfo.pWaitDstStageMask = &stageFlags;
862 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
863 m_errorMonitor->VerifyFound();
864}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600865
Dustin Gravesfce74c02016-05-10 11:42:58 -0600866TEST_F(VkLayerTest, ReservedParameter) {
867 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
868
869 ASSERT_NO_FATAL_FAILURE(InitState());
870
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600872 // Specify 0 for a reserved VkFlags parameter
873 // Expected to trigger an error with
874 // parameter_validation::validate_reserved_flags
875 VkEvent event_handle = VK_NULL_HANDLE;
876 VkEventCreateInfo event_info = {};
877 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
878 event_info.flags = 1;
879 vkCreateEvent(device(), &event_info, NULL, &event_handle);
880 m_errorMonitor->VerifyFound();
881}
882
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600883TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700884 TEST_DESCRIPTION(
885 "Specify an invalid VkStructureType for a Vulkan "
886 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600887
888 ASSERT_NO_FATAL_FAILURE(InitState());
889
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600891 // Zero struct memory, effectively setting sType to
892 // VK_STRUCTURE_TYPE_APPLICATION_INFO
893 // Expected to trigger an error with
894 // parameter_validation::validate_struct_type
895 VkMemoryAllocateInfo alloc_info = {};
896 VkDeviceMemory memory = VK_NULL_HANDLE;
897 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
898 m_errorMonitor->VerifyFound();
899
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600901 // Zero struct memory, effectively setting sType to
902 // VK_STRUCTURE_TYPE_APPLICATION_INFO
903 // Expected to trigger an error with
904 // parameter_validation::validate_struct_type_array
905 VkSubmitInfo submit_info = {};
906 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
907 m_errorMonitor->VerifyFound();
908}
909
910TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600911 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600912
913 ASSERT_NO_FATAL_FAILURE(InitState());
914
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600916 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600917 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600918 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600919 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600920 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600921 // Zero-initialization will provide the correct sType
922 VkApplicationInfo app_info = {};
923 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
924 event_alloc_info.pNext = &app_info;
925 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
926 m_errorMonitor->VerifyFound();
927
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
929 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600930 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
931 // a function that has allowed pNext structure types and specify
932 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600933 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600934 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600935 VkMemoryAllocateInfo memory_alloc_info = {};
936 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
937 memory_alloc_info.pNext = &app_info;
938 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600939 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600940}
Dustin Graves5d33d532016-05-09 16:21:12 -0600941
942TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600943 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600944
945 ASSERT_NO_FATAL_FAILURE(InitState());
946
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
948 "does not fall within the begin..end "
949 "range of the core VkFormat "
950 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600951 // Specify an invalid VkFormat value
952 // Expected to trigger an error with
953 // parameter_validation::validate_ranged_enum
954 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600955 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600956 m_errorMonitor->VerifyFound();
957
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600958 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 -0600959 // Specify an invalid VkFlags bitmask value
960 // Expected to trigger an error with parameter_validation::validate_flags
961 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600962 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
963 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600964 m_errorMonitor->VerifyFound();
965
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600967 // Specify an invalid VkFlags array entry
968 // Expected to trigger an error with
969 // parameter_validation::validate_flags_array
970 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600972 VkSubmitInfo submit_info = {};
973 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
974 submit_info.waitSemaphoreCount = 1;
975 submit_info.pWaitSemaphores = &semaphore;
976 submit_info.pWaitDstStageMask = &stage_flags;
977 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
978 m_errorMonitor->VerifyFound();
979
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600981 // Specify an invalid VkBool32 value
982 // Expected to trigger a warning with
983 // parameter_validation::validate_bool32
984 VkSampler sampler = VK_NULL_HANDLE;
985 VkSamplerCreateInfo sampler_info = {};
986 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
987 sampler_info.pNext = NULL;
988 sampler_info.magFilter = VK_FILTER_NEAREST;
989 sampler_info.minFilter = VK_FILTER_NEAREST;
990 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
991 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
992 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
993 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
994 sampler_info.mipLodBias = 1.0;
995 sampler_info.maxAnisotropy = 1;
996 sampler_info.compareEnable = VK_FALSE;
997 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
998 sampler_info.minLod = 1.0;
999 sampler_info.maxLod = 1.0;
1000 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1001 sampler_info.unnormalizedCoordinates = VK_FALSE;
1002 // Not VK_TRUE or VK_FALSE
1003 sampler_info.anisotropyEnable = 3;
1004 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1005 m_errorMonitor->VerifyFound();
1006}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001007
1008TEST_F(VkLayerTest, FailedReturnValue) {
1009 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1010
1011 ASSERT_NO_FATAL_FAILURE(InitState());
1012
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001013 // Find an unsupported image format
1014 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1015 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1016 VkFormat format = static_cast<VkFormat>(f);
1017 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001018 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001019 unsupported = format;
1020 break;
1021 }
1022 }
1023
1024 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1026 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001027 // Specify an unsupported VkFormat value to generate a
1028 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1029 // Expected to trigger a warning from
1030 // parameter_validation::validate_result
1031 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001032 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1033 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001034 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1035 m_errorMonitor->VerifyFound();
1036 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001037}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001038
1039TEST_F(VkLayerTest, UpdateBufferAlignment) {
1040 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001041 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001042
1043 ASSERT_NO_FATAL_FAILURE(InitState());
1044
1045 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1046 vk_testing::Buffer buffer;
1047 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1048
Tony Barbour552f6c02016-12-21 14:34:07 -07001049 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001050 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001052 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1053 m_errorMonitor->VerifyFound();
1054
1055 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001057 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1058 m_errorMonitor->VerifyFound();
1059
1060 // Introduce failure by using dataSize that is < 0
1061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001062 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001063 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1064 m_errorMonitor->VerifyFound();
1065
1066 // Introduce failure by using dataSize that is > 65536
1067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001068 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001069 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1070 m_errorMonitor->VerifyFound();
1071
Tony Barbour552f6c02016-12-21 14:34:07 -07001072 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001073}
1074
1075TEST_F(VkLayerTest, FillBufferAlignment) {
1076 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1077
1078 ASSERT_NO_FATAL_FAILURE(InitState());
1079
1080 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1081 vk_testing::Buffer buffer;
1082 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1083
Tony Barbour552f6c02016-12-21 14:34:07 -07001084 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085
1086 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001088 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1089 m_errorMonitor->VerifyFound();
1090
1091 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001093 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1094 m_errorMonitor->VerifyFound();
1095
1096 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001098 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1099 m_errorMonitor->VerifyFound();
1100
Tony Barbour552f6c02016-12-21 14:34:07 -07001101 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001102}
Dustin Graves40f35822016-06-23 11:12:53 -06001103
Cortd889ff92016-07-27 09:51:27 -07001104TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1105 VkResult err;
1106
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001107 TEST_DESCRIPTION(
1108 "Attempt to use a non-solid polygon fill mode in a "
1109 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001110
1111 ASSERT_NO_FATAL_FAILURE(InitState());
1112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1113
1114 std::vector<const char *> device_extension_names;
1115 auto features = m_device->phy().features();
1116 // Artificially disable support for non-solid fill modes
1117 features.fillModeNonSolid = false;
1118 // The sacrificial device object
1119 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1120
1121 VkRenderpassObj render_pass(&test_device);
1122
1123 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1124 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1125 pipeline_layout_ci.setLayoutCount = 0;
1126 pipeline_layout_ci.pSetLayouts = NULL;
1127
1128 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001129 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001130 ASSERT_VK_SUCCESS(err);
1131
1132 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1133 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1134 rs_ci.pNext = nullptr;
1135 rs_ci.lineWidth = 1.0f;
1136 rs_ci.rasterizerDiscardEnable = true;
1137
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001138 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1139 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001140
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001141 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1143 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001144 {
1145 VkPipelineObj pipe(&test_device);
1146 pipe.AddShader(&vs);
1147 pipe.AddShader(&fs);
1148 pipe.AddColorAttachment();
1149 // Introduce failure by setting unsupported polygon mode
1150 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1151 pipe.SetRasterization(&rs_ci);
1152 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1153 }
1154 m_errorMonitor->VerifyFound();
1155
1156 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1158 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001159 {
1160 VkPipelineObj pipe(&test_device);
1161 pipe.AddShader(&vs);
1162 pipe.AddShader(&fs);
1163 pipe.AddColorAttachment();
1164 // Introduce failure by setting unsupported polygon mode
1165 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1166 pipe.SetRasterization(&rs_ci);
1167 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1168 }
1169 m_errorMonitor->VerifyFound();
1170
Cortd889ff92016-07-27 09:51:27 -07001171 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1172}
1173
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001174#endif // PARAMETER_VALIDATION_TESTS
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001175
Tobin Ehlis0788f522015-05-26 16:11:58 -06001176#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001177#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001178TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001179{
1180 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001181 VkFenceCreateInfo fenceInfo = {};
1182 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1183 fenceInfo.pNext = NULL;
1184 fenceInfo.flags = 0;
1185
Mike Weiblencce7ec72016-10-17 19:33:05 -06001186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001187
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001188 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001189
1190 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1191 vk_testing::Buffer buffer;
1192 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001193
Tony Barbourfe3351b2015-07-28 10:17:20 -06001194 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001195 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001196 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001197
1198 testFence.init(*m_device, fenceInfo);
1199
1200 // Bypass framework since it does the waits automatically
1201 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001202 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001203 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1204 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001205 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001206 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001207 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001208 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001209 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001210 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001211 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001212
1213 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001214 ASSERT_VK_SUCCESS( err );
1215
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001216 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001217 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001218
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001219 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001220}
1221
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001222TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001223{
1224 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001225 VkFenceCreateInfo fenceInfo = {};
1226 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1227 fenceInfo.pNext = NULL;
1228 fenceInfo.flags = 0;
1229
Mike Weiblencce7ec72016-10-17 19:33:05 -06001230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001231
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232 ASSERT_NO_FATAL_FAILURE(InitState());
1233 ASSERT_NO_FATAL_FAILURE(InitViewport());
1234 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1235
Tony Barbourfe3351b2015-07-28 10:17:20 -06001236 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001237 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001238 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001239
1240 testFence.init(*m_device, fenceInfo);
1241
1242 // Bypass framework since it does the waits automatically
1243 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001244 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001245 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1246 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001247 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001248 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001249 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001250 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001251 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001252 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001253 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001254
1255 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001256 ASSERT_VK_SUCCESS( err );
1257
Jon Ashburnf19916e2016-01-11 13:12:43 -07001258 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001259 VkCommandBufferBeginInfo info = {};
1260 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1261 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001262 info.renderPass = VK_NULL_HANDLE;
1263 info.subpass = 0;
1264 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001265 info.occlusionQueryEnable = VK_FALSE;
1266 info.queryFlags = 0;
1267 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001268
1269 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001270 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001271
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001272 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001273}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001274#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001275
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001276TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1277 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1278
1279 ASSERT_NO_FATAL_FAILURE(InitState());
1280
1281 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1282 VkBuffer buffer;
1283 VkBufferCreateInfo buf_info = {};
1284 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1285 buf_info.pNext = NULL;
1286 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1287 buf_info.size = 2048;
1288 buf_info.queueFamilyIndexCount = 0;
1289 buf_info.pQueueFamilyIndices = NULL;
1290 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1291 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1292 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1293 m_errorMonitor->VerifyFound();
1294
1295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1296 VkImage image;
1297 VkImageCreateInfo image_create_info = {};
1298 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1299 image_create_info.pNext = NULL;
1300 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1301 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1302 image_create_info.extent.width = 512;
1303 image_create_info.extent.height = 64;
1304 image_create_info.extent.depth = 1;
1305 image_create_info.mipLevels = 1;
1306 image_create_info.arrayLayers = 1;
1307 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1308 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1309 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1310 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1311 image_create_info.queueFamilyIndexCount = 0;
1312 image_create_info.pQueueFamilyIndices = NULL;
1313 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1314 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1315 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1316 m_errorMonitor->VerifyFound();
1317}
1318
Tobin Ehlisf11be982016-05-11 13:52:53 -06001319TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001320 TEST_DESCRIPTION(
1321 "Create a buffer and image, allocate memory, and bind the "
1322 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001323 VkResult err;
1324 bool pass;
1325 ASSERT_NO_FATAL_FAILURE(InitState());
1326
Tobin Ehlis077ded32016-05-12 17:39:13 -06001327 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001328 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001329 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001330 VkDeviceMemory mem; // buffer will be bound first
1331 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001332 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001333 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001334
1335 VkBufferCreateInfo buf_info = {};
1336 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1337 buf_info.pNext = NULL;
1338 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1339 buf_info.size = 256;
1340 buf_info.queueFamilyIndexCount = 0;
1341 buf_info.pQueueFamilyIndices = NULL;
1342 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1343 buf_info.flags = 0;
1344 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1345 ASSERT_VK_SUCCESS(err);
1346
Tobin Ehlis077ded32016-05-12 17:39:13 -06001347 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001348
1349 VkImageCreateInfo image_create_info = {};
1350 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1351 image_create_info.pNext = NULL;
1352 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1353 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1354 image_create_info.extent.width = 64;
1355 image_create_info.extent.height = 64;
1356 image_create_info.extent.depth = 1;
1357 image_create_info.mipLevels = 1;
1358 image_create_info.arrayLayers = 1;
1359 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001360 // Image tiling must be optimal to trigger error when aliasing linear buffer
1361 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001362 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1363 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1364 image_create_info.queueFamilyIndexCount = 0;
1365 image_create_info.pQueueFamilyIndices = NULL;
1366 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1367 image_create_info.flags = 0;
1368
Tobin Ehlisf11be982016-05-11 13:52:53 -06001369 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1370 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001371 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1372 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001373
Tobin Ehlis077ded32016-05-12 17:39:13 -06001374 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1375
1376 VkMemoryAllocateInfo alloc_info = {};
1377 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1378 alloc_info.pNext = NULL;
1379 alloc_info.memoryTypeIndex = 0;
1380 // Ensure memory is big enough for both bindings
1381 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001382 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1383 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001384 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001385 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001386 vkDestroyImage(m_device->device(), image, NULL);
1387 return;
1388 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001389 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1390 ASSERT_VK_SUCCESS(err);
1391 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1392 ASSERT_VK_SUCCESS(err);
1393
Rene Lindsayd14f5572016-12-16 14:57:18 -07001394 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1395
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001397 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001398 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1399 m_errorMonitor->VerifyFound();
1400
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001401 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001402 // aliasing buffer2
1403 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1404 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001405 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1406 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001407 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001408 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001410 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001411 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001412 m_errorMonitor->VerifyFound();
1413
1414 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001415 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001416 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001417 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001418 vkFreeMemory(m_device->device(), mem, NULL);
1419 vkFreeMemory(m_device->device(), mem_img, NULL);
1420}
1421
Tobin Ehlis35372522016-05-12 08:32:31 -06001422TEST_F(VkLayerTest, InvalidMemoryMapping) {
1423 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1424 VkResult err;
1425 bool pass;
1426 ASSERT_NO_FATAL_FAILURE(InitState());
1427
1428 VkBuffer buffer;
1429 VkDeviceMemory mem;
1430 VkMemoryRequirements mem_reqs;
1431
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001432 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1433
Tobin Ehlis35372522016-05-12 08:32:31 -06001434 VkBufferCreateInfo buf_info = {};
1435 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1436 buf_info.pNext = NULL;
1437 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1438 buf_info.size = 256;
1439 buf_info.queueFamilyIndexCount = 0;
1440 buf_info.pQueueFamilyIndices = NULL;
1441 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1442 buf_info.flags = 0;
1443 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1444 ASSERT_VK_SUCCESS(err);
1445
1446 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1447 VkMemoryAllocateInfo alloc_info = {};
1448 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1449 alloc_info.pNext = NULL;
1450 alloc_info.memoryTypeIndex = 0;
1451
1452 // Ensure memory is big enough for both bindings
1453 static const VkDeviceSize allocation_size = 0x10000;
1454 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001455 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 -06001456 if (!pass) {
1457 vkDestroyBuffer(m_device->device(), buffer, NULL);
1458 return;
1459 }
1460 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1461 ASSERT_VK_SUCCESS(err);
1462
1463 uint8_t *pData;
1464 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001465 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 -06001466 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1467 m_errorMonitor->VerifyFound();
1468 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001469 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001470 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1472 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1473 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001474 m_errorMonitor->VerifyFound();
1475
1476 // Unmap the memory to avoid re-map error
1477 vkUnmapMemory(m_device->device(), mem);
1478 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1480 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1481 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001482 m_errorMonitor->VerifyFound();
1483 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1485 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001486 m_errorMonitor->VerifyFound();
1487 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001489 vkUnmapMemory(m_device->device(), mem);
1490 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001491
Tobin Ehlis35372522016-05-12 08:32:31 -06001492 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001493 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001494 ASSERT_VK_SUCCESS(err);
1495 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001496 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001497 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001498 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001500 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1501 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001502
Tobin Ehlis35372522016-05-12 08:32:31 -06001503 // Now flush range that oversteps mapped range
1504 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001505 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001506 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001507 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001508 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1510 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1511 m_errorMonitor->VerifyFound();
1512
1513 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1514 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001515 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001516 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001517 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001518 mmr.size = VK_WHOLE_SIZE;
1519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001520 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1521 m_errorMonitor->VerifyFound();
1522
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001523#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001524 // Some platforms have an atomsize of 1 which makes the test meaningless
1525 if (atom_size > 3) {
1526 // Now with an offset NOT a multiple of the device limit
1527 vkUnmapMemory(m_device->device(), mem);
1528 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1529 ASSERT_VK_SUCCESS(err);
1530 mmr.offset = 3; // Not a multiple of atom_size
1531 mmr.size = VK_WHOLE_SIZE;
1532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1533 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1534 m_errorMonitor->VerifyFound();
1535
1536 // Now with a size NOT a multiple of the device limit
1537 vkUnmapMemory(m_device->device(), mem);
1538 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1539 ASSERT_VK_SUCCESS(err);
1540 mmr.offset = atom_size;
1541 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1543 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1544 m_errorMonitor->VerifyFound();
1545 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001546#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001547 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1548 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001549 if (!pass) {
1550 vkFreeMemory(m_device->device(), mem, NULL);
1551 vkDestroyBuffer(m_device->device(), buffer, NULL);
1552 return;
1553 }
1554 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1555 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1556
1557 vkDestroyBuffer(m_device->device(), buffer, NULL);
1558 vkFreeMemory(m_device->device(), mem, NULL);
1559}
1560
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001561#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001562TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1563 VkResult err;
1564 bool pass;
1565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001566 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1567 // following declaration (which is temporarily being moved below):
1568 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001569 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001570 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001571 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001572 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001573 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001574 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001575
1576 ASSERT_NO_FATAL_FAILURE(InitState());
1577
Ian Elliott3f06ce52016-04-29 14:46:21 -06001578#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1579#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1580 // Use the functions from the VK_KHR_android_surface extension without
1581 // enabling that extension:
1582
1583 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001584 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1586 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001587 pass = (err != VK_SUCCESS);
1588 ASSERT_TRUE(pass);
1589 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001590#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001591
Ian Elliott3f06ce52016-04-29 14:46:21 -06001592#if defined(VK_USE_PLATFORM_MIR_KHR)
1593 // Use the functions from the VK_KHR_mir_surface extension without enabling
1594 // that extension:
1595
1596 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001597 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001599 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1600 pass = (err != VK_SUCCESS);
1601 ASSERT_TRUE(pass);
1602 m_errorMonitor->VerifyFound();
1603
1604 // Tell whether an mir_connection supports presentation:
1605 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1607 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001608 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001609#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001610
Ian Elliott3f06ce52016-04-29 14:46:21 -06001611#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1612 // Use the functions from the VK_KHR_wayland_surface extension without
1613 // enabling that extension:
1614
1615 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001616 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1618 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001619 pass = (err != VK_SUCCESS);
1620 ASSERT_TRUE(pass);
1621 m_errorMonitor->VerifyFound();
1622
1623 // Tell whether an wayland_display supports presentation:
1624 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1626 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001627 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001628#endif // VK_USE_PLATFORM_WAYLAND_KHR
1629#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001630
Ian Elliott3f06ce52016-04-29 14:46:21 -06001631#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001632 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1633 // TO NON-LINUX PLATFORMS:
1634 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001635 // Use the functions from the VK_KHR_win32_surface extension without
1636 // enabling that extension:
1637
1638 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001639 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1641 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001642 pass = (err != VK_SUCCESS);
1643 ASSERT_TRUE(pass);
1644 m_errorMonitor->VerifyFound();
1645
1646 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001648 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001649 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001650// Set this (for now, until all platforms are supported and tested):
1651#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001652#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001653#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001654 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1655 // TO NON-LINUX PLATFORMS:
1656 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001657#endif
1658#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001659 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1660 // that extension:
1661
1662 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001663 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001665 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1666 pass = (err != VK_SUCCESS);
1667 ASSERT_TRUE(pass);
1668 m_errorMonitor->VerifyFound();
1669
1670 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001671 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001672 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1674 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001675 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001676// Set this (for now, until all platforms are supported and tested):
1677#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001678#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001679
Ian Elliott12630812016-04-29 14:35:43 -06001680#if defined(VK_USE_PLATFORM_XLIB_KHR)
1681 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1682 // that extension:
1683
1684 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001685 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001687 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1688 pass = (err != VK_SUCCESS);
1689 ASSERT_TRUE(pass);
1690 m_errorMonitor->VerifyFound();
1691
1692 // Tell whether an Xlib VisualID supports presentation:
1693 Display *dpy = NULL;
1694 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001696 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1697 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001698// Set this (for now, until all platforms are supported and tested):
1699#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001700#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001701
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001702// Use the functions from the VK_KHR_surface extension without enabling
1703// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001704
Ian Elliott489eec02016-05-05 14:12:44 -06001705#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001706 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001708 vkDestroySurfaceKHR(instance(), surface, NULL);
1709 m_errorMonitor->VerifyFound();
1710
1711 // Check if surface supports presentation:
1712 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001714 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1715 pass = (err != VK_SUCCESS);
1716 ASSERT_TRUE(pass);
1717 m_errorMonitor->VerifyFound();
1718
1719 // Check surface capabilities:
1720 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1722 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001723 pass = (err != VK_SUCCESS);
1724 ASSERT_TRUE(pass);
1725 m_errorMonitor->VerifyFound();
1726
1727 // Check surface formats:
1728 uint32_t format_count = 0;
1729 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1731 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001732 pass = (err != VK_SUCCESS);
1733 ASSERT_TRUE(pass);
1734 m_errorMonitor->VerifyFound();
1735
1736 // Check surface present modes:
1737 uint32_t present_mode_count = 0;
1738 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1740 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001741 pass = (err != VK_SUCCESS);
1742 ASSERT_TRUE(pass);
1743 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001744#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001745
Ian Elliott1c32c772016-04-28 14:47:13 -06001746 // Use the functions from the VK_KHR_swapchain extension without enabling
1747 // that extension:
1748
1749 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001751 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1752 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001753 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001754 pass = (err != VK_SUCCESS);
1755 ASSERT_TRUE(pass);
1756 m_errorMonitor->VerifyFound();
1757
1758 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1760 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001761 pass = (err != VK_SUCCESS);
1762 ASSERT_TRUE(pass);
1763 m_errorMonitor->VerifyFound();
1764
Chris Forbeseb7d5502016-09-13 18:19:21 +12001765 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1766 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1767 VkFence fence;
1768 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1769
Ian Elliott1c32c772016-04-28 14:47:13 -06001770 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001772 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001773 pass = (err != VK_SUCCESS);
1774 ASSERT_TRUE(pass);
1775 m_errorMonitor->VerifyFound();
1776
Chris Forbeseb7d5502016-09-13 18:19:21 +12001777 vkDestroyFence(m_device->device(), fence, nullptr);
1778
Ian Elliott1c32c772016-04-28 14:47:13 -06001779 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001780 //
1781 // NOTE: Currently can't test this because a real swapchain is needed (as
1782 // opposed to the fake one we created) in order for the layer to lookup the
1783 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001784
1785 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001787 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1788 m_errorMonitor->VerifyFound();
1789}
Chris Forbes09368e42016-10-13 11:59:22 +13001790#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001791
Karl Schultz6addd812016-02-02 17:17:23 -07001792TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1793 VkResult err;
1794 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001795
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1797 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001798
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001799 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001800
1801 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001802 VkImage image;
1803 VkDeviceMemory mem;
1804 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001805
Karl Schultz6addd812016-02-02 17:17:23 -07001806 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1807 const int32_t tex_width = 32;
1808 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001809
Tony Barboureb254902015-07-15 12:50:33 -06001810 VkImageCreateInfo image_create_info = {};
1811 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001812 image_create_info.pNext = NULL;
1813 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1814 image_create_info.format = tex_format;
1815 image_create_info.extent.width = tex_width;
1816 image_create_info.extent.height = tex_height;
1817 image_create_info.extent.depth = 1;
1818 image_create_info.mipLevels = 1;
1819 image_create_info.arrayLayers = 1;
1820 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1821 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1822 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1823 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001824 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001825
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001826 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001827 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001828 mem_alloc.pNext = NULL;
1829 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001830
Chia-I Wuf7458c52015-10-26 21:10:41 +08001831 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001832 ASSERT_VK_SUCCESS(err);
1833
Karl Schultz6addd812016-02-02 17:17:23 -07001834 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001835
Mark Lobodzinski23065352015-05-29 09:32:35 -05001836 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001837
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001838 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 -07001839 if (!pass) { // If we can't find any unmappable memory this test doesn't
1840 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001841 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001842 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001843 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001844
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001845 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001846 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001847 ASSERT_VK_SUCCESS(err);
1848
1849 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001850 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001851 ASSERT_VK_SUCCESS(err);
1852
1853 // Map memory as if to initialize the image
1854 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001855 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001856
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001857 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001858
Chia-I Wuf7458c52015-10-26 21:10:41 +08001859 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001860 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001861}
1862
Karl Schultz6addd812016-02-02 17:17:23 -07001863TEST_F(VkLayerTest, RebindMemory) {
1864 VkResult err;
1865 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001866
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001868
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001869 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001870
1871 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001872 VkImage image;
1873 VkDeviceMemory mem1;
1874 VkDeviceMemory mem2;
1875 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001876
Karl Schultz6addd812016-02-02 17:17:23 -07001877 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1878 const int32_t tex_width = 32;
1879 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001880
Tony Barboureb254902015-07-15 12:50:33 -06001881 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001882 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1883 image_create_info.pNext = NULL;
1884 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1885 image_create_info.format = tex_format;
1886 image_create_info.extent.width = tex_width;
1887 image_create_info.extent.height = tex_height;
1888 image_create_info.extent.depth = 1;
1889 image_create_info.mipLevels = 1;
1890 image_create_info.arrayLayers = 1;
1891 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1892 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1893 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1894 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001895
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001896 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001897 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1898 mem_alloc.pNext = NULL;
1899 mem_alloc.allocationSize = 0;
1900 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001901
Karl Schultz6addd812016-02-02 17:17:23 -07001902 // Introduce failure, do NOT set memProps to
1903 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001904 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001905 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001906 ASSERT_VK_SUCCESS(err);
1907
Karl Schultz6addd812016-02-02 17:17:23 -07001908 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001909
1910 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001911 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001912 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001913
1914 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001915 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001916 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001917 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001918 ASSERT_VK_SUCCESS(err);
1919
1920 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001921 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001922 ASSERT_VK_SUCCESS(err);
1923
Karl Schultz6addd812016-02-02 17:17:23 -07001924 // Introduce validation failure, try to bind a different memory object to
1925 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001926 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001927
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001928 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001929
Chia-I Wuf7458c52015-10-26 21:10:41 +08001930 vkDestroyImage(m_device->device(), image, NULL);
1931 vkFreeMemory(m_device->device(), mem1, NULL);
1932 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001933}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001934
Karl Schultz6addd812016-02-02 17:17:23 -07001935TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001936 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001937
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1939 "submitted in SIGNALED state. Fences "
1940 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001941
1942 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001943 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1944 fenceInfo.pNext = NULL;
1945 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001946
Tony Barbour300a6082015-04-07 13:44:53 -06001947 ASSERT_NO_FATAL_FAILURE(InitState());
1948 ASSERT_NO_FATAL_FAILURE(InitViewport());
1949 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1950
Tony Barbour552f6c02016-12-21 14:34:07 -07001951 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001952 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07001953 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001954
1955 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001956
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001957 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001958 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1959 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001960 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001961 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001962 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001963 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001964 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001965 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001966 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001967
1968 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001969 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001970
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001971 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001972}
Chris Forbes4e44c912016-06-16 10:20:00 +12001973
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001974TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001975 TEST_DESCRIPTION(
1976 "Specify wrong usage for image then create conflicting view of image "
1977 "Initialize buffer with wrong usage then perform copy expecting errors "
1978 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001980
1981 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001982
1983 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
1984
Tony Barbourf92621a2016-05-02 14:28:12 -06001985 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001986 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001987 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001988 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001989
Tony Barbourf92621a2016-05-02 14:28:12 -06001990 VkImageView dsv;
1991 VkImageViewCreateInfo dsvci = {};
1992 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1993 dsvci.image = image.handle();
1994 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001995 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06001996 dsvci.subresourceRange.layerCount = 1;
1997 dsvci.subresourceRange.baseMipLevel = 0;
1998 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001999 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002000
Tony Barbourf92621a2016-05-02 14:28:12 -06002001 // Create a view with depth / stencil aspect for image with different usage
2002 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002003
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002004 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002005
2006 // Initialize buffer with TRANSFER_DST usage
2007 vk_testing::Buffer buffer;
2008 VkMemoryPropertyFlags reqs = 0;
2009 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2010 VkBufferImageCopy region = {};
2011 region.bufferRowLength = 128;
2012 region.bufferImageHeight = 128;
2013 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2014 region.imageSubresource.layerCount = 1;
2015 region.imageExtent.height = 16;
2016 region.imageExtent.width = 16;
2017 region.imageExtent.depth = 1;
2018
Tony Barbourf92621a2016-05-02 14:28:12 -06002019 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2020 // TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002021 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002022
Chris Forbesda581202016-10-06 18:25:26 +13002023 // two separate errors from this call:
2024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2026
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002027 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2028 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002029 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002030}
Tony Barbour75d79f02016-08-30 09:39:07 -06002031
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002032#endif // MEM_TRACKER_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002033
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002034#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002035
2036TEST_F(VkLayerTest, LeakAnObject) {
2037 VkResult err;
2038
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002039 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002040
2041 // Note that we have to create a new device since destroying the
2042 // framework's device causes Teardown() to fail and just calling Teardown
2043 // will destroy the errorMonitor.
2044
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002046
2047 ASSERT_NO_FATAL_FAILURE(InitState());
2048
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002049 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002050 std::vector<VkDeviceQueueCreateInfo> queue_info;
2051 queue_info.reserve(queue_props.size());
2052 std::vector<std::vector<float>> queue_priorities;
2053 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2054 VkDeviceQueueCreateInfo qi = {};
2055 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2056 qi.pNext = NULL;
2057 qi.queueFamilyIndex = i;
2058 qi.queueCount = queue_props[i].queueCount;
2059 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2060 qi.pQueuePriorities = queue_priorities[i].data();
2061 queue_info.push_back(qi);
2062 }
2063
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002064 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002065
2066 // The sacrificial device object
2067 VkDevice testDevice;
2068 VkDeviceCreateInfo device_create_info = {};
2069 auto features = m_device->phy().features();
2070 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2071 device_create_info.pNext = NULL;
2072 device_create_info.queueCreateInfoCount = queue_info.size();
2073 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002074 device_create_info.enabledLayerCount = 0;
2075 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002076 device_create_info.pEnabledFeatures = &features;
2077 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2078 ASSERT_VK_SUCCESS(err);
2079
2080 VkFence fence;
2081 VkFenceCreateInfo fence_create_info = {};
2082 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2083 fence_create_info.pNext = NULL;
2084 fence_create_info.flags = 0;
2085 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2086 ASSERT_VK_SUCCESS(err);
2087
2088 // Induce failure by not calling vkDestroyFence
2089 vkDestroyDevice(testDevice, NULL);
2090 m_errorMonitor->VerifyFound();
2091}
2092
2093TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002094 TEST_DESCRIPTION(
2095 "Allocate command buffers from one command pool and "
2096 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002097
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002099
Cody Northropc31a84f2016-08-22 10:41:47 -06002100 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002101 VkCommandPool command_pool_one;
2102 VkCommandPool command_pool_two;
2103
2104 VkCommandPoolCreateInfo pool_create_info{};
2105 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2106 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2107 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2108
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002109 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002110
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002111 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002112
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002113 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002114 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002115 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002116 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002117 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002118 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002119 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002120
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002121 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002122
2123 m_errorMonitor->VerifyFound();
2124
2125 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2126 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2127}
2128
2129TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2130 VkResult err;
2131
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002132 TEST_DESCRIPTION(
2133 "Allocate descriptor sets from one DS pool and "
2134 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002135
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002137
2138 ASSERT_NO_FATAL_FAILURE(InitState());
2139 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2140
2141 VkDescriptorPoolSize ds_type_count = {};
2142 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2143 ds_type_count.descriptorCount = 1;
2144
2145 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2146 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2147 ds_pool_ci.pNext = NULL;
2148 ds_pool_ci.flags = 0;
2149 ds_pool_ci.maxSets = 1;
2150 ds_pool_ci.poolSizeCount = 1;
2151 ds_pool_ci.pPoolSizes = &ds_type_count;
2152
2153 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002154 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002155 ASSERT_VK_SUCCESS(err);
2156
2157 // Create a second descriptor pool
2158 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002159 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002160 ASSERT_VK_SUCCESS(err);
2161
2162 VkDescriptorSetLayoutBinding dsl_binding = {};
2163 dsl_binding.binding = 0;
2164 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2165 dsl_binding.descriptorCount = 1;
2166 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2167 dsl_binding.pImmutableSamplers = NULL;
2168
2169 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2170 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2171 ds_layout_ci.pNext = NULL;
2172 ds_layout_ci.bindingCount = 1;
2173 ds_layout_ci.pBindings = &dsl_binding;
2174
2175 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002176 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002177 ASSERT_VK_SUCCESS(err);
2178
2179 VkDescriptorSet descriptorSet;
2180 VkDescriptorSetAllocateInfo alloc_info = {};
2181 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2182 alloc_info.descriptorSetCount = 1;
2183 alloc_info.descriptorPool = ds_pool_one;
2184 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002185 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002186 ASSERT_VK_SUCCESS(err);
2187
2188 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2189
2190 m_errorMonitor->VerifyFound();
2191
2192 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2193 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2194 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2195}
2196
2197TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002199
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002200 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002201
2202 ASSERT_NO_FATAL_FAILURE(InitState());
2203
2204 // Pass bogus handle into GetImageMemoryRequirements
2205 VkMemoryRequirements mem_reqs;
2206 uint64_t fakeImageHandle = 0xCADECADE;
2207 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2208
2209 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2210
2211 m_errorMonitor->VerifyFound();
2212}
2213
Karl Schultz6addd812016-02-02 17:17:23 -07002214TEST_F(VkLayerTest, PipelineNotBound) {
2215 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002216
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002217 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002218
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002220
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002221 ASSERT_NO_FATAL_FAILURE(InitState());
2222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002223
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002224 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002225 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2226 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002227
2228 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002229 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2230 ds_pool_ci.pNext = NULL;
2231 ds_pool_ci.maxSets = 1;
2232 ds_pool_ci.poolSizeCount = 1;
2233 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002234
2235 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002236 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002237 ASSERT_VK_SUCCESS(err);
2238
2239 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002240 dsl_binding.binding = 0;
2241 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2242 dsl_binding.descriptorCount = 1;
2243 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2244 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002245
2246 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002247 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2248 ds_layout_ci.pNext = NULL;
2249 ds_layout_ci.bindingCount = 1;
2250 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002251
2252 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002253 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002254 ASSERT_VK_SUCCESS(err);
2255
2256 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002257 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002258 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002259 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002260 alloc_info.descriptorPool = ds_pool;
2261 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002262 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002263 ASSERT_VK_SUCCESS(err);
2264
2265 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002266 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2267 pipeline_layout_ci.pNext = NULL;
2268 pipeline_layout_ci.setLayoutCount = 1;
2269 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002270
2271 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002272 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002273 ASSERT_VK_SUCCESS(err);
2274
Mark Youngad779052016-01-06 14:26:04 -07002275 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002276
Tony Barbour552f6c02016-12-21 14:34:07 -07002277 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002278 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002279
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002280 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002281
Chia-I Wuf7458c52015-10-26 21:10:41 +08002282 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2283 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2284 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002285}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002286
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002287TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2288 VkResult err;
2289
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002290 TEST_DESCRIPTION(
2291 "Test validation check for an invalid memory type index "
2292 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002293
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002294 ASSERT_NO_FATAL_FAILURE(InitState());
2295
2296 // Create an image, allocate memory, set a bad typeIndex and then try to
2297 // bind it
2298 VkImage image;
2299 VkDeviceMemory mem;
2300 VkMemoryRequirements mem_reqs;
2301 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2302 const int32_t tex_width = 32;
2303 const int32_t tex_height = 32;
2304
2305 VkImageCreateInfo image_create_info = {};
2306 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2307 image_create_info.pNext = NULL;
2308 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2309 image_create_info.format = tex_format;
2310 image_create_info.extent.width = tex_width;
2311 image_create_info.extent.height = tex_height;
2312 image_create_info.extent.depth = 1;
2313 image_create_info.mipLevels = 1;
2314 image_create_info.arrayLayers = 1;
2315 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2316 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2317 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2318 image_create_info.flags = 0;
2319
2320 VkMemoryAllocateInfo mem_alloc = {};
2321 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2322 mem_alloc.pNext = NULL;
2323 mem_alloc.allocationSize = 0;
2324 mem_alloc.memoryTypeIndex = 0;
2325
2326 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2327 ASSERT_VK_SUCCESS(err);
2328
2329 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2330 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002331
2332 // Introduce Failure, select invalid TypeIndex
2333 VkPhysicalDeviceMemoryProperties memory_info;
2334
2335 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2336 unsigned int i;
2337 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2338 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2339 mem_alloc.memoryTypeIndex = i;
2340 break;
2341 }
2342 }
2343 if (i >= memory_info.memoryTypeCount) {
2344 printf("No invalid memory type index could be found; skipped.\n");
2345 vkDestroyImage(m_device->device(), image, NULL);
2346 return;
2347 }
2348
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002349 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 -06002350
2351 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2352 ASSERT_VK_SUCCESS(err);
2353
2354 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2355 (void)err;
2356
2357 m_errorMonitor->VerifyFound();
2358
2359 vkDestroyImage(m_device->device(), image, NULL);
2360 vkFreeMemory(m_device->device(), mem, NULL);
2361}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002362
Karl Schultz6addd812016-02-02 17:17:23 -07002363TEST_F(VkLayerTest, BindInvalidMemory) {
2364 VkResult err;
2365 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002366
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002368
Tobin Ehlisec598302015-09-15 15:02:17 -06002369 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002370
2371 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002372 VkImage image;
2373 VkDeviceMemory mem;
2374 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002375
Karl Schultz6addd812016-02-02 17:17:23 -07002376 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2377 const int32_t tex_width = 32;
2378 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002379
2380 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002381 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2382 image_create_info.pNext = NULL;
2383 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2384 image_create_info.format = tex_format;
2385 image_create_info.extent.width = tex_width;
2386 image_create_info.extent.height = tex_height;
2387 image_create_info.extent.depth = 1;
2388 image_create_info.mipLevels = 1;
2389 image_create_info.arrayLayers = 1;
2390 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2391 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2392 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2393 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002394
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002395 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002396 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2397 mem_alloc.pNext = NULL;
2398 mem_alloc.allocationSize = 0;
2399 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002400
Chia-I Wuf7458c52015-10-26 21:10:41 +08002401 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002402 ASSERT_VK_SUCCESS(err);
2403
Karl Schultz6addd812016-02-02 17:17:23 -07002404 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002405
2406 mem_alloc.allocationSize = mem_reqs.size;
2407
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002408 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002409 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002410
2411 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002412 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002413 ASSERT_VK_SUCCESS(err);
2414
2415 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002416 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002417
2418 // Try to bind free memory that has been freed
2419 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2420 // This may very well return an error.
2421 (void)err;
2422
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002423 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002424
Chia-I Wuf7458c52015-10-26 21:10:41 +08002425 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002426}
2427
Karl Schultz6addd812016-02-02 17:17:23 -07002428TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2429 VkResult err;
2430 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002431
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002433
Tobin Ehlisec598302015-09-15 15:02:17 -06002434 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002435
Karl Schultz6addd812016-02-02 17:17:23 -07002436 // Create an image object, allocate memory, destroy the object and then try
2437 // to bind it
2438 VkImage image;
2439 VkDeviceMemory mem;
2440 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002441
Karl Schultz6addd812016-02-02 17:17:23 -07002442 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2443 const int32_t tex_width = 32;
2444 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002445
2446 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002447 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2448 image_create_info.pNext = NULL;
2449 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2450 image_create_info.format = tex_format;
2451 image_create_info.extent.width = tex_width;
2452 image_create_info.extent.height = tex_height;
2453 image_create_info.extent.depth = 1;
2454 image_create_info.mipLevels = 1;
2455 image_create_info.arrayLayers = 1;
2456 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2457 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2458 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2459 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002460
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002461 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002462 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2463 mem_alloc.pNext = NULL;
2464 mem_alloc.allocationSize = 0;
2465 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002466
Chia-I Wuf7458c52015-10-26 21:10:41 +08002467 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002468 ASSERT_VK_SUCCESS(err);
2469
Karl Schultz6addd812016-02-02 17:17:23 -07002470 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002471
2472 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002473 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002474 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002475
2476 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002477 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002478 ASSERT_VK_SUCCESS(err);
2479
2480 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002481 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002482 ASSERT_VK_SUCCESS(err);
2483
2484 // Now Try to bind memory to this destroyed object
2485 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2486 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002487 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002488
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002489 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002490
Chia-I Wuf7458c52015-10-26 21:10:41 +08002491 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002492}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002493
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002494#endif // OBJ_TRACKER_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002495
Tobin Ehlis0788f522015-05-26 16:11:58 -06002496#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002497
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002498TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2499 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2500
2501 ASSERT_NO_FATAL_FAILURE(InitState());
2502 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2503
2504 VkVertexInputBindingDescription input_binding;
2505 memset(&input_binding, 0, sizeof(input_binding));
2506
2507 VkVertexInputAttributeDescription input_attribs;
2508 memset(&input_attribs, 0, sizeof(input_attribs));
2509
2510 // Pick a really bad format for this purpose and make sure it should fail
2511 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2512 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2513 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2514 printf("Format unsuitable for test; skipped.\n");
2515 return;
2516 }
2517
2518 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002519 char const *vsSource =
2520 "#version 450\n"
2521 "\n"
2522 "out gl_PerVertex {\n"
2523 " vec4 gl_Position;\n"
2524 "};\n"
2525 "void main(){\n"
2526 " gl_Position = vec4(1);\n"
2527 "}\n";
2528 char const *fsSource =
2529 "#version 450\n"
2530 "\n"
2531 "layout(location=0) out vec4 color;\n"
2532 "void main(){\n"
2533 " color = vec4(1);\n"
2534 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002535
2536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2537 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2538 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2539
2540 VkPipelineObj pipe(m_device);
2541 pipe.AddColorAttachment();
2542 pipe.AddShader(&vs);
2543 pipe.AddShader(&fs);
2544
2545 pipe.AddVertexInputBindings(&input_binding, 1);
2546 pipe.AddVertexInputAttribs(&input_attribs, 1);
2547
2548 VkDescriptorSetObj descriptorSet(m_device);
2549 descriptorSet.AppendDummy();
2550 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2551
2552 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2553
2554 m_errorMonitor->VerifyFound();
2555}
2556
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002557TEST_F(VkLayerTest, ImageSampleCounts) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002558 TEST_DESCRIPTION(
2559 "Use bad sample counts in image transfer calls to trigger "
2560 "validation errors.");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002561 ASSERT_NO_FATAL_FAILURE(InitState());
2562
2563 VkMemoryPropertyFlags reqs = 0;
2564 VkImageCreateInfo image_create_info = {};
2565 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2566 image_create_info.pNext = NULL;
2567 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2568 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2569 image_create_info.extent.width = 256;
2570 image_create_info.extent.height = 256;
2571 image_create_info.extent.depth = 1;
2572 image_create_info.mipLevels = 1;
2573 image_create_info.arrayLayers = 1;
2574 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2575 image_create_info.flags = 0;
2576
2577 VkImageBlit blit_region = {};
2578 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2579 blit_region.srcSubresource.baseArrayLayer = 0;
2580 blit_region.srcSubresource.layerCount = 1;
2581 blit_region.srcSubresource.mipLevel = 0;
2582 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2583 blit_region.dstSubresource.baseArrayLayer = 0;
2584 blit_region.dstSubresource.layerCount = 1;
2585 blit_region.dstSubresource.mipLevel = 0;
2586
2587 // Create two images, the source with sampleCount = 2, and attempt to blit
2588 // between them
2589 {
2590 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002591 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002592 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002593 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002594 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002595 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002596 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002597 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002598 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2600 "was created with a sample count "
2601 "of VK_SAMPLE_COUNT_2_BIT but "
2602 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002603 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2604 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002605 m_errorMonitor->VerifyFound();
2606 m_commandBuffer->EndCommandBuffer();
2607 }
2608
2609 // Create two images, the dest with sampleCount = 4, and attempt to blit
2610 // between them
2611 {
2612 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002613 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002614 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002615 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002616 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002617 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002618 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002619 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002620 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2622 "was created with a sample count "
2623 "of VK_SAMPLE_COUNT_4_BIT but "
2624 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002625 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2626 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002627 m_errorMonitor->VerifyFound();
2628 m_commandBuffer->EndCommandBuffer();
2629 }
2630
2631 VkBufferImageCopy copy_region = {};
2632 copy_region.bufferRowLength = 128;
2633 copy_region.bufferImageHeight = 128;
2634 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2635 copy_region.imageSubresource.layerCount = 1;
2636 copy_region.imageExtent.height = 64;
2637 copy_region.imageExtent.width = 64;
2638 copy_region.imageExtent.depth = 1;
2639
2640 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2641 // buffer to image
2642 {
2643 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002644 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2645 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002646 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002647 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002648 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002649 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2651 "was created with a sample count "
2652 "of VK_SAMPLE_COUNT_8_BIT but "
2653 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002654 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2655 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002656 m_errorMonitor->VerifyFound();
2657 m_commandBuffer->EndCommandBuffer();
2658 }
2659
2660 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2661 // image to buffer
2662 {
2663 vk_testing::Buffer dst_buffer;
2664 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2665 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002666 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002667 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002668 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002669 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2671 "was created with a sample count "
2672 "of VK_SAMPLE_COUNT_2_BIT but "
2673 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002674 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002675 dst_buffer.handle(), 1, &copy_region);
2676 m_errorMonitor->VerifyFound();
2677 m_commandBuffer->EndCommandBuffer();
2678 }
2679}
2680
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002681TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002682 ASSERT_NO_FATAL_FAILURE(InitState());
2683
2684 VkImageObj src_image(m_device);
2685 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2686 VkImageObj dst_image(m_device);
2687 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2688 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002689 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 -06002690
2691 VkImageBlit blitRegion = {};
2692 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2693 blitRegion.srcSubresource.baseArrayLayer = 0;
2694 blitRegion.srcSubresource.layerCount = 1;
2695 blitRegion.srcSubresource.mipLevel = 0;
2696 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2697 blitRegion.dstSubresource.baseArrayLayer = 0;
2698 blitRegion.dstSubresource.layerCount = 1;
2699 blitRegion.dstSubresource.mipLevel = 0;
2700
Dave Houlton34df4cb2016-12-01 16:43:06 -07002701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
2702
2703 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
2704 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002705
2706 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07002707 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002708 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
2709 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002710
2711 m_errorMonitor->VerifyFound();
2712
Dave Houlton34df4cb2016-12-01 16:43:06 -07002713 // Test should generate 2 VU failures
2714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
2715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002716
2717 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002718 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
2719 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002720
Dave Houlton34df4cb2016-12-01 16:43:06 -07002721 // TODO: Note that this only verifies that at least one of the VU enums was found
2722 // 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 -06002723 m_errorMonitor->VerifyFound();
2724
Tony Barbour552f6c02016-12-21 14:34:07 -07002725 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002726}
2727
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002728TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2729 VkResult err;
2730 bool pass;
2731
2732 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2733 ASSERT_NO_FATAL_FAILURE(InitState());
2734
2735 // If w/d/h granularity is 1, test is not meaningful
2736 // TODO: When virtual device limits are available, create a set of limits for this test that
2737 // will always have a granularity of > 1 for w, h, and d
2738 auto index = m_device->graphics_queue_node_index_;
2739 auto queue_family_properties = m_device->phy().queue_properties();
2740
2741 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2742 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2743 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2744 return;
2745 }
2746
2747 // Create two images of different types and try to copy between them
2748 VkImage srcImage;
2749 VkImage dstImage;
2750 VkDeviceMemory srcMem;
2751 VkDeviceMemory destMem;
2752 VkMemoryRequirements memReqs;
2753
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002754 VkImageCreateInfo image_create_info = {};
2755 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2756 image_create_info.pNext = NULL;
2757 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2758 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2759 image_create_info.extent.width = 32;
2760 image_create_info.extent.height = 32;
2761 image_create_info.extent.depth = 1;
2762 image_create_info.mipLevels = 1;
2763 image_create_info.arrayLayers = 4;
2764 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2765 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2766 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2767 image_create_info.flags = 0;
2768
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002769 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002770 ASSERT_VK_SUCCESS(err);
2771
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002772 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002773 ASSERT_VK_SUCCESS(err);
2774
2775 // Allocate memory
2776 VkMemoryAllocateInfo memAlloc = {};
2777 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2778 memAlloc.pNext = NULL;
2779 memAlloc.allocationSize = 0;
2780 memAlloc.memoryTypeIndex = 0;
2781
2782 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2783 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002784 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002785 ASSERT_TRUE(pass);
2786 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2787 ASSERT_VK_SUCCESS(err);
2788
2789 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2790 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002791 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002792 ASSERT_VK_SUCCESS(err);
2793 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2794 ASSERT_VK_SUCCESS(err);
2795
2796 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2797 ASSERT_VK_SUCCESS(err);
2798 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2799 ASSERT_VK_SUCCESS(err);
2800
Tony Barbour552f6c02016-12-21 14:34:07 -07002801 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002802 VkImageCopy copyRegion;
2803 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2804 copyRegion.srcSubresource.mipLevel = 0;
2805 copyRegion.srcSubresource.baseArrayLayer = 0;
2806 copyRegion.srcSubresource.layerCount = 1;
2807 copyRegion.srcOffset.x = 0;
2808 copyRegion.srcOffset.y = 0;
2809 copyRegion.srcOffset.z = 0;
2810 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2811 copyRegion.dstSubresource.mipLevel = 0;
2812 copyRegion.dstSubresource.baseArrayLayer = 0;
2813 copyRegion.dstSubresource.layerCount = 1;
2814 copyRegion.dstOffset.x = 0;
2815 copyRegion.dstOffset.y = 0;
2816 copyRegion.dstOffset.z = 0;
2817 copyRegion.extent.width = 1;
2818 copyRegion.extent.height = 1;
2819 copyRegion.extent.depth = 1;
2820
2821 // Introduce failure by setting srcOffset to a bad granularity value
2822 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2824 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002825 m_errorMonitor->VerifyFound();
2826
2827 // Introduce failure by setting extent to a bad granularity value
2828 copyRegion.srcOffset.y = 0;
2829 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2831 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002832 m_errorMonitor->VerifyFound();
2833
2834 // Now do some buffer/image copies
2835 vk_testing::Buffer buffer;
2836 VkMemoryPropertyFlags reqs = 0;
2837 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2838 VkBufferImageCopy region = {};
2839 region.bufferOffset = 0;
2840 region.bufferRowLength = 3;
2841 region.bufferImageHeight = 128;
2842 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2843 region.imageSubresource.layerCount = 1;
2844 region.imageExtent.height = 16;
2845 region.imageExtent.width = 16;
2846 region.imageExtent.depth = 1;
2847 region.imageOffset.x = 0;
2848 region.imageOffset.y = 0;
2849 region.imageOffset.z = 0;
2850
2851 // Introduce failure by setting bufferRowLength to a bad granularity value
2852 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2854 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2855 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002856 m_errorMonitor->VerifyFound();
2857 region.bufferRowLength = 128;
2858
2859 // Introduce failure by setting bufferOffset to a bad granularity value
2860 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2862 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2863 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002864 m_errorMonitor->VerifyFound();
2865 region.bufferOffset = 0;
2866
2867 // Introduce failure by setting bufferImageHeight to a bad granularity value
2868 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2870 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2871 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002872 m_errorMonitor->VerifyFound();
2873 region.bufferImageHeight = 128;
2874
2875 // Introduce failure by setting imageExtent to a bad granularity value
2876 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2878 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2879 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002880 m_errorMonitor->VerifyFound();
2881 region.imageExtent.width = 16;
2882
2883 // Introduce failure by setting imageOffset to a bad granularity value
2884 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2886 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2887 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002888 m_errorMonitor->VerifyFound();
2889
Tony Barbour552f6c02016-12-21 14:34:07 -07002890 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002891
2892 vkDestroyImage(m_device->device(), srcImage, NULL);
2893 vkDestroyImage(m_device->device(), dstImage, NULL);
2894 vkFreeMemory(m_device->device(), srcMem, NULL);
2895 vkFreeMemory(m_device->device(), destMem, NULL);
2896}
2897
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002898TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002899 TEST_DESCRIPTION(
2900 "Submit command buffer created using one queue family and "
2901 "attempt to submit them on a queue created in a different "
2902 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002903
Cody Northropc31a84f2016-08-22 10:41:47 -06002904 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002905 // This test is meaningless unless we have multiple queue families
2906 auto queue_family_properties = m_device->phy().queue_properties();
2907 if (queue_family_properties.size() < 2) {
2908 return;
2909 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002911 // Get safe index of another queue family
2912 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2913 ASSERT_NO_FATAL_FAILURE(InitState());
2914 // Create a second queue using a different queue family
2915 VkQueue other_queue;
2916 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2917
2918 // Record an empty cmd buffer
2919 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2920 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2921 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2922 vkEndCommandBuffer(m_commandBuffer->handle());
2923
2924 // And submit on the wrong queue
2925 VkSubmitInfo submit_info = {};
2926 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2927 submit_info.commandBufferCount = 1;
2928 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002929 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002930
2931 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002932}
2933
Chris Forbes4c24a922016-11-16 08:59:10 +13002934TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2935 ASSERT_NO_FATAL_FAILURE(InitState());
2936
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002937 // There are no attachments, but refer to attachment 0.
2938 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002939 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002940 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002941 };
2942
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002943 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002944 VkRenderPass rp;
2945
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002946 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002948 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2949 m_errorMonitor->VerifyFound();
2950}
2951
Chris Forbesa58c4522016-09-28 15:19:39 +13002952TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2953 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2954 ASSERT_NO_FATAL_FAILURE(InitState());
2955
2956 // A renderpass with two subpasses, both writing the same attachment.
2957 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002958 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2959 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
2960 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13002961 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002962 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13002963 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002964 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
2965 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13002966 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002967 VkSubpassDependency dep = {0,
2968 1,
2969 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2970 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2971 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2972 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2973 VK_DEPENDENCY_BY_REGION_BIT};
2974 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13002975 VkRenderPass rp;
2976 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2977 ASSERT_VK_SUCCESS(err);
2978
2979 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002980 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 +13002981 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2982
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002983 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13002984 VkFramebuffer fb;
2985 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2986 ASSERT_VK_SUCCESS(err);
2987
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002988 char const *vsSource =
2989 "#version 450\n"
2990 "void main() { gl_Position = vec4(1); }\n";
2991 char const *fsSource =
2992 "#version 450\n"
2993 "layout(location=0) out vec4 color;\n"
2994 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13002995
2996 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2997 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2998 VkPipelineObj pipe(m_device);
2999 pipe.AddColorAttachment();
3000 pipe.AddShader(&vs);
3001 pipe.AddShader(&fs);
3002 VkViewport view_port = {};
3003 m_viewports.push_back(view_port);
3004 pipe.SetViewport(m_viewports);
3005 VkRect2D rect = {};
3006 m_scissors.push_back(rect);
3007 pipe.SetScissor(m_scissors);
3008
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003009 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003010 VkPipelineLayout pl;
3011 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3012 ASSERT_VK_SUCCESS(err);
3013 pipe.CreateVKPipeline(pl, rp);
3014
Tony Barbour552f6c02016-12-21 14:34:07 -07003015 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003016
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003017 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3018 nullptr,
3019 rp,
3020 fb,
3021 {{
3022 0, 0,
3023 },
3024 {32, 32}},
3025 0,
3026 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003027
3028 // subtest 1: bind in the wrong subpass
3029 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3030 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003031 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 +13003032 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3033 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3034 m_errorMonitor->VerifyFound();
3035
3036 vkCmdEndRenderPass(m_commandBuffer->handle());
3037
3038 // subtest 2: bind in correct subpass, then transition to next subpass
3039 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3040 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3041 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003042 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 +13003043 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3044 m_errorMonitor->VerifyFound();
3045
3046 vkCmdEndRenderPass(m_commandBuffer->handle());
3047
Tony Barbour552f6c02016-12-21 14:34:07 -07003048 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003049
3050 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3051 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3052 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3053}
3054
Tony Barbour4e919972016-08-09 13:27:40 -06003055TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003056 TEST_DESCRIPTION(
3057 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3058 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003059 ASSERT_NO_FATAL_FAILURE(InitState());
3060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3061
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3063 "Cannot execute a render pass with renderArea "
3064 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003065
3066 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3067 m_renderPassBeginInfo.renderArea.extent.width = 257;
3068 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003069 m_commandBuffer->BeginCommandBuffer();
3070 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003071 m_errorMonitor->VerifyFound();
3072}
3073
3074TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003075 TEST_DESCRIPTION(
3076 "Generate INDEPENDENT_BLEND by disabling independent "
3077 "blend and then specifying different blend states for two "
3078 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003079 VkPhysicalDeviceFeatures features = {};
3080 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003081 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003082
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3084 "Invalid Pipeline CreateInfo: If independent blend feature not "
3085 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003086
Cody Northropc31a84f2016-08-22 10:41:47 -06003087 VkDescriptorSetObj descriptorSet(m_device);
3088 descriptorSet.AppendDummy();
3089 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003090
Cody Northropc31a84f2016-08-22 10:41:47 -06003091 VkPipelineObj pipeline(m_device);
3092 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003093 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003094 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003095
Cody Northropc31a84f2016-08-22 10:41:47 -06003096 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3097 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3098 att_state1.blendEnable = VK_TRUE;
3099 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3100 att_state2.blendEnable = VK_FALSE;
3101 pipeline.AddColorAttachment(0, &att_state1);
3102 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003103 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003104 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003105}
3106
Chris Forbes26ec2122016-11-29 08:58:33 +13003107#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003108TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3109 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3110 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003111 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003112
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3114 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003115
3116 // Create a renderPass with a single color attachment
3117 VkAttachmentReference attach = {};
3118 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3119 VkSubpassDescription subpass = {};
3120 VkRenderPassCreateInfo rpci = {};
3121 rpci.subpassCount = 1;
3122 rpci.pSubpasses = &subpass;
3123 rpci.attachmentCount = 1;
3124 VkAttachmentDescription attach_desc = {};
3125 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3126 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3127 rpci.pAttachments = &attach_desc;
3128 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3129 VkRenderPass rp;
3130 subpass.pDepthStencilAttachment = &attach;
3131 subpass.pColorAttachments = NULL;
3132 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3133 m_errorMonitor->VerifyFound();
3134}
Chris Forbes26ec2122016-11-29 08:58:33 +13003135#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003136
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003137TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003138 TEST_DESCRIPTION(
3139 "Create a framebuffer where a subpass has a preserve "
3140 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003141
3142 ASSERT_NO_FATAL_FAILURE(InitState());
3143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3144
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003146
3147 VkAttachmentReference color_attach = {};
3148 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3149 color_attach.attachment = 0;
3150 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3151 VkSubpassDescription subpass = {};
3152 subpass.colorAttachmentCount = 1;
3153 subpass.pColorAttachments = &color_attach;
3154 subpass.preserveAttachmentCount = 1;
3155 subpass.pPreserveAttachments = &preserve_attachment;
3156
3157 VkRenderPassCreateInfo rpci = {};
3158 rpci.subpassCount = 1;
3159 rpci.pSubpasses = &subpass;
3160 rpci.attachmentCount = 1;
3161 VkAttachmentDescription attach_desc = {};
3162 attach_desc.format = VK_FORMAT_UNDEFINED;
3163 rpci.pAttachments = &attach_desc;
3164 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3165 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003166 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003167
3168 m_errorMonitor->VerifyFound();
3169
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003170 if (result == VK_SUCCESS) {
3171 vkDestroyRenderPass(m_device->device(), rp, NULL);
3172 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003173}
3174
Chris Forbesc5389742016-06-29 11:49:23 +12003175TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003176 TEST_DESCRIPTION(
3177 "Ensure that CreateRenderPass produces a validation error "
3178 "when the source of a subpass multisample resolve "
3179 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003180
Chris Forbesc5389742016-06-29 11:49:23 +12003181 ASSERT_NO_FATAL_FAILURE(InitState());
3182
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3184 "Subpass 0 requests multisample resolve from attachment 0 which has "
3185 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003186
3187 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003188 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3189 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3190 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3191 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3192 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3193 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003194 };
3195
3196 VkAttachmentReference color = {
3197 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3198 };
3199
3200 VkAttachmentReference resolve = {
3201 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3202 };
3203
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003204 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003205
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003206 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003207
3208 VkRenderPass rp;
3209 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3210
3211 m_errorMonitor->VerifyFound();
3212
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003213 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003214}
3215
3216TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003217 TEST_DESCRIPTION(
3218 "Ensure CreateRenderPass produces a validation error "
3219 "when a subpass multisample resolve operation is "
3220 "requested, and the destination of that resolve has "
3221 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003222
Chris Forbesc5389742016-06-29 11:49:23 +12003223 ASSERT_NO_FATAL_FAILURE(InitState());
3224
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3226 "Subpass 0 requests multisample resolve into attachment 1, which "
3227 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003228
3229 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003230 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3231 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3232 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3233 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3234 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3235 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003236 };
3237
3238 VkAttachmentReference color = {
3239 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3240 };
3241
3242 VkAttachmentReference resolve = {
3243 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3244 };
3245
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003246 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003247
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003248 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003249
3250 VkRenderPass rp;
3251 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3252
3253 m_errorMonitor->VerifyFound();
3254
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003255 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003256}
3257
Chris Forbes3f128ef2016-06-29 14:58:53 +12003258TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003259 TEST_DESCRIPTION(
3260 "Ensure CreateRenderPass produces a validation error "
3261 "when the color and depth attachments used by a subpass "
3262 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003263
Chris Forbes3f128ef2016-06-29 14:58:53 +12003264 ASSERT_NO_FATAL_FAILURE(InitState());
3265
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3267 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003268
3269 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003270 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3271 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3272 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3273 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3274 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3275 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003276 };
3277
3278 VkAttachmentReference color[] = {
3279 {
3280 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3281 },
3282 {
3283 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3284 },
3285 };
3286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003287 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003289 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003290
3291 VkRenderPass rp;
3292 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3293
3294 m_errorMonitor->VerifyFound();
3295
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003296 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003297}
3298
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003299TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003300 TEST_DESCRIPTION(
3301 "Hit errors when attempting to create a framebuffer :\n"
3302 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3303 " 2. Use a color image as depthStencil attachment\n"
3304 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3305 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3306 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3307 " 6. Framebuffer attachment where dimensions don't match\n"
3308 " 7. Framebuffer attachment w/o identity swizzle\n"
3309 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003310
3311 ASSERT_NO_FATAL_FAILURE(InitState());
3312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3313
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3315 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3316 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003317
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003318 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003319 VkAttachmentReference attach = {};
3320 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3321 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003322 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003323 VkRenderPassCreateInfo rpci = {};
3324 rpci.subpassCount = 1;
3325 rpci.pSubpasses = &subpass;
3326 rpci.attachmentCount = 1;
3327 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003328 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003329 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003330 rpci.pAttachments = &attach_desc;
3331 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3332 VkRenderPass rp;
3333 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3334 ASSERT_VK_SUCCESS(err);
3335
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003336 VkImageView ivs[2];
3337 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3338 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003339 VkFramebufferCreateInfo fb_info = {};
3340 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3341 fb_info.pNext = NULL;
3342 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003343 // Set mis-matching attachmentCount
3344 fb_info.attachmentCount = 2;
3345 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003346 fb_info.width = 100;
3347 fb_info.height = 100;
3348 fb_info.layers = 1;
3349
3350 VkFramebuffer fb;
3351 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3352
3353 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003354 if (err == VK_SUCCESS) {
3355 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3356 }
3357 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003358
3359 // Create a renderPass with a depth-stencil attachment created with
3360 // IMAGE_USAGE_COLOR_ATTACHMENT
3361 // Add our color attachment to pDepthStencilAttachment
3362 subpass.pDepthStencilAttachment = &attach;
3363 subpass.pColorAttachments = NULL;
3364 VkRenderPass rp_ds;
3365 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3366 ASSERT_VK_SUCCESS(err);
3367 // Set correct attachment count, but attachment has COLOR usage bit set
3368 fb_info.attachmentCount = 1;
3369 fb_info.renderPass = rp_ds;
3370
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003372 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3373
3374 m_errorMonitor->VerifyFound();
3375 if (err == VK_SUCCESS) {
3376 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3377 }
3378 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003379
3380 // Create new renderpass with alternate attachment format from fb
3381 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3382 subpass.pDepthStencilAttachment = NULL;
3383 subpass.pColorAttachments = &attach;
3384 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3385 ASSERT_VK_SUCCESS(err);
3386
3387 // Cause error due to mis-matched formats between rp & fb
3388 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3389 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3391 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003392 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3393
3394 m_errorMonitor->VerifyFound();
3395 if (err == VK_SUCCESS) {
3396 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3397 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003398 vkDestroyRenderPass(m_device->device(), rp, NULL);
3399
3400 // Create new renderpass with alternate sample count from fb
3401 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3402 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3403 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3404 ASSERT_VK_SUCCESS(err);
3405
3406 // Cause error due to mis-matched sample count between rp & fb
3407 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3409 " has VK_SAMPLE_COUNT_1_BIT samples "
3410 "that do not match the "
3411 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003412 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3413
3414 m_errorMonitor->VerifyFound();
3415 if (err == VK_SUCCESS) {
3416 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3417 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003418
3419 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003420
3421 // Create a custom imageView with non-1 mip levels
3422 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003423 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 -06003424 ASSERT_TRUE(image.initialized());
3425
3426 VkImageView view;
3427 VkImageViewCreateInfo ivci = {};
3428 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3429 ivci.image = image.handle();
3430 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3431 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3432 ivci.subresourceRange.layerCount = 1;
3433 ivci.subresourceRange.baseMipLevel = 0;
3434 // Set level count 2 (only 1 is allowed for FB attachment)
3435 ivci.subresourceRange.levelCount = 2;
3436 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3437 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3438 ASSERT_VK_SUCCESS(err);
3439 // Re-create renderpass to have matching sample count
3440 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3441 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3442 ASSERT_VK_SUCCESS(err);
3443
3444 fb_info.renderPass = rp;
3445 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003447 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3448
3449 m_errorMonitor->VerifyFound();
3450 if (err == VK_SUCCESS) {
3451 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3452 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003453 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003454 // Update view to original color buffer and grow FB dimensions too big
3455 fb_info.pAttachments = ivs;
3456 fb_info.height = 1024;
3457 fb_info.width = 1024;
3458 fb_info.layers = 2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3460 " Attachment dimensions must be at "
3461 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003462 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3463
3464 m_errorMonitor->VerifyFound();
3465 if (err == VK_SUCCESS) {
3466 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3467 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003468 // Create view attachment with non-identity swizzle
3469 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3470 ivci.image = image.handle();
3471 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3472 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3473 ivci.subresourceRange.layerCount = 1;
3474 ivci.subresourceRange.baseMipLevel = 0;
3475 ivci.subresourceRange.levelCount = 1;
3476 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3477 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3478 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3479 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3480 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3481 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3482 ASSERT_VK_SUCCESS(err);
3483
3484 fb_info.pAttachments = &view;
3485 fb_info.height = 100;
3486 fb_info.width = 100;
3487 fb_info.layers = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3489 " has non-identy swizzle. All "
3490 "framebuffer attachments must have "
3491 "been created with the identity "
3492 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003493 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3494
3495 m_errorMonitor->VerifyFound();
3496 if (err == VK_SUCCESS) {
3497 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3498 }
3499 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003500 // reset attachment to color attachment
3501 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003502
3503 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003504 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003505 fb_info.height = 100;
3506 fb_info.layers = 1;
3507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
3508 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3509
3510 m_errorMonitor->VerifyFound();
3511 if (err == VK_SUCCESS) {
3512 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3513 }
3514
3515 // Request fb that exceeds max height
3516 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003517 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003518 fb_info.layers = 1;
3519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
3520 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3521
3522 m_errorMonitor->VerifyFound();
3523 if (err == VK_SUCCESS) {
3524 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3525 }
3526
3527 // Request fb that exceeds max layers
3528 fb_info.width = 100;
3529 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003530 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003532 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3533
3534 m_errorMonitor->VerifyFound();
3535 if (err == VK_SUCCESS) {
3536 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3537 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003538
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003539 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003540}
3541
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003542TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003543 TEST_DESCRIPTION(
3544 "Run a simple draw calls to validate failure when Depth Bias dynamic "
3545 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003546
Cody Northropc31a84f2016-08-22 10:41:47 -06003547 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003548 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3550 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003551 m_errorMonitor->VerifyFound();
3552}
3553
3554TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003555 TEST_DESCRIPTION(
3556 "Run a simple draw calls to validate failure when Line Width dynamic "
3557 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003558
Cody Northropc31a84f2016-08-22 10:41:47 -06003559 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003560 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3562 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003563 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003564}
3565
3566TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003567 TEST_DESCRIPTION(
3568 "Run a simple draw calls to validate failure when Viewport dynamic "
3569 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003570
Cody Northropc31a84f2016-08-22 10:41:47 -06003571 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003572 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003573 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3574 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003575 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003576 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003577}
3578
3579TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003580 TEST_DESCRIPTION(
3581 "Run a simple draw calls to validate failure when Scissor dynamic "
3582 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003583
Cody Northropc31a84f2016-08-22 10:41:47 -06003584 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003585 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3587 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003588 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003589 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003590}
3591
Cortd713fe82016-07-27 09:51:27 -07003592TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003593 TEST_DESCRIPTION(
3594 "Run a simple draw calls to validate failure when Blend Constants "
3595 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003596
3597 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003598 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3600 "Dynamic blend constants state not set for this command buffer");
3601 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003602 m_errorMonitor->VerifyFound();
3603}
3604
3605TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003606 TEST_DESCRIPTION(
3607 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
3608 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003609
3610 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003611 if (!m_device->phy().features().depthBounds) {
3612 printf("Device does not support depthBounds test; skipped.\n");
3613 return;
3614 }
3615 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3617 "Dynamic depth bounds state not set for this command buffer");
3618 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003619 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003620}
3621
3622TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003623 TEST_DESCRIPTION(
3624 "Run a simple draw calls to validate failure when Stencil Read dynamic "
3625 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003626
3627 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003628 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3630 "Dynamic stencil read mask state not set for this command buffer");
3631 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003632 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003633}
3634
3635TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003636 TEST_DESCRIPTION(
3637 "Run a simple draw calls to validate failure when Stencil Write dynamic"
3638 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003639
3640 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003641 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3643 "Dynamic stencil write mask state not set for this command buffer");
3644 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003645 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003646}
3647
3648TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003649 TEST_DESCRIPTION(
3650 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
3651 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003652
3653 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003654 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3656 "Dynamic stencil reference state not set for this command buffer");
3657 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003658 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003659}
3660
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003661TEST_F(VkLayerTest, IndexBufferNotBound) {
3662 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003663
3664 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3666 "Index buffer object not bound to this command buffer when Indexed ");
3667 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003668 m_errorMonitor->VerifyFound();
3669}
3670
Karl Schultz6addd812016-02-02 17:17:23 -07003671TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3673 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3674 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003675
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003676 ASSERT_NO_FATAL_FAILURE(InitState());
3677 ASSERT_NO_FATAL_FAILURE(InitViewport());
3678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3679
Karl Schultz6addd812016-02-02 17:17:23 -07003680 // We luck out b/c by default the framework creates CB w/ the
3681 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07003682 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003683 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07003684 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003685
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003686 // Bypass framework since it does the waits automatically
3687 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003688 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003689 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3690 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003691 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003692 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003693 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003694 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003695 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003696 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003697 submit_info.pSignalSemaphores = NULL;
3698
Chris Forbes40028e22016-06-13 09:59:34 +12003699 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003700 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003701 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003702
Karl Schultz6addd812016-02-02 17:17:23 -07003703 // Cause validation error by re-submitting cmd buffer that should only be
3704 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003705 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003706 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003708 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003709}
3710
Karl Schultz6addd812016-02-02 17:17:23 -07003711TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003712 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003713 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003714
3715 ASSERT_NO_FATAL_FAILURE(InitState());
3716 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003717
Karl Schultz6addd812016-02-02 17:17:23 -07003718 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3719 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003720 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003721 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003722 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003723
3724 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003725 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3726 ds_pool_ci.pNext = NULL;
3727 ds_pool_ci.flags = 0;
3728 ds_pool_ci.maxSets = 1;
3729 ds_pool_ci.poolSizeCount = 1;
3730 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003731
3732 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003733 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003734 ASSERT_VK_SUCCESS(err);
3735
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003736 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3737 dsl_binding_samp.binding = 0;
3738 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3739 dsl_binding_samp.descriptorCount = 1;
3740 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3741 dsl_binding_samp.pImmutableSamplers = NULL;
3742
3743 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3744 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3745 ds_layout_ci.pNext = NULL;
3746 ds_layout_ci.bindingCount = 1;
3747 ds_layout_ci.pBindings = &dsl_binding_samp;
3748
3749 VkDescriptorSetLayout ds_layout_samp;
3750 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3751 ASSERT_VK_SUCCESS(err);
3752
3753 // Try to allocate 2 sets when pool only has 1 set
3754 VkDescriptorSet descriptor_sets[2];
3755 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3756 VkDescriptorSetAllocateInfo alloc_info = {};
3757 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3758 alloc_info.descriptorSetCount = 2;
3759 alloc_info.descriptorPool = ds_pool;
3760 alloc_info.pSetLayouts = set_layouts;
3761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3762 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3763 m_errorMonitor->VerifyFound();
3764
3765 alloc_info.descriptorSetCount = 1;
3766 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003767 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003768 dsl_binding.binding = 0;
3769 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3770 dsl_binding.descriptorCount = 1;
3771 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3772 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003773
Karl Schultz6addd812016-02-02 17:17:23 -07003774 ds_layout_ci.bindingCount = 1;
3775 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003776
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003777 VkDescriptorSetLayout ds_layout_ub;
3778 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003779 ASSERT_VK_SUCCESS(err);
3780
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003781 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003782 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003783 alloc_info.pSetLayouts = &ds_layout_ub;
3784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3785 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003786
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003787 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003788
Karl Schultz2825ab92016-12-02 08:23:14 -07003789 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003790 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003791 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003792}
3793
Karl Schultz6addd812016-02-02 17:17:23 -07003794TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3795 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003796
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07003797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003798
Tobin Ehlise735c692015-10-08 13:13:50 -06003799 ASSERT_NO_FATAL_FAILURE(InitState());
3800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003801
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003802 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003803 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3804 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003805
3806 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003807 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3808 ds_pool_ci.pNext = NULL;
3809 ds_pool_ci.maxSets = 1;
3810 ds_pool_ci.poolSizeCount = 1;
3811 ds_pool_ci.flags = 0;
3812 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3813 // app can only call vkResetDescriptorPool on this pool.;
3814 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003815
3816 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003817 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003818 ASSERT_VK_SUCCESS(err);
3819
3820 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003821 dsl_binding.binding = 0;
3822 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3823 dsl_binding.descriptorCount = 1;
3824 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3825 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003826
3827 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003828 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3829 ds_layout_ci.pNext = NULL;
3830 ds_layout_ci.bindingCount = 1;
3831 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003832
3833 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003834 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003835 ASSERT_VK_SUCCESS(err);
3836
3837 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003838 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003839 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003840 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003841 alloc_info.descriptorPool = ds_pool;
3842 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003843 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003844 ASSERT_VK_SUCCESS(err);
3845
3846 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003847 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003848
Chia-I Wuf7458c52015-10-26 21:10:41 +08003849 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3850 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003851}
3852
Karl Schultz6addd812016-02-02 17:17:23 -07003853TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003854 // Attempt to clear Descriptor Pool with bad object.
3855 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003856
3857 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003859 uint64_t fake_pool_handle = 0xbaad6001;
3860 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3861 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003862 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003863}
3864
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003865TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003866 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3867 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003868 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003869 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003870
3871 uint64_t fake_set_handle = 0xbaad6001;
3872 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003873 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003875
3876 ASSERT_NO_FATAL_FAILURE(InitState());
3877
3878 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3879 layout_bindings[0].binding = 0;
3880 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3881 layout_bindings[0].descriptorCount = 1;
3882 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3883 layout_bindings[0].pImmutableSamplers = NULL;
3884
3885 VkDescriptorSetLayout descriptor_set_layout;
3886 VkDescriptorSetLayoutCreateInfo dslci = {};
3887 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3888 dslci.pNext = NULL;
3889 dslci.bindingCount = 1;
3890 dslci.pBindings = layout_bindings;
3891 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003892 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003893
3894 VkPipelineLayout pipeline_layout;
3895 VkPipelineLayoutCreateInfo plci = {};
3896 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3897 plci.pNext = NULL;
3898 plci.setLayoutCount = 1;
3899 plci.pSetLayouts = &descriptor_set_layout;
3900 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003901 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003902
Tony Barbour552f6c02016-12-21 14:34:07 -07003903 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003904 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3905 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003906 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07003907 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06003908 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3909 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003910}
3911
Karl Schultz6addd812016-02-02 17:17:23 -07003912TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003913 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3914 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003915 uint64_t fake_layout_handle = 0xbaad6001;
3916 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003918 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003919 VkPipelineLayout pipeline_layout;
3920 VkPipelineLayoutCreateInfo plci = {};
3921 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3922 plci.pNext = NULL;
3923 plci.setLayoutCount = 1;
3924 plci.pSetLayouts = &bad_layout;
3925 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3926
3927 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003928}
3929
Mark Muellerd4914412016-06-13 17:52:06 -06003930TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003931 TEST_DESCRIPTION(
3932 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3933 "1) A uniform buffer update must have a valid buffer index."
3934 "2) When using an array of descriptors in a single WriteDescriptor,"
3935 " the descriptor types and stageflags must all be the same."
3936 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06003937
Mike Weiblena6666382017-01-05 15:16:11 -07003938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06003939
3940 ASSERT_NO_FATAL_FAILURE(InitState());
3941 VkDescriptorPoolSize ds_type_count[4] = {};
3942 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3943 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003944 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003945 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003946 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003947 ds_type_count[2].descriptorCount = 1;
3948 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3949 ds_type_count[3].descriptorCount = 1;
3950
3951 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3952 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3953 ds_pool_ci.maxSets = 1;
3954 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3955 ds_pool_ci.pPoolSizes = ds_type_count;
3956
3957 VkDescriptorPool ds_pool;
3958 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3959 ASSERT_VK_SUCCESS(err);
3960
Mark Muellerb9896722016-06-16 09:54:29 -06003961 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003962 layout_binding[0].binding = 0;
3963 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3964 layout_binding[0].descriptorCount = 1;
3965 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3966 layout_binding[0].pImmutableSamplers = NULL;
3967
3968 layout_binding[1].binding = 1;
3969 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3970 layout_binding[1].descriptorCount = 1;
3971 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3972 layout_binding[1].pImmutableSamplers = NULL;
3973
3974 VkSamplerCreateInfo sampler_ci = {};
3975 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3976 sampler_ci.pNext = NULL;
3977 sampler_ci.magFilter = VK_FILTER_NEAREST;
3978 sampler_ci.minFilter = VK_FILTER_NEAREST;
3979 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3980 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3981 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3982 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3983 sampler_ci.mipLodBias = 1.0;
3984 sampler_ci.anisotropyEnable = VK_FALSE;
3985 sampler_ci.maxAnisotropy = 1;
3986 sampler_ci.compareEnable = VK_FALSE;
3987 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3988 sampler_ci.minLod = 1.0;
3989 sampler_ci.maxLod = 1.0;
3990 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3991 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3992 VkSampler sampler;
3993
3994 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3995 ASSERT_VK_SUCCESS(err);
3996
3997 layout_binding[2].binding = 2;
3998 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3999 layout_binding[2].descriptorCount = 1;
4000 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4001 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4002
Mark Muellerd4914412016-06-13 17:52:06 -06004003 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4004 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4005 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4006 ds_layout_ci.pBindings = layout_binding;
4007 VkDescriptorSetLayout ds_layout;
4008 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4009 ASSERT_VK_SUCCESS(err);
4010
4011 VkDescriptorSetAllocateInfo alloc_info = {};
4012 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4013 alloc_info.descriptorSetCount = 1;
4014 alloc_info.descriptorPool = ds_pool;
4015 alloc_info.pSetLayouts = &ds_layout;
4016 VkDescriptorSet descriptorSet;
4017 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4018 ASSERT_VK_SUCCESS(err);
4019
4020 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4021 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4022 pipeline_layout_ci.pNext = NULL;
4023 pipeline_layout_ci.setLayoutCount = 1;
4024 pipeline_layout_ci.pSetLayouts = &ds_layout;
4025
4026 VkPipelineLayout pipeline_layout;
4027 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4028 ASSERT_VK_SUCCESS(err);
4029
Mark Mueller5c838ce2016-06-16 09:54:29 -06004030 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004031 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4032 descriptor_write.dstSet = descriptorSet;
4033 descriptor_write.dstBinding = 0;
4034 descriptor_write.descriptorCount = 1;
4035 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4036
Mark Mueller5c838ce2016-06-16 09:54:29 -06004037 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004038 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4039 m_errorMonitor->VerifyFound();
4040
4041 // Create a buffer to update the descriptor with
4042 uint32_t qfi = 0;
4043 VkBufferCreateInfo buffCI = {};
4044 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4045 buffCI.size = 1024;
4046 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4047 buffCI.queueFamilyIndexCount = 1;
4048 buffCI.pQueueFamilyIndices = &qfi;
4049
4050 VkBuffer dyub;
4051 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4052 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004053
Tony Barboure132c5f2016-12-12 11:50:20 -07004054 VkDeviceMemory mem;
4055 VkMemoryRequirements mem_reqs;
4056 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4057
4058 VkMemoryAllocateInfo mem_alloc_info = {};
4059 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4060 mem_alloc_info.allocationSize = mem_reqs.size;
4061 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4062 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4063 ASSERT_VK_SUCCESS(err);
4064
4065 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4066 ASSERT_VK_SUCCESS(err);
4067
4068 VkDescriptorBufferInfo buffInfo[2] = {};
4069 buffInfo[0].buffer = dyub;
4070 buffInfo[0].offset = 0;
4071 buffInfo[0].range = 1024;
4072 buffInfo[1].buffer = dyub;
4073 buffInfo[1].offset = 0;
4074 buffInfo[1].range = 1024;
4075 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004076 descriptor_write.descriptorCount = 2;
4077
Mark Mueller5c838ce2016-06-16 09:54:29 -06004078 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004080 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4081 m_errorMonitor->VerifyFound();
4082
Mark Mueller5c838ce2016-06-16 09:54:29 -06004083 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4084 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004085 descriptor_write.dstBinding = 1;
4086 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004087
Mark Mueller5c838ce2016-06-16 09:54:29 -06004088 // Make pImageInfo index non-null to avoid complaints of it missing
4089 VkDescriptorImageInfo imageInfo = {};
4090 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4091 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004093 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4094 m_errorMonitor->VerifyFound();
4095
Mark Muellerd4914412016-06-13 17:52:06 -06004096 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004097 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004098 vkDestroySampler(m_device->device(), sampler, NULL);
4099 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4100 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4101 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4102}
4103
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004104TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004105 TEST_DESCRIPTION(
4106 "Attempt to draw with a command buffer that is invalid "
4107 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004108 ASSERT_NO_FATAL_FAILURE(InitState());
4109
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004110 VkBuffer buffer;
4111 VkDeviceMemory mem;
4112 VkMemoryRequirements mem_reqs;
4113
4114 VkBufferCreateInfo buf_info = {};
4115 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004116 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004117 buf_info.size = 256;
4118 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4119 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4120 ASSERT_VK_SUCCESS(err);
4121
4122 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4123
4124 VkMemoryAllocateInfo alloc_info = {};
4125 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4126 alloc_info.allocationSize = 256;
4127 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004128 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 -06004129 if (!pass) {
4130 vkDestroyBuffer(m_device->device(), buffer, NULL);
4131 return;
4132 }
4133 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4134 ASSERT_VK_SUCCESS(err);
4135
4136 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4137 ASSERT_VK_SUCCESS(err);
4138
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004139 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004140 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004141 m_commandBuffer->EndCommandBuffer();
4142
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004144 // Destroy buffer dependency prior to submit to cause ERROR
4145 vkDestroyBuffer(m_device->device(), buffer, NULL);
4146
4147 VkSubmitInfo submit_info = {};
4148 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4149 submit_info.commandBufferCount = 1;
4150 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4151 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4152
4153 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004154 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004155 vkFreeMemory(m_device->handle(), mem, NULL);
4156}
4157
Tobin Ehlisea413442016-09-28 10:23:59 -06004158TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4159 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4160
4161 ASSERT_NO_FATAL_FAILURE(InitState());
4162 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4163
4164 VkDescriptorPoolSize ds_type_count;
4165 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4166 ds_type_count.descriptorCount = 1;
4167
4168 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4169 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4170 ds_pool_ci.maxSets = 1;
4171 ds_pool_ci.poolSizeCount = 1;
4172 ds_pool_ci.pPoolSizes = &ds_type_count;
4173
4174 VkDescriptorPool ds_pool;
4175 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4176 ASSERT_VK_SUCCESS(err);
4177
4178 VkDescriptorSetLayoutBinding layout_binding;
4179 layout_binding.binding = 0;
4180 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4181 layout_binding.descriptorCount = 1;
4182 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4183 layout_binding.pImmutableSamplers = NULL;
4184
4185 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4186 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4187 ds_layout_ci.bindingCount = 1;
4188 ds_layout_ci.pBindings = &layout_binding;
4189 VkDescriptorSetLayout ds_layout;
4190 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4191 ASSERT_VK_SUCCESS(err);
4192
4193 VkDescriptorSetAllocateInfo alloc_info = {};
4194 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4195 alloc_info.descriptorSetCount = 1;
4196 alloc_info.descriptorPool = ds_pool;
4197 alloc_info.pSetLayouts = &ds_layout;
4198 VkDescriptorSet descriptor_set;
4199 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4200 ASSERT_VK_SUCCESS(err);
4201
4202 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4203 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4204 pipeline_layout_ci.pNext = NULL;
4205 pipeline_layout_ci.setLayoutCount = 1;
4206 pipeline_layout_ci.pSetLayouts = &ds_layout;
4207
4208 VkPipelineLayout pipeline_layout;
4209 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4210 ASSERT_VK_SUCCESS(err);
4211
4212 VkBuffer buffer;
4213 uint32_t queue_family_index = 0;
4214 VkBufferCreateInfo buffer_create_info = {};
4215 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4216 buffer_create_info.size = 1024;
4217 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4218 buffer_create_info.queueFamilyIndexCount = 1;
4219 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4220
4221 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4222 ASSERT_VK_SUCCESS(err);
4223
4224 VkMemoryRequirements memory_reqs;
4225 VkDeviceMemory buffer_memory;
4226
4227 VkMemoryAllocateInfo memory_info = {};
4228 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4229 memory_info.allocationSize = 0;
4230 memory_info.memoryTypeIndex = 0;
4231
4232 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4233 memory_info.allocationSize = memory_reqs.size;
4234 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4235 ASSERT_TRUE(pass);
4236
4237 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4238 ASSERT_VK_SUCCESS(err);
4239 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4240 ASSERT_VK_SUCCESS(err);
4241
4242 VkBufferView view;
4243 VkBufferViewCreateInfo bvci = {};
4244 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4245 bvci.buffer = buffer;
4246 bvci.format = VK_FORMAT_R8_UNORM;
4247 bvci.range = VK_WHOLE_SIZE;
4248
4249 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4250 ASSERT_VK_SUCCESS(err);
4251
4252 VkWriteDescriptorSet descriptor_write = {};
4253 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4254 descriptor_write.dstSet = descriptor_set;
4255 descriptor_write.dstBinding = 0;
4256 descriptor_write.descriptorCount = 1;
4257 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4258 descriptor_write.pTexelBufferView = &view;
4259
4260 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4261
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004262 char const *vsSource =
4263 "#version 450\n"
4264 "\n"
4265 "out gl_PerVertex { \n"
4266 " vec4 gl_Position;\n"
4267 "};\n"
4268 "void main(){\n"
4269 " gl_Position = vec4(1);\n"
4270 "}\n";
4271 char const *fsSource =
4272 "#version 450\n"
4273 "\n"
4274 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4275 "layout(location=0) out vec4 x;\n"
4276 "void main(){\n"
4277 " x = imageLoad(s, 0);\n"
4278 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004279 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4280 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4281 VkPipelineObj pipe(m_device);
4282 pipe.AddShader(&vs);
4283 pipe.AddShader(&fs);
4284 pipe.AddColorAttachment();
4285 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4286
4287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4289
Tony Barbour552f6c02016-12-21 14:34:07 -07004290 m_commandBuffer->BeginCommandBuffer();
4291 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4292
Tobin Ehlisea413442016-09-28 10:23:59 -06004293 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4294 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4295 VkRect2D scissor = {{0, 0}, {16, 16}};
4296 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4297 // Bind pipeline to cmd buffer
4298 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4299 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4300 &descriptor_set, 0, nullptr);
4301 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004302 m_commandBuffer->EndRenderPass();
4303 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004304
4305 // Delete BufferView in order to invalidate cmd buffer
4306 vkDestroyBufferView(m_device->device(), view, NULL);
4307 // Now attempt submit of cmd buffer
4308 VkSubmitInfo submit_info = {};
4309 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4310 submit_info.commandBufferCount = 1;
4311 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4312 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4313 m_errorMonitor->VerifyFound();
4314
4315 // Clean-up
4316 vkDestroyBuffer(m_device->device(), buffer, NULL);
4317 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4318 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4319 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4320 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4321}
4322
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004323TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004324 TEST_DESCRIPTION(
4325 "Attempt to draw with a command buffer that is invalid "
4326 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004327 ASSERT_NO_FATAL_FAILURE(InitState());
4328
4329 VkImage image;
4330 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4331 VkImageCreateInfo image_create_info = {};
4332 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4333 image_create_info.pNext = NULL;
4334 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4335 image_create_info.format = tex_format;
4336 image_create_info.extent.width = 32;
4337 image_create_info.extent.height = 32;
4338 image_create_info.extent.depth = 1;
4339 image_create_info.mipLevels = 1;
4340 image_create_info.arrayLayers = 1;
4341 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4342 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004343 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004344 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004345 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004346 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004347 // Have to bind memory to image before recording cmd in cmd buffer using it
4348 VkMemoryRequirements mem_reqs;
4349 VkDeviceMemory image_mem;
4350 bool pass;
4351 VkMemoryAllocateInfo mem_alloc = {};
4352 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4353 mem_alloc.pNext = NULL;
4354 mem_alloc.memoryTypeIndex = 0;
4355 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4356 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004357 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004358 ASSERT_TRUE(pass);
4359 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4360 ASSERT_VK_SUCCESS(err);
4361 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4362 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004363
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004364 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004365 VkClearColorValue ccv;
4366 ccv.float32[0] = 1.0f;
4367 ccv.float32[1] = 1.0f;
4368 ccv.float32[2] = 1.0f;
4369 ccv.float32[3] = 1.0f;
4370 VkImageSubresourceRange isr = {};
4371 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004372 isr.baseArrayLayer = 0;
4373 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004374 isr.layerCount = 1;
4375 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004376 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004377 m_commandBuffer->EndCommandBuffer();
4378
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004380 // Destroy image dependency prior to submit to cause ERROR
4381 vkDestroyImage(m_device->device(), image, NULL);
4382
4383 VkSubmitInfo submit_info = {};
4384 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4385 submit_info.commandBufferCount = 1;
4386 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4387 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4388
4389 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004390 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004391}
4392
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004393TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004394 TEST_DESCRIPTION(
4395 "Attempt to draw with a command buffer that is invalid "
4396 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004397 VkFormatProperties format_properties;
4398 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004399 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4400 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004401 return;
4402 }
4403
4404 ASSERT_NO_FATAL_FAILURE(InitState());
4405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4406
4407 VkImageCreateInfo image_ci = {};
4408 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4409 image_ci.pNext = NULL;
4410 image_ci.imageType = VK_IMAGE_TYPE_2D;
4411 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4412 image_ci.extent.width = 32;
4413 image_ci.extent.height = 32;
4414 image_ci.extent.depth = 1;
4415 image_ci.mipLevels = 1;
4416 image_ci.arrayLayers = 1;
4417 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4418 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004419 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004420 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4421 image_ci.flags = 0;
4422 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004423 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004424
4425 VkMemoryRequirements memory_reqs;
4426 VkDeviceMemory image_memory;
4427 bool pass;
4428 VkMemoryAllocateInfo memory_info = {};
4429 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4430 memory_info.pNext = NULL;
4431 memory_info.allocationSize = 0;
4432 memory_info.memoryTypeIndex = 0;
4433 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4434 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004435 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004436 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004437 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004438 ASSERT_VK_SUCCESS(err);
4439 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4440 ASSERT_VK_SUCCESS(err);
4441
4442 VkImageViewCreateInfo ivci = {
4443 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4444 nullptr,
4445 0,
4446 image,
4447 VK_IMAGE_VIEW_TYPE_2D,
4448 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004449 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004450 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4451 };
4452 VkImageView view;
4453 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4454 ASSERT_VK_SUCCESS(err);
4455
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004456 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004457 VkFramebuffer fb;
4458 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4459 ASSERT_VK_SUCCESS(err);
4460
4461 // Just use default renderpass with our framebuffer
4462 m_renderPassBeginInfo.framebuffer = fb;
4463 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004464 m_commandBuffer->BeginCommandBuffer();
4465 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4466 m_commandBuffer->EndRenderPass();
4467 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004468 // Destroy image attached to framebuffer to invalidate cmd buffer
4469 vkDestroyImage(m_device->device(), image, NULL);
4470 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004472 QueueCommandBuffer(false);
4473 m_errorMonitor->VerifyFound();
4474
4475 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4476 vkDestroyImageView(m_device->device(), view, nullptr);
4477 vkFreeMemory(m_device->device(), image_memory, nullptr);
4478}
4479
Tobin Ehlisb329f992016-10-12 13:20:29 -06004480TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4481 TEST_DESCRIPTION("Delete in-use framebuffer.");
4482 VkFormatProperties format_properties;
4483 VkResult err = VK_SUCCESS;
4484 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4485
4486 ASSERT_NO_FATAL_FAILURE(InitState());
4487 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4488
4489 VkImageObj image(m_device);
4490 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4491 ASSERT_TRUE(image.initialized());
4492 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4493
4494 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4495 VkFramebuffer fb;
4496 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4497 ASSERT_VK_SUCCESS(err);
4498
4499 // Just use default renderpass with our framebuffer
4500 m_renderPassBeginInfo.framebuffer = fb;
4501 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004502 m_commandBuffer->BeginCommandBuffer();
4503 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4504 m_commandBuffer->EndRenderPass();
4505 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06004506 // Submit cmd buffer to put it in-flight
4507 VkSubmitInfo submit_info = {};
4508 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4509 submit_info.commandBufferCount = 1;
4510 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4511 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4512 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06004514 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4515 m_errorMonitor->VerifyFound();
4516 // Wait for queue to complete so we can safely destroy everything
4517 vkQueueWaitIdle(m_device->m_queue);
4518 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4519}
4520
Tobin Ehlis88becd72016-09-21 14:33:41 -06004521TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4522 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4523 VkFormatProperties format_properties;
4524 VkResult err = VK_SUCCESS;
4525 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004526
4527 ASSERT_NO_FATAL_FAILURE(InitState());
4528 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4529
4530 VkImageCreateInfo image_ci = {};
4531 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4532 image_ci.pNext = NULL;
4533 image_ci.imageType = VK_IMAGE_TYPE_2D;
4534 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4535 image_ci.extent.width = 256;
4536 image_ci.extent.height = 256;
4537 image_ci.extent.depth = 1;
4538 image_ci.mipLevels = 1;
4539 image_ci.arrayLayers = 1;
4540 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4541 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004542 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004543 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4544 image_ci.flags = 0;
4545 VkImage image;
4546 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4547
4548 VkMemoryRequirements memory_reqs;
4549 VkDeviceMemory image_memory;
4550 bool pass;
4551 VkMemoryAllocateInfo memory_info = {};
4552 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4553 memory_info.pNext = NULL;
4554 memory_info.allocationSize = 0;
4555 memory_info.memoryTypeIndex = 0;
4556 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4557 memory_info.allocationSize = memory_reqs.size;
4558 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4559 ASSERT_TRUE(pass);
4560 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4561 ASSERT_VK_SUCCESS(err);
4562 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4563 ASSERT_VK_SUCCESS(err);
4564
4565 VkImageViewCreateInfo ivci = {
4566 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4567 nullptr,
4568 0,
4569 image,
4570 VK_IMAGE_VIEW_TYPE_2D,
4571 VK_FORMAT_B8G8R8A8_UNORM,
4572 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4573 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4574 };
4575 VkImageView view;
4576 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4577 ASSERT_VK_SUCCESS(err);
4578
4579 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4580 VkFramebuffer fb;
4581 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4582 ASSERT_VK_SUCCESS(err);
4583
4584 // Just use default renderpass with our framebuffer
4585 m_renderPassBeginInfo.framebuffer = fb;
4586 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004587 m_commandBuffer->BeginCommandBuffer();
4588 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4589 m_commandBuffer->EndRenderPass();
4590 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06004591 // Submit cmd buffer to put it (and attached imageView) in-flight
4592 VkSubmitInfo submit_info = {};
4593 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4594 submit_info.commandBufferCount = 1;
4595 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4596 // Submit cmd buffer to put framebuffer and children in-flight
4597 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4598 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004600 vkDestroyImage(m_device->device(), image, NULL);
4601 m_errorMonitor->VerifyFound();
4602 // Wait for queue to complete so we can safely destroy image and other objects
4603 vkQueueWaitIdle(m_device->m_queue);
4604 vkDestroyImage(m_device->device(), image, NULL);
4605 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4606 vkDestroyImageView(m_device->device(), view, nullptr);
4607 vkFreeMemory(m_device->device(), image_memory, nullptr);
4608}
4609
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004610TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4611 TEST_DESCRIPTION("Delete in-use renderPass.");
4612
4613 ASSERT_NO_FATAL_FAILURE(InitState());
4614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4615
4616 // Create simple renderpass
4617 VkAttachmentReference attach = {};
4618 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4619 VkSubpassDescription subpass = {};
4620 subpass.pColorAttachments = &attach;
4621 VkRenderPassCreateInfo rpci = {};
4622 rpci.subpassCount = 1;
4623 rpci.pSubpasses = &subpass;
4624 rpci.attachmentCount = 1;
4625 VkAttachmentDescription attach_desc = {};
4626 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4627 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4628 rpci.pAttachments = &attach_desc;
4629 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4630 VkRenderPass rp;
4631 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4632 ASSERT_VK_SUCCESS(err);
4633
4634 // Create a pipeline that uses the given renderpass
4635 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4636 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4637
4638 VkPipelineLayout pipeline_layout;
4639 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4640 ASSERT_VK_SUCCESS(err);
4641
4642 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4643 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4644 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004645 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004646 vp_state_ci.pViewports = &vp;
4647 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004648 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004649 vp_state_ci.pScissors = &scissors;
4650
4651 VkPipelineShaderStageCreateInfo shaderStages[2];
4652 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4653
4654 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004655 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 -06004656 // but add it to be able to run on more devices
4657 shaderStages[0] = vs.GetStageCreateInfo();
4658 shaderStages[1] = fs.GetStageCreateInfo();
4659
4660 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4661 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4662
4663 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4664 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4665 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4666
4667 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4668 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4669 rs_ci.rasterizerDiscardEnable = true;
4670 rs_ci.lineWidth = 1.0f;
4671
4672 VkPipelineColorBlendAttachmentState att = {};
4673 att.blendEnable = VK_FALSE;
4674 att.colorWriteMask = 0xf;
4675
4676 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4677 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4678 cb_ci.attachmentCount = 1;
4679 cb_ci.pAttachments = &att;
4680
4681 VkGraphicsPipelineCreateInfo gp_ci = {};
4682 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4683 gp_ci.stageCount = 2;
4684 gp_ci.pStages = shaderStages;
4685 gp_ci.pVertexInputState = &vi_ci;
4686 gp_ci.pInputAssemblyState = &ia_ci;
4687 gp_ci.pViewportState = &vp_state_ci;
4688 gp_ci.pRasterizationState = &rs_ci;
4689 gp_ci.pColorBlendState = &cb_ci;
4690 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4691 gp_ci.layout = pipeline_layout;
4692 gp_ci.renderPass = rp;
4693
4694 VkPipelineCacheCreateInfo pc_ci = {};
4695 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4696
4697 VkPipeline pipeline;
4698 VkPipelineCache pipe_cache;
4699 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4700 ASSERT_VK_SUCCESS(err);
4701
4702 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4703 ASSERT_VK_SUCCESS(err);
4704 // Bind pipeline to cmd buffer, will also bind renderpass
4705 m_commandBuffer->BeginCommandBuffer();
4706 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4707 m_commandBuffer->EndCommandBuffer();
4708
4709 VkSubmitInfo submit_info = {};
4710 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4711 submit_info.commandBufferCount = 1;
4712 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4713 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4714
4715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4716 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4717 m_errorMonitor->VerifyFound();
4718
4719 // Wait for queue to complete so we can safely destroy everything
4720 vkQueueWaitIdle(m_device->m_queue);
4721 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4722 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4723 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4724 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4725}
4726
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004727TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004728 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004729 ASSERT_NO_FATAL_FAILURE(InitState());
4730
4731 VkImage image;
4732 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4733 VkImageCreateInfo image_create_info = {};
4734 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4735 image_create_info.pNext = NULL;
4736 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4737 image_create_info.format = tex_format;
4738 image_create_info.extent.width = 32;
4739 image_create_info.extent.height = 32;
4740 image_create_info.extent.depth = 1;
4741 image_create_info.mipLevels = 1;
4742 image_create_info.arrayLayers = 1;
4743 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4744 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004745 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004746 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004747 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004748 ASSERT_VK_SUCCESS(err);
4749 // Have to bind memory to image before recording cmd in cmd buffer using it
4750 VkMemoryRequirements mem_reqs;
4751 VkDeviceMemory image_mem;
4752 bool pass;
4753 VkMemoryAllocateInfo mem_alloc = {};
4754 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4755 mem_alloc.pNext = NULL;
4756 mem_alloc.memoryTypeIndex = 0;
4757 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4758 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004759 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004760 ASSERT_TRUE(pass);
4761 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4762 ASSERT_VK_SUCCESS(err);
4763
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004764 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004766 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004767
4768 m_commandBuffer->BeginCommandBuffer();
4769 VkClearColorValue ccv;
4770 ccv.float32[0] = 1.0f;
4771 ccv.float32[1] = 1.0f;
4772 ccv.float32[2] = 1.0f;
4773 ccv.float32[3] = 1.0f;
4774 VkImageSubresourceRange isr = {};
4775 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4776 isr.baseArrayLayer = 0;
4777 isr.baseMipLevel = 0;
4778 isr.layerCount = 1;
4779 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004780 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004781 m_commandBuffer->EndCommandBuffer();
4782
4783 m_errorMonitor->VerifyFound();
4784 vkDestroyImage(m_device->device(), image, NULL);
4785 vkFreeMemory(m_device->device(), image_mem, nullptr);
4786}
4787
4788TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004789 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004790 ASSERT_NO_FATAL_FAILURE(InitState());
4791
4792 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004793 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 -06004794 VK_IMAGE_TILING_OPTIMAL, 0);
4795 ASSERT_TRUE(image.initialized());
4796
4797 VkBuffer buffer;
4798 VkDeviceMemory mem;
4799 VkMemoryRequirements mem_reqs;
4800
4801 VkBufferCreateInfo buf_info = {};
4802 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004803 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004804 buf_info.size = 256;
4805 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4806 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4807 ASSERT_VK_SUCCESS(err);
4808
4809 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4810
4811 VkMemoryAllocateInfo alloc_info = {};
4812 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4813 alloc_info.allocationSize = 256;
4814 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004815 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 -06004816 if (!pass) {
4817 vkDestroyBuffer(m_device->device(), buffer, NULL);
4818 return;
4819 }
4820 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4821 ASSERT_VK_SUCCESS(err);
4822
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004823 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004825 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004826 VkBufferImageCopy region = {};
4827 region.bufferRowLength = 128;
4828 region.bufferImageHeight = 128;
4829 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4830
4831 region.imageSubresource.layerCount = 1;
4832 region.imageExtent.height = 4;
4833 region.imageExtent.width = 4;
4834 region.imageExtent.depth = 1;
4835 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004836 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4837 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004838 m_commandBuffer->EndCommandBuffer();
4839
4840 m_errorMonitor->VerifyFound();
4841
4842 vkDestroyBuffer(m_device->device(), buffer, NULL);
4843 vkFreeMemory(m_device->handle(), mem, NULL);
4844}
4845
Tobin Ehlis85940f52016-07-07 16:57:21 -06004846TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004847 TEST_DESCRIPTION(
4848 "Attempt to draw with a command buffer that is invalid "
4849 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004850 ASSERT_NO_FATAL_FAILURE(InitState());
4851
4852 VkEvent event;
4853 VkEventCreateInfo evci = {};
4854 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4855 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4856 ASSERT_VK_SUCCESS(result);
4857
4858 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004859 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004860 m_commandBuffer->EndCommandBuffer();
4861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004863 // Destroy event dependency prior to submit to cause ERROR
4864 vkDestroyEvent(m_device->device(), event, NULL);
4865
4866 VkSubmitInfo submit_info = {};
4867 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4868 submit_info.commandBufferCount = 1;
4869 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4870 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4871
4872 m_errorMonitor->VerifyFound();
4873}
4874
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004875TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004876 TEST_DESCRIPTION(
4877 "Attempt to draw with a command buffer that is invalid "
4878 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004879 ASSERT_NO_FATAL_FAILURE(InitState());
4880
4881 VkQueryPool query_pool;
4882 VkQueryPoolCreateInfo qpci{};
4883 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4884 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4885 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004886 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004887 ASSERT_VK_SUCCESS(result);
4888
4889 m_commandBuffer->BeginCommandBuffer();
4890 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4891 m_commandBuffer->EndCommandBuffer();
4892
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004894 // Destroy query pool dependency prior to submit to cause ERROR
4895 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4896
4897 VkSubmitInfo submit_info = {};
4898 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4899 submit_info.commandBufferCount = 1;
4900 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4901 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4902
4903 m_errorMonitor->VerifyFound();
4904}
4905
Tobin Ehlis24130d92016-07-08 15:50:53 -06004906TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004907 TEST_DESCRIPTION(
4908 "Attempt to draw with a command buffer that is invalid "
4909 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004910 ASSERT_NO_FATAL_FAILURE(InitState());
4911 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4912
4913 VkResult err;
4914
4915 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4916 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4917
4918 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004919 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004920 ASSERT_VK_SUCCESS(err);
4921
4922 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4923 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4924 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004925 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004926 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004927 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004928 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06004929 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004930
4931 VkPipelineShaderStageCreateInfo shaderStages[2];
4932 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004934 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004935 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 -06004936 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004937 shaderStages[0] = vs.GetStageCreateInfo();
4938 shaderStages[1] = fs.GetStageCreateInfo();
4939
4940 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4941 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4942
4943 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4944 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4945 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4946
4947 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4948 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004949 rs_ci.rasterizerDiscardEnable = true;
4950 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004951
4952 VkPipelineColorBlendAttachmentState att = {};
4953 att.blendEnable = VK_FALSE;
4954 att.colorWriteMask = 0xf;
4955
4956 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4957 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4958 cb_ci.attachmentCount = 1;
4959 cb_ci.pAttachments = &att;
4960
4961 VkGraphicsPipelineCreateInfo gp_ci = {};
4962 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4963 gp_ci.stageCount = 2;
4964 gp_ci.pStages = shaderStages;
4965 gp_ci.pVertexInputState = &vi_ci;
4966 gp_ci.pInputAssemblyState = &ia_ci;
4967 gp_ci.pViewportState = &vp_state_ci;
4968 gp_ci.pRasterizationState = &rs_ci;
4969 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004970 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4971 gp_ci.layout = pipeline_layout;
4972 gp_ci.renderPass = renderPass();
4973
4974 VkPipelineCacheCreateInfo pc_ci = {};
4975 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4976
4977 VkPipeline pipeline;
4978 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004979 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004980 ASSERT_VK_SUCCESS(err);
4981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004982 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004983 ASSERT_VK_SUCCESS(err);
4984
4985 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004986 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004987 m_commandBuffer->EndCommandBuffer();
4988 // Now destroy pipeline in order to cause error when submitting
4989 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4990
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004992
4993 VkSubmitInfo submit_info = {};
4994 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4995 submit_info.commandBufferCount = 1;
4996 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4997 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4998
4999 m_errorMonitor->VerifyFound();
5000 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5001 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5002}
5003
Tobin Ehlis31289162016-08-17 14:57:58 -06005004TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005005 TEST_DESCRIPTION(
5006 "Attempt to draw with a command buffer that is invalid "
5007 "due to a bound descriptor set with a buffer dependency "
5008 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005009 ASSERT_NO_FATAL_FAILURE(InitState());
5010 ASSERT_NO_FATAL_FAILURE(InitViewport());
5011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5012
5013 VkDescriptorPoolSize ds_type_count = {};
5014 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5015 ds_type_count.descriptorCount = 1;
5016
5017 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5018 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5019 ds_pool_ci.pNext = NULL;
5020 ds_pool_ci.maxSets = 1;
5021 ds_pool_ci.poolSizeCount = 1;
5022 ds_pool_ci.pPoolSizes = &ds_type_count;
5023
5024 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005025 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005026 ASSERT_VK_SUCCESS(err);
5027
5028 VkDescriptorSetLayoutBinding dsl_binding = {};
5029 dsl_binding.binding = 0;
5030 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5031 dsl_binding.descriptorCount = 1;
5032 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5033 dsl_binding.pImmutableSamplers = NULL;
5034
5035 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5036 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5037 ds_layout_ci.pNext = NULL;
5038 ds_layout_ci.bindingCount = 1;
5039 ds_layout_ci.pBindings = &dsl_binding;
5040 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005041 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005042 ASSERT_VK_SUCCESS(err);
5043
5044 VkDescriptorSet descriptorSet;
5045 VkDescriptorSetAllocateInfo alloc_info = {};
5046 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5047 alloc_info.descriptorSetCount = 1;
5048 alloc_info.descriptorPool = ds_pool;
5049 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005050 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005051 ASSERT_VK_SUCCESS(err);
5052
5053 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5054 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5055 pipeline_layout_ci.pNext = NULL;
5056 pipeline_layout_ci.setLayoutCount = 1;
5057 pipeline_layout_ci.pSetLayouts = &ds_layout;
5058
5059 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005060 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005061 ASSERT_VK_SUCCESS(err);
5062
5063 // Create a buffer to update the descriptor with
5064 uint32_t qfi = 0;
5065 VkBufferCreateInfo buffCI = {};
5066 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5067 buffCI.size = 1024;
5068 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5069 buffCI.queueFamilyIndexCount = 1;
5070 buffCI.pQueueFamilyIndices = &qfi;
5071
5072 VkBuffer buffer;
5073 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5074 ASSERT_VK_SUCCESS(err);
5075 // Allocate memory and bind to buffer so we can make it to the appropriate
5076 // error
5077 VkMemoryAllocateInfo mem_alloc = {};
5078 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5079 mem_alloc.pNext = NULL;
5080 mem_alloc.allocationSize = 1024;
5081 mem_alloc.memoryTypeIndex = 0;
5082
5083 VkMemoryRequirements memReqs;
5084 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005085 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005086 if (!pass) {
5087 vkDestroyBuffer(m_device->device(), buffer, NULL);
5088 return;
5089 }
5090
5091 VkDeviceMemory mem;
5092 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5093 ASSERT_VK_SUCCESS(err);
5094 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5095 ASSERT_VK_SUCCESS(err);
5096 // Correctly update descriptor to avoid "NOT_UPDATED" error
5097 VkDescriptorBufferInfo buffInfo = {};
5098 buffInfo.buffer = buffer;
5099 buffInfo.offset = 0;
5100 buffInfo.range = 1024;
5101
5102 VkWriteDescriptorSet descriptor_write;
5103 memset(&descriptor_write, 0, sizeof(descriptor_write));
5104 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5105 descriptor_write.dstSet = descriptorSet;
5106 descriptor_write.dstBinding = 0;
5107 descriptor_write.descriptorCount = 1;
5108 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5109 descriptor_write.pBufferInfo = &buffInfo;
5110
5111 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5112
5113 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005114 char const *vsSource =
5115 "#version 450\n"
5116 "\n"
5117 "out gl_PerVertex { \n"
5118 " vec4 gl_Position;\n"
5119 "};\n"
5120 "void main(){\n"
5121 " gl_Position = vec4(1);\n"
5122 "}\n";
5123 char const *fsSource =
5124 "#version 450\n"
5125 "\n"
5126 "layout(location=0) out vec4 x;\n"
5127 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5128 "void main(){\n"
5129 " x = vec4(bar.y);\n"
5130 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005131 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5132 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5133 VkPipelineObj pipe(m_device);
5134 pipe.AddShader(&vs);
5135 pipe.AddShader(&fs);
5136 pipe.AddColorAttachment();
5137 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5138
Tony Barbour552f6c02016-12-21 14:34:07 -07005139 m_commandBuffer->BeginCommandBuffer();
5140 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005141 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5142 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5143 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005144
5145 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5146 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5147
Tobin Ehlis31289162016-08-17 14:57:58 -06005148 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005149 m_commandBuffer->EndRenderPass();
5150 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005152 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5153 vkDestroyBuffer(m_device->device(), buffer, NULL);
5154 // Attempt to submit cmd buffer
5155 VkSubmitInfo submit_info = {};
5156 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5157 submit_info.commandBufferCount = 1;
5158 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5159 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5160 m_errorMonitor->VerifyFound();
5161 // Cleanup
5162 vkFreeMemory(m_device->device(), mem, NULL);
5163
5164 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5165 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5166 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5167}
5168
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005169TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005170 TEST_DESCRIPTION(
5171 "Attempt to draw with a command buffer that is invalid "
5172 "due to a bound descriptor sets with a combined image "
5173 "sampler having their image, sampler, and descriptor set "
5174 "each respectively destroyed and then attempting to "
5175 "submit associated cmd buffers. Attempt to destroy a "
5176 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005177 ASSERT_NO_FATAL_FAILURE(InitState());
5178 ASSERT_NO_FATAL_FAILURE(InitViewport());
5179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5180
5181 VkDescriptorPoolSize ds_type_count = {};
5182 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5183 ds_type_count.descriptorCount = 1;
5184
5185 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5186 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5187 ds_pool_ci.pNext = NULL;
5188 ds_pool_ci.maxSets = 1;
5189 ds_pool_ci.poolSizeCount = 1;
5190 ds_pool_ci.pPoolSizes = &ds_type_count;
5191
5192 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005193 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005194 ASSERT_VK_SUCCESS(err);
5195
5196 VkDescriptorSetLayoutBinding dsl_binding = {};
5197 dsl_binding.binding = 0;
5198 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5199 dsl_binding.descriptorCount = 1;
5200 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5201 dsl_binding.pImmutableSamplers = NULL;
5202
5203 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5204 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5205 ds_layout_ci.pNext = NULL;
5206 ds_layout_ci.bindingCount = 1;
5207 ds_layout_ci.pBindings = &dsl_binding;
5208 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005209 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005210 ASSERT_VK_SUCCESS(err);
5211
5212 VkDescriptorSet descriptorSet;
5213 VkDescriptorSetAllocateInfo alloc_info = {};
5214 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5215 alloc_info.descriptorSetCount = 1;
5216 alloc_info.descriptorPool = ds_pool;
5217 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005218 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005219 ASSERT_VK_SUCCESS(err);
5220
5221 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5222 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5223 pipeline_layout_ci.pNext = NULL;
5224 pipeline_layout_ci.setLayoutCount = 1;
5225 pipeline_layout_ci.pSetLayouts = &ds_layout;
5226
5227 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005228 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005229 ASSERT_VK_SUCCESS(err);
5230
5231 // Create images to update the descriptor with
5232 VkImage image;
5233 VkImage image2;
5234 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5235 const int32_t tex_width = 32;
5236 const int32_t tex_height = 32;
5237 VkImageCreateInfo image_create_info = {};
5238 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5239 image_create_info.pNext = NULL;
5240 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5241 image_create_info.format = tex_format;
5242 image_create_info.extent.width = tex_width;
5243 image_create_info.extent.height = tex_height;
5244 image_create_info.extent.depth = 1;
5245 image_create_info.mipLevels = 1;
5246 image_create_info.arrayLayers = 1;
5247 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5248 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5249 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5250 image_create_info.flags = 0;
5251 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5252 ASSERT_VK_SUCCESS(err);
5253 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5254 ASSERT_VK_SUCCESS(err);
5255
5256 VkMemoryRequirements memory_reqs;
5257 VkDeviceMemory image_memory;
5258 bool pass;
5259 VkMemoryAllocateInfo memory_info = {};
5260 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5261 memory_info.pNext = NULL;
5262 memory_info.allocationSize = 0;
5263 memory_info.memoryTypeIndex = 0;
5264 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5265 // Allocate enough memory for both images
5266 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005267 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005268 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005269 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005270 ASSERT_VK_SUCCESS(err);
5271 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5272 ASSERT_VK_SUCCESS(err);
5273 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005274 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005275 ASSERT_VK_SUCCESS(err);
5276
5277 VkImageViewCreateInfo image_view_create_info = {};
5278 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5279 image_view_create_info.image = image;
5280 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5281 image_view_create_info.format = tex_format;
5282 image_view_create_info.subresourceRange.layerCount = 1;
5283 image_view_create_info.subresourceRange.baseMipLevel = 0;
5284 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005285 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005286
5287 VkImageView view;
5288 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005289 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005290 ASSERT_VK_SUCCESS(err);
5291 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005292 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005293 ASSERT_VK_SUCCESS(err);
5294 // Create Samplers
5295 VkSamplerCreateInfo sampler_ci = {};
5296 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5297 sampler_ci.pNext = NULL;
5298 sampler_ci.magFilter = VK_FILTER_NEAREST;
5299 sampler_ci.minFilter = VK_FILTER_NEAREST;
5300 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5301 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5302 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5303 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5304 sampler_ci.mipLodBias = 1.0;
5305 sampler_ci.anisotropyEnable = VK_FALSE;
5306 sampler_ci.maxAnisotropy = 1;
5307 sampler_ci.compareEnable = VK_FALSE;
5308 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5309 sampler_ci.minLod = 1.0;
5310 sampler_ci.maxLod = 1.0;
5311 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5312 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5313 VkSampler sampler;
5314 VkSampler sampler2;
5315 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5316 ASSERT_VK_SUCCESS(err);
5317 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5318 ASSERT_VK_SUCCESS(err);
5319 // Update descriptor with image and sampler
5320 VkDescriptorImageInfo img_info = {};
5321 img_info.sampler = sampler;
5322 img_info.imageView = view;
5323 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5324
5325 VkWriteDescriptorSet descriptor_write;
5326 memset(&descriptor_write, 0, sizeof(descriptor_write));
5327 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5328 descriptor_write.dstSet = descriptorSet;
5329 descriptor_write.dstBinding = 0;
5330 descriptor_write.descriptorCount = 1;
5331 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5332 descriptor_write.pImageInfo = &img_info;
5333
5334 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5335
5336 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005337 char const *vsSource =
5338 "#version 450\n"
5339 "\n"
5340 "out gl_PerVertex { \n"
5341 " vec4 gl_Position;\n"
5342 "};\n"
5343 "void main(){\n"
5344 " gl_Position = vec4(1);\n"
5345 "}\n";
5346 char const *fsSource =
5347 "#version 450\n"
5348 "\n"
5349 "layout(set=0, binding=0) uniform sampler2D s;\n"
5350 "layout(location=0) out vec4 x;\n"
5351 "void main(){\n"
5352 " x = texture(s, vec2(1));\n"
5353 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005354 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5355 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5356 VkPipelineObj pipe(m_device);
5357 pipe.AddShader(&vs);
5358 pipe.AddShader(&fs);
5359 pipe.AddColorAttachment();
5360 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5361
5362 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005364 m_commandBuffer->BeginCommandBuffer();
5365 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005366 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5367 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5368 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005369 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5370 VkRect2D scissor = {{0, 0}, {16, 16}};
5371 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5372 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005373 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005374 m_commandBuffer->EndRenderPass();
5375 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005376 // Destroy sampler invalidates the cmd buffer, causing error on submit
5377 vkDestroySampler(m_device->device(), sampler, NULL);
5378 // Attempt to submit cmd buffer
5379 VkSubmitInfo submit_info = {};
5380 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5381 submit_info.commandBufferCount = 1;
5382 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5383 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5384 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005385
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005386 // Now re-update descriptor with valid sampler and delete image
5387 img_info.sampler = sampler2;
5388 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005390 m_commandBuffer->BeginCommandBuffer();
5391 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005392 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5393 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5394 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005395 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5396 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005397 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005398 m_commandBuffer->EndRenderPass();
5399 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005400 // Destroy image invalidates the cmd buffer, causing error on submit
5401 vkDestroyImage(m_device->device(), image, NULL);
5402 // Attempt to submit cmd buffer
5403 submit_info = {};
5404 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5405 submit_info.commandBufferCount = 1;
5406 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5407 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5408 m_errorMonitor->VerifyFound();
5409 // Now update descriptor to be valid, but then free descriptor
5410 img_info.imageView = view2;
5411 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07005412 m_commandBuffer->BeginCommandBuffer();
5413 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005414 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5415 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5416 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005417 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5418 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005419 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005420 m_commandBuffer->EndRenderPass();
5421 m_commandBuffer->EndCommandBuffer();
Dave Houltonfbf52152017-01-06 12:55:29 -07005422
5423 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005425 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005426 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005427
5428 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07005429 // 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 -07005430 vkQueueWaitIdle(m_device->m_queue);
5431 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5432
5433 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005434 submit_info = {};
5435 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5436 submit_info.commandBufferCount = 1;
5437 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005439 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5440 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005441
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005442 // Cleanup
5443 vkFreeMemory(m_device->device(), image_memory, NULL);
5444 vkDestroySampler(m_device->device(), sampler2, NULL);
5445 vkDestroyImage(m_device->device(), image2, NULL);
5446 vkDestroyImageView(m_device->device(), view, NULL);
5447 vkDestroyImageView(m_device->device(), view2, NULL);
5448 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5449 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5450 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5451}
5452
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005453TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5454 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5455 ASSERT_NO_FATAL_FAILURE(InitState());
5456 ASSERT_NO_FATAL_FAILURE(InitViewport());
5457 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5458
5459 VkDescriptorPoolSize ds_type_count = {};
5460 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5461 ds_type_count.descriptorCount = 1;
5462
5463 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5464 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5465 ds_pool_ci.pNext = NULL;
5466 ds_pool_ci.maxSets = 1;
5467 ds_pool_ci.poolSizeCount = 1;
5468 ds_pool_ci.pPoolSizes = &ds_type_count;
5469
5470 VkDescriptorPool ds_pool;
5471 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5472 ASSERT_VK_SUCCESS(err);
5473
5474 VkDescriptorSetLayoutBinding dsl_binding = {};
5475 dsl_binding.binding = 0;
5476 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5477 dsl_binding.descriptorCount = 1;
5478 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5479 dsl_binding.pImmutableSamplers = NULL;
5480
5481 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5482 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5483 ds_layout_ci.pNext = NULL;
5484 ds_layout_ci.bindingCount = 1;
5485 ds_layout_ci.pBindings = &dsl_binding;
5486 VkDescriptorSetLayout ds_layout;
5487 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5488 ASSERT_VK_SUCCESS(err);
5489
5490 VkDescriptorSet descriptor_set;
5491 VkDescriptorSetAllocateInfo alloc_info = {};
5492 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5493 alloc_info.descriptorSetCount = 1;
5494 alloc_info.descriptorPool = ds_pool;
5495 alloc_info.pSetLayouts = &ds_layout;
5496 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5497 ASSERT_VK_SUCCESS(err);
5498
5499 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5500 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5501 pipeline_layout_ci.pNext = NULL;
5502 pipeline_layout_ci.setLayoutCount = 1;
5503 pipeline_layout_ci.pSetLayouts = &ds_layout;
5504
5505 VkPipelineLayout pipeline_layout;
5506 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5507 ASSERT_VK_SUCCESS(err);
5508
5509 // Create image to update the descriptor with
5510 VkImageObj image(m_device);
5511 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5512 ASSERT_TRUE(image.initialized());
5513
5514 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5515 // Create Sampler
5516 VkSamplerCreateInfo sampler_ci = {};
5517 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5518 sampler_ci.pNext = NULL;
5519 sampler_ci.magFilter = VK_FILTER_NEAREST;
5520 sampler_ci.minFilter = VK_FILTER_NEAREST;
5521 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5522 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5523 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5524 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5525 sampler_ci.mipLodBias = 1.0;
5526 sampler_ci.anisotropyEnable = VK_FALSE;
5527 sampler_ci.maxAnisotropy = 1;
5528 sampler_ci.compareEnable = VK_FALSE;
5529 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5530 sampler_ci.minLod = 1.0;
5531 sampler_ci.maxLod = 1.0;
5532 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5533 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5534 VkSampler sampler;
5535 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5536 ASSERT_VK_SUCCESS(err);
5537 // Update descriptor with image and sampler
5538 VkDescriptorImageInfo img_info = {};
5539 img_info.sampler = sampler;
5540 img_info.imageView = view;
5541 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5542
5543 VkWriteDescriptorSet descriptor_write;
5544 memset(&descriptor_write, 0, sizeof(descriptor_write));
5545 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5546 descriptor_write.dstSet = descriptor_set;
5547 descriptor_write.dstBinding = 0;
5548 descriptor_write.descriptorCount = 1;
5549 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5550 descriptor_write.pImageInfo = &img_info;
5551
5552 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5553
5554 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005555 char const *vsSource =
5556 "#version 450\n"
5557 "\n"
5558 "out gl_PerVertex { \n"
5559 " vec4 gl_Position;\n"
5560 "};\n"
5561 "void main(){\n"
5562 " gl_Position = vec4(1);\n"
5563 "}\n";
5564 char const *fsSource =
5565 "#version 450\n"
5566 "\n"
5567 "layout(set=0, binding=0) uniform sampler2D s;\n"
5568 "layout(location=0) out vec4 x;\n"
5569 "void main(){\n"
5570 " x = texture(s, vec2(1));\n"
5571 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005572 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5573 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5574 VkPipelineObj pipe(m_device);
5575 pipe.AddShader(&vs);
5576 pipe.AddShader(&fs);
5577 pipe.AddColorAttachment();
5578 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5579
Tony Barbour552f6c02016-12-21 14:34:07 -07005580 m_commandBuffer->BeginCommandBuffer();
5581 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005582 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5583 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5584 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005585
5586 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5587 VkRect2D scissor = {{0, 0}, {16, 16}};
5588 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5589 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
5590
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005591 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005592 m_commandBuffer->EndRenderPass();
5593 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005594 // Submit cmd buffer to put pool in-flight
5595 VkSubmitInfo submit_info = {};
5596 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5597 submit_info.commandBufferCount = 1;
5598 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5599 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5600 // Destroy pool while in-flight, causing error
5601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5602 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5603 m_errorMonitor->VerifyFound();
5604 vkQueueWaitIdle(m_device->m_queue);
5605 // Cleanup
5606 vkDestroySampler(m_device->device(), sampler, NULL);
5607 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5608 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5609 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005610 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005611}
5612
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005613TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5614 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5615 ASSERT_NO_FATAL_FAILURE(InitState());
5616 ASSERT_NO_FATAL_FAILURE(InitViewport());
5617 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5618
5619 VkDescriptorPoolSize ds_type_count = {};
5620 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5621 ds_type_count.descriptorCount = 1;
5622
5623 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5624 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5625 ds_pool_ci.pNext = NULL;
5626 ds_pool_ci.maxSets = 1;
5627 ds_pool_ci.poolSizeCount = 1;
5628 ds_pool_ci.pPoolSizes = &ds_type_count;
5629
5630 VkDescriptorPool ds_pool;
5631 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5632 ASSERT_VK_SUCCESS(err);
5633
5634 VkDescriptorSetLayoutBinding dsl_binding = {};
5635 dsl_binding.binding = 0;
5636 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5637 dsl_binding.descriptorCount = 1;
5638 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5639 dsl_binding.pImmutableSamplers = NULL;
5640
5641 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5642 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5643 ds_layout_ci.pNext = NULL;
5644 ds_layout_ci.bindingCount = 1;
5645 ds_layout_ci.pBindings = &dsl_binding;
5646 VkDescriptorSetLayout ds_layout;
5647 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5648 ASSERT_VK_SUCCESS(err);
5649
5650 VkDescriptorSet descriptorSet;
5651 VkDescriptorSetAllocateInfo alloc_info = {};
5652 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5653 alloc_info.descriptorSetCount = 1;
5654 alloc_info.descriptorPool = ds_pool;
5655 alloc_info.pSetLayouts = &ds_layout;
5656 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5657 ASSERT_VK_SUCCESS(err);
5658
5659 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5660 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5661 pipeline_layout_ci.pNext = NULL;
5662 pipeline_layout_ci.setLayoutCount = 1;
5663 pipeline_layout_ci.pSetLayouts = &ds_layout;
5664
5665 VkPipelineLayout pipeline_layout;
5666 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5667 ASSERT_VK_SUCCESS(err);
5668
5669 // Create images to update the descriptor with
5670 VkImage image;
5671 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5672 const int32_t tex_width = 32;
5673 const int32_t tex_height = 32;
5674 VkImageCreateInfo image_create_info = {};
5675 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5676 image_create_info.pNext = NULL;
5677 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5678 image_create_info.format = tex_format;
5679 image_create_info.extent.width = tex_width;
5680 image_create_info.extent.height = tex_height;
5681 image_create_info.extent.depth = 1;
5682 image_create_info.mipLevels = 1;
5683 image_create_info.arrayLayers = 1;
5684 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5685 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5686 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5687 image_create_info.flags = 0;
5688 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5689 ASSERT_VK_SUCCESS(err);
5690 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5691 VkMemoryRequirements memory_reqs;
5692 VkDeviceMemory image_memory;
5693 bool pass;
5694 VkMemoryAllocateInfo memory_info = {};
5695 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5696 memory_info.pNext = NULL;
5697 memory_info.allocationSize = 0;
5698 memory_info.memoryTypeIndex = 0;
5699 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5700 // Allocate enough memory for image
5701 memory_info.allocationSize = memory_reqs.size;
5702 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5703 ASSERT_TRUE(pass);
5704 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5705 ASSERT_VK_SUCCESS(err);
5706 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5707 ASSERT_VK_SUCCESS(err);
5708
5709 VkImageViewCreateInfo image_view_create_info = {};
5710 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5711 image_view_create_info.image = image;
5712 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5713 image_view_create_info.format = tex_format;
5714 image_view_create_info.subresourceRange.layerCount = 1;
5715 image_view_create_info.subresourceRange.baseMipLevel = 0;
5716 image_view_create_info.subresourceRange.levelCount = 1;
5717 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5718
5719 VkImageView view;
5720 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5721 ASSERT_VK_SUCCESS(err);
5722 // Create Samplers
5723 VkSamplerCreateInfo sampler_ci = {};
5724 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5725 sampler_ci.pNext = NULL;
5726 sampler_ci.magFilter = VK_FILTER_NEAREST;
5727 sampler_ci.minFilter = VK_FILTER_NEAREST;
5728 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5729 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5730 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5731 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5732 sampler_ci.mipLodBias = 1.0;
5733 sampler_ci.anisotropyEnable = VK_FALSE;
5734 sampler_ci.maxAnisotropy = 1;
5735 sampler_ci.compareEnable = VK_FALSE;
5736 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5737 sampler_ci.minLod = 1.0;
5738 sampler_ci.maxLod = 1.0;
5739 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5740 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5741 VkSampler sampler;
5742 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5743 ASSERT_VK_SUCCESS(err);
5744 // Update descriptor with image and sampler
5745 VkDescriptorImageInfo img_info = {};
5746 img_info.sampler = sampler;
5747 img_info.imageView = view;
5748 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5749
5750 VkWriteDescriptorSet descriptor_write;
5751 memset(&descriptor_write, 0, sizeof(descriptor_write));
5752 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5753 descriptor_write.dstSet = descriptorSet;
5754 descriptor_write.dstBinding = 0;
5755 descriptor_write.descriptorCount = 1;
5756 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5757 descriptor_write.pImageInfo = &img_info;
5758 // Break memory binding and attempt update
5759 vkFreeMemory(m_device->device(), image_memory, nullptr);
5760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005761 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5763 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5764 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5765 m_errorMonitor->VerifyFound();
5766 // Cleanup
5767 vkDestroyImage(m_device->device(), image, NULL);
5768 vkDestroySampler(m_device->device(), sampler, NULL);
5769 vkDestroyImageView(m_device->device(), view, NULL);
5770 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5771 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5772 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5773}
5774
Karl Schultz6addd812016-02-02 17:17:23 -07005775TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005776 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5777 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005778 // Create a valid cmd buffer
5779 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005780 uint64_t fake_pipeline_handle = 0xbaad6001;
5781 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005782 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005783 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5784
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07005786 m_commandBuffer->BeginCommandBuffer();
5787 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005788 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005789 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005790
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005791 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005792 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 -06005793 Draw(1, 0, 0, 0);
5794 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005795
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005796 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005797 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 -07005798 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005799 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5800 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005801}
5802
Karl Schultz6addd812016-02-02 17:17:23 -07005803TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005804 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005805 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005806
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005808
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005809 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005810 ASSERT_NO_FATAL_FAILURE(InitViewport());
5811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005812 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005813 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5814 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005815
5816 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005817 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5818 ds_pool_ci.pNext = NULL;
5819 ds_pool_ci.maxSets = 1;
5820 ds_pool_ci.poolSizeCount = 1;
5821 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005822
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005823 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005824 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005825 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005826
Tony Barboureb254902015-07-15 12:50:33 -06005827 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005828 dsl_binding.binding = 0;
5829 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5830 dsl_binding.descriptorCount = 1;
5831 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5832 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005833
Tony Barboureb254902015-07-15 12:50:33 -06005834 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005835 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5836 ds_layout_ci.pNext = NULL;
5837 ds_layout_ci.bindingCount = 1;
5838 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005839 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005840 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005841 ASSERT_VK_SUCCESS(err);
5842
5843 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005844 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005845 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005846 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005847 alloc_info.descriptorPool = ds_pool;
5848 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005849 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005850 ASSERT_VK_SUCCESS(err);
5851
Tony Barboureb254902015-07-15 12:50:33 -06005852 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005853 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5854 pipeline_layout_ci.pNext = NULL;
5855 pipeline_layout_ci.setLayoutCount = 1;
5856 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005857
5858 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005859 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005860 ASSERT_VK_SUCCESS(err);
5861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005862 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005863 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005864 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005865 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005866
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005867 VkPipelineObj pipe(m_device);
5868 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005869 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005870 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005871 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005872
Tony Barbour552f6c02016-12-21 14:34:07 -07005873 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005874 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5875 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5876 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005877
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005878 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005879
Chia-I Wuf7458c52015-10-26 21:10:41 +08005880 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5881 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5882 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005883}
5884
Karl Schultz6addd812016-02-02 17:17:23 -07005885TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005886 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005887 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005888
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005890
5891 ASSERT_NO_FATAL_FAILURE(InitState());
5892 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005893 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5894 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005895
5896 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005897 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5898 ds_pool_ci.pNext = NULL;
5899 ds_pool_ci.maxSets = 1;
5900 ds_pool_ci.poolSizeCount = 1;
5901 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005902
5903 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005904 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005905 ASSERT_VK_SUCCESS(err);
5906
5907 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005908 dsl_binding.binding = 0;
5909 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5910 dsl_binding.descriptorCount = 1;
5911 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5912 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005913
5914 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005915 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5916 ds_layout_ci.pNext = NULL;
5917 ds_layout_ci.bindingCount = 1;
5918 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005919 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005920 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005921 ASSERT_VK_SUCCESS(err);
5922
5923 VkDescriptorSet descriptorSet;
5924 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005925 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005926 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005927 alloc_info.descriptorPool = ds_pool;
5928 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005929 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005930 ASSERT_VK_SUCCESS(err);
5931
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005932 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005933 VkWriteDescriptorSet descriptor_write;
5934 memset(&descriptor_write, 0, sizeof(descriptor_write));
5935 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5936 descriptor_write.dstSet = descriptorSet;
5937 descriptor_write.dstBinding = 0;
5938 descriptor_write.descriptorCount = 1;
5939 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5940 descriptor_write.pTexelBufferView = &view;
5941
5942 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5943
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005944 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005945
5946 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5947 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5948}
5949
Mark Youngd339ba32016-05-30 13:28:35 -06005950TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005951 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 -06005952
5953 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005955 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005956
5957 ASSERT_NO_FATAL_FAILURE(InitState());
5958
5959 // Create a buffer with no bound memory and then attempt to create
5960 // a buffer view.
5961 VkBufferCreateInfo buff_ci = {};
5962 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005963 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005964 buff_ci.size = 256;
5965 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5966 VkBuffer buffer;
5967 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5968 ASSERT_VK_SUCCESS(err);
5969
5970 VkBufferViewCreateInfo buff_view_ci = {};
5971 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5972 buff_view_ci.buffer = buffer;
5973 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5974 buff_view_ci.range = VK_WHOLE_SIZE;
5975 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005976 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005977
5978 m_errorMonitor->VerifyFound();
5979 vkDestroyBuffer(m_device->device(), buffer, NULL);
5980 // If last error is success, it still created the view, so delete it.
5981 if (err == VK_SUCCESS) {
5982 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5983 }
5984}
5985
Karl Schultz6addd812016-02-02 17:17:23 -07005986TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5987 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5988 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005989 // 1. No dynamicOffset supplied
5990 // 2. Too many dynamicOffsets supplied
5991 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005992 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5994 " requires 1 dynamicOffsets, but only "
5995 "0 dynamicOffsets are left in "
5996 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005997
5998 ASSERT_NO_FATAL_FAILURE(InitState());
5999 ASSERT_NO_FATAL_FAILURE(InitViewport());
6000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6001
6002 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006003 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6004 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006005
6006 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006007 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6008 ds_pool_ci.pNext = NULL;
6009 ds_pool_ci.maxSets = 1;
6010 ds_pool_ci.poolSizeCount = 1;
6011 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006012
6013 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006014 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006015 ASSERT_VK_SUCCESS(err);
6016
6017 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006018 dsl_binding.binding = 0;
6019 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6020 dsl_binding.descriptorCount = 1;
6021 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6022 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006023
6024 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006025 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6026 ds_layout_ci.pNext = NULL;
6027 ds_layout_ci.bindingCount = 1;
6028 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006029 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006030 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006031 ASSERT_VK_SUCCESS(err);
6032
6033 VkDescriptorSet descriptorSet;
6034 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006035 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006036 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006037 alloc_info.descriptorPool = ds_pool;
6038 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006039 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006040 ASSERT_VK_SUCCESS(err);
6041
6042 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006043 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6044 pipeline_layout_ci.pNext = NULL;
6045 pipeline_layout_ci.setLayoutCount = 1;
6046 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006047
6048 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006049 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006050 ASSERT_VK_SUCCESS(err);
6051
6052 // Create a buffer to update the descriptor with
6053 uint32_t qfi = 0;
6054 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006055 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6056 buffCI.size = 1024;
6057 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6058 buffCI.queueFamilyIndexCount = 1;
6059 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006060
6061 VkBuffer dyub;
6062 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6063 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006064 // Allocate memory and bind to buffer so we can make it to the appropriate
6065 // error
6066 VkMemoryAllocateInfo mem_alloc = {};
6067 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6068 mem_alloc.pNext = NULL;
6069 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006070 mem_alloc.memoryTypeIndex = 0;
6071
6072 VkMemoryRequirements memReqs;
6073 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006074 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006075 if (!pass) {
6076 vkDestroyBuffer(m_device->device(), dyub, NULL);
6077 return;
6078 }
6079
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006080 VkDeviceMemory mem;
6081 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6082 ASSERT_VK_SUCCESS(err);
6083 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6084 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006085 // Correctly update descriptor to avoid "NOT_UPDATED" error
6086 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006087 buffInfo.buffer = dyub;
6088 buffInfo.offset = 0;
6089 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006090
6091 VkWriteDescriptorSet descriptor_write;
6092 memset(&descriptor_write, 0, sizeof(descriptor_write));
6093 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6094 descriptor_write.dstSet = descriptorSet;
6095 descriptor_write.dstBinding = 0;
6096 descriptor_write.descriptorCount = 1;
6097 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6098 descriptor_write.pBufferInfo = &buffInfo;
6099
6100 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6101
Tony Barbour552f6c02016-12-21 14:34:07 -07006102 m_commandBuffer->BeginCommandBuffer();
6103 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006104 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6105 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006106 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006107 uint32_t pDynOff[2] = {512, 756};
6108 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6110 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6111 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6112 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006113 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006114 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6116 " dynamic offset 512 combined with "
6117 "offset 0 and range 1024 that "
6118 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006119 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006120 char const *vsSource =
6121 "#version 450\n"
6122 "\n"
6123 "out gl_PerVertex { \n"
6124 " vec4 gl_Position;\n"
6125 "};\n"
6126 "void main(){\n"
6127 " gl_Position = vec4(1);\n"
6128 "}\n";
6129 char const *fsSource =
6130 "#version 450\n"
6131 "\n"
6132 "layout(location=0) out vec4 x;\n"
6133 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6134 "void main(){\n"
6135 " x = vec4(bar.y);\n"
6136 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006137 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6138 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6139 VkPipelineObj pipe(m_device);
6140 pipe.AddShader(&vs);
6141 pipe.AddShader(&fs);
6142 pipe.AddColorAttachment();
6143 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6144
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006145 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6146 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6147 VkRect2D scissor = {{0, 0}, {16, 16}};
6148 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6149
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006150 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006151 // This update should succeed, but offset size of 512 will overstep buffer
6152 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006153 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6154 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006155 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006156 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006157
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006158 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006159 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006160
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006161 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006162 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006163 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6164}
6165
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006166TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006167 TEST_DESCRIPTION(
6168 "Attempt to update a descriptor with a non-sparse buffer "
6169 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006170 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006172 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6174 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006175
6176 ASSERT_NO_FATAL_FAILURE(InitState());
6177 ASSERT_NO_FATAL_FAILURE(InitViewport());
6178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6179
6180 VkDescriptorPoolSize ds_type_count = {};
6181 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6182 ds_type_count.descriptorCount = 1;
6183
6184 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6185 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6186 ds_pool_ci.pNext = NULL;
6187 ds_pool_ci.maxSets = 1;
6188 ds_pool_ci.poolSizeCount = 1;
6189 ds_pool_ci.pPoolSizes = &ds_type_count;
6190
6191 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006192 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006193 ASSERT_VK_SUCCESS(err);
6194
6195 VkDescriptorSetLayoutBinding dsl_binding = {};
6196 dsl_binding.binding = 0;
6197 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6198 dsl_binding.descriptorCount = 1;
6199 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6200 dsl_binding.pImmutableSamplers = NULL;
6201
6202 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6203 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6204 ds_layout_ci.pNext = NULL;
6205 ds_layout_ci.bindingCount = 1;
6206 ds_layout_ci.pBindings = &dsl_binding;
6207 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006208 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006209 ASSERT_VK_SUCCESS(err);
6210
6211 VkDescriptorSet descriptorSet;
6212 VkDescriptorSetAllocateInfo alloc_info = {};
6213 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6214 alloc_info.descriptorSetCount = 1;
6215 alloc_info.descriptorPool = ds_pool;
6216 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006217 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006218 ASSERT_VK_SUCCESS(err);
6219
6220 // Create a buffer to update the descriptor with
6221 uint32_t qfi = 0;
6222 VkBufferCreateInfo buffCI = {};
6223 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6224 buffCI.size = 1024;
6225 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6226 buffCI.queueFamilyIndexCount = 1;
6227 buffCI.pQueueFamilyIndices = &qfi;
6228
6229 VkBuffer dyub;
6230 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6231 ASSERT_VK_SUCCESS(err);
6232
6233 // Attempt to update descriptor without binding memory to it
6234 VkDescriptorBufferInfo buffInfo = {};
6235 buffInfo.buffer = dyub;
6236 buffInfo.offset = 0;
6237 buffInfo.range = 1024;
6238
6239 VkWriteDescriptorSet descriptor_write;
6240 memset(&descriptor_write, 0, sizeof(descriptor_write));
6241 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6242 descriptor_write.dstSet = descriptorSet;
6243 descriptor_write.dstBinding = 0;
6244 descriptor_write.descriptorCount = 1;
6245 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6246 descriptor_write.pBufferInfo = &buffInfo;
6247
6248 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6249 m_errorMonitor->VerifyFound();
6250
6251 vkDestroyBuffer(m_device->device(), dyub, NULL);
6252 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6253 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6254}
6255
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006256TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006257 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006258 ASSERT_NO_FATAL_FAILURE(InitState());
6259 ASSERT_NO_FATAL_FAILURE(InitViewport());
6260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6261
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006262 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006263 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006264 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6265 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6266 pipeline_layout_ci.pushConstantRangeCount = 1;
6267 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6268
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006269 //
6270 // Check for invalid push constant ranges in pipeline layouts.
6271 //
6272 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006273 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006274 char const *msg;
6275 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006276
Karl Schultzc81037d2016-05-12 08:11:23 -06006277 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6278 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6279 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6280 "vkCreatePipelineLayout() call has push constants index 0 with "
6281 "size 0."},
6282 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6283 "vkCreatePipelineLayout() call has push constants index 0 with "
6284 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006285 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006286 "vkCreatePipelineLayout() call has push constants index 0 with "
6287 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006288 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006289 "vkCreatePipelineLayout() call has push constants index 0 with "
6290 "size 0."},
6291 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6292 "vkCreatePipelineLayout() call has push constants index 0 with "
6293 "offset 1. Offset must"},
6294 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6295 "vkCreatePipelineLayout() call has push constants index 0 "
6296 "with offset "},
6297 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6298 "vkCreatePipelineLayout() call has push constants "
6299 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006300 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006301 "vkCreatePipelineLayout() call has push constants index 0 "
6302 "with offset "},
6303 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6304 "vkCreatePipelineLayout() call has push "
6305 "constants index 0 with offset "},
6306 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6307 "vkCreatePipelineLayout() call has push "
6308 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006309 }};
6310
6311 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006312 for (const auto &iter : range_tests) {
6313 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6315 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006316 m_errorMonitor->VerifyFound();
6317 if (VK_SUCCESS == err) {
6318 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6319 }
6320 }
6321
6322 // Check for invalid stage flag
6323 pc_range.offset = 0;
6324 pc_range.size = 16;
6325 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006326 m_errorMonitor->SetDesiredFailureMsg(
6327 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6328 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006329 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006330 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006331 if (VK_SUCCESS == err) {
6332 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6333 }
6334
6335 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006336 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006337 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006338 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006339 char const *msg;
6340 };
6341
Karl Schultzc81037d2016-05-12 08:11:23 -06006342 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006343 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6344 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6345 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6346 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6347 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006348 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006349 {
6350 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6351 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6352 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6353 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6354 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006355 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006356 },
6357 {
6358 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6359 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6360 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6361 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6362 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006363 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006364 },
6365 {
6366 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6367 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6368 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6369 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6370 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006371 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006372 },
6373 {
6374 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6375 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6376 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6377 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6378 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006379 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006380 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006381
Karl Schultzc81037d2016-05-12 08:11:23 -06006382 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006383 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006384 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6386 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006387 m_errorMonitor->VerifyFound();
6388 if (VK_SUCCESS == err) {
6389 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6390 }
6391 }
6392
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006393 //
6394 // CmdPushConstants tests
6395 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006396 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006397
6398 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006399 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6400 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006401 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006402 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6403 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006404 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006405 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6406 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006407 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006408 "vkCmdPushConstants() call has push constants with offset 1. "
6409 "Offset must be a multiple of 4."},
6410 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6411 "vkCmdPushConstants() call has push constants with offset 1. "
6412 "Offset must be a multiple of 4."},
6413 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6414 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6415 "0x1 not within flag-matching ranges in pipeline layout"},
6416 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6417 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6418 "0x1 not within flag-matching ranges in pipeline layout"},
6419 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6420 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6421 "0x1 not within flag-matching ranges in pipeline layout"},
6422 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6423 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6424 "0x1 not within flag-matching ranges in pipeline layout"},
6425 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6426 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6427 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006428 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006429 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6430 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006431 }};
6432
Tony Barbour552f6c02016-12-21 14:34:07 -07006433 m_commandBuffer->BeginCommandBuffer();
6434 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006435
6436 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006437 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006438 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006439 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006440 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006441 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006442 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006443 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006444 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6446 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006447 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006448 m_errorMonitor->VerifyFound();
6449 }
6450
6451 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006453 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006454 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006455 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006456
Karl Schultzc81037d2016-05-12 08:11:23 -06006457 // overlapping range tests with cmd
6458 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6459 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6460 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6461 "0x1 not within flag-matching ranges in pipeline layout"},
6462 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6463 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6464 "0x1 not within flag-matching ranges in pipeline layout"},
6465 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6466 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6467 "0x1 not within flag-matching ranges in pipeline layout"},
6468 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006469 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006470 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006471 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6472 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006473 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006474 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006475 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006476 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006477 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006478 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6480 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006481 iter.range.size, dummy_values);
6482 m_errorMonitor->VerifyFound();
6483 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006484 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6485
Tony Barbour552f6c02016-12-21 14:34:07 -07006486 m_commandBuffer->EndRenderPass();
6487 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006488}
6489
Karl Schultz6addd812016-02-02 17:17:23 -07006490TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006491 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006492 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006493
6494 ASSERT_NO_FATAL_FAILURE(InitState());
6495 ASSERT_NO_FATAL_FAILURE(InitViewport());
6496 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6497
6498 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6499 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006500 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6501 ds_type_count[0].descriptorCount = 10;
6502 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6503 ds_type_count[1].descriptorCount = 2;
6504 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6505 ds_type_count[2].descriptorCount = 2;
6506 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6507 ds_type_count[3].descriptorCount = 5;
6508 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6509 // type
6510 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6511 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6512 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006513
6514 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006515 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6516 ds_pool_ci.pNext = NULL;
6517 ds_pool_ci.maxSets = 5;
6518 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6519 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006520
6521 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006522 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006523 ASSERT_VK_SUCCESS(err);
6524
6525 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6526 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006527 dsl_binding[0].binding = 0;
6528 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6529 dsl_binding[0].descriptorCount = 5;
6530 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6531 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006532
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006533 // Create layout identical to set0 layout but w/ different stageFlags
6534 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006535 dsl_fs_stage_only.binding = 0;
6536 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6537 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006538 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6539 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006540 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006541 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006542 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6543 ds_layout_ci.pNext = NULL;
6544 ds_layout_ci.bindingCount = 1;
6545 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006546 static const uint32_t NUM_LAYOUTS = 4;
6547 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006548 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006549 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6550 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006551 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006552 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006553 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006554 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006555 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006556 dsl_binding[0].binding = 0;
6557 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006558 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006559 dsl_binding[1].binding = 1;
6560 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6561 dsl_binding[1].descriptorCount = 2;
6562 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6563 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006564 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006565 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006566 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006567 ASSERT_VK_SUCCESS(err);
6568 dsl_binding[0].binding = 0;
6569 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006570 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006571 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006572 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006573 ASSERT_VK_SUCCESS(err);
6574 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006575 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006576 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006577 ASSERT_VK_SUCCESS(err);
6578
6579 static const uint32_t NUM_SETS = 4;
6580 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6581 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006582 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006583 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006584 alloc_info.descriptorPool = ds_pool;
6585 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006586 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006587 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006588 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006589 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006590 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006591 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006592 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006593
6594 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006595 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6596 pipeline_layout_ci.pNext = NULL;
6597 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6598 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006599
6600 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006601 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006602 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006603 // Create pipelineLayout with only one setLayout
6604 pipeline_layout_ci.setLayoutCount = 1;
6605 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006606 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006607 ASSERT_VK_SUCCESS(err);
6608 // Create pipelineLayout with 2 descriptor setLayout at index 0
6609 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6610 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006611 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006612 ASSERT_VK_SUCCESS(err);
6613 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6614 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6615 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006616 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006617 ASSERT_VK_SUCCESS(err);
6618 // Create pipelineLayout with UB type, but stageFlags for FS only
6619 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6620 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006621 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006622 ASSERT_VK_SUCCESS(err);
6623 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6624 VkDescriptorSetLayout pl_bad_s0[2] = {};
6625 pl_bad_s0[0] = ds_layout_fs_only;
6626 pl_bad_s0[1] = ds_layout[1];
6627 pipeline_layout_ci.setLayoutCount = 2;
6628 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6629 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006630 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006631 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006632
Tobin Ehlis88452832015-12-03 09:40:56 -07006633 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006634 char const *vsSource =
6635 "#version 450\n"
6636 "\n"
6637 "out gl_PerVertex {\n"
6638 " vec4 gl_Position;\n"
6639 "};\n"
6640 "void main(){\n"
6641 " gl_Position = vec4(1);\n"
6642 "}\n";
6643 char const *fsSource =
6644 "#version 450\n"
6645 "\n"
6646 "layout(location=0) out vec4 x;\n"
6647 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6648 "void main(){\n"
6649 " x = vec4(bar.y);\n"
6650 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006651 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6652 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006653 VkPipelineObj pipe(m_device);
6654 pipe.AddShader(&vs);
6655 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006656 pipe.AddColorAttachment();
6657 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006658
Tony Barbour552f6c02016-12-21 14:34:07 -07006659 m_commandBuffer->BeginCommandBuffer();
6660 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07006661
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006662 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006663 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6664 // of PSO
6665 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6666 // cmd_pipeline.c
6667 // due to the fact that cmd_alloc_dset_data() has not been called in
6668 // cmd_bind_graphics_pipeline()
6669 // TODO : Want to cause various binding incompatibility issues here to test
6670 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006671 // First cause various verify_layout_compatibility() fails
6672 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006673 // verify_set_layout_compatibility fail cases:
6674 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006676 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6677 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006678 m_errorMonitor->VerifyFound();
6679
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006680 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6682 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6683 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006684 m_errorMonitor->VerifyFound();
6685
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006686 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006687 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6688 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6690 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6691 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006692 m_errorMonitor->VerifyFound();
6693
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006694 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6695 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6697 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6698 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006699 m_errorMonitor->VerifyFound();
6700
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006701 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6702 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6704 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6705 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6706 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006707 m_errorMonitor->VerifyFound();
6708
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006709 // Cause INFO messages due to disturbing previously bound Sets
6710 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006711 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6712 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006713 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6715 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6716 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006717 m_errorMonitor->VerifyFound();
6718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006719 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6720 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006721 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006722 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6723 " newly bound as set #0 so set #1 and "
6724 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006725 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6726 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006727 m_errorMonitor->VerifyFound();
6728
Tobin Ehlis10fad692016-07-07 12:00:36 -06006729 // Now that we're done actively using the pipelineLayout that gfx pipeline
6730 // was created with, we should be able to delete it. Do that now to verify
6731 // that validation obeys pipelineLayout lifetime
6732 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6733
Tobin Ehlis88452832015-12-03 09:40:56 -07006734 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006735 // 1. Error due to not binding required set (we actually use same code as
6736 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006737 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6738 &descriptorSet[0], 0, NULL);
6739 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6740 &descriptorSet[1], 0, NULL);
6741 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 -07006742
6743 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6744 VkRect2D scissor = {{0, 0}, {16, 16}};
6745 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6746 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6747
Tobin Ehlis88452832015-12-03 09:40:56 -07006748 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006749 m_errorMonitor->VerifyFound();
6750
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006751 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006752 // 2. Error due to bound set not being compatible with PSO's
6753 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006754 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6755 &descriptorSet[0], 0, NULL);
6756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006757 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006758 m_errorMonitor->VerifyFound();
6759
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006760 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006761 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006762 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6763 }
6764 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006765 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6766 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6767}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006768
Karl Schultz6addd812016-02-02 17:17:23 -07006769TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6771 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006772
6773 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006774 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006775 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006776 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006777
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006778 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006779}
6780
Karl Schultz6addd812016-02-02 17:17:23 -07006781TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6782 VkResult err;
6783 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006784
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006786
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006787 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006788
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006789 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006790 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006791 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006792 cmd.commandPool = m_commandPool;
6793 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006794 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006795
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006796 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006797 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006798
6799 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07006800 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07006801 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
6802
6803 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006804 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006805 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006806 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 -07006807 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006808
6809 // The error should be caught by validation of the BeginCommandBuffer call
6810 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6811
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006812 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006813 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006814}
6815
Karl Schultz6addd812016-02-02 17:17:23 -07006816TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006817 // Cause error due to Begin while recording CB
6818 // Then cause 2 errors for attempting to reset CB w/o having
6819 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6820 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006822
6823 ASSERT_NO_FATAL_FAILURE(InitState());
6824
6825 // Calls AllocateCommandBuffers
6826 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6827
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006828 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07006829 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006830 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
6831 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006832 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6833 cmd_buf_info.pNext = NULL;
6834 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006835 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006836
6837 // Begin CB to transition to recording state
6838 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6839 // Can't re-begin. This should trigger error
6840 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006841 m_errorMonitor->VerifyFound();
6842
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006844 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006845 // Reset attempt will trigger error due to incorrect CommandPool state
6846 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006847 m_errorMonitor->VerifyFound();
6848
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006850 // Transition CB to RECORDED state
6851 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6852 // Now attempting to Begin will implicitly reset, which triggers error
6853 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006854 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006855}
6856
Karl Schultz6addd812016-02-02 17:17:23 -07006857TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006858 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006859 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006860
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07006861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6862 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006863
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006864 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006866
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006867 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006868 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6869 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006870
6871 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006872 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6873 ds_pool_ci.pNext = NULL;
6874 ds_pool_ci.maxSets = 1;
6875 ds_pool_ci.poolSizeCount = 1;
6876 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006877
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006878 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006879 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006880 ASSERT_VK_SUCCESS(err);
6881
Tony Barboureb254902015-07-15 12:50:33 -06006882 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006883 dsl_binding.binding = 0;
6884 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6885 dsl_binding.descriptorCount = 1;
6886 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6887 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006888
Tony Barboureb254902015-07-15 12:50:33 -06006889 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006890 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6891 ds_layout_ci.pNext = NULL;
6892 ds_layout_ci.bindingCount = 1;
6893 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006894
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006895 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006896 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006897 ASSERT_VK_SUCCESS(err);
6898
6899 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006900 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006901 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006902 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006903 alloc_info.descriptorPool = ds_pool;
6904 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006905 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006906 ASSERT_VK_SUCCESS(err);
6907
Tony Barboureb254902015-07-15 12:50:33 -06006908 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006909 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6910 pipeline_layout_ci.setLayoutCount = 1;
6911 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006912
6913 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006914 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006915 ASSERT_VK_SUCCESS(err);
6916
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006917 VkViewport vp = {}; // Just need dummy vp to point to
6918 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006919
6920 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006921 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6922 vp_state_ci.scissorCount = 1;
6923 vp_state_ci.pScissors = &sc;
6924 vp_state_ci.viewportCount = 1;
6925 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006926
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006927 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6928 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6929 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6930 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6931 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6932 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07006933 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006934 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07006935 rs_state_ci.lineWidth = 1.0f;
6936
6937 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6938 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6939 vi_ci.pNext = nullptr;
6940 vi_ci.vertexBindingDescriptionCount = 0;
6941 vi_ci.pVertexBindingDescriptions = nullptr;
6942 vi_ci.vertexAttributeDescriptionCount = 0;
6943 vi_ci.pVertexAttributeDescriptions = nullptr;
6944
6945 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6946 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6947 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6948
6949 VkPipelineShaderStageCreateInfo shaderStages[2];
6950 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6951
6952 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
6953 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6954 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
6955 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006956
Tony Barboureb254902015-07-15 12:50:33 -06006957 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006958 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6959 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006960 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006961 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6962 gp_ci.layout = pipeline_layout;
6963 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07006964 gp_ci.pVertexInputState = &vi_ci;
6965 gp_ci.pInputAssemblyState = &ia_ci;
6966
6967 gp_ci.stageCount = 1;
6968 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06006969
6970 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006971 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6972 pc_ci.initialDataSize = 0;
6973 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006974
6975 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006976 VkPipelineCache pipelineCache;
6977
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006978 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006979 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006980 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006981 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006982
Chia-I Wuf7458c52015-10-26 21:10:41 +08006983 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6984 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6985 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6986 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006987}
Rene Lindsayae4977b2017-01-23 14:55:54 -07006988
Tobin Ehlis912df022015-09-17 08:46:18 -06006989/*// TODO : This test should be good, but needs Tess support in compiler to run
6990TEST_F(VkLayerTest, InvalidPatchControlPoints)
6991{
6992 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006993 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006994
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006996 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6997primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006998
Tobin Ehlis912df022015-09-17 08:46:18 -06006999 ASSERT_NO_FATAL_FAILURE(InitState());
7000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007001
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007002 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007003 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007004 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007005
7006 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7007 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7008 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007009 ds_pool_ci.poolSizeCount = 1;
7010 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007011
7012 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007013 err = vkCreateDescriptorPool(m_device->device(),
7014VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007015 ASSERT_VK_SUCCESS(err);
7016
7017 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007018 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007019 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007020 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007021 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7022 dsl_binding.pImmutableSamplers = NULL;
7023
7024 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007025 ds_layout_ci.sType =
7026VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007027 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007028 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007029 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007030
7031 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007032 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7033&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007034 ASSERT_VK_SUCCESS(err);
7035
7036 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007037 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7038VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007039 ASSERT_VK_SUCCESS(err);
7040
7041 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007042 pipeline_layout_ci.sType =
7043VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007044 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007045 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007046 pipeline_layout_ci.pSetLayouts = &ds_layout;
7047
7048 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007049 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7050&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007051 ASSERT_VK_SUCCESS(err);
7052
7053 VkPipelineShaderStageCreateInfo shaderStages[3];
7054 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7055
Karl Schultz6addd812016-02-02 17:17:23 -07007056 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7057this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007058 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007059 VkShaderObj
7060tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7061this);
7062 VkShaderObj
7063te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7064this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007065
Karl Schultz6addd812016-02-02 17:17:23 -07007066 shaderStages[0].sType =
7067VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007068 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007069 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007070 shaderStages[1].sType =
7071VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007072 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007073 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007074 shaderStages[2].sType =
7075VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007076 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007077 shaderStages[2].shader = te.handle();
7078
7079 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007080 iaCI.sType =
7081VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007082 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007083
7084 VkPipelineTessellationStateCreateInfo tsCI = {};
7085 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7086 tsCI.patchControlPoints = 0; // This will cause an error
7087
7088 VkGraphicsPipelineCreateInfo gp_ci = {};
7089 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7090 gp_ci.pNext = NULL;
7091 gp_ci.stageCount = 3;
7092 gp_ci.pStages = shaderStages;
7093 gp_ci.pVertexInputState = NULL;
7094 gp_ci.pInputAssemblyState = &iaCI;
7095 gp_ci.pTessellationState = &tsCI;
7096 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007097 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007098 gp_ci.pMultisampleState = NULL;
7099 gp_ci.pDepthStencilState = NULL;
7100 gp_ci.pColorBlendState = NULL;
7101 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7102 gp_ci.layout = pipeline_layout;
7103 gp_ci.renderPass = renderPass();
7104
7105 VkPipelineCacheCreateInfo pc_ci = {};
7106 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7107 pc_ci.pNext = NULL;
7108 pc_ci.initialSize = 0;
7109 pc_ci.initialData = 0;
7110 pc_ci.maxSize = 0;
7111
7112 VkPipeline pipeline;
7113 VkPipelineCache pipelineCache;
7114
Karl Schultz6addd812016-02-02 17:17:23 -07007115 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7116&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007117 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007118 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7119&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007120
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007121 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007122
Chia-I Wuf7458c52015-10-26 21:10:41 +08007123 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7124 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7125 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7126 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007127}
7128*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007129
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007130TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007131 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007132
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007133 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007134
Tobin Ehlise68360f2015-10-01 11:15:13 -06007135 ASSERT_NO_FATAL_FAILURE(InitState());
7136 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007137
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007138 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007139 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7140 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007141
7142 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007143 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7144 ds_pool_ci.maxSets = 1;
7145 ds_pool_ci.poolSizeCount = 1;
7146 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007147
7148 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007149 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007150 ASSERT_VK_SUCCESS(err);
7151
7152 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007153 dsl_binding.binding = 0;
7154 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7155 dsl_binding.descriptorCount = 1;
7156 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007157
7158 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007159 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7160 ds_layout_ci.bindingCount = 1;
7161 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007162
7163 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007164 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007165 ASSERT_VK_SUCCESS(err);
7166
7167 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007168 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007169 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007170 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007171 alloc_info.descriptorPool = ds_pool;
7172 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007173 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007174 ASSERT_VK_SUCCESS(err);
7175
7176 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007177 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7178 pipeline_layout_ci.setLayoutCount = 1;
7179 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007180
7181 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007182 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007183 ASSERT_VK_SUCCESS(err);
7184
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007185 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007186 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007187 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007188 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007189 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007190 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007191
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007192 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7193 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7194 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7195 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7196 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7197 rs_state_ci.depthClampEnable = VK_FALSE;
7198 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7199 rs_state_ci.depthBiasEnable = VK_FALSE;
7200
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007201 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7202 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7203 vi_ci.pNext = nullptr;
7204 vi_ci.vertexBindingDescriptionCount = 0;
7205 vi_ci.pVertexBindingDescriptions = nullptr;
7206 vi_ci.vertexAttributeDescriptionCount = 0;
7207 vi_ci.pVertexAttributeDescriptions = nullptr;
7208
7209 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7210 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7211 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7212
7213 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7214 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7215 pipe_ms_state_ci.pNext = NULL;
7216 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7217 pipe_ms_state_ci.sampleShadingEnable = 0;
7218 pipe_ms_state_ci.minSampleShading = 1.0;
7219 pipe_ms_state_ci.pSampleMask = NULL;
7220
Cody Northropeb3a6c12015-10-05 14:44:45 -06007221 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007222 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007223
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007224 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007225 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007226 shaderStages[0] = vs.GetStageCreateInfo();
7227 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007228
7229 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007230 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7231 gp_ci.stageCount = 2;
7232 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007233 gp_ci.pVertexInputState = &vi_ci;
7234 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007235 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007236 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007237 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007238 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7239 gp_ci.layout = pipeline_layout;
7240 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007241
7242 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007243 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007244
7245 VkPipeline pipeline;
7246 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007247 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007248 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007249
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007250 if (!m_device->phy().features().multiViewport) {
7251 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7252
7253 // Check case where multiViewport is disabled and viewport count is not 1
7254 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7257 vp_state_ci.scissorCount = 0;
7258 vp_state_ci.viewportCount = 0;
7259 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7260 m_errorMonitor->VerifyFound();
7261 } else {
7262 if (m_device->props.limits.maxViewports == 1) {
7263 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7264 } else {
7265 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7266
7267 // Check is that viewportcount and scissorcount match
7268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7269 vp_state_ci.scissorCount = 1;
7270 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7271 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7272 m_errorMonitor->VerifyFound();
7273
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007274 // Check case where multiViewport is enabled and viewport count is greater than max
7275 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7278 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7279 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7280 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7281 m_errorMonitor->VerifyFound();
7282 }
7283 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007284
Chia-I Wuf7458c52015-10-26 21:10:41 +08007285 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7286 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7287 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7288 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007289}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007290
7291// 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
7292// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007293TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007294 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007295
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007296 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7297
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007299
Tobin Ehlise68360f2015-10-01 11:15:13 -06007300 ASSERT_NO_FATAL_FAILURE(InitState());
7301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007302
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007303 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007304 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7305 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007306
7307 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007308 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7309 ds_pool_ci.maxSets = 1;
7310 ds_pool_ci.poolSizeCount = 1;
7311 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007312
7313 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007314 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007315 ASSERT_VK_SUCCESS(err);
7316
7317 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007318 dsl_binding.binding = 0;
7319 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7320 dsl_binding.descriptorCount = 1;
7321 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007322
7323 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007324 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7325 ds_layout_ci.bindingCount = 1;
7326 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007327
7328 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007330 ASSERT_VK_SUCCESS(err);
7331
7332 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007333 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007334 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007335 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007336 alloc_info.descriptorPool = ds_pool;
7337 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007338 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007339 ASSERT_VK_SUCCESS(err);
7340
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007341 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7342 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7343 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7344
7345 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7346 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7347 vi_ci.pNext = nullptr;
7348 vi_ci.vertexBindingDescriptionCount = 0;
7349 vi_ci.pVertexBindingDescriptions = nullptr;
7350 vi_ci.vertexAttributeDescriptionCount = 0;
7351 vi_ci.pVertexAttributeDescriptions = nullptr;
7352
7353 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7354 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7355 pipe_ms_state_ci.pNext = NULL;
7356 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7357 pipe_ms_state_ci.sampleShadingEnable = 0;
7358 pipe_ms_state_ci.minSampleShading = 1.0;
7359 pipe_ms_state_ci.pSampleMask = NULL;
7360
Tobin Ehlise68360f2015-10-01 11:15:13 -06007361 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007362 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7363 pipeline_layout_ci.setLayoutCount = 1;
7364 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007365
7366 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007367 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007368 ASSERT_VK_SUCCESS(err);
7369
7370 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7371 // Set scissor as dynamic to avoid second error
7372 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007373 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7374 dyn_state_ci.dynamicStateCount = 1;
7375 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007376
Cody Northropeb3a6c12015-10-05 14:44:45 -06007377 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007378 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007379
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007380 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007381 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7382 // 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 +08007383 shaderStages[0] = vs.GetStageCreateInfo();
7384 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007385
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007386 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7387 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7388 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7389 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7390 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7391 rs_state_ci.depthClampEnable = VK_FALSE;
7392 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7393 rs_state_ci.depthBiasEnable = VK_FALSE;
7394
Tobin Ehlise68360f2015-10-01 11:15:13 -06007395 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007396 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7397 gp_ci.stageCount = 2;
7398 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007399 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007400 // Not setting VP state w/o dynamic vp state should cause validation error
7401 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007402 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007403 gp_ci.pVertexInputState = &vi_ci;
7404 gp_ci.pInputAssemblyState = &ia_ci;
7405 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007406 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7407 gp_ci.layout = pipeline_layout;
7408 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007409
7410 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007411 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007412
7413 VkPipeline pipeline;
7414 VkPipelineCache pipelineCache;
7415
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007416 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007417 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007418 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007419
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007420 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007421
Chia-I Wuf7458c52015-10-26 21:10:41 +08007422 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7423 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7424 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7425 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007426}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007427
7428// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7429// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007430TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7431 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007432
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007434
Tobin Ehlise68360f2015-10-01 11:15:13 -06007435 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007436
7437 if (!m_device->phy().features().multiViewport) {
7438 printf("Device does not support multiple viewports/scissors; skipped.\n");
7439 return;
7440 }
7441
Tobin Ehlise68360f2015-10-01 11:15:13 -06007442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007443
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007444 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007445 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7446 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007447
7448 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007449 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7450 ds_pool_ci.maxSets = 1;
7451 ds_pool_ci.poolSizeCount = 1;
7452 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007453
7454 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007455 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007456 ASSERT_VK_SUCCESS(err);
7457
7458 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007459 dsl_binding.binding = 0;
7460 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7461 dsl_binding.descriptorCount = 1;
7462 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007463
7464 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007465 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7466 ds_layout_ci.bindingCount = 1;
7467 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007468
7469 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007470 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007471 ASSERT_VK_SUCCESS(err);
7472
7473 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007474 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007475 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007476 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007477 alloc_info.descriptorPool = ds_pool;
7478 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007479 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007480 ASSERT_VK_SUCCESS(err);
7481
7482 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007483 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7484 pipeline_layout_ci.setLayoutCount = 1;
7485 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007486
7487 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007488 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007489 ASSERT_VK_SUCCESS(err);
7490
7491 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007492 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7493 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007494 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007495 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007496 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007497
7498 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7499 // Set scissor as dynamic to avoid that error
7500 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007501 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7502 dyn_state_ci.dynamicStateCount = 1;
7503 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007504
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007505 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7506 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7507 pipe_ms_state_ci.pNext = NULL;
7508 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7509 pipe_ms_state_ci.sampleShadingEnable = 0;
7510 pipe_ms_state_ci.minSampleShading = 1.0;
7511 pipe_ms_state_ci.pSampleMask = NULL;
7512
Cody Northropeb3a6c12015-10-05 14:44:45 -06007513 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007514 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007515
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007516 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007517 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7518 // 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 +08007519 shaderStages[0] = vs.GetStageCreateInfo();
7520 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007521
Cody Northropf6622dc2015-10-06 10:33:21 -06007522 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7523 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7524 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007525 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007526 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007527 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007528 vi_ci.pVertexAttributeDescriptions = nullptr;
7529
7530 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7531 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7532 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7533
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007534 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007535 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007536 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007537 rs_ci.pNext = nullptr;
7538
Mark Youngc89c6312016-03-31 16:03:20 -06007539 VkPipelineColorBlendAttachmentState att = {};
7540 att.blendEnable = VK_FALSE;
7541 att.colorWriteMask = 0xf;
7542
Cody Northropf6622dc2015-10-06 10:33:21 -06007543 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7544 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7545 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007546 cb_ci.attachmentCount = 1;
7547 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007548
Tobin Ehlise68360f2015-10-01 11:15:13 -06007549 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007550 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7551 gp_ci.stageCount = 2;
7552 gp_ci.pStages = shaderStages;
7553 gp_ci.pVertexInputState = &vi_ci;
7554 gp_ci.pInputAssemblyState = &ia_ci;
7555 gp_ci.pViewportState = &vp_state_ci;
7556 gp_ci.pRasterizationState = &rs_ci;
7557 gp_ci.pColorBlendState = &cb_ci;
7558 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007559 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007560 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7561 gp_ci.layout = pipeline_layout;
7562 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007563
7564 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007565 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007566
7567 VkPipeline pipeline;
7568 VkPipelineCache pipelineCache;
7569
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007570 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007571 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007572 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007573
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007574 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007575
Tobin Ehlisd332f282015-10-02 11:00:56 -06007576 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007577 // First need to successfully create the PSO from above by setting
7578 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007579 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 -07007580
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007581 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07007582 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007583 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007584 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007585 m_commandBuffer->BeginCommandBuffer();
7586 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007587 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007588 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007589 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007590 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007591 Draw(1, 0, 0, 0);
7592
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007593 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007594
7595 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7596 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7597 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7598 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007599 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007600}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007601
7602// 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 -07007603// viewportCount
7604TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7605 VkResult err;
7606
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007608
7609 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007610
7611 if (!m_device->phy().features().multiViewport) {
7612 printf("Device does not support multiple viewports/scissors; skipped.\n");
7613 return;
7614 }
7615
Karl Schultz6addd812016-02-02 17:17:23 -07007616 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7617
7618 VkDescriptorPoolSize ds_type_count = {};
7619 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7620 ds_type_count.descriptorCount = 1;
7621
7622 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7623 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7624 ds_pool_ci.maxSets = 1;
7625 ds_pool_ci.poolSizeCount = 1;
7626 ds_pool_ci.pPoolSizes = &ds_type_count;
7627
7628 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007629 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007630 ASSERT_VK_SUCCESS(err);
7631
7632 VkDescriptorSetLayoutBinding dsl_binding = {};
7633 dsl_binding.binding = 0;
7634 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7635 dsl_binding.descriptorCount = 1;
7636 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7637
7638 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7639 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7640 ds_layout_ci.bindingCount = 1;
7641 ds_layout_ci.pBindings = &dsl_binding;
7642
7643 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007644 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007645 ASSERT_VK_SUCCESS(err);
7646
7647 VkDescriptorSet descriptorSet;
7648 VkDescriptorSetAllocateInfo alloc_info = {};
7649 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7650 alloc_info.descriptorSetCount = 1;
7651 alloc_info.descriptorPool = ds_pool;
7652 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007653 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007654 ASSERT_VK_SUCCESS(err);
7655
7656 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7657 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7658 pipeline_layout_ci.setLayoutCount = 1;
7659 pipeline_layout_ci.pSetLayouts = &ds_layout;
7660
7661 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007662 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007663 ASSERT_VK_SUCCESS(err);
7664
7665 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7666 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7667 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007668 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007669 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007670 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007671
7672 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7673 // Set scissor as dynamic to avoid that error
7674 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7675 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7676 dyn_state_ci.dynamicStateCount = 1;
7677 dyn_state_ci.pDynamicStates = &vp_state;
7678
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007679 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7680 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7681 pipe_ms_state_ci.pNext = NULL;
7682 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7683 pipe_ms_state_ci.sampleShadingEnable = 0;
7684 pipe_ms_state_ci.minSampleShading = 1.0;
7685 pipe_ms_state_ci.pSampleMask = NULL;
7686
Karl Schultz6addd812016-02-02 17:17:23 -07007687 VkPipelineShaderStageCreateInfo shaderStages[2];
7688 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7689
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007690 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007691 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7692 // 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 -07007693 shaderStages[0] = vs.GetStageCreateInfo();
7694 shaderStages[1] = fs.GetStageCreateInfo();
7695
7696 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7697 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7698 vi_ci.pNext = nullptr;
7699 vi_ci.vertexBindingDescriptionCount = 0;
7700 vi_ci.pVertexBindingDescriptions = nullptr;
7701 vi_ci.vertexAttributeDescriptionCount = 0;
7702 vi_ci.pVertexAttributeDescriptions = nullptr;
7703
7704 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7705 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7706 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7707
7708 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7709 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007710 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007711 rs_ci.pNext = nullptr;
7712
Mark Youngc89c6312016-03-31 16:03:20 -06007713 VkPipelineColorBlendAttachmentState att = {};
7714 att.blendEnable = VK_FALSE;
7715 att.colorWriteMask = 0xf;
7716
Karl Schultz6addd812016-02-02 17:17:23 -07007717 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7718 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7719 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007720 cb_ci.attachmentCount = 1;
7721 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007722
7723 VkGraphicsPipelineCreateInfo gp_ci = {};
7724 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7725 gp_ci.stageCount = 2;
7726 gp_ci.pStages = shaderStages;
7727 gp_ci.pVertexInputState = &vi_ci;
7728 gp_ci.pInputAssemblyState = &ia_ci;
7729 gp_ci.pViewportState = &vp_state_ci;
7730 gp_ci.pRasterizationState = &rs_ci;
7731 gp_ci.pColorBlendState = &cb_ci;
7732 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007733 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007734 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7735 gp_ci.layout = pipeline_layout;
7736 gp_ci.renderPass = renderPass();
7737
7738 VkPipelineCacheCreateInfo pc_ci = {};
7739 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7740
7741 VkPipeline pipeline;
7742 VkPipelineCache pipelineCache;
7743
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007744 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007745 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007746 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007747
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007748 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007749
7750 // Now hit second fail case where we set scissor w/ different count than PSO
7751 // First need to successfully create the PSO from above by setting
7752 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7754 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007755
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007756 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06007757 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007758 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007759 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007760 m_commandBuffer->BeginCommandBuffer();
7761 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007762 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007763 VkViewport viewports[1] = {};
7764 viewports[0].width = 8;
7765 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007766 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007767 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007768 Draw(1, 0, 0, 0);
7769
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007770 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007771
Chia-I Wuf7458c52015-10-26 21:10:41 +08007772 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7773 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7774 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7775 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007776 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007777}
7778
Mark Young7394fdd2016-03-31 14:56:43 -06007779TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7780 VkResult err;
7781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007783
7784 ASSERT_NO_FATAL_FAILURE(InitState());
7785 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7786
7787 VkDescriptorPoolSize ds_type_count = {};
7788 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7789 ds_type_count.descriptorCount = 1;
7790
7791 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7792 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7793 ds_pool_ci.maxSets = 1;
7794 ds_pool_ci.poolSizeCount = 1;
7795 ds_pool_ci.pPoolSizes = &ds_type_count;
7796
7797 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007798 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007799 ASSERT_VK_SUCCESS(err);
7800
7801 VkDescriptorSetLayoutBinding dsl_binding = {};
7802 dsl_binding.binding = 0;
7803 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7804 dsl_binding.descriptorCount = 1;
7805 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7806
7807 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7808 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7809 ds_layout_ci.bindingCount = 1;
7810 ds_layout_ci.pBindings = &dsl_binding;
7811
7812 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007813 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007814 ASSERT_VK_SUCCESS(err);
7815
7816 VkDescriptorSet descriptorSet;
7817 VkDescriptorSetAllocateInfo alloc_info = {};
7818 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7819 alloc_info.descriptorSetCount = 1;
7820 alloc_info.descriptorPool = ds_pool;
7821 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007822 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007823 ASSERT_VK_SUCCESS(err);
7824
7825 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7826 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7827 pipeline_layout_ci.setLayoutCount = 1;
7828 pipeline_layout_ci.pSetLayouts = &ds_layout;
7829
7830 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007831 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007832 ASSERT_VK_SUCCESS(err);
7833
7834 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7835 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7836 vp_state_ci.scissorCount = 1;
7837 vp_state_ci.pScissors = NULL;
7838 vp_state_ci.viewportCount = 1;
7839 vp_state_ci.pViewports = NULL;
7840
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007841 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007842 // Set scissor as dynamic to avoid that error
7843 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7844 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7845 dyn_state_ci.dynamicStateCount = 2;
7846 dyn_state_ci.pDynamicStates = dynamic_states;
7847
7848 VkPipelineShaderStageCreateInfo shaderStages[2];
7849 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7850
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007851 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7852 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007853 this); // TODO - We shouldn't need a fragment shader
7854 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06007855 shaderStages[0] = vs.GetStageCreateInfo();
7856 shaderStages[1] = fs.GetStageCreateInfo();
7857
7858 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7859 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7860 vi_ci.pNext = nullptr;
7861 vi_ci.vertexBindingDescriptionCount = 0;
7862 vi_ci.pVertexBindingDescriptions = nullptr;
7863 vi_ci.vertexAttributeDescriptionCount = 0;
7864 vi_ci.pVertexAttributeDescriptions = nullptr;
7865
7866 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7867 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7868 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7869
7870 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7871 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7872 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07007873 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06007874
Mark Young47107952016-05-02 15:59:55 -06007875 // Check too low (line width of -1.0f).
7876 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007877
7878 VkPipelineColorBlendAttachmentState att = {};
7879 att.blendEnable = VK_FALSE;
7880 att.colorWriteMask = 0xf;
7881
7882 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7883 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7884 cb_ci.pNext = nullptr;
7885 cb_ci.attachmentCount = 1;
7886 cb_ci.pAttachments = &att;
7887
7888 VkGraphicsPipelineCreateInfo gp_ci = {};
7889 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7890 gp_ci.stageCount = 2;
7891 gp_ci.pStages = shaderStages;
7892 gp_ci.pVertexInputState = &vi_ci;
7893 gp_ci.pInputAssemblyState = &ia_ci;
7894 gp_ci.pViewportState = &vp_state_ci;
7895 gp_ci.pRasterizationState = &rs_ci;
7896 gp_ci.pColorBlendState = &cb_ci;
7897 gp_ci.pDynamicState = &dyn_state_ci;
7898 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7899 gp_ci.layout = pipeline_layout;
7900 gp_ci.renderPass = renderPass();
7901
7902 VkPipelineCacheCreateInfo pc_ci = {};
7903 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7904
7905 VkPipeline pipeline;
7906 VkPipelineCache pipelineCache;
7907
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007908 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007909 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007910 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007911
7912 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007913 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007914
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007916
7917 // Check too high (line width of 65536.0f).
7918 rs_ci.lineWidth = 65536.0f;
7919
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007920 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007921 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007922 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007923
7924 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007925 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007926
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007928
7929 dyn_state_ci.dynamicStateCount = 3;
7930
7931 rs_ci.lineWidth = 1.0f;
7932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007933 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007934 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007935 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07007936 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007937 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007938
7939 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007940 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007941 m_errorMonitor->VerifyFound();
7942
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007944
7945 // Check too high with dynamic setting.
7946 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7947 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07007948 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06007949
7950 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7951 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7952 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7953 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007954 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007955}
7956
Karl Schultz6addd812016-02-02 17:17:23 -07007957TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007958 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07007960 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007961
7962 ASSERT_NO_FATAL_FAILURE(InitState());
7963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007964
Tony Barbour552f6c02016-12-21 14:34:07 -07007965 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007966 // Don't care about RenderPass handle b/c error should be flagged before
7967 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007968 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007969
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007970 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007971}
7972
Karl Schultz6addd812016-02-02 17:17:23 -07007973TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007974 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7976 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007977
7978 ASSERT_NO_FATAL_FAILURE(InitState());
7979 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007980
Tony Barbour552f6c02016-12-21 14:34:07 -07007981 m_commandBuffer->BeginCommandBuffer();
7982 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07007983 // Just create a dummy Renderpass that's non-NULL so we can get to the
7984 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007985 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007986
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007987 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007988}
7989
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007990TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007991 TEST_DESCRIPTION(
7992 "Begin a renderPass where clearValueCount is less than"
7993 "the number of renderPass attachments that use loadOp"
7994 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007995
7996 ASSERT_NO_FATAL_FAILURE(InitState());
7997 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7998
7999 // Create a renderPass with a single attachment that uses loadOp CLEAR
8000 VkAttachmentReference attach = {};
8001 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8002 VkSubpassDescription subpass = {};
8003 subpass.inputAttachmentCount = 1;
8004 subpass.pInputAttachments = &attach;
8005 VkRenderPassCreateInfo rpci = {};
8006 rpci.subpassCount = 1;
8007 rpci.pSubpasses = &subpass;
8008 rpci.attachmentCount = 1;
8009 VkAttachmentDescription attach_desc = {};
8010 attach_desc.format = VK_FORMAT_UNDEFINED;
8011 // Set loadOp to CLEAR
8012 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8013 rpci.pAttachments = &attach_desc;
8014 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8015 VkRenderPass rp;
8016 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8017
8018 VkCommandBufferInheritanceInfo hinfo = {};
8019 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8020 hinfo.renderPass = VK_NULL_HANDLE;
8021 hinfo.subpass = 0;
8022 hinfo.framebuffer = VK_NULL_HANDLE;
8023 hinfo.occlusionQueryEnable = VK_FALSE;
8024 hinfo.queryFlags = 0;
8025 hinfo.pipelineStatistics = 0;
8026 VkCommandBufferBeginInfo info = {};
8027 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8028 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8029 info.pInheritanceInfo = &hinfo;
8030
8031 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8032 VkRenderPassBeginInfo rp_begin = {};
8033 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8034 rp_begin.pNext = NULL;
8035 rp_begin.renderPass = renderPass();
8036 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008037 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008038
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008040
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008041 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008042
8043 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008044
8045 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008046}
8047
Slawomir Cygan0808f392016-11-28 17:53:23 +01008048TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008049 TEST_DESCRIPTION(
8050 "Begin a renderPass where clearValueCount is greater than"
8051 "the number of renderPass attachments that use loadOp"
8052 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008053
8054 ASSERT_NO_FATAL_FAILURE(InitState());
8055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8056
8057 // Create a renderPass with a single attachment that uses loadOp CLEAR
8058 VkAttachmentReference attach = {};
8059 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8060 VkSubpassDescription subpass = {};
8061 subpass.inputAttachmentCount = 1;
8062 subpass.pInputAttachments = &attach;
8063 VkRenderPassCreateInfo rpci = {};
8064 rpci.subpassCount = 1;
8065 rpci.pSubpasses = &subpass;
8066 rpci.attachmentCount = 1;
8067 VkAttachmentDescription attach_desc = {};
8068 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8069 // Set loadOp to CLEAR
8070 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8071 rpci.pAttachments = &attach_desc;
8072 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8073 VkRenderPass rp;
8074 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8075
8076 VkCommandBufferBeginInfo info = {};
8077 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8078 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8079
8080 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8081 VkRenderPassBeginInfo rp_begin = {};
8082 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8083 rp_begin.pNext = NULL;
8084 rp_begin.renderPass = renderPass();
8085 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008086 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008087
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8089 " has a clearValueCount of"
8090 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008091
8092 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8093
8094 m_errorMonitor->VerifyFound();
8095
8096 vkDestroyRenderPass(m_device->device(), rp, NULL);
8097}
8098
Cody Northrop3bb4d962016-05-09 16:15:57 -06008099TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008100 TEST_DESCRIPTION("End a command buffer with an active render pass");
8101
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8103 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008104
8105 ASSERT_NO_FATAL_FAILURE(InitState());
8106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8107
Tony Barbour552f6c02016-12-21 14:34:07 -07008108 m_commandBuffer->BeginCommandBuffer();
8109 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8110 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008111
8112 m_errorMonitor->VerifyFound();
8113
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008114 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8115 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008116}
8117
Karl Schultz6addd812016-02-02 17:17:23 -07008118TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008119 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8121 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008122
8123 ASSERT_NO_FATAL_FAILURE(InitState());
8124 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008125
Tony Barbour552f6c02016-12-21 14:34:07 -07008126 m_commandBuffer->BeginCommandBuffer();
8127 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008128
8129 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008130 vk_testing::Buffer dstBuffer;
8131 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008132
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008133 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008134
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008135 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008136}
8137
Karl Schultz6addd812016-02-02 17:17:23 -07008138TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008139 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8141 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008142
8143 ASSERT_NO_FATAL_FAILURE(InitState());
8144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008145
Tony Barbour552f6c02016-12-21 14:34:07 -07008146 m_commandBuffer->BeginCommandBuffer();
8147 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008148
8149 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008150 vk_testing::Buffer dstBuffer;
8151 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008152
Karl Schultz6addd812016-02-02 17:17:23 -07008153 VkDeviceSize dstOffset = 0;
8154 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008155 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008157 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008158
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008159 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008160}
8161
Karl Schultz6addd812016-02-02 17:17:23 -07008162TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008163 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8165 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008166
8167 ASSERT_NO_FATAL_FAILURE(InitState());
8168 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008169
Tony Barbour552f6c02016-12-21 14:34:07 -07008170 m_commandBuffer->BeginCommandBuffer();
8171 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008172
Michael Lentine0a369f62016-02-03 16:51:46 -06008173 VkClearColorValue clear_color;
8174 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008175 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8176 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8177 const int32_t tex_width = 32;
8178 const int32_t tex_height = 32;
8179 VkImageCreateInfo image_create_info = {};
8180 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8181 image_create_info.pNext = NULL;
8182 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8183 image_create_info.format = tex_format;
8184 image_create_info.extent.width = tex_width;
8185 image_create_info.extent.height = tex_height;
8186 image_create_info.extent.depth = 1;
8187 image_create_info.mipLevels = 1;
8188 image_create_info.arrayLayers = 1;
8189 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8190 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8191 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008192
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008193 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008194 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008195
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008196 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008197
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008198 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008199
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008200 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008201}
8202
Karl Schultz6addd812016-02-02 17:17:23 -07008203TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008204 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8206 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008207
8208 ASSERT_NO_FATAL_FAILURE(InitState());
8209 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008210
Tony Barbour552f6c02016-12-21 14:34:07 -07008211 m_commandBuffer->BeginCommandBuffer();
8212 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008213
8214 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008215 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008216 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8217 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8218 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8219 image_create_info.extent.width = 64;
8220 image_create_info.extent.height = 64;
8221 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8222 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008223
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008224 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008225 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008227 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008228
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008229 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8230 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008231
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008232 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008233}
8234
Karl Schultz6addd812016-02-02 17:17:23 -07008235TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008236 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008237 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008238
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8240 "vkCmdClearAttachments(): This call "
8241 "must be issued inside an active "
8242 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008243
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008244 ASSERT_NO_FATAL_FAILURE(InitState());
8245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008246
8247 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008248 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008249 ASSERT_VK_SUCCESS(err);
8250
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008251 VkClearAttachment color_attachment;
8252 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8253 color_attachment.clearValue.color.float32[0] = 0;
8254 color_attachment.clearValue.color.float32[1] = 0;
8255 color_attachment.clearValue.color.float32[2] = 0;
8256 color_attachment.clearValue.color.float32[3] = 0;
8257 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008258 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008259 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008260
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008261 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008262}
8263
Chris Forbes3b97e932016-09-07 11:29:24 +12008264TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008265 TEST_DESCRIPTION(
8266 "Test that an error is produced when CmdNextSubpass is "
8267 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008268
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8270 "vkCmdNextSubpass(): Attempted to advance "
8271 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008272
8273 ASSERT_NO_FATAL_FAILURE(InitState());
8274 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8275
Tony Barbour552f6c02016-12-21 14:34:07 -07008276 m_commandBuffer->BeginCommandBuffer();
8277 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008278
8279 // error here.
8280 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8281 m_errorMonitor->VerifyFound();
8282
Tony Barbour552f6c02016-12-21 14:34:07 -07008283 m_commandBuffer->EndRenderPass();
8284 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008285}
8286
Chris Forbes6d624702016-09-07 13:57:05 +12008287TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008288 TEST_DESCRIPTION(
8289 "Test that an error is produced when CmdEndRenderPass is "
8290 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008291
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8293 "vkCmdEndRenderPass(): Called before reaching "
8294 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008295
8296 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008297 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8298 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008299
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008300 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008301
8302 VkRenderPass rp;
8303 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8304 ASSERT_VK_SUCCESS(err);
8305
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008306 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008307
8308 VkFramebuffer fb;
8309 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8310 ASSERT_VK_SUCCESS(err);
8311
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008312 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008313
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008314 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 +12008315
8316 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8317
8318 // Error here.
8319 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8320 m_errorMonitor->VerifyFound();
8321
8322 // Clean up.
8323 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8324 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8325}
8326
Karl Schultz9e66a292016-04-21 15:57:51 -06008327TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8328 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8330 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008331
8332 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008333 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008334
8335 VkBufferMemoryBarrier buf_barrier = {};
8336 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8337 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8338 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8339 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8340 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8341 buf_barrier.buffer = VK_NULL_HANDLE;
8342 buf_barrier.offset = 0;
8343 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008344 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8345 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008346
8347 m_errorMonitor->VerifyFound();
8348}
8349
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008350TEST_F(VkLayerTest, InvalidBarriers) {
8351 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8352
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008354
8355 ASSERT_NO_FATAL_FAILURE(InitState());
8356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8357
8358 VkMemoryBarrier mem_barrier = {};
8359 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8360 mem_barrier.pNext = NULL;
8361 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8362 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008363 m_commandBuffer->BeginCommandBuffer();
8364 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008365 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008366 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008367 &mem_barrier, 0, nullptr, 0, nullptr);
8368 m_errorMonitor->VerifyFound();
8369
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008371 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008372 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 -06008373 ASSERT_TRUE(image.initialized());
8374 VkImageMemoryBarrier img_barrier = {};
8375 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8376 img_barrier.pNext = NULL;
8377 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8378 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8379 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8380 // New layout can't be UNDEFINED
8381 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8382 img_barrier.image = image.handle();
8383 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8384 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8385 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8386 img_barrier.subresourceRange.baseArrayLayer = 0;
8387 img_barrier.subresourceRange.baseMipLevel = 0;
8388 img_barrier.subresourceRange.layerCount = 1;
8389 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008390 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8391 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008392 m_errorMonitor->VerifyFound();
8393 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8394
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8396 "Subresource must have the sum of the "
8397 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008398 // baseArrayLayer + layerCount must be <= image's arrayLayers
8399 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008400 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8401 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008402 m_errorMonitor->VerifyFound();
8403 img_barrier.subresourceRange.baseArrayLayer = 0;
8404
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008406 // baseMipLevel + levelCount must be <= image's mipLevels
8407 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008408 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8409 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008410 m_errorMonitor->VerifyFound();
8411 img_barrier.subresourceRange.baseMipLevel = 0;
8412
Mike Weiblen7053aa32017-01-25 15:21:10 -07008413 // levelCount must be non-zero.
8414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8415 img_barrier.subresourceRange.levelCount = 0;
8416 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8417 nullptr, 0, nullptr, 1, &img_barrier);
8418 m_errorMonitor->VerifyFound();
8419 img_barrier.subresourceRange.levelCount = 1;
8420
8421 // layerCount must be non-zero.
8422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8423 img_barrier.subresourceRange.layerCount = 0;
8424 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8425 nullptr, 0, nullptr, 1, &img_barrier);
8426 m_errorMonitor->VerifyFound();
8427 img_barrier.subresourceRange.layerCount = 1;
8428
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008429 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 -06008430 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008431 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8432 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008433 VkBufferMemoryBarrier buf_barrier = {};
8434 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8435 buf_barrier.pNext = NULL;
8436 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8437 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8438 buf_barrier.buffer = buffer.handle();
8439 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8440 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8441 buf_barrier.offset = 0;
8442 buf_barrier.size = VK_WHOLE_SIZE;
8443 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008444 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8445 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008446 m_errorMonitor->VerifyFound();
8447 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8448
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008450 buf_barrier.offset = 257;
8451 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008452 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8453 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008454 m_errorMonitor->VerifyFound();
8455 buf_barrier.offset = 0;
8456
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008458 buf_barrier.size = 257;
8459 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008460 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8461 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008462 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008463
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008464 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008465 m_errorMonitor->SetDesiredFailureMsg(
8466 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008467 "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 -06008468 VkDepthStencilObj ds_image(m_device);
8469 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8470 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008471 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8472 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008473 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008474
8475 // Not having DEPTH or STENCIL set is an error
8476 img_barrier.subresourceRange.aspectMask = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008477 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8478 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008479 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07008480
8481 // Having anything other than DEPTH or STENCIL is an error
8482 m_errorMonitor->SetDesiredFailureMsg(
8483 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8484 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8485 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
8486 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8487 nullptr, 0, nullptr, 1, &img_barrier);
8488 m_errorMonitor->VerifyFound();
8489
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008490 // Now test depth-only
8491 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008492 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8493 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008494 VkDepthStencilObj d_image(m_device);
8495 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8496 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008497 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008498 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008499 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008500
8501 // DEPTH bit must be set
8502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8503 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8504 img_barrier.subresourceRange.aspectMask = 0;
8505 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8506 0, nullptr, 0, nullptr, 1, &img_barrier);
8507 m_errorMonitor->VerifyFound();
8508
8509 // No bits other than DEPTH may be set
8510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8511 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8512 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008513 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8514 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008515 m_errorMonitor->VerifyFound();
8516 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008517
8518 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008519 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8520 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8522 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008523 VkDepthStencilObj s_image(m_device);
8524 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8525 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008526 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008527 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008528 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008529 // Use of COLOR aspect on depth image is error
8530 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008531 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8532 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008533 m_errorMonitor->VerifyFound();
8534 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008535
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008536 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008537 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008538 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 -06008539 ASSERT_TRUE(c_image.initialized());
8540 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8541 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8542 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008543
8544 // COLOR bit must be set
8545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8546 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8547 img_barrier.subresourceRange.aspectMask = 0;
8548 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8549 nullptr, 0, nullptr, 1, &img_barrier);
8550 m_errorMonitor->VerifyFound();
8551
8552 // No bits other than COLOR may be set
8553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8554 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
8555 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008556 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8557 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008558 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008559
8560 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8561
8562 // Create command pool with incompatible queueflags
8563 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8564 uint32_t queue_family_index = UINT32_MAX;
8565 for (uint32_t i = 0; i < queue_props.size(); i++) {
8566 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8567 queue_family_index = i;
8568 break;
8569 }
8570 }
8571 if (queue_family_index == UINT32_MAX) {
8572 printf("No non-compute queue found; skipped.\n");
8573 return;
8574 }
8575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8576
8577 VkCommandPool command_pool;
8578 VkCommandPoolCreateInfo pool_create_info{};
8579 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8580 pool_create_info.queueFamilyIndex = queue_family_index;
8581 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8582 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8583
8584 // Allocate a command buffer
8585 VkCommandBuffer bad_command_buffer;
8586 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8587 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8588 command_buffer_allocate_info.commandPool = command_pool;
8589 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8590 command_buffer_allocate_info.commandBufferCount = 1;
8591 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8592
8593 VkCommandBufferBeginInfo cbbi = {};
8594 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8595 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8596 buf_barrier.offset = 0;
8597 buf_barrier.size = VK_WHOLE_SIZE;
8598 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8599 &buf_barrier, 0, nullptr);
8600 m_errorMonitor->VerifyFound();
8601
8602 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8603 vkEndCommandBuffer(bad_command_buffer);
8604 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8605 printf("The non-compute queue does not support graphics; skipped.\n");
8606 return;
8607 }
8608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8609 VkEvent event;
8610 VkEventCreateInfo event_create_info{};
8611 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8612 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8613 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8614 nullptr, 0, nullptr);
8615 m_errorMonitor->VerifyFound();
8616
8617 vkEndCommandBuffer(bad_command_buffer);
8618 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008619}
8620
Tony Barbour18ba25c2016-09-29 13:42:40 -06008621TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8622 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8623
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06008625 ASSERT_NO_FATAL_FAILURE(InitState());
8626 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008627 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 -06008628 ASSERT_TRUE(image.initialized());
8629
8630 VkImageMemoryBarrier barrier = {};
8631 VkImageSubresourceRange range;
8632 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8633 barrier.srcAccessMask = 0;
8634 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8635 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8636 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8637 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8638 barrier.image = image.handle();
8639 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8640 range.baseMipLevel = 0;
8641 range.levelCount = 1;
8642 range.baseArrayLayer = 0;
8643 range.layerCount = 1;
8644 barrier.subresourceRange = range;
8645 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8646 cmdbuf.BeginCommandBuffer();
8647 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8648 &barrier);
8649 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8650 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8651 barrier.srcAccessMask = 0;
8652 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8653 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8654 &barrier);
8655
8656 m_errorMonitor->VerifyFound();
8657}
8658
Karl Schultz6addd812016-02-02 17:17:23 -07008659TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008660 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008661 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008662
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008664
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008665 ASSERT_NO_FATAL_FAILURE(InitState());
8666 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008667 uint32_t qfi = 0;
8668 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008669 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8670 buffCI.size = 1024;
8671 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8672 buffCI.queueFamilyIndexCount = 1;
8673 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008674
8675 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008676 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008677 ASSERT_VK_SUCCESS(err);
8678
Tony Barbour552f6c02016-12-21 14:34:07 -07008679 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008680 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008681 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8682 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008683 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008684 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008685
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008686 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008687
Chia-I Wuf7458c52015-10-26 21:10:41 +08008688 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008689}
8690
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008691TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8692 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8694 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8695 "of the indices specified when the device was created, via the "
8696 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008697
8698 ASSERT_NO_FATAL_FAILURE(InitState());
8699 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8700 VkBufferCreateInfo buffCI = {};
8701 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8702 buffCI.size = 1024;
8703 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8704 buffCI.queueFamilyIndexCount = 1;
8705 // Introduce failure by specifying invalid queue_family_index
8706 uint32_t qfi = 777;
8707 buffCI.pQueueFamilyIndices = &qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008708 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008709
8710 VkBuffer ib;
8711 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8712
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008713 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008714 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008715}
8716
Karl Schultz6addd812016-02-02 17:17:23 -07008717TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008718 TEST_DESCRIPTION(
8719 "Attempt vkCmdExecuteCommands with a primary command buffer"
8720 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008721
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008722 ASSERT_NO_FATAL_FAILURE(InitState());
8723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008724
Chris Forbesf29a84f2016-10-06 18:39:28 +13008725 // An empty primary command buffer
8726 VkCommandBufferObj cb(m_device, m_commandPool);
8727 cb.BeginCommandBuffer();
8728 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008729
Chris Forbesf29a84f2016-10-06 18:39:28 +13008730 m_commandBuffer->BeginCommandBuffer();
8731 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8732 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008733
Chris Forbesf29a84f2016-10-06 18:39:28 +13008734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8735 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008736 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008737}
8738
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008739TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008740 TEST_DESCRIPTION(
8741 "Attempt to update descriptor sets for images and buffers "
8742 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008743 VkResult err;
8744
8745 ASSERT_NO_FATAL_FAILURE(InitState());
8746 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8747 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8748 ds_type_count[i].type = VkDescriptorType(i);
8749 ds_type_count[i].descriptorCount = 1;
8750 }
8751 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8752 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8753 ds_pool_ci.pNext = NULL;
8754 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8755 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8756 ds_pool_ci.pPoolSizes = ds_type_count;
8757
8758 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008759 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008760 ASSERT_VK_SUCCESS(err);
8761
8762 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008763 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008764 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8765 dsl_binding[i].binding = 0;
8766 dsl_binding[i].descriptorType = VkDescriptorType(i);
8767 dsl_binding[i].descriptorCount = 1;
8768 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8769 dsl_binding[i].pImmutableSamplers = NULL;
8770 }
8771
8772 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8773 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8774 ds_layout_ci.pNext = NULL;
8775 ds_layout_ci.bindingCount = 1;
8776 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8777 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8778 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008779 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008780 ASSERT_VK_SUCCESS(err);
8781 }
8782 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8783 VkDescriptorSetAllocateInfo alloc_info = {};
8784 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8785 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8786 alloc_info.descriptorPool = ds_pool;
8787 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008788 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008789 ASSERT_VK_SUCCESS(err);
8790
8791 // Create a buffer & bufferView to be used for invalid updates
8792 VkBufferCreateInfo buff_ci = {};
8793 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07008794 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008795 buff_ci.size = 256;
8796 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07008797 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008798 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8799 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07008800
8801 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
8802 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
8803 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
8804 ASSERT_VK_SUCCESS(err);
8805
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008806 VkMemoryRequirements mem_reqs;
8807 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
8808 VkMemoryAllocateInfo mem_alloc_info = {};
8809 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8810 mem_alloc_info.pNext = NULL;
8811 mem_alloc_info.memoryTypeIndex = 0;
8812 mem_alloc_info.allocationSize = mem_reqs.size;
8813 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8814 if (!pass) {
8815 vkDestroyBuffer(m_device->device(), buffer, NULL);
8816 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8817 return;
8818 }
8819 VkDeviceMemory mem;
8820 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
8821 ASSERT_VK_SUCCESS(err);
8822 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8823 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008824
8825 VkBufferViewCreateInfo buff_view_ci = {};
8826 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8827 buff_view_ci.buffer = buffer;
8828 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8829 buff_view_ci.range = VK_WHOLE_SIZE;
8830 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008831 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008832 ASSERT_VK_SUCCESS(err);
8833
Tony Barbour415497c2017-01-24 10:06:09 -07008834 // Now get resources / view for storage_texel_buffer
8835 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
8836 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8837 if (!pass) {
8838 vkDestroyBuffer(m_device->device(), buffer, NULL);
8839 vkDestroyBufferView(m_device->device(), buff_view, NULL);
8840 vkFreeMemory(m_device->device(), mem, NULL);
8841 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
8842 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8843 return;
8844 }
8845 VkDeviceMemory storage_texel_buffer_mem;
8846 VkBufferView storage_texel_buffer_view;
8847 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
8848 ASSERT_VK_SUCCESS(err);
8849 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
8850 ASSERT_VK_SUCCESS(err);
8851 buff_view_ci.buffer = storage_texel_buffer;
8852 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
8853 ASSERT_VK_SUCCESS(err);
8854
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008855 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07008856 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008857 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07008858 image_ci.format = VK_FORMAT_UNDEFINED;
8859 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
8860 VkFormat format = static_cast<VkFormat>(f);
8861 VkFormatProperties fProps = m_device->format_properties(format);
8862 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
8863 image_ci.format = format;
8864 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8865 break;
8866 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
8867 image_ci.format = format;
8868 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
8869 break;
8870 }
8871 }
8872 if (image_ci.format == VK_FORMAT_UNDEFINED) {
8873 return;
8874 }
8875
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008876 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8877 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008878 image_ci.extent.width = 64;
8879 image_ci.extent.height = 64;
8880 image_ci.extent.depth = 1;
8881 image_ci.mipLevels = 1;
8882 image_ci.arrayLayers = 1;
8883 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008884 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07008885 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008886 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8887 VkImage image;
8888 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8889 ASSERT_VK_SUCCESS(err);
8890 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008891 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008892
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008893 VkMemoryAllocateInfo mem_alloc = {};
8894 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8895 mem_alloc.pNext = NULL;
8896 mem_alloc.allocationSize = 0;
8897 mem_alloc.memoryTypeIndex = 0;
8898 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8899 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008900 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008901 ASSERT_TRUE(pass);
8902 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8903 ASSERT_VK_SUCCESS(err);
8904 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8905 ASSERT_VK_SUCCESS(err);
8906 // Now create view for image
8907 VkImageViewCreateInfo image_view_ci = {};
8908 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8909 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07008910 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008911 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8912 image_view_ci.subresourceRange.layerCount = 1;
8913 image_view_ci.subresourceRange.baseArrayLayer = 0;
8914 image_view_ci.subresourceRange.levelCount = 1;
8915 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8916 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008917 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008918 ASSERT_VK_SUCCESS(err);
8919
8920 VkDescriptorBufferInfo buff_info = {};
8921 buff_info.buffer = buffer;
8922 VkDescriptorImageInfo img_info = {};
8923 img_info.imageView = image_view;
8924 VkWriteDescriptorSet descriptor_write = {};
8925 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8926 descriptor_write.dstBinding = 0;
8927 descriptor_write.descriptorCount = 1;
8928 descriptor_write.pTexelBufferView = &buff_view;
8929 descriptor_write.pBufferInfo = &buff_info;
8930 descriptor_write.pImageInfo = &img_info;
8931
8932 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008933 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008934 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
8935 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
8936 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
8937 VALIDATION_ERROR_00943, // STORAGE_IMAGE
8938 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
8939 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
8940 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
8941 VALIDATION_ERROR_00947, // STORAGE_BUFFER
8942 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
8943 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
8944 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008945 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008946 // Start loop at 1 as SAMPLER desc type has no usage bit error
8947 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07008948 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
8949 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
8950 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
8951 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008952 descriptor_write.descriptorType = VkDescriptorType(i);
8953 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008955
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008956 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008957
8958 m_errorMonitor->VerifyFound();
8959 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07008960 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
8961 descriptor_write.pTexelBufferView = &buff_view;
8962 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008963 }
Tony Barbour415497c2017-01-24 10:06:09 -07008964
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8966 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008967 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008968 vkDestroyImageView(m_device->device(), image_view, NULL);
8969 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07008970 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008971 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07008972 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008973 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07008974 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008975 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8976}
8977
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008978TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008979 TEST_DESCRIPTION(
8980 "Attempt to update buffer descriptor set that has incorrect "
8981 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8982 "1. offset value greater than buffer size\n"
8983 "2. range value of 0\n"
8984 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008985 VkResult err;
8986
8987 ASSERT_NO_FATAL_FAILURE(InitState());
8988 VkDescriptorPoolSize ds_type_count = {};
8989 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8990 ds_type_count.descriptorCount = 1;
8991
8992 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8993 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8994 ds_pool_ci.pNext = NULL;
8995 ds_pool_ci.maxSets = 1;
8996 ds_pool_ci.poolSizeCount = 1;
8997 ds_pool_ci.pPoolSizes = &ds_type_count;
8998
8999 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009000 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009001 ASSERT_VK_SUCCESS(err);
9002
9003 // Create layout with single uniform buffer descriptor
9004 VkDescriptorSetLayoutBinding dsl_binding = {};
9005 dsl_binding.binding = 0;
9006 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9007 dsl_binding.descriptorCount = 1;
9008 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9009 dsl_binding.pImmutableSamplers = NULL;
9010
9011 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9012 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9013 ds_layout_ci.pNext = NULL;
9014 ds_layout_ci.bindingCount = 1;
9015 ds_layout_ci.pBindings = &dsl_binding;
9016 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009017 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009018 ASSERT_VK_SUCCESS(err);
9019
9020 VkDescriptorSet descriptor_set = {};
9021 VkDescriptorSetAllocateInfo alloc_info = {};
9022 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9023 alloc_info.descriptorSetCount = 1;
9024 alloc_info.descriptorPool = ds_pool;
9025 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009026 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009027 ASSERT_VK_SUCCESS(err);
9028
9029 // Create a buffer to be used for invalid updates
9030 VkBufferCreateInfo buff_ci = {};
9031 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9032 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9033 buff_ci.size = 256;
9034 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9035 VkBuffer buffer;
9036 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9037 ASSERT_VK_SUCCESS(err);
9038 // Have to bind memory to buffer before descriptor update
9039 VkMemoryAllocateInfo mem_alloc = {};
9040 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9041 mem_alloc.pNext = NULL;
9042 mem_alloc.allocationSize = 256;
9043 mem_alloc.memoryTypeIndex = 0;
9044
9045 VkMemoryRequirements mem_reqs;
9046 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009047 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009048 if (!pass) {
9049 vkDestroyBuffer(m_device->device(), buffer, NULL);
9050 return;
9051 }
9052
9053 VkDeviceMemory mem;
9054 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9055 ASSERT_VK_SUCCESS(err);
9056 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9057 ASSERT_VK_SUCCESS(err);
9058
9059 VkDescriptorBufferInfo buff_info = {};
9060 buff_info.buffer = buffer;
9061 // First make offset 1 larger than buffer size
9062 buff_info.offset = 257;
9063 buff_info.range = VK_WHOLE_SIZE;
9064 VkWriteDescriptorSet descriptor_write = {};
9065 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9066 descriptor_write.dstBinding = 0;
9067 descriptor_write.descriptorCount = 1;
9068 descriptor_write.pTexelBufferView = nullptr;
9069 descriptor_write.pBufferInfo = &buff_info;
9070 descriptor_write.pImageInfo = nullptr;
9071
9072 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9073 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009075
9076 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9077
9078 m_errorMonitor->VerifyFound();
9079 // Now cause error due to range of 0
9080 buff_info.offset = 0;
9081 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009083
9084 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9085
9086 m_errorMonitor->VerifyFound();
9087 // Now cause error due to range exceeding buffer size - offset
9088 buff_info.offset = 128;
9089 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009091
9092 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9093
9094 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009095 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009096 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9097 vkDestroyBuffer(m_device->device(), buffer, NULL);
9098 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9099 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9100}
9101
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009102TEST_F(VkLayerTest, DSAspectBitsErrors) {
9103 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9104 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009105 TEST_DESCRIPTION(
9106 "Attempt to update descriptor sets for images "
9107 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009108 VkResult err;
9109
9110 ASSERT_NO_FATAL_FAILURE(InitState());
9111 VkDescriptorPoolSize ds_type_count = {};
9112 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9113 ds_type_count.descriptorCount = 1;
9114
9115 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9116 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9117 ds_pool_ci.pNext = NULL;
9118 ds_pool_ci.maxSets = 5;
9119 ds_pool_ci.poolSizeCount = 1;
9120 ds_pool_ci.pPoolSizes = &ds_type_count;
9121
9122 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009123 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009124 ASSERT_VK_SUCCESS(err);
9125
9126 VkDescriptorSetLayoutBinding dsl_binding = {};
9127 dsl_binding.binding = 0;
9128 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9129 dsl_binding.descriptorCount = 1;
9130 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9131 dsl_binding.pImmutableSamplers = NULL;
9132
9133 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9134 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9135 ds_layout_ci.pNext = NULL;
9136 ds_layout_ci.bindingCount = 1;
9137 ds_layout_ci.pBindings = &dsl_binding;
9138 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009139 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009140 ASSERT_VK_SUCCESS(err);
9141
9142 VkDescriptorSet descriptor_set = {};
9143 VkDescriptorSetAllocateInfo alloc_info = {};
9144 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9145 alloc_info.descriptorSetCount = 1;
9146 alloc_info.descriptorPool = ds_pool;
9147 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009148 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009149 ASSERT_VK_SUCCESS(err);
9150
9151 // Create an image to be used for invalid updates
9152 VkImageCreateInfo image_ci = {};
9153 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9154 image_ci.imageType = VK_IMAGE_TYPE_2D;
9155 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9156 image_ci.extent.width = 64;
9157 image_ci.extent.height = 64;
9158 image_ci.extent.depth = 1;
9159 image_ci.mipLevels = 1;
9160 image_ci.arrayLayers = 1;
9161 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9162 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9163 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9164 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9165 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9166 VkImage image;
9167 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9168 ASSERT_VK_SUCCESS(err);
9169 // Bind memory to image
9170 VkMemoryRequirements mem_reqs;
9171 VkDeviceMemory image_mem;
9172 bool pass;
9173 VkMemoryAllocateInfo mem_alloc = {};
9174 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9175 mem_alloc.pNext = NULL;
9176 mem_alloc.allocationSize = 0;
9177 mem_alloc.memoryTypeIndex = 0;
9178 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9179 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009180 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009181 ASSERT_TRUE(pass);
9182 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9183 ASSERT_VK_SUCCESS(err);
9184 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9185 ASSERT_VK_SUCCESS(err);
9186 // Now create view for image
9187 VkImageViewCreateInfo image_view_ci = {};
9188 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9189 image_view_ci.image = image;
9190 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9191 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9192 image_view_ci.subresourceRange.layerCount = 1;
9193 image_view_ci.subresourceRange.baseArrayLayer = 0;
9194 image_view_ci.subresourceRange.levelCount = 1;
9195 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009196 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009197
9198 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009199 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009200 ASSERT_VK_SUCCESS(err);
9201
9202 VkDescriptorImageInfo img_info = {};
9203 img_info.imageView = image_view;
9204 VkWriteDescriptorSet descriptor_write = {};
9205 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9206 descriptor_write.dstBinding = 0;
9207 descriptor_write.descriptorCount = 1;
9208 descriptor_write.pTexelBufferView = NULL;
9209 descriptor_write.pBufferInfo = NULL;
9210 descriptor_write.pImageInfo = &img_info;
9211 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9212 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009213 const char *error_msg =
9214 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9215 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009217
9218 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9219
9220 m_errorMonitor->VerifyFound();
9221 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9222 vkDestroyImage(m_device->device(), image, NULL);
9223 vkFreeMemory(m_device->device(), image_mem, NULL);
9224 vkDestroyImageView(m_device->device(), image_view, NULL);
9225 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9226 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9227}
9228
Karl Schultz6addd812016-02-02 17:17:23 -07009229TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009230 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009231 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009232
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9234 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9235 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009236
Tobin Ehlis3b780662015-05-28 12:11:26 -06009237 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009238 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009239 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009240 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9241 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009242
9243 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009244 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9245 ds_pool_ci.pNext = NULL;
9246 ds_pool_ci.maxSets = 1;
9247 ds_pool_ci.poolSizeCount = 1;
9248 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009249
Tobin Ehlis3b780662015-05-28 12:11:26 -06009250 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009251 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009252 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009253 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009254 dsl_binding.binding = 0;
9255 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9256 dsl_binding.descriptorCount = 1;
9257 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9258 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009259
Tony Barboureb254902015-07-15 12:50:33 -06009260 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009261 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9262 ds_layout_ci.pNext = NULL;
9263 ds_layout_ci.bindingCount = 1;
9264 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009265
Tobin Ehlis3b780662015-05-28 12:11:26 -06009266 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009267 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009268 ASSERT_VK_SUCCESS(err);
9269
9270 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009271 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009272 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009273 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009274 alloc_info.descriptorPool = ds_pool;
9275 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009276 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009277 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009278
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009279 VkSamplerCreateInfo sampler_ci = {};
9280 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9281 sampler_ci.pNext = NULL;
9282 sampler_ci.magFilter = VK_FILTER_NEAREST;
9283 sampler_ci.minFilter = VK_FILTER_NEAREST;
9284 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9285 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9286 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9287 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9288 sampler_ci.mipLodBias = 1.0;
9289 sampler_ci.anisotropyEnable = VK_FALSE;
9290 sampler_ci.maxAnisotropy = 1;
9291 sampler_ci.compareEnable = VK_FALSE;
9292 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9293 sampler_ci.minLod = 1.0;
9294 sampler_ci.maxLod = 1.0;
9295 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9296 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9297 VkSampler sampler;
9298 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9299 ASSERT_VK_SUCCESS(err);
9300
9301 VkDescriptorImageInfo info = {};
9302 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009303
9304 VkWriteDescriptorSet descriptor_write;
9305 memset(&descriptor_write, 0, sizeof(descriptor_write));
9306 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009307 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009308 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009309 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009310 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009311 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009312
9313 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9314
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009315 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009316
Chia-I Wuf7458c52015-10-26 21:10:41 +08009317 vkDestroySampler(m_device->device(), sampler, NULL);
9318 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9319 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009320}
9321
Karl Schultz6addd812016-02-02 17:17:23 -07009322TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009323 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009324 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009325
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009327
Tobin Ehlis3b780662015-05-28 12:11:26 -06009328 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009329 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009330 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009331 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9332 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009333
9334 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009335 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9336 ds_pool_ci.pNext = NULL;
9337 ds_pool_ci.maxSets = 1;
9338 ds_pool_ci.poolSizeCount = 1;
9339 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009340
Tobin Ehlis3b780662015-05-28 12:11:26 -06009341 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009342 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009343 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009344
Tony Barboureb254902015-07-15 12:50:33 -06009345 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009346 dsl_binding.binding = 0;
9347 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9348 dsl_binding.descriptorCount = 1;
9349 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9350 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009351
9352 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009353 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9354 ds_layout_ci.pNext = NULL;
9355 ds_layout_ci.bindingCount = 1;
9356 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009357
Tobin Ehlis3b780662015-05-28 12:11:26 -06009358 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009359 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009360 ASSERT_VK_SUCCESS(err);
9361
9362 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009363 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009364 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009365 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009366 alloc_info.descriptorPool = ds_pool;
9367 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009368 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009369 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009370
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009371 // Correctly update descriptor to avoid "NOT_UPDATED" error
9372 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009373 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009374 buff_info.offset = 0;
9375 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009376
9377 VkWriteDescriptorSet descriptor_write;
9378 memset(&descriptor_write, 0, sizeof(descriptor_write));
9379 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009380 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009381 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009382 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009383 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9384 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009385
9386 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9387
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009388 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009389
Chia-I Wuf7458c52015-10-26 21:10:41 +08009390 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9391 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009392}
9393
Karl Schultz6addd812016-02-02 17:17:23 -07009394TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009395 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009396 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009397
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009399
Tobin Ehlis3b780662015-05-28 12:11:26 -06009400 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009401 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009402 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009403 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9404 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009405
9406 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009407 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9408 ds_pool_ci.pNext = NULL;
9409 ds_pool_ci.maxSets = 1;
9410 ds_pool_ci.poolSizeCount = 1;
9411 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009412
Tobin Ehlis3b780662015-05-28 12:11:26 -06009413 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009414 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009415 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009416
Tony Barboureb254902015-07-15 12:50:33 -06009417 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009418 dsl_binding.binding = 0;
9419 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9420 dsl_binding.descriptorCount = 1;
9421 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9422 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009423
9424 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009425 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9426 ds_layout_ci.pNext = NULL;
9427 ds_layout_ci.bindingCount = 1;
9428 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009429 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009430 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009431 ASSERT_VK_SUCCESS(err);
9432
9433 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009434 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009435 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009436 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009437 alloc_info.descriptorPool = ds_pool;
9438 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009439 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009440 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009441
Tony Barboureb254902015-07-15 12:50:33 -06009442 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009443 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9444 sampler_ci.pNext = NULL;
9445 sampler_ci.magFilter = VK_FILTER_NEAREST;
9446 sampler_ci.minFilter = VK_FILTER_NEAREST;
9447 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9448 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9449 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9450 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9451 sampler_ci.mipLodBias = 1.0;
9452 sampler_ci.anisotropyEnable = VK_FALSE;
9453 sampler_ci.maxAnisotropy = 1;
9454 sampler_ci.compareEnable = VK_FALSE;
9455 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9456 sampler_ci.minLod = 1.0;
9457 sampler_ci.maxLod = 1.0;
9458 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9459 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009460
Tobin Ehlis3b780662015-05-28 12:11:26 -06009461 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009462 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009463 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009464
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009465 VkDescriptorImageInfo info = {};
9466 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009467
9468 VkWriteDescriptorSet descriptor_write;
9469 memset(&descriptor_write, 0, sizeof(descriptor_write));
9470 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009471 descriptor_write.dstSet = descriptorSet;
9472 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009473 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009474 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009475 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009476 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009477
9478 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9479
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009480 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009481
Chia-I Wuf7458c52015-10-26 21:10:41 +08009482 vkDestroySampler(m_device->device(), sampler, NULL);
9483 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9484 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009485}
9486
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009487TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9488 // Create layout w/ empty binding and attempt to update it
9489 VkResult err;
9490
9491 ASSERT_NO_FATAL_FAILURE(InitState());
9492
9493 VkDescriptorPoolSize ds_type_count = {};
9494 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9495 ds_type_count.descriptorCount = 1;
9496
9497 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9498 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9499 ds_pool_ci.pNext = NULL;
9500 ds_pool_ci.maxSets = 1;
9501 ds_pool_ci.poolSizeCount = 1;
9502 ds_pool_ci.pPoolSizes = &ds_type_count;
9503
9504 VkDescriptorPool ds_pool;
9505 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9506 ASSERT_VK_SUCCESS(err);
9507
9508 VkDescriptorSetLayoutBinding dsl_binding = {};
9509 dsl_binding.binding = 0;
9510 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9511 dsl_binding.descriptorCount = 0;
9512 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9513 dsl_binding.pImmutableSamplers = NULL;
9514
9515 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9516 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9517 ds_layout_ci.pNext = NULL;
9518 ds_layout_ci.bindingCount = 1;
9519 ds_layout_ci.pBindings = &dsl_binding;
9520 VkDescriptorSetLayout ds_layout;
9521 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9522 ASSERT_VK_SUCCESS(err);
9523
9524 VkDescriptorSet descriptor_set;
9525 VkDescriptorSetAllocateInfo alloc_info = {};
9526 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9527 alloc_info.descriptorSetCount = 1;
9528 alloc_info.descriptorPool = ds_pool;
9529 alloc_info.pSetLayouts = &ds_layout;
9530 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9531 ASSERT_VK_SUCCESS(err);
9532
9533 VkSamplerCreateInfo sampler_ci = {};
9534 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9535 sampler_ci.magFilter = VK_FILTER_NEAREST;
9536 sampler_ci.minFilter = VK_FILTER_NEAREST;
9537 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9538 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9539 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9540 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9541 sampler_ci.mipLodBias = 1.0;
9542 sampler_ci.maxAnisotropy = 1;
9543 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9544 sampler_ci.minLod = 1.0;
9545 sampler_ci.maxLod = 1.0;
9546 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9547
9548 VkSampler sampler;
9549 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9550 ASSERT_VK_SUCCESS(err);
9551
9552 VkDescriptorImageInfo info = {};
9553 info.sampler = sampler;
9554
9555 VkWriteDescriptorSet descriptor_write;
9556 memset(&descriptor_write, 0, sizeof(descriptor_write));
9557 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9558 descriptor_write.dstSet = descriptor_set;
9559 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009560 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009561 // This is the wrong type, but empty binding error will be flagged first
9562 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9563 descriptor_write.pImageInfo = &info;
9564
9565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9566 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9567 m_errorMonitor->VerifyFound();
9568
9569 vkDestroySampler(m_device->device(), sampler, NULL);
9570 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9571 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9572}
9573
Karl Schultz6addd812016-02-02 17:17:23 -07009574TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9575 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9576 // types
9577 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009578
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009579 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 -06009580
Tobin Ehlis3b780662015-05-28 12:11:26 -06009581 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009582
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009583 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009584 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9585 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009586
9587 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009588 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9589 ds_pool_ci.pNext = NULL;
9590 ds_pool_ci.maxSets = 1;
9591 ds_pool_ci.poolSizeCount = 1;
9592 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009593
Tobin Ehlis3b780662015-05-28 12:11:26 -06009594 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009595 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009596 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009597 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009598 dsl_binding.binding = 0;
9599 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9600 dsl_binding.descriptorCount = 1;
9601 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9602 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009603
Tony Barboureb254902015-07-15 12:50:33 -06009604 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009605 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9606 ds_layout_ci.pNext = NULL;
9607 ds_layout_ci.bindingCount = 1;
9608 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009609
Tobin Ehlis3b780662015-05-28 12:11:26 -06009610 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009611 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009612 ASSERT_VK_SUCCESS(err);
9613
9614 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009615 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009616 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009617 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009618 alloc_info.descriptorPool = ds_pool;
9619 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009620 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009621 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009622
Tony Barboureb254902015-07-15 12:50:33 -06009623 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009624 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9625 sampler_ci.pNext = NULL;
9626 sampler_ci.magFilter = VK_FILTER_NEAREST;
9627 sampler_ci.minFilter = VK_FILTER_NEAREST;
9628 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9629 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9630 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9631 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9632 sampler_ci.mipLodBias = 1.0;
9633 sampler_ci.anisotropyEnable = VK_FALSE;
9634 sampler_ci.maxAnisotropy = 1;
9635 sampler_ci.compareEnable = VK_FALSE;
9636 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9637 sampler_ci.minLod = 1.0;
9638 sampler_ci.maxLod = 1.0;
9639 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9640 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009641 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009642 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009643 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009644
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009645 VkDescriptorImageInfo info = {};
9646 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009647
9648 VkWriteDescriptorSet descriptor_write;
9649 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009650 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009651 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009652 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009653 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009654 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009655 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009656
9657 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9658
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009659 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009660
Chia-I Wuf7458c52015-10-26 21:10:41 +08009661 vkDestroySampler(m_device->device(), sampler, NULL);
9662 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9663 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009664}
9665
Karl Schultz6addd812016-02-02 17:17:23 -07009666TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009667 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009668 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009669
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009671
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009672 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009673 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9674 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009675 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009676 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9677 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009678
9679 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009680 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9681 ds_pool_ci.pNext = NULL;
9682 ds_pool_ci.maxSets = 1;
9683 ds_pool_ci.poolSizeCount = 1;
9684 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009685
9686 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009687 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009688 ASSERT_VK_SUCCESS(err);
9689
9690 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009691 dsl_binding.binding = 0;
9692 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9693 dsl_binding.descriptorCount = 1;
9694 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9695 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009696
9697 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009698 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9699 ds_layout_ci.pNext = NULL;
9700 ds_layout_ci.bindingCount = 1;
9701 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009702 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009703 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009704 ASSERT_VK_SUCCESS(err);
9705
9706 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009707 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009708 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009709 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009710 alloc_info.descriptorPool = ds_pool;
9711 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009712 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009713 ASSERT_VK_SUCCESS(err);
9714
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009715 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009716
9717 VkDescriptorImageInfo descriptor_info;
9718 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9719 descriptor_info.sampler = sampler;
9720
9721 VkWriteDescriptorSet descriptor_write;
9722 memset(&descriptor_write, 0, sizeof(descriptor_write));
9723 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009724 descriptor_write.dstSet = descriptorSet;
9725 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009726 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009727 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9728 descriptor_write.pImageInfo = &descriptor_info;
9729
9730 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9731
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009732 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009733
Chia-I Wuf7458c52015-10-26 21:10:41 +08009734 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9735 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009736}
9737
Karl Schultz6addd812016-02-02 17:17:23 -07009738TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9739 // Create a single combined Image/Sampler descriptor and send it an invalid
9740 // imageView
9741 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009742
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009744
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009745 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009746 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009747 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9748 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009749
9750 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009751 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9752 ds_pool_ci.pNext = NULL;
9753 ds_pool_ci.maxSets = 1;
9754 ds_pool_ci.poolSizeCount = 1;
9755 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009756
9757 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009758 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009759 ASSERT_VK_SUCCESS(err);
9760
9761 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009762 dsl_binding.binding = 0;
9763 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9764 dsl_binding.descriptorCount = 1;
9765 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9766 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009767
9768 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009769 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9770 ds_layout_ci.pNext = NULL;
9771 ds_layout_ci.bindingCount = 1;
9772 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009773 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009774 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009775 ASSERT_VK_SUCCESS(err);
9776
9777 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009778 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009779 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009780 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009781 alloc_info.descriptorPool = ds_pool;
9782 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009783 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009784 ASSERT_VK_SUCCESS(err);
9785
9786 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009787 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9788 sampler_ci.pNext = NULL;
9789 sampler_ci.magFilter = VK_FILTER_NEAREST;
9790 sampler_ci.minFilter = VK_FILTER_NEAREST;
9791 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9792 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9793 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9794 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9795 sampler_ci.mipLodBias = 1.0;
9796 sampler_ci.anisotropyEnable = VK_FALSE;
9797 sampler_ci.maxAnisotropy = 1;
9798 sampler_ci.compareEnable = VK_FALSE;
9799 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9800 sampler_ci.minLod = 1.0;
9801 sampler_ci.maxLod = 1.0;
9802 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9803 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009804
9805 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009806 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009807 ASSERT_VK_SUCCESS(err);
9808
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009809 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009810
9811 VkDescriptorImageInfo descriptor_info;
9812 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9813 descriptor_info.sampler = sampler;
9814 descriptor_info.imageView = view;
9815
9816 VkWriteDescriptorSet descriptor_write;
9817 memset(&descriptor_write, 0, sizeof(descriptor_write));
9818 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009819 descriptor_write.dstSet = descriptorSet;
9820 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009821 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009822 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9823 descriptor_write.pImageInfo = &descriptor_info;
9824
9825 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9826
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009827 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009828
Chia-I Wuf7458c52015-10-26 21:10:41 +08009829 vkDestroySampler(m_device->device(), sampler, NULL);
9830 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9831 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009832}
9833
Karl Schultz6addd812016-02-02 17:17:23 -07009834TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9835 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9836 // into the other
9837 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009838
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9840 " binding #1 with type "
9841 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9842 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009843
Tobin Ehlis04356f92015-10-27 16:35:27 -06009844 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009845 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009846 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009847 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9848 ds_type_count[0].descriptorCount = 1;
9849 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9850 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009851
9852 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009853 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9854 ds_pool_ci.pNext = NULL;
9855 ds_pool_ci.maxSets = 1;
9856 ds_pool_ci.poolSizeCount = 2;
9857 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009858
9859 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009860 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009861 ASSERT_VK_SUCCESS(err);
9862 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009863 dsl_binding[0].binding = 0;
9864 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9865 dsl_binding[0].descriptorCount = 1;
9866 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9867 dsl_binding[0].pImmutableSamplers = NULL;
9868 dsl_binding[1].binding = 1;
9869 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9870 dsl_binding[1].descriptorCount = 1;
9871 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9872 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009873
9874 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009875 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9876 ds_layout_ci.pNext = NULL;
9877 ds_layout_ci.bindingCount = 2;
9878 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009879
9880 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009881 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009882 ASSERT_VK_SUCCESS(err);
9883
9884 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009885 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009886 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009887 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009888 alloc_info.descriptorPool = ds_pool;
9889 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009890 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009891 ASSERT_VK_SUCCESS(err);
9892
9893 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009894 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9895 sampler_ci.pNext = NULL;
9896 sampler_ci.magFilter = VK_FILTER_NEAREST;
9897 sampler_ci.minFilter = VK_FILTER_NEAREST;
9898 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9899 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9900 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9901 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9902 sampler_ci.mipLodBias = 1.0;
9903 sampler_ci.anisotropyEnable = VK_FALSE;
9904 sampler_ci.maxAnisotropy = 1;
9905 sampler_ci.compareEnable = VK_FALSE;
9906 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9907 sampler_ci.minLod = 1.0;
9908 sampler_ci.maxLod = 1.0;
9909 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9910 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009911
9912 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009913 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009914 ASSERT_VK_SUCCESS(err);
9915
9916 VkDescriptorImageInfo info = {};
9917 info.sampler = sampler;
9918
9919 VkWriteDescriptorSet descriptor_write;
9920 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9921 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009922 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009923 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009924 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009925 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9926 descriptor_write.pImageInfo = &info;
9927 // This write update should succeed
9928 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9929 // Now perform a copy update that fails due to type mismatch
9930 VkCopyDescriptorSet copy_ds_update;
9931 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9932 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9933 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009934 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009935 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009936 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
9937 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009938 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9939
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009940 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009941 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009942 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 -06009943 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9944 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9945 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009946 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009947 copy_ds_update.dstSet = descriptorSet;
9948 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009949 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009950 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9951
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009952 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009953
Tobin Ehlis04356f92015-10-27 16:35:27 -06009954 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9956 " binding#1 with offset index of 1 plus "
9957 "update array offset of 0 and update of "
9958 "5 descriptors oversteps total number "
9959 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009960
Tobin Ehlis04356f92015-10-27 16:35:27 -06009961 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9962 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9963 copy_ds_update.srcSet = descriptorSet;
9964 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009965 copy_ds_update.dstSet = descriptorSet;
9966 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009967 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009968 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9969
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009970 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009971
Chia-I Wuf7458c52015-10-26 21:10:41 +08009972 vkDestroySampler(m_device->device(), sampler, NULL);
9973 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9974 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009975}
9976
Karl Schultz6addd812016-02-02 17:17:23 -07009977TEST_F(VkLayerTest, NumSamplesMismatch) {
9978 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9979 // sampleCount
9980 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009983
Tobin Ehlis3b780662015-05-28 12:11:26 -06009984 ASSERT_NO_FATAL_FAILURE(InitState());
9985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009986 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009987 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009988 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009989
9990 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009991 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9992 ds_pool_ci.pNext = NULL;
9993 ds_pool_ci.maxSets = 1;
9994 ds_pool_ci.poolSizeCount = 1;
9995 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009996
Tobin Ehlis3b780662015-05-28 12:11:26 -06009997 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009998 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009999 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010000
Tony Barboureb254902015-07-15 12:50:33 -060010001 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010002 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010003 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010004 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010005 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10006 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010007
Tony Barboureb254902015-07-15 12:50:33 -060010008 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10009 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10010 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010011 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010012 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010013
Tobin Ehlis3b780662015-05-28 12:11:26 -060010014 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010015 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010016 ASSERT_VK_SUCCESS(err);
10017
10018 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010019 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010020 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010021 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010022 alloc_info.descriptorPool = ds_pool;
10023 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010024 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010025 ASSERT_VK_SUCCESS(err);
10026
Tony Barboureb254902015-07-15 12:50:33 -060010027 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010028 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010029 pipe_ms_state_ci.pNext = NULL;
10030 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10031 pipe_ms_state_ci.sampleShadingEnable = 0;
10032 pipe_ms_state_ci.minSampleShading = 1.0;
10033 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010034
Tony Barboureb254902015-07-15 12:50:33 -060010035 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010036 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10037 pipeline_layout_ci.pNext = NULL;
10038 pipeline_layout_ci.setLayoutCount = 1;
10039 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010040
10041 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010042 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010043 ASSERT_VK_SUCCESS(err);
10044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010045 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010046 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 -060010047 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010048 VkPipelineObj pipe(m_device);
10049 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010050 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010051 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010052 pipe.SetMSAA(&pipe_ms_state_ci);
10053 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010054
Tony Barbour552f6c02016-12-21 14:34:07 -070010055 m_commandBuffer->BeginCommandBuffer();
10056 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010057 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010058
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010059 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10060 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10061 VkRect2D scissor = {{0, 0}, {16, 16}};
10062 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10063
Mark Young29927482016-05-04 14:38:51 -060010064 // Render triangle (the error should trigger on the attempt to draw).
10065 Draw(3, 1, 0, 0);
10066
10067 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010068 m_commandBuffer->EndRenderPass();
10069 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010070
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010071 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010072
Chia-I Wuf7458c52015-10-26 21:10:41 +080010073 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10074 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10075 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010076}
Mark Young29927482016-05-04 14:38:51 -060010077
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010078TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010079 TEST_DESCRIPTION(
10080 "Hit RenderPass incompatible cases. "
10081 "Initial case is drawing with an active renderpass that's "
10082 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010083 VkResult err;
10084
10085 ASSERT_NO_FATAL_FAILURE(InitState());
10086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10087
10088 VkDescriptorSetLayoutBinding dsl_binding = {};
10089 dsl_binding.binding = 0;
10090 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10091 dsl_binding.descriptorCount = 1;
10092 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10093 dsl_binding.pImmutableSamplers = NULL;
10094
10095 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10096 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10097 ds_layout_ci.pNext = NULL;
10098 ds_layout_ci.bindingCount = 1;
10099 ds_layout_ci.pBindings = &dsl_binding;
10100
10101 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010102 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010103 ASSERT_VK_SUCCESS(err);
10104
10105 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10106 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10107 pipeline_layout_ci.pNext = NULL;
10108 pipeline_layout_ci.setLayoutCount = 1;
10109 pipeline_layout_ci.pSetLayouts = &ds_layout;
10110
10111 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010112 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010113 ASSERT_VK_SUCCESS(err);
10114
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010115 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010116 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 -060010117 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010118 // Create a renderpass that will be incompatible with default renderpass
10119 VkAttachmentReference attach = {};
10120 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10121 VkAttachmentReference color_att = {};
10122 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10123 VkSubpassDescription subpass = {};
10124 subpass.inputAttachmentCount = 1;
10125 subpass.pInputAttachments = &attach;
10126 subpass.colorAttachmentCount = 1;
10127 subpass.pColorAttachments = &color_att;
10128 VkRenderPassCreateInfo rpci = {};
10129 rpci.subpassCount = 1;
10130 rpci.pSubpasses = &subpass;
10131 rpci.attachmentCount = 1;
10132 VkAttachmentDescription attach_desc = {};
10133 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010134 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10135 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010136 rpci.pAttachments = &attach_desc;
10137 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10138 VkRenderPass rp;
10139 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10140 VkPipelineObj pipe(m_device);
10141 pipe.AddShader(&vs);
10142 pipe.AddShader(&fs);
10143 pipe.AddColorAttachment();
10144 VkViewport view_port = {};
10145 m_viewports.push_back(view_port);
10146 pipe.SetViewport(m_viewports);
10147 VkRect2D rect = {};
10148 m_scissors.push_back(rect);
10149 pipe.SetScissor(m_scissors);
10150 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10151
10152 VkCommandBufferInheritanceInfo cbii = {};
10153 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10154 cbii.renderPass = rp;
10155 cbii.subpass = 0;
10156 VkCommandBufferBeginInfo cbbi = {};
10157 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10158 cbbi.pInheritanceInfo = &cbii;
10159 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10160 VkRenderPassBeginInfo rpbi = {};
10161 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10162 rpbi.framebuffer = m_framebuffer;
10163 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010164 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10165 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010166
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010168 // Render triangle (the error should trigger on the attempt to draw).
10169 Draw(3, 1, 0, 0);
10170
10171 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010172 m_commandBuffer->EndRenderPass();
10173 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010174
10175 m_errorMonitor->VerifyFound();
10176
10177 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10178 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10179 vkDestroyRenderPass(m_device->device(), rp, NULL);
10180}
10181
Mark Youngc89c6312016-03-31 16:03:20 -060010182TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10183 // Create Pipeline where the number of blend attachments doesn't match the
10184 // number of color attachments. In this case, we don't add any color
10185 // blend attachments even though we have a color attachment.
10186 VkResult err;
10187
10188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010189 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010190
10191 ASSERT_NO_FATAL_FAILURE(InitState());
10192 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10193 VkDescriptorPoolSize ds_type_count = {};
10194 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10195 ds_type_count.descriptorCount = 1;
10196
10197 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10198 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10199 ds_pool_ci.pNext = NULL;
10200 ds_pool_ci.maxSets = 1;
10201 ds_pool_ci.poolSizeCount = 1;
10202 ds_pool_ci.pPoolSizes = &ds_type_count;
10203
10204 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010205 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010206 ASSERT_VK_SUCCESS(err);
10207
10208 VkDescriptorSetLayoutBinding dsl_binding = {};
10209 dsl_binding.binding = 0;
10210 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10211 dsl_binding.descriptorCount = 1;
10212 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10213 dsl_binding.pImmutableSamplers = NULL;
10214
10215 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10216 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10217 ds_layout_ci.pNext = NULL;
10218 ds_layout_ci.bindingCount = 1;
10219 ds_layout_ci.pBindings = &dsl_binding;
10220
10221 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010222 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010223 ASSERT_VK_SUCCESS(err);
10224
10225 VkDescriptorSet descriptorSet;
10226 VkDescriptorSetAllocateInfo alloc_info = {};
10227 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10228 alloc_info.descriptorSetCount = 1;
10229 alloc_info.descriptorPool = ds_pool;
10230 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010231 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010232 ASSERT_VK_SUCCESS(err);
10233
10234 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010235 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010236 pipe_ms_state_ci.pNext = NULL;
10237 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10238 pipe_ms_state_ci.sampleShadingEnable = 0;
10239 pipe_ms_state_ci.minSampleShading = 1.0;
10240 pipe_ms_state_ci.pSampleMask = NULL;
10241
10242 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10243 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10244 pipeline_layout_ci.pNext = NULL;
10245 pipeline_layout_ci.setLayoutCount = 1;
10246 pipeline_layout_ci.pSetLayouts = &ds_layout;
10247
10248 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010249 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010250 ASSERT_VK_SUCCESS(err);
10251
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010252 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010253 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 -060010254 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010255 VkPipelineObj pipe(m_device);
10256 pipe.AddShader(&vs);
10257 pipe.AddShader(&fs);
10258 pipe.SetMSAA(&pipe_ms_state_ci);
10259 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10260
Tony Barbour552f6c02016-12-21 14:34:07 -070010261 m_commandBuffer->BeginCommandBuffer();
10262 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010263 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010264
Rene Lindsay6d5c4fe2017-01-13 09:41:19 -070010265 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10266 VkRect2D scissor = {{0, 0}, {16, 16}};
10267 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10268 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10269
Mark Young29927482016-05-04 14:38:51 -060010270 // Render triangle (the error should trigger on the attempt to draw).
10271 Draw(3, 1, 0, 0);
10272
10273 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010274 m_commandBuffer->EndRenderPass();
10275 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010276
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010277 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010278
10279 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10280 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10281 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10282}
Mark Young29927482016-05-04 14:38:51 -060010283
Mark Muellerd4914412016-06-13 17:52:06 -060010284TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010285 TEST_DESCRIPTION(
10286 "Points to a wrong colorAttachment index in a VkClearAttachment "
10287 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010288 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010290
10291 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10292 m_errorMonitor->VerifyFound();
10293}
10294
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010295TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010296 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10297 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010298
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010299 ASSERT_NO_FATAL_FAILURE(InitState());
10300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010301
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010302 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010303 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10304 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010305
10306 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010307 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10308 ds_pool_ci.pNext = NULL;
10309 ds_pool_ci.maxSets = 1;
10310 ds_pool_ci.poolSizeCount = 1;
10311 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010312
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010313 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010314 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010315 ASSERT_VK_SUCCESS(err);
10316
Tony Barboureb254902015-07-15 12:50:33 -060010317 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010318 dsl_binding.binding = 0;
10319 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10320 dsl_binding.descriptorCount = 1;
10321 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10322 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010323
Tony Barboureb254902015-07-15 12:50:33 -060010324 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010325 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10326 ds_layout_ci.pNext = NULL;
10327 ds_layout_ci.bindingCount = 1;
10328 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010329
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010330 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010331 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010332 ASSERT_VK_SUCCESS(err);
10333
10334 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010335 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010336 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010337 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010338 alloc_info.descriptorPool = ds_pool;
10339 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010340 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010341 ASSERT_VK_SUCCESS(err);
10342
Tony Barboureb254902015-07-15 12:50:33 -060010343 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010344 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010345 pipe_ms_state_ci.pNext = NULL;
10346 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10347 pipe_ms_state_ci.sampleShadingEnable = 0;
10348 pipe_ms_state_ci.minSampleShading = 1.0;
10349 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010350
Tony Barboureb254902015-07-15 12:50:33 -060010351 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010352 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10353 pipeline_layout_ci.pNext = NULL;
10354 pipeline_layout_ci.setLayoutCount = 1;
10355 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010356
10357 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010358 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010359 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010360
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010361 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010362 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010363 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010364 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010365
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010366 VkPipelineObj pipe(m_device);
10367 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010368 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010369 pipe.SetMSAA(&pipe_ms_state_ci);
10370 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010371
Tony Barbour552f6c02016-12-21 14:34:07 -070010372 m_commandBuffer->BeginCommandBuffer();
10373 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010374
Karl Schultz6addd812016-02-02 17:17:23 -070010375 // Main thing we care about for this test is that the VkImage obj we're
10376 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010377 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010378 VkClearAttachment color_attachment;
10379 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10380 color_attachment.clearValue.color.float32[0] = 1.0;
10381 color_attachment.clearValue.color.float32[1] = 1.0;
10382 color_attachment.clearValue.color.float32[2] = 1.0;
10383 color_attachment.clearValue.color.float32[3] = 1.0;
10384 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010385 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010386
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010387 // Call for full-sized FB Color attachment prior to issuing a Draw
10388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070010389 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010390 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010391 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010392
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010393 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
10394 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
10395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
10396 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
10397 m_errorMonitor->VerifyFound();
10398
10399 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
10400 clear_rect.layerCount = 2;
10401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
10402 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010403 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010404
Chia-I Wuf7458c52015-10-26 21:10:41 +080010405 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10406 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10407 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010408}
10409
Karl Schultz6addd812016-02-02 17:17:23 -070010410TEST_F(VkLayerTest, VtxBufferBadIndex) {
10411 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010412
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10414 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010415
Tobin Ehlis502480b2015-06-24 15:53:07 -060010416 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010417 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010419
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010420 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010421 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10422 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010423
10424 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010425 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10426 ds_pool_ci.pNext = NULL;
10427 ds_pool_ci.maxSets = 1;
10428 ds_pool_ci.poolSizeCount = 1;
10429 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010430
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010431 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010432 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010433 ASSERT_VK_SUCCESS(err);
10434
Tony Barboureb254902015-07-15 12:50:33 -060010435 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010436 dsl_binding.binding = 0;
10437 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10438 dsl_binding.descriptorCount = 1;
10439 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10440 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010441
Tony Barboureb254902015-07-15 12:50:33 -060010442 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010443 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10444 ds_layout_ci.pNext = NULL;
10445 ds_layout_ci.bindingCount = 1;
10446 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010447
Tobin Ehlis502480b2015-06-24 15:53:07 -060010448 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010449 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010450 ASSERT_VK_SUCCESS(err);
10451
10452 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010453 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010454 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010455 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010456 alloc_info.descriptorPool = ds_pool;
10457 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010458 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010459 ASSERT_VK_SUCCESS(err);
10460
Tony Barboureb254902015-07-15 12:50:33 -060010461 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010462 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010463 pipe_ms_state_ci.pNext = NULL;
10464 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10465 pipe_ms_state_ci.sampleShadingEnable = 0;
10466 pipe_ms_state_ci.minSampleShading = 1.0;
10467 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010468
Tony Barboureb254902015-07-15 12:50:33 -060010469 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010470 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10471 pipeline_layout_ci.pNext = NULL;
10472 pipeline_layout_ci.setLayoutCount = 1;
10473 pipeline_layout_ci.pSetLayouts = &ds_layout;
10474 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010475
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010476 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010477 ASSERT_VK_SUCCESS(err);
10478
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010479 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010480 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 -060010481 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010482 VkPipelineObj pipe(m_device);
10483 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010484 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010485 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010486 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010487 pipe.SetViewport(m_viewports);
10488 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010489 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010490
Tony Barbour552f6c02016-12-21 14:34:07 -070010491 m_commandBuffer->BeginCommandBuffer();
10492 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010493 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010494 // Don't care about actual data, just need to get to draw to flag error
10495 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010496 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010497 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010498 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010499
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010500 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010501
Chia-I Wuf7458c52015-10-26 21:10:41 +080010502 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10503 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10504 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010505}
Mark Muellerdfe37552016-07-07 14:47:42 -060010506
Mark Mueller2ee294f2016-08-04 12:59:48 -060010507TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010508 TEST_DESCRIPTION(
10509 "Use an invalid count in a vkEnumeratePhysicalDevices call."
10510 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010511 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010512
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010513 const char *invalid_queueFamilyIndex_message =
10514 "Invalid queue create request in vkCreateDevice(). Invalid "
10515 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010516
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010517 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010518
Mark Mueller880fce52016-08-17 15:23:23 -060010519 // The following test fails with recent NVidia drivers.
10520 // By the time core_validation is reached, the NVidia
10521 // driver has sanitized the invalid condition and core_validation
10522 // is not introduced to the failure condition. This is not the case
10523 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010524 // uint32_t count = static_cast<uint32_t>(~0);
10525 // VkPhysicalDevice physical_device;
10526 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10527 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010528
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010530 float queue_priority = 0.0;
10531
10532 VkDeviceQueueCreateInfo queue_create_info = {};
10533 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10534 queue_create_info.queueCount = 1;
10535 queue_create_info.pQueuePriorities = &queue_priority;
10536 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10537
10538 VkPhysicalDeviceFeatures features = m_device->phy().features();
10539 VkDevice testDevice;
10540 VkDeviceCreateInfo device_create_info = {};
10541 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10542 device_create_info.queueCreateInfoCount = 1;
10543 device_create_info.pQueueCreateInfos = &queue_create_info;
10544 device_create_info.pEnabledFeatures = &features;
10545 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10546 m_errorMonitor->VerifyFound();
10547
10548 queue_create_info.queueFamilyIndex = 1;
10549
10550 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10551 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10552 for (unsigned i = 0; i < feature_count; i++) {
10553 if (VK_FALSE == feature_array[i]) {
10554 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010556 device_create_info.pEnabledFeatures = &features;
10557 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10558 m_errorMonitor->VerifyFound();
10559 break;
10560 }
10561 }
10562}
10563
Tobin Ehlis16edf082016-11-21 12:33:49 -070010564TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10565 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10566
10567 ASSERT_NO_FATAL_FAILURE(InitState());
10568
10569 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10570 std::vector<VkDeviceQueueCreateInfo> queue_info;
10571 queue_info.reserve(queue_props.size());
10572 std::vector<std::vector<float>> queue_priorities;
10573 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10574 VkDeviceQueueCreateInfo qi{};
10575 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10576 qi.queueFamilyIndex = i;
10577 qi.queueCount = queue_props[i].queueCount;
10578 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10579 qi.pQueuePriorities = queue_priorities[i].data();
10580 queue_info.push_back(qi);
10581 }
10582
10583 std::vector<const char *> device_extension_names;
10584
10585 VkDevice local_device;
10586 VkDeviceCreateInfo device_create_info = {};
10587 auto features = m_device->phy().features();
10588 // Intentionally disable pipeline stats
10589 features.pipelineStatisticsQuery = VK_FALSE;
10590 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10591 device_create_info.pNext = NULL;
10592 device_create_info.queueCreateInfoCount = queue_info.size();
10593 device_create_info.pQueueCreateInfos = queue_info.data();
10594 device_create_info.enabledLayerCount = 0;
10595 device_create_info.ppEnabledLayerNames = NULL;
10596 device_create_info.pEnabledFeatures = &features;
10597 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10598 ASSERT_VK_SUCCESS(err);
10599
10600 VkQueryPoolCreateInfo qpci{};
10601 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10602 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10603 qpci.queryCount = 1;
10604 VkQueryPool query_pool;
10605
10606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10607 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10608 m_errorMonitor->VerifyFound();
10609
10610 vkDestroyDevice(local_device, nullptr);
10611}
10612
Mark Mueller2ee294f2016-08-04 12:59:48 -060010613TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010614 TEST_DESCRIPTION(
10615 "Use an invalid queue index in a vkCmdWaitEvents call."
10616 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060010617
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010618 const char *invalid_queue_index =
10619 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10620 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10621 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010623 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010624
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010626
10627 ASSERT_NO_FATAL_FAILURE(InitState());
10628
10629 VkEvent event;
10630 VkEventCreateInfo event_create_info{};
10631 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10632 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10633
Mark Mueller2ee294f2016-08-04 12:59:48 -060010634 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010635 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010636
Tony Barbour552f6c02016-12-21 14:34:07 -070010637 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010638
10639 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010640 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 -060010641 ASSERT_TRUE(image.initialized());
10642 VkImageMemoryBarrier img_barrier = {};
10643 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10644 img_barrier.pNext = NULL;
10645 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10646 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10647 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10648 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10649 img_barrier.image = image.handle();
10650 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010651
10652 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10653 // that layer validation catches the case when it is not.
10654 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010655 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10656 img_barrier.subresourceRange.baseArrayLayer = 0;
10657 img_barrier.subresourceRange.baseMipLevel = 0;
10658 img_barrier.subresourceRange.layerCount = 1;
10659 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010660 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10661 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010662 m_errorMonitor->VerifyFound();
10663
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010665
10666 VkQueryPool query_pool;
10667 VkQueryPoolCreateInfo query_pool_create_info = {};
10668 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10669 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10670 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010671 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010672
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010673 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010674 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10675
10676 vkEndCommandBuffer(m_commandBuffer->handle());
10677 m_errorMonitor->VerifyFound();
10678
10679 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10680 vkDestroyEvent(m_device->device(), event, nullptr);
10681}
10682
Mark Muellerdfe37552016-07-07 14:47:42 -060010683TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010684 TEST_DESCRIPTION(
10685 "Submit a command buffer using deleted vertex buffer, "
10686 "delete a buffer twice, use an invalid offset for each "
10687 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060010688
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010689 const char *deleted_buffer_in_command_buffer =
10690 "Cannot submit cmd buffer "
10691 "using deleted buffer ";
10692 const char *invalid_offset_message =
10693 "vkBindBufferMemory(): "
10694 "memoryOffset is 0x";
10695 const char *invalid_storage_buffer_offset_message =
10696 "vkBindBufferMemory(): "
10697 "storage memoryOffset "
10698 "is 0x";
10699 const char *invalid_texel_buffer_offset_message =
10700 "vkBindBufferMemory(): "
10701 "texel memoryOffset "
10702 "is 0x";
10703 const char *invalid_uniform_buffer_offset_message =
10704 "vkBindBufferMemory(): "
10705 "uniform memoryOffset "
10706 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010707
10708 ASSERT_NO_FATAL_FAILURE(InitState());
10709 ASSERT_NO_FATAL_FAILURE(InitViewport());
10710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10711
10712 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010713 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010714 pipe_ms_state_ci.pNext = NULL;
10715 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10716 pipe_ms_state_ci.sampleShadingEnable = 0;
10717 pipe_ms_state_ci.minSampleShading = 1.0;
10718 pipe_ms_state_ci.pSampleMask = nullptr;
10719
10720 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10721 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10722 VkPipelineLayout pipeline_layout;
10723
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010724 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010725 ASSERT_VK_SUCCESS(err);
10726
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010727 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10728 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010729 VkPipelineObj pipe(m_device);
10730 pipe.AddShader(&vs);
10731 pipe.AddShader(&fs);
10732 pipe.AddColorAttachment();
10733 pipe.SetMSAA(&pipe_ms_state_ci);
10734 pipe.SetViewport(m_viewports);
10735 pipe.SetScissor(m_scissors);
10736 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10737
Tony Barbour552f6c02016-12-21 14:34:07 -070010738 m_commandBuffer->BeginCommandBuffer();
10739 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010740 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010741
10742 {
10743 // Create and bind a vertex buffer in a reduced scope, which will cause
10744 // it to be deleted upon leaving this scope
10745 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010746 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010747 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10748 draw_verticies.AddVertexInputToPipe(pipe);
10749 }
10750
10751 Draw(1, 0, 0, 0);
10752
Tony Barbour552f6c02016-12-21 14:34:07 -070010753 m_commandBuffer->EndRenderPass();
10754 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060010755
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010757 QueueCommandBuffer(false);
10758 m_errorMonitor->VerifyFound();
10759
10760 {
10761 // Create and bind a vertex buffer in a reduced scope, and delete it
10762 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010763 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010765 buffer_test.TestDoubleDestroy();
10766 }
10767 m_errorMonitor->VerifyFound();
10768
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010769 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010770 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10772 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10773 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010774 m_errorMonitor->VerifyFound();
10775 }
10776
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010777 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10778 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010779 // Create and bind a memory buffer with an invalid offset again,
10780 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10782 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10783 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010784 m_errorMonitor->VerifyFound();
10785 }
10786
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010787 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010788 // Create and bind a memory buffer with an invalid offset again, but
10789 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10791 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10792 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010793 m_errorMonitor->VerifyFound();
10794 }
10795
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010796 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010797 // Create and bind a memory buffer with an invalid offset again, but
10798 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10800 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10801 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010802 m_errorMonitor->VerifyFound();
10803 }
10804
10805 {
10806 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010808 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10809 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010810 m_errorMonitor->VerifyFound();
10811 }
10812
10813 {
10814 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010816 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10817 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010818 }
10819 m_errorMonitor->VerifyFound();
10820
10821 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10822}
10823
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010824// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10825TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010826 TEST_DESCRIPTION(
10827 "Hit all possible validation checks associated with the "
10828 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10829 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010830 // 3 in ValidateCmdBufImageLayouts
10831 // * -1 Attempt to submit cmd buf w/ deleted image
10832 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10833 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010834
10835 ASSERT_NO_FATAL_FAILURE(InitState());
10836 // Create src & dst images to use for copy operations
10837 VkImage src_image;
10838 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010839 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010840
10841 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10842 const int32_t tex_width = 32;
10843 const int32_t tex_height = 32;
10844
10845 VkImageCreateInfo image_create_info = {};
10846 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10847 image_create_info.pNext = NULL;
10848 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10849 image_create_info.format = tex_format;
10850 image_create_info.extent.width = tex_width;
10851 image_create_info.extent.height = tex_height;
10852 image_create_info.extent.depth = 1;
10853 image_create_info.mipLevels = 1;
10854 image_create_info.arrayLayers = 4;
10855 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10856 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10857 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010858 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010859 image_create_info.flags = 0;
10860
10861 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10862 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010863 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010864 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10865 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010866 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10867 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10868 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10869 ASSERT_VK_SUCCESS(err);
10870
10871 // Allocate memory
10872 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010873 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010874 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010875 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10876 mem_alloc.pNext = NULL;
10877 mem_alloc.allocationSize = 0;
10878 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010879
10880 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010881 mem_alloc.allocationSize = img_mem_reqs.size;
10882 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010883 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010884 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010885 ASSERT_VK_SUCCESS(err);
10886
10887 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010888 mem_alloc.allocationSize = img_mem_reqs.size;
10889 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010890 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010891 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010892 ASSERT_VK_SUCCESS(err);
10893
10894 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010895 mem_alloc.allocationSize = img_mem_reqs.size;
10896 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010897 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010898 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010899 ASSERT_VK_SUCCESS(err);
10900
10901 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10902 ASSERT_VK_SUCCESS(err);
10903 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10904 ASSERT_VK_SUCCESS(err);
10905 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10906 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010907
Tony Barbour552f6c02016-12-21 14:34:07 -070010908 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010909 VkImageCopy copy_region;
10910 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10911 copy_region.srcSubresource.mipLevel = 0;
10912 copy_region.srcSubresource.baseArrayLayer = 0;
10913 copy_region.srcSubresource.layerCount = 1;
10914 copy_region.srcOffset.x = 0;
10915 copy_region.srcOffset.y = 0;
10916 copy_region.srcOffset.z = 0;
10917 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10918 copy_region.dstSubresource.mipLevel = 0;
10919 copy_region.dstSubresource.baseArrayLayer = 0;
10920 copy_region.dstSubresource.layerCount = 1;
10921 copy_region.dstOffset.x = 0;
10922 copy_region.dstOffset.y = 0;
10923 copy_region.dstOffset.z = 0;
10924 copy_region.extent.width = 1;
10925 copy_region.extent.height = 1;
10926 copy_region.extent.depth = 1;
10927
10928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10929 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10930 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 -060010931 m_errorMonitor->VerifyFound();
10932 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10934 "Cannot copy from an image whose source layout is "
10935 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10936 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010937 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 -060010938 m_errorMonitor->VerifyFound();
10939 // Final src error is due to bad layout type
10940 m_errorMonitor->SetDesiredFailureMsg(
10941 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10942 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010943 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 -060010944 m_errorMonitor->VerifyFound();
10945 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10947 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010948 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 -060010949 m_errorMonitor->VerifyFound();
10950 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10952 "Cannot copy from an image whose dest layout is "
10953 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10954 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010955 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 -060010956 m_errorMonitor->VerifyFound();
10957 m_errorMonitor->SetDesiredFailureMsg(
10958 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10959 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010960 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 -060010961 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010962
Cort3b021012016-12-07 12:00:57 -080010963 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10964 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10965 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10966 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10967 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10968 transfer_dst_image_barrier[0].srcAccessMask = 0;
10969 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10970 transfer_dst_image_barrier[0].image = dst_image;
10971 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10972 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10973 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10974 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10975 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10976 transfer_dst_image_barrier[0].image = depth_image;
10977 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10978 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10979 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10980
10981 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010982 VkClearColorValue color_clear_value = {};
10983 VkImageSubresourceRange clear_range;
10984 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10985 clear_range.baseMipLevel = 0;
10986 clear_range.baseArrayLayer = 0;
10987 clear_range.layerCount = 1;
10988 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010989
Cort3b021012016-12-07 12:00:57 -080010990 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10991 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010994 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010995 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010996 // Fail due to provided layout not matching actual current layout for color clear.
10997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010998 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010999 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011000
Cort530cf382016-12-08 09:59:47 -080011001 VkClearDepthStencilValue depth_clear_value = {};
11002 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011003
11004 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11005 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011008 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011009 m_errorMonitor->VerifyFound();
11010 // Fail due to provided layout not matching actual current layout for depth clear.
11011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011012 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011013 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011014
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011015 // Now cause error due to bad image layout transition in PipelineBarrier
11016 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011017 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011018 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011019 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011020 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011021 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11022 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011023 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11025 "You cannot transition the layout of aspect 1 from "
11026 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11027 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011028 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11029 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011030 m_errorMonitor->VerifyFound();
11031
11032 // Finally some layout errors at RenderPass create time
11033 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11034 VkAttachmentReference attach = {};
11035 // perf warning for GENERAL layout w/ non-DS input attachment
11036 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11037 VkSubpassDescription subpass = {};
11038 subpass.inputAttachmentCount = 1;
11039 subpass.pInputAttachments = &attach;
11040 VkRenderPassCreateInfo rpci = {};
11041 rpci.subpassCount = 1;
11042 rpci.pSubpasses = &subpass;
11043 rpci.attachmentCount = 1;
11044 VkAttachmentDescription attach_desc = {};
11045 attach_desc.format = VK_FORMAT_UNDEFINED;
11046 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011047 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011048 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11050 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011051 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11052 m_errorMonitor->VerifyFound();
11053 // error w/ non-general layout
11054 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11055
11056 m_errorMonitor->SetDesiredFailureMsg(
11057 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11058 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11059 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11060 m_errorMonitor->VerifyFound();
11061 subpass.inputAttachmentCount = 0;
11062 subpass.colorAttachmentCount = 1;
11063 subpass.pColorAttachments = &attach;
11064 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11065 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11067 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011068 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11069 m_errorMonitor->VerifyFound();
11070 // error w/ non-color opt or GENERAL layout for color attachment
11071 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11072 m_errorMonitor->SetDesiredFailureMsg(
11073 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11074 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11075 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11076 m_errorMonitor->VerifyFound();
11077 subpass.colorAttachmentCount = 0;
11078 subpass.pDepthStencilAttachment = &attach;
11079 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11080 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11082 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011083 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11084 m_errorMonitor->VerifyFound();
11085 // error w/ non-ds opt or GENERAL layout for color attachment
11086 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11088 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11089 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011090 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11091 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011092 // For this error we need a valid renderpass so create default one
11093 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11094 attach.attachment = 0;
11095 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11096 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11097 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11098 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11099 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11100 // Can't do a CLEAR load on READ_ONLY initialLayout
11101 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11102 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11103 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11105 " with invalid first layout "
11106 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11107 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011108 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11109 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011110
Cort3b021012016-12-07 12:00:57 -080011111 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11112 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11113 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011114 vkDestroyImage(m_device->device(), src_image, NULL);
11115 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011116 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011117}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011118
Tobin Ehlise0936662016-10-11 08:10:51 -060011119TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11120 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11121 VkResult err;
11122
11123 ASSERT_NO_FATAL_FAILURE(InitState());
11124
11125 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11126 VkImageTiling tiling;
11127 VkFormatProperties format_properties;
11128 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11129 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11130 tiling = VK_IMAGE_TILING_LINEAR;
11131 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11132 tiling = VK_IMAGE_TILING_OPTIMAL;
11133 } else {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011134 printf(
11135 "Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11136 "skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011137 return;
11138 }
11139
11140 VkDescriptorPoolSize ds_type = {};
11141 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11142 ds_type.descriptorCount = 1;
11143
11144 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11145 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11146 ds_pool_ci.maxSets = 1;
11147 ds_pool_ci.poolSizeCount = 1;
11148 ds_pool_ci.pPoolSizes = &ds_type;
11149 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11150
11151 VkDescriptorPool ds_pool;
11152 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11153 ASSERT_VK_SUCCESS(err);
11154
11155 VkDescriptorSetLayoutBinding dsl_binding = {};
11156 dsl_binding.binding = 0;
11157 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11158 dsl_binding.descriptorCount = 1;
11159 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11160 dsl_binding.pImmutableSamplers = NULL;
11161
11162 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11163 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11164 ds_layout_ci.pNext = NULL;
11165 ds_layout_ci.bindingCount = 1;
11166 ds_layout_ci.pBindings = &dsl_binding;
11167
11168 VkDescriptorSetLayout ds_layout;
11169 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11170 ASSERT_VK_SUCCESS(err);
11171
11172 VkDescriptorSetAllocateInfo alloc_info = {};
11173 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11174 alloc_info.descriptorSetCount = 1;
11175 alloc_info.descriptorPool = ds_pool;
11176 alloc_info.pSetLayouts = &ds_layout;
11177 VkDescriptorSet descriptor_set;
11178 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11179 ASSERT_VK_SUCCESS(err);
11180
11181 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11182 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11183 pipeline_layout_ci.pNext = NULL;
11184 pipeline_layout_ci.setLayoutCount = 1;
11185 pipeline_layout_ci.pSetLayouts = &ds_layout;
11186 VkPipelineLayout pipeline_layout;
11187 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11188 ASSERT_VK_SUCCESS(err);
11189
11190 VkImageObj image(m_device);
11191 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11192 ASSERT_TRUE(image.initialized());
11193 VkImageView view = image.targetView(tex_format);
11194
11195 VkDescriptorImageInfo image_info = {};
11196 image_info.imageView = view;
11197 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11198
11199 VkWriteDescriptorSet descriptor_write = {};
11200 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11201 descriptor_write.dstSet = descriptor_set;
11202 descriptor_write.dstBinding = 0;
11203 descriptor_write.descriptorCount = 1;
11204 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11205 descriptor_write.pImageInfo = &image_info;
11206
11207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11208 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11209 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11210 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11211 m_errorMonitor->VerifyFound();
11212
11213 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11214 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11215 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11216 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11217}
11218
Mark Mueller93b938f2016-08-18 10:27:40 -060011219TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011220 TEST_DESCRIPTION(
11221 "Use vkCmdExecuteCommands with invalid state "
11222 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011223
11224 ASSERT_NO_FATAL_FAILURE(InitState());
11225 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11226
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011227 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011228 const char *simultaneous_use_message2 =
11229 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11230 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011231
11232 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011233 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011234 command_buffer_allocate_info.commandPool = m_commandPool;
11235 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11236 command_buffer_allocate_info.commandBufferCount = 1;
11237
11238 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011239 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011240 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11241 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011242 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011243 command_buffer_inheritance_info.renderPass = m_renderPass;
11244 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011245
Mark Mueller93b938f2016-08-18 10:27:40 -060011246 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011247 command_buffer_begin_info.flags =
11248 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011249 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11250
11251 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11252 vkEndCommandBuffer(secondary_command_buffer);
11253
Mark Mueller93b938f2016-08-18 10:27:40 -060011254 VkSubmitInfo submit_info = {};
11255 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11256 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011257 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011258
Mark Mueller4042b652016-09-05 22:52:21 -060011259 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011260 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11262 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011263 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011264 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011265 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11266 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011267
Dave Houltonfbf52152017-01-06 12:55:29 -070011268 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060011269 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070011270 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060011271
Mark Mueller4042b652016-09-05 22:52:21 -060011272 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011273 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011274 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11277 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011278 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011279 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11280 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011281
11282 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011283}
11284
Tobin Ehlisb093da82017-01-19 12:05:27 -070011285TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011286 TEST_DESCRIPTION(
11287 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
11288 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070011289
11290 ASSERT_NO_FATAL_FAILURE(InitState());
11291 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11292
11293 std::vector<const char *> device_extension_names;
11294 auto features = m_device->phy().features();
11295 // Make sure gs & ts are disabled
11296 features.geometryShader = false;
11297 features.tessellationShader = false;
11298 // The sacrificial device object
11299 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11300
11301 VkCommandPoolCreateInfo pool_create_info{};
11302 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
11303 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
11304
11305 VkCommandPool command_pool;
11306 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
11307
11308 VkCommandBufferAllocateInfo cmd = {};
11309 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11310 cmd.pNext = NULL;
11311 cmd.commandPool = command_pool;
11312 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
11313 cmd.commandBufferCount = 1;
11314
11315 VkCommandBuffer cmd_buffer;
11316 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
11317 ASSERT_VK_SUCCESS(err);
11318
11319 VkEvent event;
11320 VkEventCreateInfo evci = {};
11321 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11322 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
11323 ASSERT_VK_SUCCESS(result);
11324
11325 VkCommandBufferBeginInfo cbbi = {};
11326 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11327 vkBeginCommandBuffer(cmd_buffer, &cbbi);
11328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
11329 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
11330 m_errorMonitor->VerifyFound();
11331
11332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
11333 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
11334 m_errorMonitor->VerifyFound();
11335
11336 vkDestroyEvent(test_device.handle(), event, NULL);
11337 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
11338}
11339
Mark Mueller917f6bc2016-08-30 10:57:19 -060011340TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011341 TEST_DESCRIPTION(
11342 "Use vkCmdExecuteCommands with invalid state "
11343 "in primary and secondary command buffers. "
11344 "Delete objects that are inuse. Call VkQueueSubmit "
11345 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011346
11347 ASSERT_NO_FATAL_FAILURE(InitState());
11348 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011350 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011351 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011352
Tony Barbour552f6c02016-12-21 14:34:07 -070011353 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011354
11355 VkEvent event;
11356 VkEventCreateInfo event_create_info = {};
11357 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11358 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011359 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011360
Tony Barbour552f6c02016-12-21 14:34:07 -070011361 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011362 vkDestroyEvent(m_device->device(), event, nullptr);
11363
11364 VkSubmitInfo submit_info = {};
11365 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11366 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011367 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011369 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11370 m_errorMonitor->VerifyFound();
11371
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011372 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060011373 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11374
11375 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11376
Mark Mueller917f6bc2016-08-30 10:57:19 -060011377 VkSemaphoreCreateInfo semaphore_create_info = {};
11378 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11379 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011380 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011381 VkFenceCreateInfo fence_create_info = {};
11382 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11383 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011384 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011385
11386 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011387 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011388 descriptor_pool_type_count.descriptorCount = 1;
11389
11390 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11391 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11392 descriptor_pool_create_info.maxSets = 1;
11393 descriptor_pool_create_info.poolSizeCount = 1;
11394 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011395 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011396
11397 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011398 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011399
11400 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011401 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011402 descriptorset_layout_binding.descriptorCount = 1;
11403 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11404
11405 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011406 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011407 descriptorset_layout_create_info.bindingCount = 1;
11408 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11409
11410 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011411 ASSERT_VK_SUCCESS(
11412 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011413
11414 VkDescriptorSet descriptorset;
11415 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011416 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011417 descriptorset_allocate_info.descriptorSetCount = 1;
11418 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11419 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011420 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011421
Mark Mueller4042b652016-09-05 22:52:21 -060011422 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11423
11424 VkDescriptorBufferInfo buffer_info = {};
11425 buffer_info.buffer = buffer_test.GetBuffer();
11426 buffer_info.offset = 0;
11427 buffer_info.range = 1024;
11428
11429 VkWriteDescriptorSet write_descriptor_set = {};
11430 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11431 write_descriptor_set.dstSet = descriptorset;
11432 write_descriptor_set.descriptorCount = 1;
11433 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11434 write_descriptor_set.pBufferInfo = &buffer_info;
11435
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011436 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011438 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11439 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011440
11441 VkPipelineObj pipe(m_device);
11442 pipe.AddColorAttachment();
11443 pipe.AddShader(&vs);
11444 pipe.AddShader(&fs);
11445
11446 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011447 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011448 pipeline_layout_create_info.setLayoutCount = 1;
11449 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11450
11451 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011452 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011453
11454 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11455
Tony Barbour552f6c02016-12-21 14:34:07 -070011456 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011457 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011458
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011459 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11460 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11461 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011462
Tony Barbour552f6c02016-12-21 14:34:07 -070011463 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011464
Mark Mueller917f6bc2016-08-30 10:57:19 -060011465 submit_info.signalSemaphoreCount = 1;
11466 submit_info.pSignalSemaphores = &semaphore;
11467 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011468 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060011469
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011471 vkDestroyEvent(m_device->device(), event, nullptr);
11472 m_errorMonitor->VerifyFound();
11473
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011475 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11476 m_errorMonitor->VerifyFound();
11477
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011479 vkDestroyFence(m_device->device(), fence, nullptr);
11480 m_errorMonitor->VerifyFound();
11481
Tobin Ehlis122207b2016-09-01 08:50:06 -070011482 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011483 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11484 vkDestroyFence(m_device->device(), fence, nullptr);
11485 vkDestroyEvent(m_device->device(), event, nullptr);
11486 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011487 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011488 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11489}
11490
Tobin Ehlis2adda372016-09-01 08:51:06 -070011491TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11492 TEST_DESCRIPTION("Delete in-use query pool.");
11493
11494 ASSERT_NO_FATAL_FAILURE(InitState());
11495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11496
11497 VkQueryPool query_pool;
11498 VkQueryPoolCreateInfo query_pool_ci{};
11499 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11500 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11501 query_pool_ci.queryCount = 1;
11502 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011503 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011504 // Reset query pool to create binding with cmd buffer
11505 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11506
Tony Barbour552f6c02016-12-21 14:34:07 -070011507 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011508
11509 VkSubmitInfo submit_info = {};
11510 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11511 submit_info.commandBufferCount = 1;
11512 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11513 // Submit cmd buffer and then destroy query pool while in-flight
11514 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11515
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011517 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11518 m_errorMonitor->VerifyFound();
11519
11520 vkQueueWaitIdle(m_device->m_queue);
11521 // Now that cmd buffer done we can safely destroy query_pool
11522 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11523}
11524
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011525TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11526 TEST_DESCRIPTION("Delete in-use pipeline.");
11527
11528 ASSERT_NO_FATAL_FAILURE(InitState());
11529 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11530
11531 // Empty pipeline layout used for binding PSO
11532 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11533 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11534 pipeline_layout_ci.setLayoutCount = 0;
11535 pipeline_layout_ci.pSetLayouts = NULL;
11536
11537 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011538 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011539 ASSERT_VK_SUCCESS(err);
11540
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011542 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011543 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11544 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011545 // Store pipeline handle so we can actually delete it before test finishes
11546 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011547 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011548 VkPipelineObj pipe(m_device);
11549 pipe.AddShader(&vs);
11550 pipe.AddShader(&fs);
11551 pipe.AddColorAttachment();
11552 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11553 delete_this_pipeline = pipe.handle();
11554
Tony Barbour552f6c02016-12-21 14:34:07 -070011555 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011556 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011557 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011558
Tony Barbour552f6c02016-12-21 14:34:07 -070011559 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011560
11561 VkSubmitInfo submit_info = {};
11562 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11563 submit_info.commandBufferCount = 1;
11564 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11565 // Submit cmd buffer and then pipeline destroyed while in-flight
11566 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011567 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011568 m_errorMonitor->VerifyFound();
11569 // Make sure queue finished and then actually delete pipeline
11570 vkQueueWaitIdle(m_device->m_queue);
11571 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11572 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11573}
11574
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011575TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11576 TEST_DESCRIPTION("Delete in-use imageView.");
11577
11578 ASSERT_NO_FATAL_FAILURE(InitState());
11579 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11580
11581 VkDescriptorPoolSize ds_type_count;
11582 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11583 ds_type_count.descriptorCount = 1;
11584
11585 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11586 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11587 ds_pool_ci.maxSets = 1;
11588 ds_pool_ci.poolSizeCount = 1;
11589 ds_pool_ci.pPoolSizes = &ds_type_count;
11590
11591 VkDescriptorPool ds_pool;
11592 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11593 ASSERT_VK_SUCCESS(err);
11594
11595 VkSamplerCreateInfo sampler_ci = {};
11596 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11597 sampler_ci.pNext = NULL;
11598 sampler_ci.magFilter = VK_FILTER_NEAREST;
11599 sampler_ci.minFilter = VK_FILTER_NEAREST;
11600 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11601 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11602 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11603 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11604 sampler_ci.mipLodBias = 1.0;
11605 sampler_ci.anisotropyEnable = VK_FALSE;
11606 sampler_ci.maxAnisotropy = 1;
11607 sampler_ci.compareEnable = VK_FALSE;
11608 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11609 sampler_ci.minLod = 1.0;
11610 sampler_ci.maxLod = 1.0;
11611 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11612 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11613 VkSampler sampler;
11614
11615 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11616 ASSERT_VK_SUCCESS(err);
11617
11618 VkDescriptorSetLayoutBinding layout_binding;
11619 layout_binding.binding = 0;
11620 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11621 layout_binding.descriptorCount = 1;
11622 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11623 layout_binding.pImmutableSamplers = NULL;
11624
11625 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11626 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11627 ds_layout_ci.bindingCount = 1;
11628 ds_layout_ci.pBindings = &layout_binding;
11629 VkDescriptorSetLayout ds_layout;
11630 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11631 ASSERT_VK_SUCCESS(err);
11632
11633 VkDescriptorSetAllocateInfo alloc_info = {};
11634 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11635 alloc_info.descriptorSetCount = 1;
11636 alloc_info.descriptorPool = ds_pool;
11637 alloc_info.pSetLayouts = &ds_layout;
11638 VkDescriptorSet descriptor_set;
11639 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11640 ASSERT_VK_SUCCESS(err);
11641
11642 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11643 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11644 pipeline_layout_ci.pNext = NULL;
11645 pipeline_layout_ci.setLayoutCount = 1;
11646 pipeline_layout_ci.pSetLayouts = &ds_layout;
11647
11648 VkPipelineLayout pipeline_layout;
11649 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11650 ASSERT_VK_SUCCESS(err);
11651
11652 VkImageObj image(m_device);
11653 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11654 ASSERT_TRUE(image.initialized());
11655
11656 VkImageView view;
11657 VkImageViewCreateInfo ivci = {};
11658 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11659 ivci.image = image.handle();
11660 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11661 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11662 ivci.subresourceRange.layerCount = 1;
11663 ivci.subresourceRange.baseMipLevel = 0;
11664 ivci.subresourceRange.levelCount = 1;
11665 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11666
11667 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11668 ASSERT_VK_SUCCESS(err);
11669
11670 VkDescriptorImageInfo image_info{};
11671 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11672 image_info.imageView = view;
11673 image_info.sampler = sampler;
11674
11675 VkWriteDescriptorSet descriptor_write = {};
11676 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11677 descriptor_write.dstSet = descriptor_set;
11678 descriptor_write.dstBinding = 0;
11679 descriptor_write.descriptorCount = 1;
11680 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11681 descriptor_write.pImageInfo = &image_info;
11682
11683 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11684
11685 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011686 char const *vsSource =
11687 "#version 450\n"
11688 "\n"
11689 "out gl_PerVertex { \n"
11690 " vec4 gl_Position;\n"
11691 "};\n"
11692 "void main(){\n"
11693 " gl_Position = vec4(1);\n"
11694 "}\n";
11695 char const *fsSource =
11696 "#version 450\n"
11697 "\n"
11698 "layout(set=0, binding=0) uniform sampler2D s;\n"
11699 "layout(location=0) out vec4 x;\n"
11700 "void main(){\n"
11701 " x = texture(s, vec2(1));\n"
11702 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011703 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11704 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11705 VkPipelineObj pipe(m_device);
11706 pipe.AddShader(&vs);
11707 pipe.AddShader(&fs);
11708 pipe.AddColorAttachment();
11709 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11710
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011711 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011712
Tony Barbour552f6c02016-12-21 14:34:07 -070011713 m_commandBuffer->BeginCommandBuffer();
11714 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011715 // Bind pipeline to cmd buffer
11716 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11717 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11718 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070011719
11720 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11721 VkRect2D scissor = {{0, 0}, {16, 16}};
11722 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11723 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11724
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011725 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011726 m_commandBuffer->EndRenderPass();
11727 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011728 // Submit cmd buffer then destroy sampler
11729 VkSubmitInfo submit_info = {};
11730 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11731 submit_info.commandBufferCount = 1;
11732 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11733 // Submit cmd buffer and then destroy imageView while in-flight
11734 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11735
11736 vkDestroyImageView(m_device->device(), view, nullptr);
11737 m_errorMonitor->VerifyFound();
11738 vkQueueWaitIdle(m_device->m_queue);
11739 // Now we can actually destroy imageView
11740 vkDestroyImageView(m_device->device(), view, NULL);
11741 vkDestroySampler(m_device->device(), sampler, nullptr);
11742 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11743 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11744 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11745}
11746
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011747TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11748 TEST_DESCRIPTION("Delete in-use bufferView.");
11749
11750 ASSERT_NO_FATAL_FAILURE(InitState());
11751 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11752
11753 VkDescriptorPoolSize ds_type_count;
11754 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11755 ds_type_count.descriptorCount = 1;
11756
11757 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11758 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11759 ds_pool_ci.maxSets = 1;
11760 ds_pool_ci.poolSizeCount = 1;
11761 ds_pool_ci.pPoolSizes = &ds_type_count;
11762
11763 VkDescriptorPool ds_pool;
11764 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11765 ASSERT_VK_SUCCESS(err);
11766
11767 VkDescriptorSetLayoutBinding layout_binding;
11768 layout_binding.binding = 0;
11769 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11770 layout_binding.descriptorCount = 1;
11771 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11772 layout_binding.pImmutableSamplers = NULL;
11773
11774 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11775 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11776 ds_layout_ci.bindingCount = 1;
11777 ds_layout_ci.pBindings = &layout_binding;
11778 VkDescriptorSetLayout ds_layout;
11779 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11780 ASSERT_VK_SUCCESS(err);
11781
11782 VkDescriptorSetAllocateInfo alloc_info = {};
11783 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11784 alloc_info.descriptorSetCount = 1;
11785 alloc_info.descriptorPool = ds_pool;
11786 alloc_info.pSetLayouts = &ds_layout;
11787 VkDescriptorSet descriptor_set;
11788 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11789 ASSERT_VK_SUCCESS(err);
11790
11791 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11792 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11793 pipeline_layout_ci.pNext = NULL;
11794 pipeline_layout_ci.setLayoutCount = 1;
11795 pipeline_layout_ci.pSetLayouts = &ds_layout;
11796
11797 VkPipelineLayout pipeline_layout;
11798 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11799 ASSERT_VK_SUCCESS(err);
11800
11801 VkBuffer buffer;
11802 uint32_t queue_family_index = 0;
11803 VkBufferCreateInfo buffer_create_info = {};
11804 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11805 buffer_create_info.size = 1024;
11806 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11807 buffer_create_info.queueFamilyIndexCount = 1;
11808 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11809
11810 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11811 ASSERT_VK_SUCCESS(err);
11812
11813 VkMemoryRequirements memory_reqs;
11814 VkDeviceMemory buffer_memory;
11815
11816 VkMemoryAllocateInfo memory_info = {};
11817 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11818 memory_info.allocationSize = 0;
11819 memory_info.memoryTypeIndex = 0;
11820
11821 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11822 memory_info.allocationSize = memory_reqs.size;
11823 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11824 ASSERT_TRUE(pass);
11825
11826 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11827 ASSERT_VK_SUCCESS(err);
11828 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11829 ASSERT_VK_SUCCESS(err);
11830
11831 VkBufferView view;
11832 VkBufferViewCreateInfo bvci = {};
11833 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11834 bvci.buffer = buffer;
11835 bvci.format = VK_FORMAT_R8_UNORM;
11836 bvci.range = VK_WHOLE_SIZE;
11837
11838 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11839 ASSERT_VK_SUCCESS(err);
11840
11841 VkWriteDescriptorSet descriptor_write = {};
11842 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11843 descriptor_write.dstSet = descriptor_set;
11844 descriptor_write.dstBinding = 0;
11845 descriptor_write.descriptorCount = 1;
11846 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11847 descriptor_write.pTexelBufferView = &view;
11848
11849 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11850
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011851 char const *vsSource =
11852 "#version 450\n"
11853 "\n"
11854 "out gl_PerVertex { \n"
11855 " vec4 gl_Position;\n"
11856 "};\n"
11857 "void main(){\n"
11858 " gl_Position = vec4(1);\n"
11859 "}\n";
11860 char const *fsSource =
11861 "#version 450\n"
11862 "\n"
11863 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11864 "layout(location=0) out vec4 x;\n"
11865 "void main(){\n"
11866 " x = imageLoad(s, 0);\n"
11867 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011868 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11869 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11870 VkPipelineObj pipe(m_device);
11871 pipe.AddShader(&vs);
11872 pipe.AddShader(&fs);
11873 pipe.AddColorAttachment();
11874 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11875
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011877
Tony Barbour552f6c02016-12-21 14:34:07 -070011878 m_commandBuffer->BeginCommandBuffer();
11879 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011880 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11881 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11882 VkRect2D scissor = {{0, 0}, {16, 16}};
11883 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11884 // Bind pipeline to cmd buffer
11885 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11886 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11887 &descriptor_set, 0, nullptr);
11888 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011889 m_commandBuffer->EndRenderPass();
11890 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011891
11892 VkSubmitInfo submit_info = {};
11893 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11894 submit_info.commandBufferCount = 1;
11895 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11896 // Submit cmd buffer and then destroy bufferView while in-flight
11897 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11898
11899 vkDestroyBufferView(m_device->device(), view, nullptr);
11900 m_errorMonitor->VerifyFound();
11901 vkQueueWaitIdle(m_device->m_queue);
11902 // Now we can actually destroy bufferView
11903 vkDestroyBufferView(m_device->device(), view, NULL);
11904 vkDestroyBuffer(m_device->device(), buffer, NULL);
11905 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11906 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11907 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11908 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11909}
11910
Tobin Ehlis209532e2016-09-07 13:52:18 -060011911TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11912 TEST_DESCRIPTION("Delete in-use sampler.");
11913
11914 ASSERT_NO_FATAL_FAILURE(InitState());
11915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11916
11917 VkDescriptorPoolSize ds_type_count;
11918 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11919 ds_type_count.descriptorCount = 1;
11920
11921 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11922 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11923 ds_pool_ci.maxSets = 1;
11924 ds_pool_ci.poolSizeCount = 1;
11925 ds_pool_ci.pPoolSizes = &ds_type_count;
11926
11927 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011928 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011929 ASSERT_VK_SUCCESS(err);
11930
11931 VkSamplerCreateInfo sampler_ci = {};
11932 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11933 sampler_ci.pNext = NULL;
11934 sampler_ci.magFilter = VK_FILTER_NEAREST;
11935 sampler_ci.minFilter = VK_FILTER_NEAREST;
11936 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11937 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11938 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11939 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11940 sampler_ci.mipLodBias = 1.0;
11941 sampler_ci.anisotropyEnable = VK_FALSE;
11942 sampler_ci.maxAnisotropy = 1;
11943 sampler_ci.compareEnable = VK_FALSE;
11944 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11945 sampler_ci.minLod = 1.0;
11946 sampler_ci.maxLod = 1.0;
11947 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11948 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11949 VkSampler sampler;
11950
11951 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11952 ASSERT_VK_SUCCESS(err);
11953
11954 VkDescriptorSetLayoutBinding layout_binding;
11955 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011956 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011957 layout_binding.descriptorCount = 1;
11958 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11959 layout_binding.pImmutableSamplers = NULL;
11960
11961 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11962 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11963 ds_layout_ci.bindingCount = 1;
11964 ds_layout_ci.pBindings = &layout_binding;
11965 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011966 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011967 ASSERT_VK_SUCCESS(err);
11968
11969 VkDescriptorSetAllocateInfo alloc_info = {};
11970 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11971 alloc_info.descriptorSetCount = 1;
11972 alloc_info.descriptorPool = ds_pool;
11973 alloc_info.pSetLayouts = &ds_layout;
11974 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011975 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011976 ASSERT_VK_SUCCESS(err);
11977
11978 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11979 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11980 pipeline_layout_ci.pNext = NULL;
11981 pipeline_layout_ci.setLayoutCount = 1;
11982 pipeline_layout_ci.pSetLayouts = &ds_layout;
11983
11984 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011985 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011986 ASSERT_VK_SUCCESS(err);
11987
11988 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011989 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 -060011990 ASSERT_TRUE(image.initialized());
11991
11992 VkImageView view;
11993 VkImageViewCreateInfo ivci = {};
11994 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11995 ivci.image = image.handle();
11996 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11997 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11998 ivci.subresourceRange.layerCount = 1;
11999 ivci.subresourceRange.baseMipLevel = 0;
12000 ivci.subresourceRange.levelCount = 1;
12001 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12002
12003 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12004 ASSERT_VK_SUCCESS(err);
12005
12006 VkDescriptorImageInfo image_info{};
12007 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12008 image_info.imageView = view;
12009 image_info.sampler = sampler;
12010
12011 VkWriteDescriptorSet descriptor_write = {};
12012 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12013 descriptor_write.dstSet = descriptor_set;
12014 descriptor_write.dstBinding = 0;
12015 descriptor_write.descriptorCount = 1;
12016 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12017 descriptor_write.pImageInfo = &image_info;
12018
12019 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12020
12021 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012022 char const *vsSource =
12023 "#version 450\n"
12024 "\n"
12025 "out gl_PerVertex { \n"
12026 " vec4 gl_Position;\n"
12027 "};\n"
12028 "void main(){\n"
12029 " gl_Position = vec4(1);\n"
12030 "}\n";
12031 char const *fsSource =
12032 "#version 450\n"
12033 "\n"
12034 "layout(set=0, binding=0) uniform sampler2D s;\n"
12035 "layout(location=0) out vec4 x;\n"
12036 "void main(){\n"
12037 " x = texture(s, vec2(1));\n"
12038 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012039 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12040 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12041 VkPipelineObj pipe(m_device);
12042 pipe.AddShader(&vs);
12043 pipe.AddShader(&fs);
12044 pipe.AddColorAttachment();
12045 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12046
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012048
Tony Barbour552f6c02016-12-21 14:34:07 -070012049 m_commandBuffer->BeginCommandBuffer();
12050 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012051 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012052 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12053 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12054 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012055
12056 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12057 VkRect2D scissor = {{0, 0}, {16, 16}};
12058 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12059 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12060
Tobin Ehlis209532e2016-09-07 13:52:18 -060012061 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012062 m_commandBuffer->EndRenderPass();
12063 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012064 // Submit cmd buffer then destroy sampler
12065 VkSubmitInfo submit_info = {};
12066 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12067 submit_info.commandBufferCount = 1;
12068 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12069 // Submit cmd buffer and then destroy sampler while in-flight
12070 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12071
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012072 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012073 m_errorMonitor->VerifyFound();
12074 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012075
Tobin Ehlis209532e2016-09-07 13:52:18 -060012076 // Now we can actually destroy sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012077 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012078 vkDestroyImageView(m_device->device(), view, NULL);
12079 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12080 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12081 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12082}
12083
Mark Mueller1cd9f412016-08-25 13:23:52 -060012084TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012085 TEST_DESCRIPTION(
12086 "Call VkQueueSubmit with a semaphore that is already "
12087 "signaled but not waited on by the queue. Wait on a "
12088 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012089
12090 ASSERT_NO_FATAL_FAILURE(InitState());
12091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012093 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 -070012094 const char *invalid_fence_wait_message =
12095 " which has not been submitted on a Queue or during "
12096 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012097
Tony Barbour552f6c02016-12-21 14:34:07 -070012098 m_commandBuffer->BeginCommandBuffer();
12099 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012100
12101 VkSemaphoreCreateInfo semaphore_create_info = {};
12102 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12103 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012104 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012105 VkSubmitInfo submit_info = {};
12106 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12107 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012108 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012109 submit_info.signalSemaphoreCount = 1;
12110 submit_info.pSignalSemaphores = &semaphore;
12111 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012112 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012113 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012114 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012115 m_commandBuffer->BeginCommandBuffer();
12116 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012118 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12119 m_errorMonitor->VerifyFound();
12120
Mark Mueller1cd9f412016-08-25 13:23:52 -060012121 VkFenceCreateInfo fence_create_info = {};
12122 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12123 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012124 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012127 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12128 m_errorMonitor->VerifyFound();
12129
Mark Mueller4042b652016-09-05 22:52:21 -060012130 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012131 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012132 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12133}
12134
Tobin Ehlis4af23302016-07-19 10:50:30 -060012135TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012136 TEST_DESCRIPTION(
12137 "Bind a secondary command buffer with with a framebuffer "
12138 "that does not match the framebuffer for the active "
12139 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012140 ASSERT_NO_FATAL_FAILURE(InitState());
12141 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12142
12143 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012144 VkAttachmentDescription attachment = {0,
12145 VK_FORMAT_B8G8R8A8_UNORM,
12146 VK_SAMPLE_COUNT_1_BIT,
12147 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12148 VK_ATTACHMENT_STORE_OP_STORE,
12149 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12150 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12151 VK_IMAGE_LAYOUT_UNDEFINED,
12152 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012153
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012154 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012155
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012156 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012158 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012159
12160 VkRenderPass rp;
12161 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12162 ASSERT_VK_SUCCESS(err);
12163
12164 // A compatible framebuffer.
12165 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012166 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 -060012167 ASSERT_TRUE(image.initialized());
12168
12169 VkImageViewCreateInfo ivci = {
12170 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12171 nullptr,
12172 0,
12173 image.handle(),
12174 VK_IMAGE_VIEW_TYPE_2D,
12175 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012176 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12177 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012178 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12179 };
12180 VkImageView view;
12181 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12182 ASSERT_VK_SUCCESS(err);
12183
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012184 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012185 VkFramebuffer fb;
12186 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12187 ASSERT_VK_SUCCESS(err);
12188
12189 VkCommandBufferAllocateInfo cbai = {};
12190 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12191 cbai.commandPool = m_commandPool;
12192 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12193 cbai.commandBufferCount = 1;
12194
12195 VkCommandBuffer sec_cb;
12196 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12197 ASSERT_VK_SUCCESS(err);
12198 VkCommandBufferBeginInfo cbbi = {};
12199 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130012200 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060012201 cbii.renderPass = renderPass();
12202 cbii.framebuffer = fb;
12203 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12204 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012205 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 -060012206 cbbi.pInheritanceInfo = &cbii;
12207 vkBeginCommandBuffer(sec_cb, &cbbi);
12208 vkEndCommandBuffer(sec_cb);
12209
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012210 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120012211 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12212 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012215 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012216 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12217 m_errorMonitor->VerifyFound();
12218 // Cleanup
12219 vkDestroyImageView(m_device->device(), view, NULL);
12220 vkDestroyRenderPass(m_device->device(), rp, NULL);
12221 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12222}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012223
12224TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012225 TEST_DESCRIPTION(
12226 "If logicOp is available on the device, set it to an "
12227 "invalid value. If logicOp is not available, attempt to "
12228 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012229 ASSERT_NO_FATAL_FAILURE(InitState());
12230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12231
12232 auto features = m_device->phy().features();
12233 // Set the expected error depending on whether or not logicOp available
12234 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12236 "If logic operations feature not "
12237 "enabled, logicOpEnable must be "
12238 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012239 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012241 }
12242 // Create a pipeline using logicOp
12243 VkResult err;
12244
12245 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12246 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12247
12248 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012249 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012250 ASSERT_VK_SUCCESS(err);
12251
12252 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12253 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12254 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012255 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012256 vp_state_ci.pViewports = &vp;
12257 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012258 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012259 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012260
12261 VkPipelineShaderStageCreateInfo shaderStages[2];
12262 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12263
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012264 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12265 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012266 shaderStages[0] = vs.GetStageCreateInfo();
12267 shaderStages[1] = fs.GetStageCreateInfo();
12268
12269 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12270 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12271
12272 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12273 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12274 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12275
12276 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12277 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012278 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012279
12280 VkPipelineColorBlendAttachmentState att = {};
12281 att.blendEnable = VK_FALSE;
12282 att.colorWriteMask = 0xf;
12283
12284 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12285 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12286 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12287 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012288 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012289 cb_ci.attachmentCount = 1;
12290 cb_ci.pAttachments = &att;
12291
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012292 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12293 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12294 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12295
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012296 VkGraphicsPipelineCreateInfo gp_ci = {};
12297 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12298 gp_ci.stageCount = 2;
12299 gp_ci.pStages = shaderStages;
12300 gp_ci.pVertexInputState = &vi_ci;
12301 gp_ci.pInputAssemblyState = &ia_ci;
12302 gp_ci.pViewportState = &vp_state_ci;
12303 gp_ci.pRasterizationState = &rs_ci;
12304 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012305 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012306 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12307 gp_ci.layout = pipeline_layout;
12308 gp_ci.renderPass = renderPass();
12309
12310 VkPipelineCacheCreateInfo pc_ci = {};
12311 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12312
12313 VkPipeline pipeline;
12314 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012315 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012316 ASSERT_VK_SUCCESS(err);
12317
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012318 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012319 m_errorMonitor->VerifyFound();
12320 if (VK_SUCCESS == err) {
12321 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12322 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012323 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12324 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12325}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012326#endif // DRAW_STATE_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012327
Tobin Ehlis0788f522015-05-26 16:11:58 -060012328#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012329#if GTEST_IS_THREADSAFE
12330struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012331 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012332 VkEvent event;
12333 bool bailout;
12334};
12335
Karl Schultz6addd812016-02-02 17:17:23 -070012336extern "C" void *AddToCommandBuffer(void *arg) {
12337 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012338
Mike Stroyana6d14942016-07-13 15:10:05 -060012339 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012340 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012341 if (data->bailout) {
12342 break;
12343 }
12344 }
12345 return NULL;
12346}
12347
Karl Schultz6addd812016-02-02 17:17:23 -070012348TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012349 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012350
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012352
Mike Stroyanaccf7692015-05-12 16:00:45 -060012353 ASSERT_NO_FATAL_FAILURE(InitState());
12354 ASSERT_NO_FATAL_FAILURE(InitViewport());
12355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12356
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012357 // Calls AllocateCommandBuffers
12358 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012359
12360 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012361 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012362
12363 VkEventCreateInfo event_info;
12364 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012365 VkResult err;
12366
12367 memset(&event_info, 0, sizeof(event_info));
12368 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12369
Chia-I Wuf7458c52015-10-26 21:10:41 +080012370 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012371 ASSERT_VK_SUCCESS(err);
12372
Mike Stroyanaccf7692015-05-12 16:00:45 -060012373 err = vkResetEvent(device(), event);
12374 ASSERT_VK_SUCCESS(err);
12375
12376 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012377 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012378 data.event = event;
12379 data.bailout = false;
12380 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012381
12382 // First do some correct operations using multiple threads.
12383 // Add many entries to command buffer from another thread.
12384 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12385 // Make non-conflicting calls from this thread at the same time.
12386 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012387 uint32_t count;
12388 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012389 }
12390 test_platform_thread_join(thread, NULL);
12391
12392 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012393 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012394 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012395 // Add many entries to command buffer from this thread at the same time.
12396 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012397
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012398 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012399 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012400
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012401 m_errorMonitor->SetBailout(NULL);
12402
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012403 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012404
Chia-I Wuf7458c52015-10-26 21:10:41 +080012405 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012406}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012407#endif // GTEST_IS_THREADSAFE
12408#endif // THREADING_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012409
Chris Forbes9f7ff632015-05-25 11:13:08 +120012410#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012411TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012412 TEST_DESCRIPTION(
12413 "Test that an error is produced for a spirv module "
12414 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120012415
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012417
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012418 ASSERT_NO_FATAL_FAILURE(InitState());
12419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12420
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012421 VkShaderModule module;
12422 VkShaderModuleCreateInfo moduleCreateInfo;
12423 struct icd_spv_header spv;
12424
12425 spv.magic = ICD_SPV_MAGIC;
12426 spv.version = ICD_SPV_VERSION;
12427 spv.gen_magic = 0;
12428
12429 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12430 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012431 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012432 moduleCreateInfo.codeSize = 4;
12433 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012434 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012435
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012436 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012437}
12438
Karl Schultz6addd812016-02-02 17:17:23 -070012439TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012440 TEST_DESCRIPTION(
12441 "Test that an error is produced for a spirv module "
12442 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120012443
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012445
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012446 ASSERT_NO_FATAL_FAILURE(InitState());
12447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12448
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012449 VkShaderModule module;
12450 VkShaderModuleCreateInfo moduleCreateInfo;
12451 struct icd_spv_header spv;
12452
12453 spv.magic = ~ICD_SPV_MAGIC;
12454 spv.version = ICD_SPV_VERSION;
12455 spv.gen_magic = 0;
12456
12457 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12458 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012459 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012460 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12461 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012462 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012463
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012464 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012465}
12466
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012467#if 0
12468// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012469TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012471 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012472
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012473 ASSERT_NO_FATAL_FAILURE(InitState());
12474 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12475
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012476 VkShaderModule module;
12477 VkShaderModuleCreateInfo moduleCreateInfo;
12478 struct icd_spv_header spv;
12479
12480 spv.magic = ICD_SPV_MAGIC;
12481 spv.version = ~ICD_SPV_VERSION;
12482 spv.gen_magic = 0;
12483
12484 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12485 moduleCreateInfo.pNext = NULL;
12486
Karl Schultz6addd812016-02-02 17:17:23 -070012487 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012488 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12489 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012490 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012491
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012492 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012493}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012494#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012495
Karl Schultz6addd812016-02-02 17:17:23 -070012496TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012497 TEST_DESCRIPTION(
12498 "Test that a warning is produced for a vertex output that "
12499 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012501
Chris Forbes9f7ff632015-05-25 11:13:08 +120012502 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012504
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012505 char const *vsSource =
12506 "#version 450\n"
12507 "\n"
12508 "layout(location=0) out float x;\n"
12509 "out gl_PerVertex {\n"
12510 " vec4 gl_Position;\n"
12511 "};\n"
12512 "void main(){\n"
12513 " gl_Position = vec4(1);\n"
12514 " x = 0;\n"
12515 "}\n";
12516 char const *fsSource =
12517 "#version 450\n"
12518 "\n"
12519 "layout(location=0) out vec4 color;\n"
12520 "void main(){\n"
12521 " color = vec4(1);\n"
12522 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012523
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012524 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12525 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012526
12527 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012528 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012529 pipe.AddShader(&vs);
12530 pipe.AddShader(&fs);
12531
Chris Forbes9f7ff632015-05-25 11:13:08 +120012532 VkDescriptorSetObj descriptorSet(m_device);
12533 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012534 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012535
Tony Barbour5781e8f2015-08-04 16:23:11 -060012536 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012537
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012538 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012539}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012540
Mark Mueller098c9cb2016-09-08 09:01:57 -060012541TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12542 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12543
12544 ASSERT_NO_FATAL_FAILURE(InitState());
12545 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12546
12547 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012548 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012549
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012550 char const *vsSource =
12551 "#version 450\n"
12552 "\n"
12553 "out gl_PerVertex {\n"
12554 " vec4 gl_Position;\n"
12555 "};\n"
12556 "void main(){\n"
12557 " gl_Position = vec4(1);\n"
12558 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012559
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012560 char const *fsSource =
12561 "#version 450\n"
12562 "\n"
12563 "layout (constant_id = 0) const float r = 0.0f;\n"
12564 "layout(location = 0) out vec4 uFragColor;\n"
12565 "void main(){\n"
12566 " uFragColor = vec4(r,1,0,1);\n"
12567 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012568
12569 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12570 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12571
12572 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12573 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12574
12575 VkPipelineLayout pipeline_layout;
12576 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12577
12578 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12579 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12580 vp_state_create_info.viewportCount = 1;
12581 VkViewport viewport = {};
12582 vp_state_create_info.pViewports = &viewport;
12583 vp_state_create_info.scissorCount = 1;
12584 VkRect2D scissors = {};
12585 vp_state_create_info.pScissors = &scissors;
12586
12587 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12588
12589 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12590 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12591 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12592 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12593
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012594 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060012595
12596 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12597 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12598
12599 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12600 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12601 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12602
12603 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12604 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12605 rasterization_state_create_info.pNext = nullptr;
12606 rasterization_state_create_info.lineWidth = 1.0f;
12607 rasterization_state_create_info.rasterizerDiscardEnable = true;
12608
12609 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12610 color_blend_attachment_state.blendEnable = VK_FALSE;
12611 color_blend_attachment_state.colorWriteMask = 0xf;
12612
12613 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12614 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12615 color_blend_state_create_info.attachmentCount = 1;
12616 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12617
12618 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12619 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12620 graphicspipe_create_info.stageCount = 2;
12621 graphicspipe_create_info.pStages = shader_stage_create_info;
12622 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12623 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12624 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12625 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12626 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12627 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12628 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12629 graphicspipe_create_info.layout = pipeline_layout;
12630 graphicspipe_create_info.renderPass = renderPass();
12631
12632 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12633 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12634
12635 VkPipelineCache pipelineCache;
12636 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12637
12638 // This structure maps constant ids to data locations.
12639 const VkSpecializationMapEntry entry =
12640 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012641 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060012642
12643 uint32_t data = 1;
12644
12645 // Set up the info describing spec map and data
12646 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012647 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060012648 };
12649 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12650
12651 VkPipeline pipeline;
12652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12653 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12654 m_errorMonitor->VerifyFound();
12655
12656 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12657 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12658}
12659
12660TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12661 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12662
12663 ASSERT_NO_FATAL_FAILURE(InitState());
12664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12665
12666 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12667
12668 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12669 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12670 descriptor_pool_type_count[0].descriptorCount = 1;
12671 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12672 descriptor_pool_type_count[1].descriptorCount = 1;
12673
12674 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12675 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12676 descriptor_pool_create_info.maxSets = 1;
12677 descriptor_pool_create_info.poolSizeCount = 2;
12678 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12679 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12680
12681 VkDescriptorPool descriptorset_pool;
12682 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12683
12684 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12685 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12686 descriptorset_layout_binding.descriptorCount = 1;
12687 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12688
12689 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12690 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12691 descriptorset_layout_create_info.bindingCount = 1;
12692 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12693
12694 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012695 ASSERT_VK_SUCCESS(
12696 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060012697
12698 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12699 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12700 descriptorset_allocate_info.descriptorSetCount = 1;
12701 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12702 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12703 VkDescriptorSet descriptorset;
12704 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12705
12706 // Challenge core_validation with a non uniform buffer type.
12707 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12708
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012709 char const *vsSource =
12710 "#version 450\n"
12711 "\n"
12712 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12713 " mat4 mvp;\n"
12714 "} ubuf;\n"
12715 "out gl_PerVertex {\n"
12716 " vec4 gl_Position;\n"
12717 "};\n"
12718 "void main(){\n"
12719 " gl_Position = ubuf.mvp * vec4(1);\n"
12720 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012721
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012722 char const *fsSource =
12723 "#version 450\n"
12724 "\n"
12725 "layout(location = 0) out vec4 uFragColor;\n"
12726 "void main(){\n"
12727 " uFragColor = vec4(0,1,0,1);\n"
12728 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012729
12730 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12731 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12732
12733 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12734 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12735 pipeline_layout_create_info.setLayoutCount = 1;
12736 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12737
12738 VkPipelineLayout pipeline_layout;
12739 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12740
12741 VkPipelineObj pipe(m_device);
12742 pipe.AddColorAttachment();
12743 pipe.AddShader(&vs);
12744 pipe.AddShader(&fs);
12745
12746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12747 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12748 m_errorMonitor->VerifyFound();
12749
12750 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12751 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12752 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12753}
12754
12755TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12756 TEST_DESCRIPTION(
12757 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12758
12759 ASSERT_NO_FATAL_FAILURE(InitState());
12760 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12761
12762 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12763
12764 VkDescriptorPoolSize descriptor_pool_type_count = {};
12765 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12766 descriptor_pool_type_count.descriptorCount = 1;
12767
12768 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12769 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12770 descriptor_pool_create_info.maxSets = 1;
12771 descriptor_pool_create_info.poolSizeCount = 1;
12772 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12773 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12774
12775 VkDescriptorPool descriptorset_pool;
12776 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12777
12778 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12779 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12780 descriptorset_layout_binding.descriptorCount = 1;
12781 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12782 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12783
12784 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12785 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12786 descriptorset_layout_create_info.bindingCount = 1;
12787 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12788
12789 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012790 ASSERT_VK_SUCCESS(
12791 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060012792
12793 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12794 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12795 descriptorset_allocate_info.descriptorSetCount = 1;
12796 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12797 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12798 VkDescriptorSet descriptorset;
12799 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12800
12801 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12802
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012803 char const *vsSource =
12804 "#version 450\n"
12805 "\n"
12806 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12807 " mat4 mvp;\n"
12808 "} ubuf;\n"
12809 "out gl_PerVertex {\n"
12810 " vec4 gl_Position;\n"
12811 "};\n"
12812 "void main(){\n"
12813 " gl_Position = ubuf.mvp * vec4(1);\n"
12814 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012815
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012816 char const *fsSource =
12817 "#version 450\n"
12818 "\n"
12819 "layout(location = 0) out vec4 uFragColor;\n"
12820 "void main(){\n"
12821 " uFragColor = vec4(0,1,0,1);\n"
12822 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012823
12824 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12825 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12826
12827 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12828 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12829 pipeline_layout_create_info.setLayoutCount = 1;
12830 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12831
12832 VkPipelineLayout pipeline_layout;
12833 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12834
12835 VkPipelineObj pipe(m_device);
12836 pipe.AddColorAttachment();
12837 pipe.AddShader(&vs);
12838 pipe.AddShader(&fs);
12839
12840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12841 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12842 m_errorMonitor->VerifyFound();
12843
12844 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12845 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12846 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12847}
12848
12849TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012850 TEST_DESCRIPTION(
12851 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12852 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060012853
12854 ASSERT_NO_FATAL_FAILURE(InitState());
12855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12856
12857 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012858 "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 -060012859
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012860 char const *vsSource =
12861 "#version 450\n"
12862 "\n"
12863 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12864 "out gl_PerVertex {\n"
12865 " vec4 gl_Position;\n"
12866 "};\n"
12867 "void main(){\n"
12868 " gl_Position = vec4(consts.x);\n"
12869 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012870
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012871 char const *fsSource =
12872 "#version 450\n"
12873 "\n"
12874 "layout(location = 0) out vec4 uFragColor;\n"
12875 "void main(){\n"
12876 " uFragColor = vec4(0,1,0,1);\n"
12877 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012878
12879 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12880 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12881
12882 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12883 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12884
12885 // Set up a push constant range
12886 VkPushConstantRange push_constant_ranges = {};
12887 // Set to the wrong stage to challenge core_validation
12888 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12889 push_constant_ranges.size = 4;
12890
12891 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12892 pipeline_layout_create_info.pushConstantRangeCount = 1;
12893
12894 VkPipelineLayout pipeline_layout;
12895 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12896
12897 VkPipelineObj pipe(m_device);
12898 pipe.AddColorAttachment();
12899 pipe.AddShader(&vs);
12900 pipe.AddShader(&fs);
12901
12902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12903 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12904 m_errorMonitor->VerifyFound();
12905
12906 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12907}
12908
12909TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12910 TEST_DESCRIPTION(
12911 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12912
12913 ASSERT_NO_FATAL_FAILURE(InitState());
12914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12915
12916 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012917 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012918
12919 // Some awkward steps are required to test with custom device features.
12920 std::vector<const char *> device_extension_names;
12921 auto features = m_device->phy().features();
12922 // Disable support for 64 bit floats
12923 features.shaderFloat64 = false;
12924 // The sacrificial device object
12925 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12926
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012927 char const *vsSource =
12928 "#version 450\n"
12929 "\n"
12930 "out gl_PerVertex {\n"
12931 " vec4 gl_Position;\n"
12932 "};\n"
12933 "void main(){\n"
12934 " gl_Position = vec4(1);\n"
12935 "}\n";
12936 char const *fsSource =
12937 "#version 450\n"
12938 "\n"
12939 "layout(location=0) out vec4 color;\n"
12940 "void main(){\n"
12941 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12942 " color = vec4(green);\n"
12943 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012944
12945 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12946 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12947
12948 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012949
12950 VkPipelineObj pipe(&test_device);
12951 pipe.AddColorAttachment();
12952 pipe.AddShader(&vs);
12953 pipe.AddShader(&fs);
12954
12955 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12956 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12957 VkPipelineLayout pipeline_layout;
12958 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12959
12960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12961 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12962 m_errorMonitor->VerifyFound();
12963
12964 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12965}
12966
12967TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12968 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12969
12970 ASSERT_NO_FATAL_FAILURE(InitState());
12971 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12972
12973 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12974
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012975 char const *vsSource =
12976 "#version 450\n"
12977 "\n"
12978 "out gl_PerVertex {\n"
12979 " vec4 gl_Position;\n"
12980 "};\n"
12981 "layout(xfb_buffer = 1) out;"
12982 "void main(){\n"
12983 " gl_Position = vec4(1);\n"
12984 "}\n";
12985 char const *fsSource =
12986 "#version 450\n"
12987 "\n"
12988 "layout(location=0) out vec4 color;\n"
12989 "void main(){\n"
12990 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12991 " color = vec4(green);\n"
12992 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012993
12994 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12995 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12996
12997 VkPipelineObj pipe(m_device);
12998 pipe.AddColorAttachment();
12999 pipe.AddShader(&vs);
13000 pipe.AddShader(&fs);
13001
13002 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13003 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13004 VkPipelineLayout pipeline_layout;
13005 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13006
13007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13008 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13009 m_errorMonitor->VerifyFound();
13010
13011 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13012}
13013
Karl Schultz6addd812016-02-02 17:17:23 -070013014TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013015 TEST_DESCRIPTION(
13016 "Test that an error is produced for a fragment shader input "
13017 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013018
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013020
Chris Forbes59cb88d2015-05-25 11:13:13 +120013021 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013022 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013023
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013024 char const *vsSource =
13025 "#version 450\n"
13026 "\n"
13027 "out gl_PerVertex {\n"
13028 " vec4 gl_Position;\n"
13029 "};\n"
13030 "void main(){\n"
13031 " gl_Position = vec4(1);\n"
13032 "}\n";
13033 char const *fsSource =
13034 "#version 450\n"
13035 "\n"
13036 "layout(location=0) in float x;\n"
13037 "layout(location=0) out vec4 color;\n"
13038 "void main(){\n"
13039 " color = vec4(x);\n"
13040 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013041
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013042 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13043 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013044
13045 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013046 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013047 pipe.AddShader(&vs);
13048 pipe.AddShader(&fs);
13049
Chris Forbes59cb88d2015-05-25 11:13:13 +120013050 VkDescriptorSetObj descriptorSet(m_device);
13051 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013052 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013053
Tony Barbour5781e8f2015-08-04 16:23:11 -060013054 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013055
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013056 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013057}
13058
Karl Schultz6addd812016-02-02 17:17:23 -070013059TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013060 TEST_DESCRIPTION(
13061 "Test that an error is produced for a fragment shader input "
13062 "within an interace block, which is not present in the outputs "
13063 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013065
13066 ASSERT_NO_FATAL_FAILURE(InitState());
13067 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13068
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013069 char const *vsSource =
13070 "#version 450\n"
13071 "\n"
13072 "out gl_PerVertex {\n"
13073 " vec4 gl_Position;\n"
13074 "};\n"
13075 "void main(){\n"
13076 " gl_Position = vec4(1);\n"
13077 "}\n";
13078 char const *fsSource =
13079 "#version 450\n"
13080 "\n"
13081 "in block { layout(location=0) float x; } ins;\n"
13082 "layout(location=0) out vec4 color;\n"
13083 "void main(){\n"
13084 " color = vec4(ins.x);\n"
13085 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013086
13087 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13088 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13089
13090 VkPipelineObj pipe(m_device);
13091 pipe.AddColorAttachment();
13092 pipe.AddShader(&vs);
13093 pipe.AddShader(&fs);
13094
13095 VkDescriptorSetObj descriptorSet(m_device);
13096 descriptorSet.AppendDummy();
13097 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13098
13099 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13100
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013101 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013102}
13103
Karl Schultz6addd812016-02-02 17:17:23 -070013104TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013105 TEST_DESCRIPTION(
13106 "Test that an error is produced for mismatched array sizes "
13107 "across the vertex->fragment shader interface");
13108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13109 "Type mismatch on location 0.0: 'ptr to "
13110 "output arr[2] of float32' vs 'ptr to "
13111 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013112
13113 ASSERT_NO_FATAL_FAILURE(InitState());
13114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13115
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013116 char const *vsSource =
13117 "#version 450\n"
13118 "\n"
13119 "layout(location=0) out float x[2];\n"
13120 "out gl_PerVertex {\n"
13121 " vec4 gl_Position;\n"
13122 "};\n"
13123 "void main(){\n"
13124 " x[0] = 0; x[1] = 0;\n"
13125 " gl_Position = vec4(1);\n"
13126 "}\n";
13127 char const *fsSource =
13128 "#version 450\n"
13129 "\n"
13130 "layout(location=0) in float x[1];\n"
13131 "layout(location=0) out vec4 color;\n"
13132 "void main(){\n"
13133 " color = vec4(x[0]);\n"
13134 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013135
13136 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13137 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13138
13139 VkPipelineObj pipe(m_device);
13140 pipe.AddColorAttachment();
13141 pipe.AddShader(&vs);
13142 pipe.AddShader(&fs);
13143
13144 VkDescriptorSetObj descriptorSet(m_device);
13145 descriptorSet.AppendDummy();
13146 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13147
13148 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13149
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013150 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013151}
13152
Karl Schultz6addd812016-02-02 17:17:23 -070013153TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013154 TEST_DESCRIPTION(
13155 "Test that an error is produced for mismatched types across "
13156 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013158
Chris Forbesb56af562015-05-25 11:13:17 +120013159 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013161
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013162 char const *vsSource =
13163 "#version 450\n"
13164 "\n"
13165 "layout(location=0) out int x;\n"
13166 "out gl_PerVertex {\n"
13167 " vec4 gl_Position;\n"
13168 "};\n"
13169 "void main(){\n"
13170 " x = 0;\n"
13171 " gl_Position = vec4(1);\n"
13172 "}\n";
13173 char const *fsSource =
13174 "#version 450\n"
13175 "\n"
13176 "layout(location=0) in float x;\n" /* VS writes int */
13177 "layout(location=0) out vec4 color;\n"
13178 "void main(){\n"
13179 " color = vec4(x);\n"
13180 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013181
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013182 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13183 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013184
13185 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013186 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013187 pipe.AddShader(&vs);
13188 pipe.AddShader(&fs);
13189
Chris Forbesb56af562015-05-25 11:13:17 +120013190 VkDescriptorSetObj descriptorSet(m_device);
13191 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013192 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013193
Tony Barbour5781e8f2015-08-04 16:23:11 -060013194 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013195
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013196 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013197}
13198
Karl Schultz6addd812016-02-02 17:17:23 -070013199TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013200 TEST_DESCRIPTION(
13201 "Test that an error is produced for mismatched types across "
13202 "the vertex->fragment shader interface, when the variable is contained within "
13203 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013205
13206 ASSERT_NO_FATAL_FAILURE(InitState());
13207 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13208
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013209 char const *vsSource =
13210 "#version 450\n"
13211 "\n"
13212 "out block { layout(location=0) int x; } outs;\n"
13213 "out gl_PerVertex {\n"
13214 " vec4 gl_Position;\n"
13215 "};\n"
13216 "void main(){\n"
13217 " outs.x = 0;\n"
13218 " gl_Position = vec4(1);\n"
13219 "}\n";
13220 char const *fsSource =
13221 "#version 450\n"
13222 "\n"
13223 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13224 "layout(location=0) out vec4 color;\n"
13225 "void main(){\n"
13226 " color = vec4(ins.x);\n"
13227 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013228
13229 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13230 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13231
13232 VkPipelineObj pipe(m_device);
13233 pipe.AddColorAttachment();
13234 pipe.AddShader(&vs);
13235 pipe.AddShader(&fs);
13236
13237 VkDescriptorSetObj descriptorSet(m_device);
13238 descriptorSet.AppendDummy();
13239 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13240
13241 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13242
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013243 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013244}
13245
13246TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013247 TEST_DESCRIPTION(
13248 "Test that an error is produced for location mismatches across "
13249 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
13250 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013251 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 +130013252
13253 ASSERT_NO_FATAL_FAILURE(InitState());
13254 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13255
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013256 char const *vsSource =
13257 "#version 450\n"
13258 "\n"
13259 "out block { layout(location=1) float x; } outs;\n"
13260 "out gl_PerVertex {\n"
13261 " vec4 gl_Position;\n"
13262 "};\n"
13263 "void main(){\n"
13264 " outs.x = 0;\n"
13265 " gl_Position = vec4(1);\n"
13266 "}\n";
13267 char const *fsSource =
13268 "#version 450\n"
13269 "\n"
13270 "in block { layout(location=0) float x; } ins;\n"
13271 "layout(location=0) out vec4 color;\n"
13272 "void main(){\n"
13273 " color = vec4(ins.x);\n"
13274 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013275
13276 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13277 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13278
13279 VkPipelineObj pipe(m_device);
13280 pipe.AddColorAttachment();
13281 pipe.AddShader(&vs);
13282 pipe.AddShader(&fs);
13283
13284 VkDescriptorSetObj descriptorSet(m_device);
13285 descriptorSet.AppendDummy();
13286 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13287
13288 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13289
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013290 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013291}
13292
13293TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013294 TEST_DESCRIPTION(
13295 "Test that an error is produced for component mismatches across the "
13296 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
13297 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013298 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 +130013299
13300 ASSERT_NO_FATAL_FAILURE(InitState());
13301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13302
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013303 char const *vsSource =
13304 "#version 450\n"
13305 "\n"
13306 "out block { layout(location=0, component=0) float x; } outs;\n"
13307 "out gl_PerVertex {\n"
13308 " vec4 gl_Position;\n"
13309 "};\n"
13310 "void main(){\n"
13311 " outs.x = 0;\n"
13312 " gl_Position = vec4(1);\n"
13313 "}\n";
13314 char const *fsSource =
13315 "#version 450\n"
13316 "\n"
13317 "in block { layout(location=0, component=1) float x; } ins;\n"
13318 "layout(location=0) out vec4 color;\n"
13319 "void main(){\n"
13320 " color = vec4(ins.x);\n"
13321 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013322
13323 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13324 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13325
13326 VkPipelineObj pipe(m_device);
13327 pipe.AddColorAttachment();
13328 pipe.AddShader(&vs);
13329 pipe.AddShader(&fs);
13330
13331 VkDescriptorSetObj descriptorSet(m_device);
13332 descriptorSet.AppendDummy();
13333 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13334
13335 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13336
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013337 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013338}
13339
Chris Forbes1f3b0152016-11-30 12:48:40 +130013340TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13341 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13342
13343 ASSERT_NO_FATAL_FAILURE(InitState());
13344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13345
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013346 char const *vsSource =
13347 "#version 450\n"
13348 "layout(location=0) out mediump float x;\n"
13349 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13350 char const *fsSource =
13351 "#version 450\n"
13352 "layout(location=0) in highp float x;\n"
13353 "layout(location=0) out vec4 color;\n"
13354 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130013355
13356 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13357 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13358
13359 VkPipelineObj pipe(m_device);
13360 pipe.AddColorAttachment();
13361 pipe.AddShader(&vs);
13362 pipe.AddShader(&fs);
13363
13364 VkDescriptorSetObj descriptorSet(m_device);
13365 descriptorSet.AppendDummy();
13366 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13367
13368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13369
13370 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13371
13372 m_errorMonitor->VerifyFound();
13373}
13374
Chris Forbes870a39e2016-11-30 12:55:56 +130013375TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13376 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13377
13378 ASSERT_NO_FATAL_FAILURE(InitState());
13379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13380
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013381 char const *vsSource =
13382 "#version 450\n"
13383 "out block { layout(location=0) mediump float x; };\n"
13384 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13385 char const *fsSource =
13386 "#version 450\n"
13387 "in block { layout(location=0) highp float x; };\n"
13388 "layout(location=0) out vec4 color;\n"
13389 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130013390
13391 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13392 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13393
13394 VkPipelineObj pipe(m_device);
13395 pipe.AddColorAttachment();
13396 pipe.AddShader(&vs);
13397 pipe.AddShader(&fs);
13398
13399 VkDescriptorSetObj descriptorSet(m_device);
13400 descriptorSet.AppendDummy();
13401 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13402
13403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13404
13405 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13406
13407 m_errorMonitor->VerifyFound();
13408}
13409
Karl Schultz6addd812016-02-02 17:17:23 -070013410TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013411 TEST_DESCRIPTION(
13412 "Test that a warning is produced for a vertex attribute which is "
13413 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013415
Chris Forbesde136e02015-05-25 11:13:28 +120013416 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013418
13419 VkVertexInputBindingDescription input_binding;
13420 memset(&input_binding, 0, sizeof(input_binding));
13421
13422 VkVertexInputAttributeDescription input_attrib;
13423 memset(&input_attrib, 0, sizeof(input_attrib));
13424 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13425
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013426 char const *vsSource =
13427 "#version 450\n"
13428 "\n"
13429 "out gl_PerVertex {\n"
13430 " vec4 gl_Position;\n"
13431 "};\n"
13432 "void main(){\n"
13433 " gl_Position = vec4(1);\n"
13434 "}\n";
13435 char const *fsSource =
13436 "#version 450\n"
13437 "\n"
13438 "layout(location=0) out vec4 color;\n"
13439 "void main(){\n"
13440 " color = vec4(1);\n"
13441 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013442
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013443 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13444 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013445
13446 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013447 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013448 pipe.AddShader(&vs);
13449 pipe.AddShader(&fs);
13450
13451 pipe.AddVertexInputBindings(&input_binding, 1);
13452 pipe.AddVertexInputAttribs(&input_attrib, 1);
13453
Chris Forbesde136e02015-05-25 11:13:28 +120013454 VkDescriptorSetObj descriptorSet(m_device);
13455 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013456 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013457
Tony Barbour5781e8f2015-08-04 16:23:11 -060013458 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013459
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013460 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013461}
13462
Karl Schultz6addd812016-02-02 17:17:23 -070013463TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013464 TEST_DESCRIPTION(
13465 "Test that a warning is produced for a location mismatch on "
13466 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013468
13469 ASSERT_NO_FATAL_FAILURE(InitState());
13470 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13471
13472 VkVertexInputBindingDescription input_binding;
13473 memset(&input_binding, 0, sizeof(input_binding));
13474
13475 VkVertexInputAttributeDescription input_attrib;
13476 memset(&input_attrib, 0, sizeof(input_attrib));
13477 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13478
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013479 char const *vsSource =
13480 "#version 450\n"
13481 "\n"
13482 "layout(location=1) in float x;\n"
13483 "out gl_PerVertex {\n"
13484 " vec4 gl_Position;\n"
13485 "};\n"
13486 "void main(){\n"
13487 " gl_Position = vec4(x);\n"
13488 "}\n";
13489 char const *fsSource =
13490 "#version 450\n"
13491 "\n"
13492 "layout(location=0) out vec4 color;\n"
13493 "void main(){\n"
13494 " color = vec4(1);\n"
13495 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013496
13497 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13498 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13499
13500 VkPipelineObj pipe(m_device);
13501 pipe.AddColorAttachment();
13502 pipe.AddShader(&vs);
13503 pipe.AddShader(&fs);
13504
13505 pipe.AddVertexInputBindings(&input_binding, 1);
13506 pipe.AddVertexInputAttribs(&input_attrib, 1);
13507
13508 VkDescriptorSetObj descriptorSet(m_device);
13509 descriptorSet.AppendDummy();
13510 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13511
13512 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13513
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013514 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013515}
13516
Karl Schultz6addd812016-02-02 17:17:23 -070013517TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013518 TEST_DESCRIPTION(
13519 "Test that an error is produced for a vertex shader input which is not "
13520 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13522 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013523
Chris Forbes62e8e502015-05-25 11:13:29 +120013524 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013525 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013526
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013527 char const *vsSource =
13528 "#version 450\n"
13529 "\n"
13530 "layout(location=0) in vec4 x;\n" /* not provided */
13531 "out gl_PerVertex {\n"
13532 " vec4 gl_Position;\n"
13533 "};\n"
13534 "void main(){\n"
13535 " gl_Position = x;\n"
13536 "}\n";
13537 char const *fsSource =
13538 "#version 450\n"
13539 "\n"
13540 "layout(location=0) out vec4 color;\n"
13541 "void main(){\n"
13542 " color = vec4(1);\n"
13543 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013544
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013545 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13546 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013547
13548 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013549 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013550 pipe.AddShader(&vs);
13551 pipe.AddShader(&fs);
13552
Chris Forbes62e8e502015-05-25 11:13:29 +120013553 VkDescriptorSetObj descriptorSet(m_device);
13554 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013555 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013556
Tony Barbour5781e8f2015-08-04 16:23:11 -060013557 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013558
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013559 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013560}
13561
Karl Schultz6addd812016-02-02 17:17:23 -070013562TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013563 TEST_DESCRIPTION(
13564 "Test that an error is produced for a mismatch between the "
13565 "fundamental type (float/int/uint) of an attribute and the "
13566 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013567 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 -060013568
Chris Forbesc97d98e2015-05-25 11:13:31 +120013569 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013570 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013571
13572 VkVertexInputBindingDescription input_binding;
13573 memset(&input_binding, 0, sizeof(input_binding));
13574
13575 VkVertexInputAttributeDescription input_attrib;
13576 memset(&input_attrib, 0, sizeof(input_attrib));
13577 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13578
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013579 char const *vsSource =
13580 "#version 450\n"
13581 "\n"
13582 "layout(location=0) in int x;\n" /* attrib provided float */
13583 "out gl_PerVertex {\n"
13584 " vec4 gl_Position;\n"
13585 "};\n"
13586 "void main(){\n"
13587 " gl_Position = vec4(x);\n"
13588 "}\n";
13589 char const *fsSource =
13590 "#version 450\n"
13591 "\n"
13592 "layout(location=0) out vec4 color;\n"
13593 "void main(){\n"
13594 " color = vec4(1);\n"
13595 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013596
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013597 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13598 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013599
13600 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013601 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013602 pipe.AddShader(&vs);
13603 pipe.AddShader(&fs);
13604
13605 pipe.AddVertexInputBindings(&input_binding, 1);
13606 pipe.AddVertexInputAttribs(&input_attrib, 1);
13607
Chris Forbesc97d98e2015-05-25 11:13:31 +120013608 VkDescriptorSetObj descriptorSet(m_device);
13609 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013610 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013611
Tony Barbour5781e8f2015-08-04 16:23:11 -060013612 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013613
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013614 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013615}
13616
Chris Forbesc68b43c2016-04-06 11:18:47 +120013617TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013618 TEST_DESCRIPTION(
13619 "Test that an error is produced for a pipeline containing multiple "
13620 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13622 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013623
13624 ASSERT_NO_FATAL_FAILURE(InitState());
13625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13626
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013627 char const *vsSource =
13628 "#version 450\n"
13629 "\n"
13630 "out gl_PerVertex {\n"
13631 " vec4 gl_Position;\n"
13632 "};\n"
13633 "void main(){\n"
13634 " gl_Position = vec4(1);\n"
13635 "}\n";
13636 char const *fsSource =
13637 "#version 450\n"
13638 "\n"
13639 "layout(location=0) out vec4 color;\n"
13640 "void main(){\n"
13641 " color = vec4(1);\n"
13642 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013643
13644 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13645 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13646
13647 VkPipelineObj pipe(m_device);
13648 pipe.AddColorAttachment();
13649 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013650 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013651 pipe.AddShader(&fs);
13652
13653 VkDescriptorSetObj descriptorSet(m_device);
13654 descriptorSet.AppendDummy();
13655 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13656
13657 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13658
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013659 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013660}
13661
Chris Forbes82ff92a2016-09-09 10:50:24 +120013662TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120013664
13665 ASSERT_NO_FATAL_FAILURE(InitState());
13666 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13667
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013668 char const *vsSource =
13669 "#version 450\n"
13670 "out gl_PerVertex {\n"
13671 " vec4 gl_Position;\n"
13672 "};\n"
13673 "void main(){\n"
13674 " gl_Position = vec4(0);\n"
13675 "}\n";
13676 char const *fsSource =
13677 "#version 450\n"
13678 "\n"
13679 "layout(location=0) out vec4 color;\n"
13680 "void main(){\n"
13681 " color = vec4(1);\n"
13682 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120013683
13684 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13685 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13686
13687 VkPipelineObj pipe(m_device);
13688 pipe.AddColorAttachment();
13689 pipe.AddShader(&vs);
13690 pipe.AddShader(&fs);
13691
13692 VkDescriptorSetObj descriptorSet(m_device);
13693 descriptorSet.AppendDummy();
13694 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13695
13696 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13697
13698 m_errorMonitor->VerifyFound();
13699}
13700
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013701TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13703 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13704 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013705
13706 ASSERT_NO_FATAL_FAILURE(InitState());
13707 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13708
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013709 char const *vsSource =
13710 "#version 450\n"
13711 "void main(){ gl_Position = vec4(0); }\n";
13712 char const *fsSource =
13713 "#version 450\n"
13714 "\n"
13715 "layout(location=0) out vec4 color;\n"
13716 "void main(){\n"
13717 " color = vec4(1);\n"
13718 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013719
13720 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13721 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13722
13723 VkPipelineObj pipe(m_device);
13724 pipe.AddColorAttachment();
13725 pipe.AddShader(&vs);
13726 pipe.AddShader(&fs);
13727
13728 VkDescriptorSetObj descriptorSet(m_device);
13729 descriptorSet.AppendDummy();
13730 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13731
13732 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013733 {
13734 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13735 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
13736 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013737 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013738 {
13739 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13740 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
13741 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013742 },
13743 };
13744 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013745 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013746 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013747 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
13748 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013749 VkRenderPass rp;
13750 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13751 ASSERT_VK_SUCCESS(err);
13752
13753 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13754
13755 m_errorMonitor->VerifyFound();
13756
13757 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13758}
13759
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013760TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013761 TEST_DESCRIPTION(
13762 "Test that an error is produced for a variable output from "
13763 "the TCS without the patch decoration, but consumed in the TES "
13764 "with the decoration.");
13765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13766 "is per-vertex in tessellation control shader stage "
13767 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013768
13769 ASSERT_NO_FATAL_FAILURE(InitState());
13770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13771
Chris Forbesc1e852d2016-04-04 19:26:42 +120013772 if (!m_device->phy().features().tessellationShader) {
13773 printf("Device does not support tessellation shaders; skipped.\n");
13774 return;
13775 }
13776
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013777 char const *vsSource =
13778 "#version 450\n"
13779 "void main(){}\n";
13780 char const *tcsSource =
13781 "#version 450\n"
13782 "layout(location=0) out int x[];\n"
13783 "layout(vertices=3) out;\n"
13784 "void main(){\n"
13785 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13786 " gl_TessLevelInner[0] = 1;\n"
13787 " x[gl_InvocationID] = gl_InvocationID;\n"
13788 "}\n";
13789 char const *tesSource =
13790 "#version 450\n"
13791 "layout(triangles, equal_spacing, cw) in;\n"
13792 "layout(location=0) patch in int x;\n"
13793 "out gl_PerVertex { vec4 gl_Position; };\n"
13794 "void main(){\n"
13795 " gl_Position.xyz = gl_TessCoord;\n"
13796 " gl_Position.w = x;\n"
13797 "}\n";
13798 char const *fsSource =
13799 "#version 450\n"
13800 "layout(location=0) out vec4 color;\n"
13801 "void main(){\n"
13802 " color = vec4(1);\n"
13803 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013804
13805 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13806 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13807 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13808 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13809
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013810 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13811 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013813 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013814
13815 VkPipelineObj pipe(m_device);
13816 pipe.SetInputAssembly(&iasci);
13817 pipe.SetTessellation(&tsci);
13818 pipe.AddColorAttachment();
13819 pipe.AddShader(&vs);
13820 pipe.AddShader(&tcs);
13821 pipe.AddShader(&tes);
13822 pipe.AddShader(&fs);
13823
13824 VkDescriptorSetObj descriptorSet(m_device);
13825 descriptorSet.AppendDummy();
13826 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13827
13828 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13829
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013830 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013831}
13832
Karl Schultz6addd812016-02-02 17:17:23 -070013833TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013834 TEST_DESCRIPTION(
13835 "Test that an error is produced for a vertex attribute setup where multiple "
13836 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13838 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013839
Chris Forbes280ba2c2015-06-12 11:16:41 +120013840 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013841 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013842
13843 /* Two binding descriptions for binding 0 */
13844 VkVertexInputBindingDescription input_bindings[2];
13845 memset(input_bindings, 0, sizeof(input_bindings));
13846
13847 VkVertexInputAttributeDescription input_attrib;
13848 memset(&input_attrib, 0, sizeof(input_attrib));
13849 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13850
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013851 char const *vsSource =
13852 "#version 450\n"
13853 "\n"
13854 "layout(location=0) in float x;\n" /* attrib provided float */
13855 "out gl_PerVertex {\n"
13856 " vec4 gl_Position;\n"
13857 "};\n"
13858 "void main(){\n"
13859 " gl_Position = vec4(x);\n"
13860 "}\n";
13861 char const *fsSource =
13862 "#version 450\n"
13863 "\n"
13864 "layout(location=0) out vec4 color;\n"
13865 "void main(){\n"
13866 " color = vec4(1);\n"
13867 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013868
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013869 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13870 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013871
13872 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013873 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013874 pipe.AddShader(&vs);
13875 pipe.AddShader(&fs);
13876
13877 pipe.AddVertexInputBindings(input_bindings, 2);
13878 pipe.AddVertexInputAttribs(&input_attrib, 1);
13879
Chris Forbes280ba2c2015-06-12 11:16:41 +120013880 VkDescriptorSetObj descriptorSet(m_device);
13881 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013882 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013883
Tony Barbour5781e8f2015-08-04 16:23:11 -060013884 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013885
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013886 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013887}
Chris Forbes8f68b562015-05-25 11:13:32 +120013888
Karl Schultz6addd812016-02-02 17:17:23 -070013889TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013890 TEST_DESCRIPTION(
13891 "Test that an error is produced for a fragment shader which does not "
13892 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013894
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013895 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013896
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013897 char const *vsSource =
13898 "#version 450\n"
13899 "\n"
13900 "out gl_PerVertex {\n"
13901 " vec4 gl_Position;\n"
13902 "};\n"
13903 "void main(){\n"
13904 " gl_Position = vec4(1);\n"
13905 "}\n";
13906 char const *fsSource =
13907 "#version 450\n"
13908 "\n"
13909 "void main(){\n"
13910 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013911
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013912 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13913 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013914
13915 VkPipelineObj pipe(m_device);
13916 pipe.AddShader(&vs);
13917 pipe.AddShader(&fs);
13918
Chia-I Wu08accc62015-07-07 11:50:03 +080013919 /* set up CB 0, not written */
13920 pipe.AddColorAttachment();
13921 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013922
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013923 VkDescriptorSetObj descriptorSet(m_device);
13924 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013925 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013926
Tony Barbour5781e8f2015-08-04 16:23:11 -060013927 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013928
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013929 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013930}
13931
Karl Schultz6addd812016-02-02 17:17:23 -070013932TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013933 TEST_DESCRIPTION(
13934 "Test that a warning is produced for a fragment shader which provides a spurious "
13935 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013937 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013938
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013939 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013940
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013941 char const *vsSource =
13942 "#version 450\n"
13943 "\n"
13944 "out gl_PerVertex {\n"
13945 " vec4 gl_Position;\n"
13946 "};\n"
13947 "void main(){\n"
13948 " gl_Position = vec4(1);\n"
13949 "}\n";
13950 char const *fsSource =
13951 "#version 450\n"
13952 "\n"
13953 "layout(location=0) out vec4 x;\n"
13954 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13955 "void main(){\n"
13956 " x = vec4(1);\n"
13957 " y = vec4(1);\n"
13958 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013959
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013960 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13961 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013962
13963 VkPipelineObj pipe(m_device);
13964 pipe.AddShader(&vs);
13965 pipe.AddShader(&fs);
13966
Chia-I Wu08accc62015-07-07 11:50:03 +080013967 /* set up CB 0, not written */
13968 pipe.AddColorAttachment();
13969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013970 /* FS writes CB 1, but we don't configure it */
13971
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013972 VkDescriptorSetObj descriptorSet(m_device);
13973 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013974 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013975
Tony Barbour5781e8f2015-08-04 16:23:11 -060013976 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013977
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013978 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013979}
13980
Karl Schultz6addd812016-02-02 17:17:23 -070013981TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013982 TEST_DESCRIPTION(
13983 "Test that an error is produced for a mismatch between the fundamental "
13984 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013986
Chris Forbesa36d69e2015-05-25 11:13:44 +120013987 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013988
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013989 char const *vsSource =
13990 "#version 450\n"
13991 "\n"
13992 "out gl_PerVertex {\n"
13993 " vec4 gl_Position;\n"
13994 "};\n"
13995 "void main(){\n"
13996 " gl_Position = vec4(1);\n"
13997 "}\n";
13998 char const *fsSource =
13999 "#version 450\n"
14000 "\n"
14001 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14002 "void main(){\n"
14003 " x = ivec4(1);\n"
14004 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014005
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014006 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14007 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014008
14009 VkPipelineObj pipe(m_device);
14010 pipe.AddShader(&vs);
14011 pipe.AddShader(&fs);
14012
Chia-I Wu08accc62015-07-07 11:50:03 +080014013 /* set up CB 0; type is UNORM by default */
14014 pipe.AddColorAttachment();
14015 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014016
Chris Forbesa36d69e2015-05-25 11:13:44 +120014017 VkDescriptorSetObj descriptorSet(m_device);
14018 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014019 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014020
Tony Barbour5781e8f2015-08-04 16:23:11 -060014021 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014022
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014023 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014024}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014025
Karl Schultz6addd812016-02-02 17:17:23 -070014026TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014027 TEST_DESCRIPTION(
14028 "Test that an error is produced for a shader consuming a uniform "
14029 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014031
Chris Forbes556c76c2015-08-14 12:04:59 +120014032 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014033
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014034 char const *vsSource =
14035 "#version 450\n"
14036 "\n"
14037 "out gl_PerVertex {\n"
14038 " vec4 gl_Position;\n"
14039 "};\n"
14040 "void main(){\n"
14041 " gl_Position = vec4(1);\n"
14042 "}\n";
14043 char const *fsSource =
14044 "#version 450\n"
14045 "\n"
14046 "layout(location=0) out vec4 x;\n"
14047 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14048 "void main(){\n"
14049 " x = vec4(bar.y);\n"
14050 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014051
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014052 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14053 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014054
Chris Forbes556c76c2015-08-14 12:04:59 +120014055 VkPipelineObj pipe(m_device);
14056 pipe.AddShader(&vs);
14057 pipe.AddShader(&fs);
14058
14059 /* set up CB 0; type is UNORM by default */
14060 pipe.AddColorAttachment();
14061 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14062
14063 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014064 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014065
14066 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14067
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014068 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014069}
14070
Chris Forbes5c59e902016-02-26 16:56:09 +130014071TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014072 TEST_DESCRIPTION(
14073 "Test that an error is produced for a shader consuming push constants "
14074 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014076
14077 ASSERT_NO_FATAL_FAILURE(InitState());
14078
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014079 char const *vsSource =
14080 "#version 450\n"
14081 "\n"
14082 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14083 "out gl_PerVertex {\n"
14084 " vec4 gl_Position;\n"
14085 "};\n"
14086 "void main(){\n"
14087 " gl_Position = vec4(consts.x);\n"
14088 "}\n";
14089 char const *fsSource =
14090 "#version 450\n"
14091 "\n"
14092 "layout(location=0) out vec4 x;\n"
14093 "void main(){\n"
14094 " x = vec4(1);\n"
14095 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014096
14097 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14098 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14099
14100 VkPipelineObj pipe(m_device);
14101 pipe.AddShader(&vs);
14102 pipe.AddShader(&fs);
14103
14104 /* set up CB 0; type is UNORM by default */
14105 pipe.AddColorAttachment();
14106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14107
14108 VkDescriptorSetObj descriptorSet(m_device);
14109 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14110
14111 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14112
14113 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014114 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014115}
14116
Chris Forbes3fb17902016-08-22 14:57:55 +120014117TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014118 TEST_DESCRIPTION(
14119 "Test that an error is produced for a shader consuming an input attachment "
14120 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14122 "consumes input attachment index 0 but not provided in subpass");
14123
14124 ASSERT_NO_FATAL_FAILURE(InitState());
14125
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014126 char const *vsSource =
14127 "#version 450\n"
14128 "\n"
14129 "out gl_PerVertex {\n"
14130 " vec4 gl_Position;\n"
14131 "};\n"
14132 "void main(){\n"
14133 " gl_Position = vec4(1);\n"
14134 "}\n";
14135 char const *fsSource =
14136 "#version 450\n"
14137 "\n"
14138 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14139 "layout(location=0) out vec4 color;\n"
14140 "void main() {\n"
14141 " color = subpassLoad(x);\n"
14142 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014143
14144 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14145 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14146
14147 VkPipelineObj pipe(m_device);
14148 pipe.AddShader(&vs);
14149 pipe.AddShader(&fs);
14150 pipe.AddColorAttachment();
14151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14152
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014153 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14154 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014155 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014156 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014157 ASSERT_VK_SUCCESS(err);
14158
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014159 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014160 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014161 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014162 ASSERT_VK_SUCCESS(err);
14163
14164 // error here.
14165 pipe.CreateVKPipeline(pl, renderPass());
14166
14167 m_errorMonitor->VerifyFound();
14168
14169 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14170 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14171}
14172
Chris Forbes5a9a0472016-08-22 16:02:09 +120014173TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014174 TEST_DESCRIPTION(
14175 "Test that an error is produced for a shader consuming an input attachment "
14176 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120014177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14178 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14179
14180 ASSERT_NO_FATAL_FAILURE(InitState());
14181
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014182 char const *vsSource =
14183 "#version 450\n"
14184 "\n"
14185 "out gl_PerVertex {\n"
14186 " vec4 gl_Position;\n"
14187 "};\n"
14188 "void main(){\n"
14189 " gl_Position = vec4(1);\n"
14190 "}\n";
14191 char const *fsSource =
14192 "#version 450\n"
14193 "\n"
14194 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14195 "layout(location=0) out vec4 color;\n"
14196 "void main() {\n"
14197 " color = subpassLoad(x);\n"
14198 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014199
14200 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14201 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14202
14203 VkPipelineObj pipe(m_device);
14204 pipe.AddShader(&vs);
14205 pipe.AddShader(&fs);
14206 pipe.AddColorAttachment();
14207 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14208
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014209 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14210 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014211 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014212 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014213 ASSERT_VK_SUCCESS(err);
14214
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014215 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014216 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014217 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014218 ASSERT_VK_SUCCESS(err);
14219
14220 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014221 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14222 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14223 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14224 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14225 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 +120014226 };
14227 VkAttachmentReference color = {
14228 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14229 };
14230 VkAttachmentReference input = {
14231 1, VK_IMAGE_LAYOUT_GENERAL,
14232 };
14233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014234 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014236 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014237 VkRenderPass rp;
14238 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14239 ASSERT_VK_SUCCESS(err);
14240
14241 // error here.
14242 pipe.CreateVKPipeline(pl, rp);
14243
14244 m_errorMonitor->VerifyFound();
14245
14246 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14247 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14248 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14249}
14250
Chris Forbes541f7b02016-08-22 15:30:27 +120014251TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014252 TEST_DESCRIPTION(
14253 "Test that an error is produced for a shader consuming an input attachment "
14254 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120014255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070014256 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120014257
14258 ASSERT_NO_FATAL_FAILURE(InitState());
14259
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014260 char const *vsSource =
14261 "#version 450\n"
14262 "\n"
14263 "out gl_PerVertex {\n"
14264 " vec4 gl_Position;\n"
14265 "};\n"
14266 "void main(){\n"
14267 " gl_Position = vec4(1);\n"
14268 "}\n";
14269 char const *fsSource =
14270 "#version 450\n"
14271 "\n"
14272 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
14273 "layout(location=0) out vec4 color;\n"
14274 "void main() {\n"
14275 " color = subpassLoad(xs[0]);\n"
14276 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014277
14278 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14279 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14280
14281 VkPipelineObj pipe(m_device);
14282 pipe.AddShader(&vs);
14283 pipe.AddShader(&fs);
14284 pipe.AddColorAttachment();
14285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014287 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14288 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014289 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014290 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014291 ASSERT_VK_SUCCESS(err);
14292
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014293 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014294 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014295 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014296 ASSERT_VK_SUCCESS(err);
14297
14298 // error here.
14299 pipe.CreateVKPipeline(pl, renderPass());
14300
14301 m_errorMonitor->VerifyFound();
14302
14303 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14304 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14305}
14306
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014307TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014308 TEST_DESCRIPTION(
14309 "Test that an error is produced for a compute pipeline consuming a "
14310 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014312
14313 ASSERT_NO_FATAL_FAILURE(InitState());
14314
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014315 char const *csSource =
14316 "#version 450\n"
14317 "\n"
14318 "layout(local_size_x=1) in;\n"
14319 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14320 "void main(){\n"
14321 " x = vec4(1);\n"
14322 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014323
14324 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14325
14326 VkDescriptorSetObj descriptorSet(m_device);
14327 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014329 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14330 nullptr,
14331 0,
14332 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14333 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14334 descriptorSet.GetPipelineLayout(),
14335 VK_NULL_HANDLE,
14336 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014337
14338 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014339 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014340
14341 m_errorMonitor->VerifyFound();
14342
14343 if (err == VK_SUCCESS) {
14344 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14345 }
14346}
14347
Chris Forbes22a9b092016-07-19 14:34:05 +120014348TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014349 TEST_DESCRIPTION(
14350 "Test that an error is produced for a pipeline consuming a "
14351 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14353 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014354
14355 ASSERT_NO_FATAL_FAILURE(InitState());
14356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014357 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14358 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014359 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014360 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014361 ASSERT_VK_SUCCESS(err);
14362
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014363 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014364 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014365 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014366 ASSERT_VK_SUCCESS(err);
14367
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014368 char const *csSource =
14369 "#version 450\n"
14370 "\n"
14371 "layout(local_size_x=1) in;\n"
14372 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14373 "void main() {\n"
14374 " x.x = 1.0f;\n"
14375 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014376 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14377
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014378 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14379 nullptr,
14380 0,
14381 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14382 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14383 pl,
14384 VK_NULL_HANDLE,
14385 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014386
14387 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014388 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014389
14390 m_errorMonitor->VerifyFound();
14391
14392 if (err == VK_SUCCESS) {
14393 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14394 }
14395
14396 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14397 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14398}
14399
Chris Forbes50020592016-07-27 13:52:41 +120014400TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014401 TEST_DESCRIPTION(
14402 "Test that an error is produced when an image view type "
14403 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120014404
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014405 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 +120014406
14407 ASSERT_NO_FATAL_FAILURE(InitState());
14408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14409
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014410 char const *vsSource =
14411 "#version 450\n"
14412 "\n"
14413 "out gl_PerVertex { vec4 gl_Position; };\n"
14414 "void main() { gl_Position = vec4(0); }\n";
14415 char const *fsSource =
14416 "#version 450\n"
14417 "\n"
14418 "layout(set=0, binding=0) uniform sampler3D s;\n"
14419 "layout(location=0) out vec4 color;\n"
14420 "void main() {\n"
14421 " color = texture(s, vec3(0));\n"
14422 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014423 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14424 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14425
14426 VkPipelineObj pipe(m_device);
14427 pipe.AddShader(&vs);
14428 pipe.AddShader(&fs);
14429 pipe.AddColorAttachment();
14430
14431 VkTextureObj texture(m_device, nullptr);
14432 VkSamplerObj sampler(m_device);
14433
14434 VkDescriptorSetObj descriptorSet(m_device);
14435 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14436 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14437
14438 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14439 ASSERT_VK_SUCCESS(err);
14440
Tony Barbour552f6c02016-12-21 14:34:07 -070014441 m_commandBuffer->BeginCommandBuffer();
14442 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014443
14444 m_commandBuffer->BindPipeline(pipe);
14445 m_commandBuffer->BindDescriptorSet(descriptorSet);
14446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014447 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014448 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014449 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014450 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14451
14452 // error produced here.
14453 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14454
14455 m_errorMonitor->VerifyFound();
14456
Tony Barbour552f6c02016-12-21 14:34:07 -070014457 m_commandBuffer->EndRenderPass();
14458 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014459}
14460
Chris Forbes5533bfc2016-07-27 14:12:34 +120014461TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014462 TEST_DESCRIPTION(
14463 "Test that an error is produced when a multisampled images "
14464 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014467
14468 ASSERT_NO_FATAL_FAILURE(InitState());
14469 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14470
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014471 char const *vsSource =
14472 "#version 450\n"
14473 "\n"
14474 "out gl_PerVertex { vec4 gl_Position; };\n"
14475 "void main() { gl_Position = vec4(0); }\n";
14476 char const *fsSource =
14477 "#version 450\n"
14478 "\n"
14479 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14480 "layout(location=0) out vec4 color;\n"
14481 "void main() {\n"
14482 " color = texelFetch(s, ivec2(0), 0);\n"
14483 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014484 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14485 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14486
14487 VkPipelineObj pipe(m_device);
14488 pipe.AddShader(&vs);
14489 pipe.AddShader(&fs);
14490 pipe.AddColorAttachment();
14491
14492 VkTextureObj texture(m_device, nullptr);
14493 VkSamplerObj sampler(m_device);
14494
14495 VkDescriptorSetObj descriptorSet(m_device);
14496 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14497 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14498
14499 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14500 ASSERT_VK_SUCCESS(err);
14501
Tony Barbour552f6c02016-12-21 14:34:07 -070014502 m_commandBuffer->BeginCommandBuffer();
14503 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014504
14505 m_commandBuffer->BindPipeline(pipe);
14506 m_commandBuffer->BindDescriptorSet(descriptorSet);
14507
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014508 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014509 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014510 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014511 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14512
14513 // error produced here.
14514 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14515
14516 m_errorMonitor->VerifyFound();
14517
Tony Barbour552f6c02016-12-21 14:34:07 -070014518 m_commandBuffer->EndRenderPass();
14519 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014520}
14521
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014522#endif // SHADER_CHECKER_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014523
14524#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014525TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014527
14528 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014529
14530 // Create an image
14531 VkImage image;
14532
Karl Schultz6addd812016-02-02 17:17:23 -070014533 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14534 const int32_t tex_width = 32;
14535 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014536
14537 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014538 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14539 image_create_info.pNext = NULL;
14540 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14541 image_create_info.format = tex_format;
14542 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014543 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014544 image_create_info.extent.depth = 1;
14545 image_create_info.mipLevels = 1;
14546 image_create_info.arrayLayers = 1;
14547 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14548 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14549 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14550 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014551
14552 // Introduce error by sending down a bogus width extent
14553 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014554 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014555
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014556 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014557}
14558
Mark Youngc48c4c12016-04-11 14:26:49 -060014559TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14561 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014562
14563 ASSERT_NO_FATAL_FAILURE(InitState());
14564
14565 // Create an image
14566 VkImage image;
14567
14568 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14569 const int32_t tex_width = 32;
14570 const int32_t tex_height = 32;
14571
14572 VkImageCreateInfo image_create_info = {};
14573 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14574 image_create_info.pNext = NULL;
14575 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14576 image_create_info.format = tex_format;
14577 image_create_info.extent.width = tex_width;
14578 image_create_info.extent.height = tex_height;
14579 image_create_info.extent.depth = 1;
14580 image_create_info.mipLevels = 1;
14581 image_create_info.arrayLayers = 1;
14582 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14583 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14584 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14585 image_create_info.flags = 0;
14586
14587 // Introduce error by sending down a bogus width extent
14588 image_create_info.extent.width = 0;
14589 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14590
14591 m_errorMonitor->VerifyFound();
14592}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014593#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014594
Tobin Ehliscde08892015-09-22 10:11:37 -060014595#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014596
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014597TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014598 TEST_DESCRIPTION(
14599 "Create a render pass with an attachment description "
14600 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014601
14602 ASSERT_NO_FATAL_FAILURE(InitState());
14603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14604
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014606
14607 VkAttachmentReference color_attach = {};
14608 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14609 color_attach.attachment = 0;
14610 VkSubpassDescription subpass = {};
14611 subpass.colorAttachmentCount = 1;
14612 subpass.pColorAttachments = &color_attach;
14613
14614 VkRenderPassCreateInfo rpci = {};
14615 rpci.subpassCount = 1;
14616 rpci.pSubpasses = &subpass;
14617 rpci.attachmentCount = 1;
14618 VkAttachmentDescription attach_desc = {};
14619 attach_desc.format = VK_FORMAT_UNDEFINED;
14620 rpci.pAttachments = &attach_desc;
14621 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14622 VkRenderPass rp;
14623 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14624
14625 m_errorMonitor->VerifyFound();
14626
14627 if (result == VK_SUCCESS) {
14628 vkDestroyRenderPass(m_device->device(), rp, NULL);
14629 }
14630}
14631
Karl Schultz6addd812016-02-02 17:17:23 -070014632TEST_F(VkLayerTest, InvalidImageView) {
14633 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014634
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014636
Tobin Ehliscde08892015-09-22 10:11:37 -060014637 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014638
Mike Stroyana3082432015-09-25 13:39:21 -060014639 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014640 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014641
Karl Schultz6addd812016-02-02 17:17:23 -070014642 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14643 const int32_t tex_width = 32;
14644 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014645
14646 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014647 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14648 image_create_info.pNext = NULL;
14649 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14650 image_create_info.format = tex_format;
14651 image_create_info.extent.width = tex_width;
14652 image_create_info.extent.height = tex_height;
14653 image_create_info.extent.depth = 1;
14654 image_create_info.mipLevels = 1;
14655 image_create_info.arrayLayers = 1;
14656 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14657 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14658 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14659 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014660
Chia-I Wuf7458c52015-10-26 21:10:41 +080014661 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014662 ASSERT_VK_SUCCESS(err);
14663
14664 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014665 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014666 image_view_create_info.image = image;
14667 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14668 image_view_create_info.format = tex_format;
14669 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014670 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070014671 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014672 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014673
14674 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014675 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014676
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014677 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014678 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014679}
Mike Stroyana3082432015-09-25 13:39:21 -060014680
Mark Youngd339ba32016-05-30 13:28:35 -060014681TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14682 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014684 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014685
14686 ASSERT_NO_FATAL_FAILURE(InitState());
14687
14688 // Create an image and try to create a view with no memory backing the image
14689 VkImage image;
14690
14691 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14692 const int32_t tex_width = 32;
14693 const int32_t tex_height = 32;
14694
14695 VkImageCreateInfo image_create_info = {};
14696 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14697 image_create_info.pNext = NULL;
14698 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14699 image_create_info.format = tex_format;
14700 image_create_info.extent.width = tex_width;
14701 image_create_info.extent.height = tex_height;
14702 image_create_info.extent.depth = 1;
14703 image_create_info.mipLevels = 1;
14704 image_create_info.arrayLayers = 1;
14705 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14706 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14707 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14708 image_create_info.flags = 0;
14709
14710 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14711 ASSERT_VK_SUCCESS(err);
14712
14713 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014714 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014715 image_view_create_info.image = image;
14716 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14717 image_view_create_info.format = tex_format;
14718 image_view_create_info.subresourceRange.layerCount = 1;
14719 image_view_create_info.subresourceRange.baseMipLevel = 0;
14720 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014721 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014722
14723 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014724 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014725
14726 m_errorMonitor->VerifyFound();
14727 vkDestroyImage(m_device->device(), image, NULL);
14728 // If last error is success, it still created the view, so delete it.
14729 if (err == VK_SUCCESS) {
14730 vkDestroyImageView(m_device->device(), view, NULL);
14731 }
Mark Youngd339ba32016-05-30 13:28:35 -060014732}
14733
Karl Schultz6addd812016-02-02 17:17:23 -070014734TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014735 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014737
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014738 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014739
Karl Schultz6addd812016-02-02 17:17:23 -070014740 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014741 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014742 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014743 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014744
14745 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014746 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014747 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014748 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14749 image_view_create_info.format = tex_format;
14750 image_view_create_info.subresourceRange.baseMipLevel = 0;
14751 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014752 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014753 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014754 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014755
14756 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014757 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014758
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014759 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014760}
14761
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014762TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014763 VkResult err;
14764 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014765
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014767
Mike Stroyana3082432015-09-25 13:39:21 -060014768 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014769
14770 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014771 VkImage srcImage;
14772 VkImage dstImage;
14773 VkDeviceMemory srcMem;
14774 VkDeviceMemory destMem;
14775 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014776
14777 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014778 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14779 image_create_info.pNext = NULL;
14780 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14781 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14782 image_create_info.extent.width = 32;
14783 image_create_info.extent.height = 32;
14784 image_create_info.extent.depth = 1;
14785 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014786 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014787 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14788 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14789 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14790 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014791
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014792 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014793 ASSERT_VK_SUCCESS(err);
14794
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014795 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014796 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014797 ASSERT_VK_SUCCESS(err);
14798
14799 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014800 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014801 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14802 memAlloc.pNext = NULL;
14803 memAlloc.allocationSize = 0;
14804 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014805
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014806 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014807 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014808 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014809 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014810 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014811 ASSERT_VK_SUCCESS(err);
14812
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014813 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014814 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014815 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014816 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014817 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014818 ASSERT_VK_SUCCESS(err);
14819
14820 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14821 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014822 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014823 ASSERT_VK_SUCCESS(err);
14824
Tony Barbour552f6c02016-12-21 14:34:07 -070014825 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014826 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014827 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014828 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014829 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014830 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014831 copyRegion.srcOffset.x = 0;
14832 copyRegion.srcOffset.y = 0;
14833 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014834 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014835 copyRegion.dstSubresource.mipLevel = 0;
14836 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014837 // Introduce failure by forcing the dst layerCount to differ from src
14838 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014839 copyRegion.dstOffset.x = 0;
14840 copyRegion.dstOffset.y = 0;
14841 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014842 copyRegion.extent.width = 1;
14843 copyRegion.extent.height = 1;
14844 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014845 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070014846 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014847
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014848 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014849
Chia-I Wuf7458c52015-10-26 21:10:41 +080014850 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014851 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014852 vkFreeMemory(m_device->device(), srcMem, NULL);
14853 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014854}
14855
Tony Barbourd6673642016-05-05 14:46:39 -060014856TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060014857 TEST_DESCRIPTION("Creating images with unsuported formats ");
14858
14859 ASSERT_NO_FATAL_FAILURE(InitState());
14860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14861 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014862 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 -060014863 VK_IMAGE_TILING_OPTIMAL, 0);
14864 ASSERT_TRUE(image.initialized());
14865
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014866 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014867 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014868 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014869 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14870 image_create_info.format = VK_FORMAT_UNDEFINED;
14871 image_create_info.extent.width = 32;
14872 image_create_info.extent.height = 32;
14873 image_create_info.extent.depth = 1;
14874 image_create_info.mipLevels = 1;
14875 image_create_info.arrayLayers = 1;
14876 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14877 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14878 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014879
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14881 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014882
14883 VkImage localImage;
14884 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14885 m_errorMonitor->VerifyFound();
14886
Tony Barbourd6673642016-05-05 14:46:39 -060014887 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014888 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014889 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14890 VkFormat format = static_cast<VkFormat>(f);
14891 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014892 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014893 unsupported = format;
14894 break;
14895 }
14896 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014897
Tony Barbourd6673642016-05-05 14:46:39 -060014898 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014899 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014901
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014902 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014903 m_errorMonitor->VerifyFound();
14904 }
14905}
14906
14907TEST_F(VkLayerTest, ImageLayerViewTests) {
14908 VkResult ret;
14909 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14910
14911 ASSERT_NO_FATAL_FAILURE(InitState());
14912
14913 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014914 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 -060014915 VK_IMAGE_TILING_OPTIMAL, 0);
14916 ASSERT_TRUE(image.initialized());
14917
14918 VkImageView imgView;
14919 VkImageViewCreateInfo imgViewInfo = {};
14920 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14921 imgViewInfo.image = image.handle();
14922 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14923 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14924 imgViewInfo.subresourceRange.layerCount = 1;
14925 imgViewInfo.subresourceRange.baseMipLevel = 0;
14926 imgViewInfo.subresourceRange.levelCount = 1;
14927 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14928
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060014930 // View can't have baseMipLevel >= image's mipLevels - Expect
14931 // VIEW_CREATE_ERROR
14932 imgViewInfo.subresourceRange.baseMipLevel = 1;
14933 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14934 m_errorMonitor->VerifyFound();
14935 imgViewInfo.subresourceRange.baseMipLevel = 0;
14936
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060014938 // View can't have baseArrayLayer >= image's arraySize - Expect
14939 // VIEW_CREATE_ERROR
14940 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14941 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14942 m_errorMonitor->VerifyFound();
14943 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14944
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070014945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060014946 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14947 imgViewInfo.subresourceRange.levelCount = 0;
14948 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14949 m_errorMonitor->VerifyFound();
14950 imgViewInfo.subresourceRange.levelCount = 1;
14951
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014952 m_errorMonitor->SetDesiredFailureMsg(
14953 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14954 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014955 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14956 imgViewInfo.subresourceRange.layerCount = 0;
14957 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14958 m_errorMonitor->VerifyFound();
14959 imgViewInfo.subresourceRange.layerCount = 1;
14960
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14962 "Formats MUST be IDENTICAL unless "
14963 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14964 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014965 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14966 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14967 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14968 m_errorMonitor->VerifyFound();
14969 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14970
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060014972 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14973 // VIEW_CREATE_ERROR
14974 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14975 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14976 m_errorMonitor->VerifyFound();
14977 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14978
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014980 // TODO: Update framework to easily passing mutable flag into ImageObj init
14981 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070014982 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
14983 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14984 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014985 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14986 // VIEW_CREATE_ERROR
14987 VkImageCreateInfo mutImgInfo = image.create_info();
14988 VkImage mutImage;
14989 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014990 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014991 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14992 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14993 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14994 ASSERT_VK_SUCCESS(ret);
14995 imgViewInfo.image = mutImage;
14996 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14997 m_errorMonitor->VerifyFound();
14998 imgViewInfo.image = image.handle();
14999 vkDestroyImage(m_device->handle(), mutImage, NULL);
15000}
15001
15002TEST_F(VkLayerTest, MiscImageLayerTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060015003 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15004
15005 ASSERT_NO_FATAL_FAILURE(InitState());
15006
Rene Lindsay135204f2016-12-22 17:11:09 -070015007 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060015008 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070015009 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 -070015010 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060015011 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060015012 vk_testing::Buffer buffer;
15013 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070015014 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060015015 VkBufferImageCopy region = {};
15016 region.bufferRowLength = 128;
15017 region.bufferImageHeight = 128;
15018 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15019 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070015020 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015021 region.imageExtent.height = 4;
15022 region.imageExtent.width = 4;
15023 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070015024
15025 VkImageObj image2(m_device);
15026 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 -070015027 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070015028 ASSERT_TRUE(image2.initialized());
15029 vk_testing::Buffer buffer2;
15030 VkMemoryPropertyFlags reqs2 = 0;
15031 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
15032 VkBufferImageCopy region2 = {};
15033 region2.bufferRowLength = 128;
15034 region2.bufferImageHeight = 128;
15035 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15036 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15037 region2.imageSubresource.layerCount = 1;
15038 region2.imageExtent.height = 4;
15039 region2.imageExtent.width = 4;
15040 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015041 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060015042
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015043 // Image must have offset.z of 0 and extent.depth of 1
15044 // Introduce failure by setting imageExtent.depth to 0
15045 region.imageExtent.depth = 0;
15046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15047 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015048 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015049 m_errorMonitor->VerifyFound();
15050
15051 region.imageExtent.depth = 1;
15052
15053 // Image must have offset.z of 0 and extent.depth of 1
15054 // Introduce failure by setting imageOffset.z to 4
15055 region.imageOffset.z = 4;
15056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15057 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015058 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015059 m_errorMonitor->VerifyFound();
15060
15061 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015062 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15063 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070015064 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015066 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15067 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015068 m_errorMonitor->VerifyFound();
15069
15070 // BufferOffset must be a multiple of 4
15071 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070015072 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070015074 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
15075 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015076 m_errorMonitor->VerifyFound();
15077
15078 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15079 region.bufferOffset = 0;
15080 region.imageExtent.height = 128;
15081 region.imageExtent.width = 128;
15082 // Introduce failure by setting bufferRowLength > 0 but less than width
15083 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015085 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15086 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015087 m_errorMonitor->VerifyFound();
15088
15089 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15090 region.bufferRowLength = 128;
15091 // Introduce failure by setting bufferRowHeight > 0 but less than height
15092 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015094 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15095 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015096 m_errorMonitor->VerifyFound();
15097
15098 region.bufferImageHeight = 128;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15100 "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015101 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060015102 // Expect INVALID_FILTER
15103 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015104 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
15105 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015106 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015107 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15108 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015109 VkImageBlit blitRegion = {};
15110 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15111 blitRegion.srcSubresource.baseArrayLayer = 0;
15112 blitRegion.srcSubresource.layerCount = 1;
15113 blitRegion.srcSubresource.mipLevel = 0;
15114 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15115 blitRegion.dstSubresource.baseArrayLayer = 0;
15116 blitRegion.dstSubresource.layerCount = 1;
15117 blitRegion.dstSubresource.mipLevel = 0;
15118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015119 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015120 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060015121 m_errorMonitor->VerifyFound();
15122
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015123 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
15125 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15126 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015127 m_errorMonitor->VerifyFound();
15128
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060015130 VkImageMemoryBarrier img_barrier;
15131 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15132 img_barrier.pNext = NULL;
15133 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15134 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15135 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15136 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15137 img_barrier.image = image.handle();
15138 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15139 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15140 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15141 img_barrier.subresourceRange.baseArrayLayer = 0;
15142 img_barrier.subresourceRange.baseMipLevel = 0;
15143 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
15144 img_barrier.subresourceRange.layerCount = 0;
15145 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015146 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
15147 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060015148 m_errorMonitor->VerifyFound();
15149 img_barrier.subresourceRange.layerCount = 1;
15150}
15151
15152TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060015153 TEST_DESCRIPTION("Exceed the limits of image format ");
15154
Cody Northropc31a84f2016-08-22 10:41:47 -060015155 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060015157 VkImageCreateInfo image_create_info = {};
15158 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15159 image_create_info.pNext = NULL;
15160 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15161 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15162 image_create_info.extent.width = 32;
15163 image_create_info.extent.height = 32;
15164 image_create_info.extent.depth = 1;
15165 image_create_info.mipLevels = 1;
15166 image_create_info.arrayLayers = 1;
15167 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15168 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15169 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15170 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15171 image_create_info.flags = 0;
15172
15173 VkImage nullImg;
15174 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15176 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070015177 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015178 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15179 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15180 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070015181 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015182
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015184 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15185 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15186 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15187 m_errorMonitor->VerifyFound();
15188 image_create_info.mipLevels = 1;
15189
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015191 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15192 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15193 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15194 m_errorMonitor->VerifyFound();
15195 image_create_info.arrayLayers = 1;
15196
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060015198 int samples = imgFmtProps.sampleCounts >> 1;
15199 image_create_info.samples = (VkSampleCountFlagBits)samples;
15200 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15201 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15202 m_errorMonitor->VerifyFound();
15203 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15204
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15206 "pCreateInfo->initialLayout, must be "
15207 "VK_IMAGE_LAYOUT_UNDEFINED or "
15208 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060015209 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15210 // Expect INVALID_LAYOUT
15211 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15212 m_errorMonitor->VerifyFound();
15213 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15214}
15215
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015216TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015217 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015219
15220 ASSERT_NO_FATAL_FAILURE(InitState());
15221
15222 VkImageObj src_image(m_device);
15223 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15224 VkImageObj dst_image(m_device);
15225 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15226
Tony Barbour552f6c02016-12-21 14:34:07 -070015227 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015228 VkImageCopy copy_region;
15229 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15230 copy_region.srcSubresource.mipLevel = 0;
15231 copy_region.srcSubresource.baseArrayLayer = 0;
15232 copy_region.srcSubresource.layerCount = 0;
15233 copy_region.srcOffset.x = 0;
15234 copy_region.srcOffset.y = 0;
15235 copy_region.srcOffset.z = 0;
15236 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15237 copy_region.dstSubresource.mipLevel = 0;
15238 copy_region.dstSubresource.baseArrayLayer = 0;
15239 copy_region.dstSubresource.layerCount = 0;
15240 copy_region.dstOffset.x = 0;
15241 copy_region.dstOffset.y = 0;
15242 copy_region.dstOffset.z = 0;
15243 copy_region.extent.width = 64;
15244 copy_region.extent.height = 64;
15245 copy_region.extent.depth = 1;
15246 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15247 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015248 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015249
15250 m_errorMonitor->VerifyFound();
15251}
15252
15253TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015254 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015256
15257 ASSERT_NO_FATAL_FAILURE(InitState());
15258
15259 VkImageObj src_image(m_device);
15260 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15261 VkImageObj dst_image(m_device);
15262 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15263
Tony Barbour552f6c02016-12-21 14:34:07 -070015264 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015265 VkImageCopy copy_region;
15266 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15267 copy_region.srcSubresource.mipLevel = 0;
15268 copy_region.srcSubresource.baseArrayLayer = 0;
15269 copy_region.srcSubresource.layerCount = 0;
15270 copy_region.srcOffset.x = 0;
15271 copy_region.srcOffset.y = 0;
15272 copy_region.srcOffset.z = 0;
15273 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15274 copy_region.dstSubresource.mipLevel = 0;
15275 copy_region.dstSubresource.baseArrayLayer = 0;
15276 copy_region.dstSubresource.layerCount = 0;
15277 copy_region.dstOffset.x = 0;
15278 copy_region.dstOffset.y = 0;
15279 copy_region.dstOffset.z = 0;
15280 copy_region.extent.width = 64;
15281 copy_region.extent.height = 64;
15282 copy_region.extent.depth = 1;
15283 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15284 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015285 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015286
15287 m_errorMonitor->VerifyFound();
15288}
15289
Karl Schultz6addd812016-02-02 17:17:23 -070015290TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015291 VkResult err;
15292 bool pass;
15293
15294 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015296
15297 ASSERT_NO_FATAL_FAILURE(InitState());
15298
15299 // Create two images of different types and try to copy between them
15300 VkImage srcImage;
15301 VkImage dstImage;
15302 VkDeviceMemory srcMem;
15303 VkDeviceMemory destMem;
15304 VkMemoryRequirements memReqs;
15305
15306 VkImageCreateInfo image_create_info = {};
15307 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15308 image_create_info.pNext = NULL;
15309 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15310 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15311 image_create_info.extent.width = 32;
15312 image_create_info.extent.height = 32;
15313 image_create_info.extent.depth = 1;
15314 image_create_info.mipLevels = 1;
15315 image_create_info.arrayLayers = 1;
15316 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15317 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15318 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15319 image_create_info.flags = 0;
15320
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015321 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015322 ASSERT_VK_SUCCESS(err);
15323
15324 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15325 // Introduce failure by creating second image with a different-sized format.
15326 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15327
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015328 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015329 ASSERT_VK_SUCCESS(err);
15330
15331 // Allocate memory
15332 VkMemoryAllocateInfo memAlloc = {};
15333 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15334 memAlloc.pNext = NULL;
15335 memAlloc.allocationSize = 0;
15336 memAlloc.memoryTypeIndex = 0;
15337
15338 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15339 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015340 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015341 ASSERT_TRUE(pass);
15342 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15343 ASSERT_VK_SUCCESS(err);
15344
15345 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15346 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015347 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015348 ASSERT_TRUE(pass);
15349 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15350 ASSERT_VK_SUCCESS(err);
15351
15352 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15353 ASSERT_VK_SUCCESS(err);
15354 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15355 ASSERT_VK_SUCCESS(err);
15356
Tony Barbour552f6c02016-12-21 14:34:07 -070015357 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015358 VkImageCopy copyRegion;
15359 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15360 copyRegion.srcSubresource.mipLevel = 0;
15361 copyRegion.srcSubresource.baseArrayLayer = 0;
15362 copyRegion.srcSubresource.layerCount = 0;
15363 copyRegion.srcOffset.x = 0;
15364 copyRegion.srcOffset.y = 0;
15365 copyRegion.srcOffset.z = 0;
15366 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15367 copyRegion.dstSubresource.mipLevel = 0;
15368 copyRegion.dstSubresource.baseArrayLayer = 0;
15369 copyRegion.dstSubresource.layerCount = 0;
15370 copyRegion.dstOffset.x = 0;
15371 copyRegion.dstOffset.y = 0;
15372 copyRegion.dstOffset.z = 0;
15373 copyRegion.extent.width = 1;
15374 copyRegion.extent.height = 1;
15375 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015376 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015377 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015378
15379 m_errorMonitor->VerifyFound();
15380
15381 vkDestroyImage(m_device->device(), srcImage, NULL);
15382 vkDestroyImage(m_device->device(), dstImage, NULL);
15383 vkFreeMemory(m_device->device(), srcMem, NULL);
15384 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015385}
15386
Karl Schultz6addd812016-02-02 17:17:23 -070015387TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15388 VkResult err;
15389 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015390
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015391 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15393 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015394
Mike Stroyana3082432015-09-25 13:39:21 -060015395 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015396
15397 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015398 VkImage srcImage;
15399 VkImage dstImage;
15400 VkDeviceMemory srcMem;
15401 VkDeviceMemory destMem;
15402 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015403
15404 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015405 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15406 image_create_info.pNext = NULL;
15407 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15408 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15409 image_create_info.extent.width = 32;
15410 image_create_info.extent.height = 32;
15411 image_create_info.extent.depth = 1;
15412 image_create_info.mipLevels = 1;
15413 image_create_info.arrayLayers = 1;
15414 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15415 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15416 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15417 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015418
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015419 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015420 ASSERT_VK_SUCCESS(err);
15421
Karl Schultzbdb75952016-04-19 11:36:49 -060015422 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15423
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015424 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015425 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015426 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015427 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015428
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015429 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015430 ASSERT_VK_SUCCESS(err);
15431
15432 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015433 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015434 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15435 memAlloc.pNext = NULL;
15436 memAlloc.allocationSize = 0;
15437 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015438
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015439 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015440 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015441 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015442 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015443 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015444 ASSERT_VK_SUCCESS(err);
15445
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015446 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015447 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015448 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015449 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015450 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015451 ASSERT_VK_SUCCESS(err);
15452
15453 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15454 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015455 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015456 ASSERT_VK_SUCCESS(err);
15457
Tony Barbour552f6c02016-12-21 14:34:07 -070015458 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015459 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015460 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015461 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015462 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015463 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015464 copyRegion.srcOffset.x = 0;
15465 copyRegion.srcOffset.y = 0;
15466 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015467 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015468 copyRegion.dstSubresource.mipLevel = 0;
15469 copyRegion.dstSubresource.baseArrayLayer = 0;
15470 copyRegion.dstSubresource.layerCount = 0;
15471 copyRegion.dstOffset.x = 0;
15472 copyRegion.dstOffset.y = 0;
15473 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015474 copyRegion.extent.width = 1;
15475 copyRegion.extent.height = 1;
15476 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015477 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015478 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015479
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015480 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015481
Chia-I Wuf7458c52015-10-26 21:10:41 +080015482 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015483 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015484 vkFreeMemory(m_device->device(), srcMem, NULL);
15485 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015486}
15487
Karl Schultz6addd812016-02-02 17:17:23 -070015488TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15489 VkResult err;
15490 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15493 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015494
Mike Stroyana3082432015-09-25 13:39:21 -060015495 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015496
15497 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015498 VkImage srcImage;
15499 VkImage dstImage;
15500 VkDeviceMemory srcMem;
15501 VkDeviceMemory destMem;
15502 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015503
15504 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015505 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15506 image_create_info.pNext = NULL;
15507 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15508 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15509 image_create_info.extent.width = 32;
15510 image_create_info.extent.height = 1;
15511 image_create_info.extent.depth = 1;
15512 image_create_info.mipLevels = 1;
15513 image_create_info.arrayLayers = 1;
15514 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15515 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15516 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15517 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015518
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015519 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015520 ASSERT_VK_SUCCESS(err);
15521
Karl Schultz6addd812016-02-02 17:17:23 -070015522 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015523
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015524 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015525 ASSERT_VK_SUCCESS(err);
15526
15527 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015528 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015529 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15530 memAlloc.pNext = NULL;
15531 memAlloc.allocationSize = 0;
15532 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015533
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015534 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015535 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015536 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015537 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015538 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015539 ASSERT_VK_SUCCESS(err);
15540
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015541 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015542 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015543 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015544 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015545 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015546 ASSERT_VK_SUCCESS(err);
15547
15548 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15549 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015550 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015551 ASSERT_VK_SUCCESS(err);
15552
Tony Barbour552f6c02016-12-21 14:34:07 -070015553 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015554 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015555 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15556 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015557 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015558 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015559 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015560 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015561 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015562 resolveRegion.srcOffset.x = 0;
15563 resolveRegion.srcOffset.y = 0;
15564 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015565 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015566 resolveRegion.dstSubresource.mipLevel = 0;
15567 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015568 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015569 resolveRegion.dstOffset.x = 0;
15570 resolveRegion.dstOffset.y = 0;
15571 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015572 resolveRegion.extent.width = 1;
15573 resolveRegion.extent.height = 1;
15574 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015575 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015576 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015577
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015578 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015579
Chia-I Wuf7458c52015-10-26 21:10:41 +080015580 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015581 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015582 vkFreeMemory(m_device->device(), srcMem, NULL);
15583 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015584}
15585
Karl Schultz6addd812016-02-02 17:17:23 -070015586TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15587 VkResult err;
15588 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015589
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15591 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015592
Mike Stroyana3082432015-09-25 13:39:21 -060015593 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015594
Chris Forbesa7530692016-05-08 12:35:39 +120015595 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015596 VkImage srcImage;
15597 VkImage dstImage;
15598 VkDeviceMemory srcMem;
15599 VkDeviceMemory destMem;
15600 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015601
15602 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015603 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15604 image_create_info.pNext = NULL;
15605 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15606 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15607 image_create_info.extent.width = 32;
15608 image_create_info.extent.height = 1;
15609 image_create_info.extent.depth = 1;
15610 image_create_info.mipLevels = 1;
15611 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015612 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015613 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15614 // Note: Some implementations expect color attachment usage for any
15615 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015616 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015617 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015619 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015620 ASSERT_VK_SUCCESS(err);
15621
Karl Schultz6addd812016-02-02 17:17:23 -070015622 // Note: Some implementations expect color attachment usage for any
15623 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015624 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015625
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015626 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015627 ASSERT_VK_SUCCESS(err);
15628
15629 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015630 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015631 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15632 memAlloc.pNext = NULL;
15633 memAlloc.allocationSize = 0;
15634 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015635
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015636 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015637 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015638 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015639 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015640 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015641 ASSERT_VK_SUCCESS(err);
15642
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015643 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015644 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015645 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015646 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015647 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015648 ASSERT_VK_SUCCESS(err);
15649
15650 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15651 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015652 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015653 ASSERT_VK_SUCCESS(err);
15654
Tony Barbour552f6c02016-12-21 14:34:07 -070015655 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015656 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015657 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15658 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015659 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015660 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015661 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015662 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015663 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015664 resolveRegion.srcOffset.x = 0;
15665 resolveRegion.srcOffset.y = 0;
15666 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015667 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015668 resolveRegion.dstSubresource.mipLevel = 0;
15669 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015670 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015671 resolveRegion.dstOffset.x = 0;
15672 resolveRegion.dstOffset.y = 0;
15673 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015674 resolveRegion.extent.width = 1;
15675 resolveRegion.extent.height = 1;
15676 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015677 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015678 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015679
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015680 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015681
Chia-I Wuf7458c52015-10-26 21:10:41 +080015682 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015683 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015684 vkFreeMemory(m_device->device(), srcMem, NULL);
15685 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015686}
15687
Karl Schultz6addd812016-02-02 17:17:23 -070015688TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15689 VkResult err;
15690 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015691
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15693 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015694
Mike Stroyana3082432015-09-25 13:39:21 -060015695 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015696
15697 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015698 VkImage srcImage;
15699 VkImage dstImage;
15700 VkDeviceMemory srcMem;
15701 VkDeviceMemory destMem;
15702 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015703
15704 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015705 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15706 image_create_info.pNext = NULL;
15707 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15708 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15709 image_create_info.extent.width = 32;
15710 image_create_info.extent.height = 1;
15711 image_create_info.extent.depth = 1;
15712 image_create_info.mipLevels = 1;
15713 image_create_info.arrayLayers = 1;
15714 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15715 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15716 // Note: Some implementations expect color attachment usage for any
15717 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015718 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015719 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015720
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015721 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015722 ASSERT_VK_SUCCESS(err);
15723
Karl Schultz6addd812016-02-02 17:17:23 -070015724 // Set format to something other than source image
15725 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15726 // Note: Some implementations expect color attachment usage for any
15727 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015728 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015729 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015730
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015731 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015732 ASSERT_VK_SUCCESS(err);
15733
15734 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015735 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015736 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15737 memAlloc.pNext = NULL;
15738 memAlloc.allocationSize = 0;
15739 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015740
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015741 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015742 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015743 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015744 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015745 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015746 ASSERT_VK_SUCCESS(err);
15747
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015748 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015749 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015750 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015751 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015752 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015753 ASSERT_VK_SUCCESS(err);
15754
15755 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15756 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015757 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015758 ASSERT_VK_SUCCESS(err);
15759
Tony Barbour552f6c02016-12-21 14:34:07 -070015760 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015761 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015762 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15763 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015764 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015765 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015766 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015767 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015768 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015769 resolveRegion.srcOffset.x = 0;
15770 resolveRegion.srcOffset.y = 0;
15771 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015772 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015773 resolveRegion.dstSubresource.mipLevel = 0;
15774 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015775 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015776 resolveRegion.dstOffset.x = 0;
15777 resolveRegion.dstOffset.y = 0;
15778 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015779 resolveRegion.extent.width = 1;
15780 resolveRegion.extent.height = 1;
15781 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015782 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015783 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015784
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015785 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015786
Chia-I Wuf7458c52015-10-26 21:10:41 +080015787 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015788 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015789 vkFreeMemory(m_device->device(), srcMem, NULL);
15790 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015791}
15792
Karl Schultz6addd812016-02-02 17:17:23 -070015793TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15794 VkResult err;
15795 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015796
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15798 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015799
Mike Stroyana3082432015-09-25 13:39:21 -060015800 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015801
15802 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015803 VkImage srcImage;
15804 VkImage dstImage;
15805 VkDeviceMemory srcMem;
15806 VkDeviceMemory destMem;
15807 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015808
15809 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015810 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15811 image_create_info.pNext = NULL;
15812 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15813 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15814 image_create_info.extent.width = 32;
15815 image_create_info.extent.height = 1;
15816 image_create_info.extent.depth = 1;
15817 image_create_info.mipLevels = 1;
15818 image_create_info.arrayLayers = 1;
15819 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15820 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15821 // Note: Some implementations expect color attachment usage for any
15822 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015823 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015824 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015825
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015826 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015827 ASSERT_VK_SUCCESS(err);
15828
Karl Schultz6addd812016-02-02 17:17:23 -070015829 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15830 // Note: Some implementations expect color attachment usage for any
15831 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015832 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015833 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015835 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015836 ASSERT_VK_SUCCESS(err);
15837
15838 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015839 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015840 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15841 memAlloc.pNext = NULL;
15842 memAlloc.allocationSize = 0;
15843 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015844
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015845 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015846 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015847 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015848 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015849 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015850 ASSERT_VK_SUCCESS(err);
15851
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015852 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015853 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015854 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015855 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015856 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015857 ASSERT_VK_SUCCESS(err);
15858
15859 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15860 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015861 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015862 ASSERT_VK_SUCCESS(err);
15863
Tony Barbour552f6c02016-12-21 14:34:07 -070015864 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015865 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015866 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15867 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015868 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015869 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015870 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015871 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015872 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015873 resolveRegion.srcOffset.x = 0;
15874 resolveRegion.srcOffset.y = 0;
15875 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015876 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015877 resolveRegion.dstSubresource.mipLevel = 0;
15878 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015879 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015880 resolveRegion.dstOffset.x = 0;
15881 resolveRegion.dstOffset.y = 0;
15882 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015883 resolveRegion.extent.width = 1;
15884 resolveRegion.extent.height = 1;
15885 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015886 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015887 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015888
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015889 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015890
Chia-I Wuf7458c52015-10-26 21:10:41 +080015891 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015892 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015893 vkFreeMemory(m_device->device(), srcMem, NULL);
15894 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015895}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015896
Karl Schultz6addd812016-02-02 17:17:23 -070015897TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015898 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015899 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15900 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015901 // The image format check comes 2nd in validation so we trigger it first,
15902 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015903 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015904
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15906 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015907
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015908 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015909
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015910 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015911 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15912 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015913
15914 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015915 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15916 ds_pool_ci.pNext = NULL;
15917 ds_pool_ci.maxSets = 1;
15918 ds_pool_ci.poolSizeCount = 1;
15919 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015920
15921 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015922 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015923 ASSERT_VK_SUCCESS(err);
15924
15925 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015926 dsl_binding.binding = 0;
15927 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15928 dsl_binding.descriptorCount = 1;
15929 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15930 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015931
15932 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015933 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15934 ds_layout_ci.pNext = NULL;
15935 ds_layout_ci.bindingCount = 1;
15936 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015937 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015938 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015939 ASSERT_VK_SUCCESS(err);
15940
15941 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015942 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015943 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015944 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015945 alloc_info.descriptorPool = ds_pool;
15946 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015947 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015948 ASSERT_VK_SUCCESS(err);
15949
Karl Schultz6addd812016-02-02 17:17:23 -070015950 VkImage image_bad;
15951 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015952 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015953 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015954 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015955 const int32_t tex_width = 32;
15956 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015957
15958 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015959 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15960 image_create_info.pNext = NULL;
15961 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15962 image_create_info.format = tex_format_bad;
15963 image_create_info.extent.width = tex_width;
15964 image_create_info.extent.height = tex_height;
15965 image_create_info.extent.depth = 1;
15966 image_create_info.mipLevels = 1;
15967 image_create_info.arrayLayers = 1;
15968 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15969 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015970 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015971 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015972
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015973 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015974 ASSERT_VK_SUCCESS(err);
15975 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015976 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15977 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015978 ASSERT_VK_SUCCESS(err);
15979
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015980 // ---Bind image memory---
15981 VkMemoryRequirements img_mem_reqs;
15982 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
15983 VkMemoryAllocateInfo image_alloc_info = {};
15984 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15985 image_alloc_info.pNext = NULL;
15986 image_alloc_info.memoryTypeIndex = 0;
15987 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015988 bool pass =
15989 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 -070015990 ASSERT_TRUE(pass);
15991 VkDeviceMemory mem;
15992 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
15993 ASSERT_VK_SUCCESS(err);
15994 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
15995 ASSERT_VK_SUCCESS(err);
15996 // -----------------------
15997
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015998 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015999 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016000 image_view_create_info.image = image_bad;
16001 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16002 image_view_create_info.format = tex_format_bad;
16003 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16004 image_view_create_info.subresourceRange.baseMipLevel = 0;
16005 image_view_create_info.subresourceRange.layerCount = 1;
16006 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016007 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016008
16009 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016010 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016011
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016012 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016013
Chia-I Wuf7458c52015-10-26 21:10:41 +080016014 vkDestroyImage(m_device->device(), image_bad, NULL);
16015 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016016 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16017 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016018
16019 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016020}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016021
16022TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016023 TEST_DESCRIPTION(
16024 "Call ClearColorImage w/ a depth|stencil image and "
16025 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016026
16027 ASSERT_NO_FATAL_FAILURE(InitState());
16028 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16029
Tony Barbour552f6c02016-12-21 14:34:07 -070016030 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016031
16032 // Color image
16033 VkClearColorValue clear_color;
16034 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16035 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16036 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16037 const int32_t img_width = 32;
16038 const int32_t img_height = 32;
16039 VkImageCreateInfo image_create_info = {};
16040 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16041 image_create_info.pNext = NULL;
16042 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16043 image_create_info.format = color_format;
16044 image_create_info.extent.width = img_width;
16045 image_create_info.extent.height = img_height;
16046 image_create_info.extent.depth = 1;
16047 image_create_info.mipLevels = 1;
16048 image_create_info.arrayLayers = 1;
16049 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16050 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16051 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16052
16053 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016054 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016055
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016056 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016057
16058 // Depth/Stencil image
16059 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016060 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016061 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16062 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16063 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16064 ds_image_create_info.extent.width = 64;
16065 ds_image_create_info.extent.height = 64;
16066 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016067 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 -060016068
16069 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016070 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016072 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 -060016073
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016075
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016076 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016077 &color_range);
16078
16079 m_errorMonitor->VerifyFound();
16080
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16082 "vkCmdClearColorImage called with "
16083 "image created without "
16084 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016085
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016086 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016087 &color_range);
16088
16089 m_errorMonitor->VerifyFound();
16090
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016091 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16093 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016094
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016095 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
16096 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016097
16098 m_errorMonitor->VerifyFound();
16099}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016100#endif // IMAGE_TESTS
Tobin Ehliscde08892015-09-22 10:11:37 -060016101
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016102// WSI Enabled Tests
16103//
Chris Forbes09368e42016-10-13 11:59:22 +130016104#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016105TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
16106
16107#if defined(VK_USE_PLATFORM_XCB_KHR)
16108 VkSurfaceKHR surface = VK_NULL_HANDLE;
16109
16110 VkResult err;
16111 bool pass;
16112 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
16113 VkSwapchainCreateInfoKHR swapchain_create_info = {};
16114 // uint32_t swapchain_image_count = 0;
16115 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
16116 // uint32_t image_index = 0;
16117 // VkPresentInfoKHR present_info = {};
16118
16119 ASSERT_NO_FATAL_FAILURE(InitState());
16120
16121 // Use the create function from one of the VK_KHR_*_surface extension in
16122 // order to create a surface, testing all known errors in the process,
16123 // before successfully creating a surface:
16124 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
16125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
16126 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
16127 pass = (err != VK_SUCCESS);
16128 ASSERT_TRUE(pass);
16129 m_errorMonitor->VerifyFound();
16130
16131 // Next, try to create a surface with the wrong
16132 // VkXcbSurfaceCreateInfoKHR::sType:
16133 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
16134 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16136 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16137 pass = (err != VK_SUCCESS);
16138 ASSERT_TRUE(pass);
16139 m_errorMonitor->VerifyFound();
16140
16141 // Create a native window, and then correctly create a surface:
16142 xcb_connection_t *connection;
16143 xcb_screen_t *screen;
16144 xcb_window_t xcb_window;
16145 xcb_intern_atom_reply_t *atom_wm_delete_window;
16146
16147 const xcb_setup_t *setup;
16148 xcb_screen_iterator_t iter;
16149 int scr;
16150 uint32_t value_mask, value_list[32];
16151 int width = 1;
16152 int height = 1;
16153
16154 connection = xcb_connect(NULL, &scr);
16155 ASSERT_TRUE(connection != NULL);
16156 setup = xcb_get_setup(connection);
16157 iter = xcb_setup_roots_iterator(setup);
16158 while (scr-- > 0)
16159 xcb_screen_next(&iter);
16160 screen = iter.data;
16161
16162 xcb_window = xcb_generate_id(connection);
16163
16164 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
16165 value_list[0] = screen->black_pixel;
16166 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
16167
16168 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
16169 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
16170
16171 /* Magic code that will send notification when window is destroyed */
16172 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
16173 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
16174
16175 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
16176 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
16177 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
16178 free(reply);
16179
16180 xcb_map_window(connection, xcb_window);
16181
16182 // Force the x/y coordinates to 100,100 results are identical in consecutive
16183 // runs
16184 const uint32_t coords[] = { 100, 100 };
16185 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
16186
16187 // Finally, try to correctly create a surface:
16188 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
16189 xcb_create_info.pNext = NULL;
16190 xcb_create_info.flags = 0;
16191 xcb_create_info.connection = connection;
16192 xcb_create_info.window = xcb_window;
16193 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16194 pass = (err == VK_SUCCESS);
16195 ASSERT_TRUE(pass);
16196
16197 // Check if surface supports presentation:
16198
16199 // 1st, do so without having queried the queue families:
16200 VkBool32 supported = false;
16201 // TODO: Get the following error to come out:
16202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16203 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
16204 "function");
16205 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16206 pass = (err != VK_SUCCESS);
16207 // ASSERT_TRUE(pass);
16208 // m_errorMonitor->VerifyFound();
16209
16210 // Next, query a queue family index that's too large:
16211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16212 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
16213 pass = (err != VK_SUCCESS);
16214 ASSERT_TRUE(pass);
16215 m_errorMonitor->VerifyFound();
16216
16217 // Finally, do so correctly:
16218 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16219 // SUPPORTED
16220 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16221 pass = (err == VK_SUCCESS);
16222 ASSERT_TRUE(pass);
16223
16224 // Before proceeding, try to create a swapchain without having called
16225 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
16226 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16227 swapchain_create_info.pNext = NULL;
16228 swapchain_create_info.flags = 0;
16229 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16230 swapchain_create_info.surface = surface;
16231 swapchain_create_info.imageArrayLayers = 1;
16232 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
16233 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
16234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16235 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
16236 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16237 pass = (err != VK_SUCCESS);
16238 ASSERT_TRUE(pass);
16239 m_errorMonitor->VerifyFound();
16240
16241 // Get the surface capabilities:
16242 VkSurfaceCapabilitiesKHR surface_capabilities;
16243
16244 // Do so correctly (only error logged by this entrypoint is if the
16245 // extension isn't enabled):
16246 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
16247 pass = (err == VK_SUCCESS);
16248 ASSERT_TRUE(pass);
16249
16250 // Get the surface formats:
16251 uint32_t surface_format_count;
16252
16253 // First, try without a pointer to surface_format_count:
16254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
16255 "specified as NULL");
16256 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
16257 pass = (err == VK_SUCCESS);
16258 ASSERT_TRUE(pass);
16259 m_errorMonitor->VerifyFound();
16260
16261 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
16262 // correctly done a 1st try (to get the count):
16263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16264 surface_format_count = 0;
16265 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
16266 pass = (err == VK_SUCCESS);
16267 ASSERT_TRUE(pass);
16268 m_errorMonitor->VerifyFound();
16269
16270 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16271 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16272 pass = (err == VK_SUCCESS);
16273 ASSERT_TRUE(pass);
16274
16275 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16276 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
16277
16278 // Next, do a 2nd try with surface_format_count being set too high:
16279 surface_format_count += 5;
16280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16281 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16282 pass = (err == VK_SUCCESS);
16283 ASSERT_TRUE(pass);
16284 m_errorMonitor->VerifyFound();
16285
16286 // Finally, do a correct 1st and 2nd try:
16287 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16288 pass = (err == VK_SUCCESS);
16289 ASSERT_TRUE(pass);
16290 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16291 pass = (err == VK_SUCCESS);
16292 ASSERT_TRUE(pass);
16293
16294 // Get the surface present modes:
16295 uint32_t surface_present_mode_count;
16296
16297 // First, try without a pointer to surface_format_count:
16298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16299 "specified as NULL");
16300
16301 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16302 pass = (err == VK_SUCCESS);
16303 ASSERT_TRUE(pass);
16304 m_errorMonitor->VerifyFound();
16305
16306 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16307 // correctly done a 1st try (to get the count):
16308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16309 surface_present_mode_count = 0;
16310 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16311 (VkPresentModeKHR *)&surface_present_mode_count);
16312 pass = (err == VK_SUCCESS);
16313 ASSERT_TRUE(pass);
16314 m_errorMonitor->VerifyFound();
16315
16316 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16317 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16318 pass = (err == VK_SUCCESS);
16319 ASSERT_TRUE(pass);
16320
16321 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16322 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16323
16324 // Next, do a 2nd try with surface_format_count being set too high:
16325 surface_present_mode_count += 5;
16326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16327 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16328 pass = (err == VK_SUCCESS);
16329 ASSERT_TRUE(pass);
16330 m_errorMonitor->VerifyFound();
16331
16332 // Finally, do a correct 1st and 2nd try:
16333 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16334 pass = (err == VK_SUCCESS);
16335 ASSERT_TRUE(pass);
16336 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16337 pass = (err == VK_SUCCESS);
16338 ASSERT_TRUE(pass);
16339
16340 // Create a swapchain:
16341
16342 // First, try without a pointer to swapchain_create_info:
16343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16344 "specified as NULL");
16345
16346 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16347 pass = (err != VK_SUCCESS);
16348 ASSERT_TRUE(pass);
16349 m_errorMonitor->VerifyFound();
16350
16351 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16352 // sType:
16353 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16355
16356 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16357 pass = (err != VK_SUCCESS);
16358 ASSERT_TRUE(pass);
16359 m_errorMonitor->VerifyFound();
16360
16361 // Next, call with a NULL swapchain pointer:
16362 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16363 swapchain_create_info.pNext = NULL;
16364 swapchain_create_info.flags = 0;
16365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16366 "specified as NULL");
16367
16368 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16369 pass = (err != VK_SUCCESS);
16370 ASSERT_TRUE(pass);
16371 m_errorMonitor->VerifyFound();
16372
16373 // TODO: Enhance swapchain layer so that
16374 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16375
16376 // Next, call with a queue family index that's too large:
16377 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16378 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16379 swapchain_create_info.queueFamilyIndexCount = 2;
16380 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16382 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16383 pass = (err != VK_SUCCESS);
16384 ASSERT_TRUE(pass);
16385 m_errorMonitor->VerifyFound();
16386
16387 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16388 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16389 swapchain_create_info.queueFamilyIndexCount = 1;
16390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16391 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16392 "pCreateInfo->pQueueFamilyIndices).");
16393 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16394 pass = (err != VK_SUCCESS);
16395 ASSERT_TRUE(pass);
16396 m_errorMonitor->VerifyFound();
16397
16398 // Next, call with an invalid imageSharingMode:
16399 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16400 swapchain_create_info.queueFamilyIndexCount = 1;
16401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16402 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16403 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16404 pass = (err != VK_SUCCESS);
16405 ASSERT_TRUE(pass);
16406 m_errorMonitor->VerifyFound();
16407 // Fix for the future:
16408 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16409 // SUPPORTED
16410 swapchain_create_info.queueFamilyIndexCount = 0;
16411 queueFamilyIndex[0] = 0;
16412 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16413
16414 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16415 // Get the images from a swapchain:
16416 // Acquire an image from a swapchain:
16417 // Present an image to a swapchain:
16418 // Destroy the swapchain:
16419
16420 // TODOs:
16421 //
16422 // - Try destroying the device without first destroying the swapchain
16423 //
16424 // - Try destroying the device without first destroying the surface
16425 //
16426 // - Try destroying the surface without first destroying the swapchain
16427
16428 // Destroy the surface:
16429 vkDestroySurfaceKHR(instance(), surface, NULL);
16430
16431 // Tear down the window:
16432 xcb_destroy_window(connection, xcb_window);
16433 xcb_disconnect(connection);
16434
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016435#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016436 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016437#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016438}
Chris Forbes09368e42016-10-13 11:59:22 +130016439#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016440
16441//
16442// POSITIVE VALIDATION TESTS
16443//
16444// These tests do not expect to encounter ANY validation errors pass only if this is true
16445
Tobin Ehlise0006882016-11-03 10:14:28 -060016446TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016447 TEST_DESCRIPTION(
16448 "Perform an image layout transition in a secondary command buffer followed "
16449 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060016450 VkResult err;
16451 m_errorMonitor->ExpectSuccess();
16452 ASSERT_NO_FATAL_FAILURE(InitState());
16453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16454 // Allocate a secondary and primary cmd buffer
16455 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16456 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16457 command_buffer_allocate_info.commandPool = m_commandPool;
16458 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16459 command_buffer_allocate_info.commandBufferCount = 1;
16460
16461 VkCommandBuffer secondary_command_buffer;
16462 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16463 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16464 VkCommandBuffer primary_command_buffer;
16465 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16466 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16467 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16468 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16469 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16470 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16471 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16472
16473 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16474 ASSERT_VK_SUCCESS(err);
16475 VkImageObj image(m_device);
16476 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16477 ASSERT_TRUE(image.initialized());
16478 VkImageMemoryBarrier img_barrier = {};
16479 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16480 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16481 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16482 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16483 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16484 img_barrier.image = image.handle();
16485 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16486 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16487 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16488 img_barrier.subresourceRange.baseArrayLayer = 0;
16489 img_barrier.subresourceRange.baseMipLevel = 0;
16490 img_barrier.subresourceRange.layerCount = 1;
16491 img_barrier.subresourceRange.levelCount = 1;
16492 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16493 0, nullptr, 1, &img_barrier);
16494 err = vkEndCommandBuffer(secondary_command_buffer);
16495 ASSERT_VK_SUCCESS(err);
16496
16497 // Now update primary cmd buffer to execute secondary and transitions image
16498 command_buffer_begin_info.pInheritanceInfo = nullptr;
16499 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16500 ASSERT_VK_SUCCESS(err);
16501 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16502 VkImageMemoryBarrier img_barrier2 = {};
16503 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16504 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16505 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16506 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16507 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16508 img_barrier2.image = image.handle();
16509 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16510 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16511 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16512 img_barrier2.subresourceRange.baseArrayLayer = 0;
16513 img_barrier2.subresourceRange.baseMipLevel = 0;
16514 img_barrier2.subresourceRange.layerCount = 1;
16515 img_barrier2.subresourceRange.levelCount = 1;
16516 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16517 nullptr, 1, &img_barrier2);
16518 err = vkEndCommandBuffer(primary_command_buffer);
16519 ASSERT_VK_SUCCESS(err);
16520 VkSubmitInfo submit_info = {};
16521 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16522 submit_info.commandBufferCount = 1;
16523 submit_info.pCommandBuffers = &primary_command_buffer;
16524 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16525 ASSERT_VK_SUCCESS(err);
16526 m_errorMonitor->VerifyNotFound();
16527 err = vkDeviceWaitIdle(m_device->device());
16528 ASSERT_VK_SUCCESS(err);
16529 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16530 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16531}
16532
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016533// This is a positive test. No failures are expected.
16534TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016535 TEST_DESCRIPTION(
16536 "Ensure that the vkUpdateDescriptorSets validation code "
16537 "is ignoring VkWriteDescriptorSet members that are not "
16538 "related to the descriptor type specified by "
16539 "VkWriteDescriptorSet::descriptorType. Correct "
16540 "validation behavior will result in the test running to "
16541 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016542
16543 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16544
16545 ASSERT_NO_FATAL_FAILURE(InitState());
16546
16547 // Image Case
16548 {
16549 m_errorMonitor->ExpectSuccess();
16550
16551 VkImage image;
16552 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16553 const int32_t tex_width = 32;
16554 const int32_t tex_height = 32;
16555 VkImageCreateInfo image_create_info = {};
16556 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16557 image_create_info.pNext = NULL;
16558 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16559 image_create_info.format = tex_format;
16560 image_create_info.extent.width = tex_width;
16561 image_create_info.extent.height = tex_height;
16562 image_create_info.extent.depth = 1;
16563 image_create_info.mipLevels = 1;
16564 image_create_info.arrayLayers = 1;
16565 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16566 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16567 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16568 image_create_info.flags = 0;
16569 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16570 ASSERT_VK_SUCCESS(err);
16571
16572 VkMemoryRequirements memory_reqs;
16573 VkDeviceMemory image_memory;
16574 bool pass;
16575 VkMemoryAllocateInfo memory_info = {};
16576 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16577 memory_info.pNext = NULL;
16578 memory_info.allocationSize = 0;
16579 memory_info.memoryTypeIndex = 0;
16580 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16581 memory_info.allocationSize = memory_reqs.size;
16582 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16583 ASSERT_TRUE(pass);
16584 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16585 ASSERT_VK_SUCCESS(err);
16586 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16587 ASSERT_VK_SUCCESS(err);
16588
16589 VkImageViewCreateInfo image_view_create_info = {};
16590 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16591 image_view_create_info.image = image;
16592 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16593 image_view_create_info.format = tex_format;
16594 image_view_create_info.subresourceRange.layerCount = 1;
16595 image_view_create_info.subresourceRange.baseMipLevel = 0;
16596 image_view_create_info.subresourceRange.levelCount = 1;
16597 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16598
16599 VkImageView view;
16600 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16601 ASSERT_VK_SUCCESS(err);
16602
16603 VkDescriptorPoolSize ds_type_count = {};
16604 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16605 ds_type_count.descriptorCount = 1;
16606
16607 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16608 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16609 ds_pool_ci.pNext = NULL;
16610 ds_pool_ci.maxSets = 1;
16611 ds_pool_ci.poolSizeCount = 1;
16612 ds_pool_ci.pPoolSizes = &ds_type_count;
16613
16614 VkDescriptorPool ds_pool;
16615 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16616 ASSERT_VK_SUCCESS(err);
16617
16618 VkDescriptorSetLayoutBinding dsl_binding = {};
16619 dsl_binding.binding = 0;
16620 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16621 dsl_binding.descriptorCount = 1;
16622 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16623 dsl_binding.pImmutableSamplers = NULL;
16624
16625 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16626 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16627 ds_layout_ci.pNext = NULL;
16628 ds_layout_ci.bindingCount = 1;
16629 ds_layout_ci.pBindings = &dsl_binding;
16630 VkDescriptorSetLayout ds_layout;
16631 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16632 ASSERT_VK_SUCCESS(err);
16633
16634 VkDescriptorSet descriptor_set;
16635 VkDescriptorSetAllocateInfo alloc_info = {};
16636 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16637 alloc_info.descriptorSetCount = 1;
16638 alloc_info.descriptorPool = ds_pool;
16639 alloc_info.pSetLayouts = &ds_layout;
16640 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16641 ASSERT_VK_SUCCESS(err);
16642
16643 VkDescriptorImageInfo image_info = {};
16644 image_info.imageView = view;
16645 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16646
16647 VkWriteDescriptorSet descriptor_write;
16648 memset(&descriptor_write, 0, sizeof(descriptor_write));
16649 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16650 descriptor_write.dstSet = descriptor_set;
16651 descriptor_write.dstBinding = 0;
16652 descriptor_write.descriptorCount = 1;
16653 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16654 descriptor_write.pImageInfo = &image_info;
16655
16656 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16657 // be
16658 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16659 // This will most likely produce a crash if the parameter_validation
16660 // layer
16661 // does not correctly ignore pBufferInfo.
16662 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16663 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16664
16665 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16666
16667 m_errorMonitor->VerifyNotFound();
16668
16669 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16670 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16671 vkDestroyImageView(m_device->device(), view, NULL);
16672 vkDestroyImage(m_device->device(), image, NULL);
16673 vkFreeMemory(m_device->device(), image_memory, NULL);
16674 }
16675
16676 // Buffer Case
16677 {
16678 m_errorMonitor->ExpectSuccess();
16679
16680 VkBuffer buffer;
16681 uint32_t queue_family_index = 0;
16682 VkBufferCreateInfo buffer_create_info = {};
16683 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16684 buffer_create_info.size = 1024;
16685 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16686 buffer_create_info.queueFamilyIndexCount = 1;
16687 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16688
16689 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16690 ASSERT_VK_SUCCESS(err);
16691
16692 VkMemoryRequirements memory_reqs;
16693 VkDeviceMemory buffer_memory;
16694 bool pass;
16695 VkMemoryAllocateInfo memory_info = {};
16696 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16697 memory_info.pNext = NULL;
16698 memory_info.allocationSize = 0;
16699 memory_info.memoryTypeIndex = 0;
16700
16701 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16702 memory_info.allocationSize = memory_reqs.size;
16703 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16704 ASSERT_TRUE(pass);
16705
16706 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16707 ASSERT_VK_SUCCESS(err);
16708 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16709 ASSERT_VK_SUCCESS(err);
16710
16711 VkDescriptorPoolSize ds_type_count = {};
16712 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16713 ds_type_count.descriptorCount = 1;
16714
16715 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16716 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16717 ds_pool_ci.pNext = NULL;
16718 ds_pool_ci.maxSets = 1;
16719 ds_pool_ci.poolSizeCount = 1;
16720 ds_pool_ci.pPoolSizes = &ds_type_count;
16721
16722 VkDescriptorPool ds_pool;
16723 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16724 ASSERT_VK_SUCCESS(err);
16725
16726 VkDescriptorSetLayoutBinding dsl_binding = {};
16727 dsl_binding.binding = 0;
16728 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16729 dsl_binding.descriptorCount = 1;
16730 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16731 dsl_binding.pImmutableSamplers = NULL;
16732
16733 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16734 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16735 ds_layout_ci.pNext = NULL;
16736 ds_layout_ci.bindingCount = 1;
16737 ds_layout_ci.pBindings = &dsl_binding;
16738 VkDescriptorSetLayout ds_layout;
16739 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16740 ASSERT_VK_SUCCESS(err);
16741
16742 VkDescriptorSet descriptor_set;
16743 VkDescriptorSetAllocateInfo alloc_info = {};
16744 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16745 alloc_info.descriptorSetCount = 1;
16746 alloc_info.descriptorPool = ds_pool;
16747 alloc_info.pSetLayouts = &ds_layout;
16748 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16749 ASSERT_VK_SUCCESS(err);
16750
16751 VkDescriptorBufferInfo buffer_info = {};
16752 buffer_info.buffer = buffer;
16753 buffer_info.offset = 0;
16754 buffer_info.range = 1024;
16755
16756 VkWriteDescriptorSet descriptor_write;
16757 memset(&descriptor_write, 0, sizeof(descriptor_write));
16758 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16759 descriptor_write.dstSet = descriptor_set;
16760 descriptor_write.dstBinding = 0;
16761 descriptor_write.descriptorCount = 1;
16762 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16763 descriptor_write.pBufferInfo = &buffer_info;
16764
16765 // Set pImageInfo and pTexelBufferView to invalid values, which should
16766 // be
16767 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16768 // This will most likely produce a crash if the parameter_validation
16769 // layer
16770 // does not correctly ignore pImageInfo.
16771 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16772 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16773
16774 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16775
16776 m_errorMonitor->VerifyNotFound();
16777
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016778 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16779 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16780 vkDestroyBuffer(m_device->device(), buffer, NULL);
16781 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16782 }
16783
16784 // Texel Buffer Case
16785 {
16786 m_errorMonitor->ExpectSuccess();
16787
16788 VkBuffer buffer;
16789 uint32_t queue_family_index = 0;
16790 VkBufferCreateInfo buffer_create_info = {};
16791 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16792 buffer_create_info.size = 1024;
16793 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16794 buffer_create_info.queueFamilyIndexCount = 1;
16795 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16796
16797 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16798 ASSERT_VK_SUCCESS(err);
16799
16800 VkMemoryRequirements memory_reqs;
16801 VkDeviceMemory buffer_memory;
16802 bool pass;
16803 VkMemoryAllocateInfo memory_info = {};
16804 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16805 memory_info.pNext = NULL;
16806 memory_info.allocationSize = 0;
16807 memory_info.memoryTypeIndex = 0;
16808
16809 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16810 memory_info.allocationSize = memory_reqs.size;
16811 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16812 ASSERT_TRUE(pass);
16813
16814 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16815 ASSERT_VK_SUCCESS(err);
16816 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16817 ASSERT_VK_SUCCESS(err);
16818
16819 VkBufferViewCreateInfo buff_view_ci = {};
16820 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16821 buff_view_ci.buffer = buffer;
16822 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16823 buff_view_ci.range = VK_WHOLE_SIZE;
16824 VkBufferView buffer_view;
16825 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16826
16827 VkDescriptorPoolSize ds_type_count = {};
16828 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16829 ds_type_count.descriptorCount = 1;
16830
16831 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16832 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16833 ds_pool_ci.pNext = NULL;
16834 ds_pool_ci.maxSets = 1;
16835 ds_pool_ci.poolSizeCount = 1;
16836 ds_pool_ci.pPoolSizes = &ds_type_count;
16837
16838 VkDescriptorPool ds_pool;
16839 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16840 ASSERT_VK_SUCCESS(err);
16841
16842 VkDescriptorSetLayoutBinding dsl_binding = {};
16843 dsl_binding.binding = 0;
16844 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16845 dsl_binding.descriptorCount = 1;
16846 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16847 dsl_binding.pImmutableSamplers = NULL;
16848
16849 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16850 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16851 ds_layout_ci.pNext = NULL;
16852 ds_layout_ci.bindingCount = 1;
16853 ds_layout_ci.pBindings = &dsl_binding;
16854 VkDescriptorSetLayout ds_layout;
16855 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16856 ASSERT_VK_SUCCESS(err);
16857
16858 VkDescriptorSet descriptor_set;
16859 VkDescriptorSetAllocateInfo alloc_info = {};
16860 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16861 alloc_info.descriptorSetCount = 1;
16862 alloc_info.descriptorPool = ds_pool;
16863 alloc_info.pSetLayouts = &ds_layout;
16864 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16865 ASSERT_VK_SUCCESS(err);
16866
16867 VkWriteDescriptorSet descriptor_write;
16868 memset(&descriptor_write, 0, sizeof(descriptor_write));
16869 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16870 descriptor_write.dstSet = descriptor_set;
16871 descriptor_write.dstBinding = 0;
16872 descriptor_write.descriptorCount = 1;
16873 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16874 descriptor_write.pTexelBufferView = &buffer_view;
16875
16876 // Set pImageInfo and pBufferInfo to invalid values, which should be
16877 // ignored for descriptorType ==
16878 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16879 // This will most likely produce a crash if the parameter_validation
16880 // layer
16881 // does not correctly ignore pImageInfo and pBufferInfo.
16882 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16883 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16884
16885 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16886
16887 m_errorMonitor->VerifyNotFound();
16888
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016889 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16890 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16891 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16892 vkDestroyBuffer(m_device->device(), buffer, NULL);
16893 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16894 }
16895}
16896
Tobin Ehlisf7428442016-10-25 07:58:24 -060016897TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16898 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16899
16900 ASSERT_NO_FATAL_FAILURE(InitState());
16901 // Create layout where two binding #s are "1"
16902 static const uint32_t NUM_BINDINGS = 3;
16903 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16904 dsl_binding[0].binding = 1;
16905 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16906 dsl_binding[0].descriptorCount = 1;
16907 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16908 dsl_binding[0].pImmutableSamplers = NULL;
16909 dsl_binding[1].binding = 0;
16910 dsl_binding[1].descriptorCount = 1;
16911 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16912 dsl_binding[1].descriptorCount = 1;
16913 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16914 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016915 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060016916 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16917 dsl_binding[2].descriptorCount = 1;
16918 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16919 dsl_binding[2].pImmutableSamplers = NULL;
16920
16921 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16922 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16923 ds_layout_ci.pNext = NULL;
16924 ds_layout_ci.bindingCount = NUM_BINDINGS;
16925 ds_layout_ci.pBindings = dsl_binding;
16926 VkDescriptorSetLayout ds_layout;
16927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16928 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16929 m_errorMonitor->VerifyFound();
16930}
16931
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016932TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016933 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16934
16935 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016936
Tony Barbour552f6c02016-12-21 14:34:07 -070016937 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016938
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016939 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16940
16941 {
16942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16943 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16944 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16945 m_errorMonitor->VerifyFound();
16946 }
16947
16948 {
16949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16950 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16951 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16952 m_errorMonitor->VerifyFound();
16953 }
16954
16955 {
16956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16957 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16958 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16959 m_errorMonitor->VerifyFound();
16960 }
16961
16962 {
16963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16964 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16965 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16966 m_errorMonitor->VerifyFound();
16967 }
16968
16969 {
16970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16971 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16972 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16973 m_errorMonitor->VerifyFound();
16974 }
16975
16976 {
16977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16978 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16979 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16980 m_errorMonitor->VerifyFound();
16981 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016982
16983 {
16984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16985 VkRect2D scissor = {{-1, 0}, {16, 16}};
16986 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16987 m_errorMonitor->VerifyFound();
16988 }
16989
16990 {
16991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16992 VkRect2D scissor = {{0, -2}, {16, 16}};
16993 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16994 m_errorMonitor->VerifyFound();
16995 }
16996
16997 {
16998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16999 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
17000 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17001 m_errorMonitor->VerifyFound();
17002 }
17003
17004 {
17005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
17006 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
17007 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17008 m_errorMonitor->VerifyFound();
17009 }
17010
Tony Barbour552f6c02016-12-21 14:34:07 -070017011 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017012}
17013
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017014// This is a positive test. No failures are expected.
17015TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
17016 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
17017 VkResult err;
17018
17019 ASSERT_NO_FATAL_FAILURE(InitState());
17020 m_errorMonitor->ExpectSuccess();
17021 VkDescriptorPoolSize ds_type_count = {};
17022 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17023 ds_type_count.descriptorCount = 2;
17024
17025 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17026 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17027 ds_pool_ci.pNext = NULL;
17028 ds_pool_ci.maxSets = 1;
17029 ds_pool_ci.poolSizeCount = 1;
17030 ds_pool_ci.pPoolSizes = &ds_type_count;
17031
17032 VkDescriptorPool ds_pool;
17033 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17034 ASSERT_VK_SUCCESS(err);
17035
17036 // Create layout with two uniform buffer descriptors w/ empty binding between them
17037 static const uint32_t NUM_BINDINGS = 3;
17038 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17039 dsl_binding[0].binding = 0;
17040 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17041 dsl_binding[0].descriptorCount = 1;
17042 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
17043 dsl_binding[0].pImmutableSamplers = NULL;
17044 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017045 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017046 dsl_binding[2].binding = 2;
17047 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17048 dsl_binding[2].descriptorCount = 1;
17049 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
17050 dsl_binding[2].pImmutableSamplers = NULL;
17051
17052 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17053 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17054 ds_layout_ci.pNext = NULL;
17055 ds_layout_ci.bindingCount = NUM_BINDINGS;
17056 ds_layout_ci.pBindings = dsl_binding;
17057 VkDescriptorSetLayout ds_layout;
17058 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17059 ASSERT_VK_SUCCESS(err);
17060
17061 VkDescriptorSet descriptor_set = {};
17062 VkDescriptorSetAllocateInfo alloc_info = {};
17063 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17064 alloc_info.descriptorSetCount = 1;
17065 alloc_info.descriptorPool = ds_pool;
17066 alloc_info.pSetLayouts = &ds_layout;
17067 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17068 ASSERT_VK_SUCCESS(err);
17069
17070 // Create a buffer to be used for update
17071 VkBufferCreateInfo buff_ci = {};
17072 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17073 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17074 buff_ci.size = 256;
17075 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17076 VkBuffer buffer;
17077 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
17078 ASSERT_VK_SUCCESS(err);
17079 // Have to bind memory to buffer before descriptor update
17080 VkMemoryAllocateInfo mem_alloc = {};
17081 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17082 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017083 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017084 mem_alloc.memoryTypeIndex = 0;
17085
17086 VkMemoryRequirements mem_reqs;
17087 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17088 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
17089 if (!pass) {
17090 vkDestroyBuffer(m_device->device(), buffer, NULL);
17091 return;
17092 }
17093
17094 VkDeviceMemory mem;
17095 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17096 ASSERT_VK_SUCCESS(err);
17097 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17098 ASSERT_VK_SUCCESS(err);
17099
17100 // Only update the descriptor at binding 2
17101 VkDescriptorBufferInfo buff_info = {};
17102 buff_info.buffer = buffer;
17103 buff_info.offset = 0;
17104 buff_info.range = VK_WHOLE_SIZE;
17105 VkWriteDescriptorSet descriptor_write = {};
17106 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17107 descriptor_write.dstBinding = 2;
17108 descriptor_write.descriptorCount = 1;
17109 descriptor_write.pTexelBufferView = nullptr;
17110 descriptor_write.pBufferInfo = &buff_info;
17111 descriptor_write.pImageInfo = nullptr;
17112 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17113 descriptor_write.dstSet = descriptor_set;
17114
17115 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17116
17117 m_errorMonitor->VerifyNotFound();
17118 // Cleanup
17119 vkFreeMemory(m_device->device(), mem, NULL);
17120 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17121 vkDestroyBuffer(m_device->device(), buffer, NULL);
17122 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17123}
17124
17125// This is a positive test. No failures are expected.
17126TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
17127 VkResult err;
17128 bool pass;
17129
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017130 TEST_DESCRIPTION(
17131 "Create a buffer, allocate memory, bind memory, destroy "
17132 "the buffer, create an image, and bind the same memory to "
17133 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017134
17135 m_errorMonitor->ExpectSuccess();
17136
17137 ASSERT_NO_FATAL_FAILURE(InitState());
17138
17139 VkBuffer buffer;
17140 VkImage image;
17141 VkDeviceMemory mem;
17142 VkMemoryRequirements mem_reqs;
17143
17144 VkBufferCreateInfo buf_info = {};
17145 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17146 buf_info.pNext = NULL;
17147 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17148 buf_info.size = 256;
17149 buf_info.queueFamilyIndexCount = 0;
17150 buf_info.pQueueFamilyIndices = NULL;
17151 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17152 buf_info.flags = 0;
17153 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
17154 ASSERT_VK_SUCCESS(err);
17155
17156 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17157
17158 VkMemoryAllocateInfo alloc_info = {};
17159 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17160 alloc_info.pNext = NULL;
17161 alloc_info.memoryTypeIndex = 0;
17162
17163 // Ensure memory is big enough for both bindings
17164 alloc_info.allocationSize = 0x10000;
17165
17166 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17167 if (!pass) {
17168 vkDestroyBuffer(m_device->device(), buffer, NULL);
17169 return;
17170 }
17171
17172 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17173 ASSERT_VK_SUCCESS(err);
17174
17175 uint8_t *pData;
17176 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
17177 ASSERT_VK_SUCCESS(err);
17178
17179 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
17180
17181 vkUnmapMemory(m_device->device(), mem);
17182
17183 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17184 ASSERT_VK_SUCCESS(err);
17185
17186 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
17187 // memory. In fact, it was never used by the GPU.
17188 // Just be be sure, wait for idle.
17189 vkDestroyBuffer(m_device->device(), buffer, NULL);
17190 vkDeviceWaitIdle(m_device->device());
17191
Tobin Ehlis6a005702016-12-28 15:25:56 -070017192 // Use optimal as some platforms report linear support but then fail image creation
17193 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
17194 VkImageFormatProperties image_format_properties;
17195 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
17196 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
17197 if (image_format_properties.maxExtent.width == 0) {
17198 printf("Image format not supported; skipped.\n");
17199 vkFreeMemory(m_device->device(), mem, NULL);
17200 return;
17201 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017202 VkImageCreateInfo image_create_info = {};
17203 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17204 image_create_info.pNext = NULL;
17205 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17206 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
17207 image_create_info.extent.width = 64;
17208 image_create_info.extent.height = 64;
17209 image_create_info.extent.depth = 1;
17210 image_create_info.mipLevels = 1;
17211 image_create_info.arrayLayers = 1;
17212 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070017213 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017214 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
17215 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17216 image_create_info.queueFamilyIndexCount = 0;
17217 image_create_info.pQueueFamilyIndices = NULL;
17218 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17219 image_create_info.flags = 0;
17220
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017221 /* Create a mappable image. It will be the texture if linear images are ok
17222 * to be textures or it will be the staging image if they are not.
17223 */
17224 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17225 ASSERT_VK_SUCCESS(err);
17226
17227 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
17228
Tobin Ehlis6a005702016-12-28 15:25:56 -070017229 VkMemoryAllocateInfo mem_alloc = {};
17230 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17231 mem_alloc.pNext = NULL;
17232 mem_alloc.allocationSize = 0;
17233 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017234 mem_alloc.allocationSize = mem_reqs.size;
17235
17236 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17237 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070017238 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017239 vkDestroyImage(m_device->device(), image, NULL);
17240 return;
17241 }
17242
17243 // VALIDATION FAILURE:
17244 err = vkBindImageMemory(m_device->device(), image, mem, 0);
17245 ASSERT_VK_SUCCESS(err);
17246
17247 m_errorMonitor->VerifyNotFound();
17248
17249 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017250 vkDestroyImage(m_device->device(), image, NULL);
17251}
17252
Tobin Ehlis953e8392016-11-17 10:54:13 -070017253TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
17254 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
17255 // We previously had a bug where dynamic offset of inactive bindings was still being used
17256 VkResult err;
17257 m_errorMonitor->ExpectSuccess();
17258
17259 ASSERT_NO_FATAL_FAILURE(InitState());
17260 ASSERT_NO_FATAL_FAILURE(InitViewport());
17261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17262
17263 VkDescriptorPoolSize ds_type_count = {};
17264 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17265 ds_type_count.descriptorCount = 3;
17266
17267 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17268 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17269 ds_pool_ci.pNext = NULL;
17270 ds_pool_ci.maxSets = 1;
17271 ds_pool_ci.poolSizeCount = 1;
17272 ds_pool_ci.pPoolSizes = &ds_type_count;
17273
17274 VkDescriptorPool ds_pool;
17275 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17276 ASSERT_VK_SUCCESS(err);
17277
17278 const uint32_t BINDING_COUNT = 3;
17279 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017280 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017281 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17282 dsl_binding[0].descriptorCount = 1;
17283 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17284 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017285 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017286 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17287 dsl_binding[1].descriptorCount = 1;
17288 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17289 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017290 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017291 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17292 dsl_binding[2].descriptorCount = 1;
17293 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17294 dsl_binding[2].pImmutableSamplers = NULL;
17295
17296 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17297 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17298 ds_layout_ci.pNext = NULL;
17299 ds_layout_ci.bindingCount = BINDING_COUNT;
17300 ds_layout_ci.pBindings = dsl_binding;
17301 VkDescriptorSetLayout ds_layout;
17302 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17303 ASSERT_VK_SUCCESS(err);
17304
17305 VkDescriptorSet descriptor_set;
17306 VkDescriptorSetAllocateInfo alloc_info = {};
17307 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17308 alloc_info.descriptorSetCount = 1;
17309 alloc_info.descriptorPool = ds_pool;
17310 alloc_info.pSetLayouts = &ds_layout;
17311 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17312 ASSERT_VK_SUCCESS(err);
17313
17314 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17315 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17316 pipeline_layout_ci.pNext = NULL;
17317 pipeline_layout_ci.setLayoutCount = 1;
17318 pipeline_layout_ci.pSetLayouts = &ds_layout;
17319
17320 VkPipelineLayout pipeline_layout;
17321 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17322 ASSERT_VK_SUCCESS(err);
17323
17324 // Create two buffers to update the descriptors with
17325 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17326 uint32_t qfi = 0;
17327 VkBufferCreateInfo buffCI = {};
17328 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17329 buffCI.size = 2048;
17330 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17331 buffCI.queueFamilyIndexCount = 1;
17332 buffCI.pQueueFamilyIndices = &qfi;
17333
17334 VkBuffer dyub1;
17335 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17336 ASSERT_VK_SUCCESS(err);
17337 // buffer2
17338 buffCI.size = 1024;
17339 VkBuffer dyub2;
17340 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17341 ASSERT_VK_SUCCESS(err);
17342 // Allocate memory and bind to buffers
17343 VkMemoryAllocateInfo mem_alloc[2] = {};
17344 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17345 mem_alloc[0].pNext = NULL;
17346 mem_alloc[0].memoryTypeIndex = 0;
17347 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17348 mem_alloc[1].pNext = NULL;
17349 mem_alloc[1].memoryTypeIndex = 0;
17350
17351 VkMemoryRequirements mem_reqs1;
17352 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17353 VkMemoryRequirements mem_reqs2;
17354 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17355 mem_alloc[0].allocationSize = mem_reqs1.size;
17356 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17357 mem_alloc[1].allocationSize = mem_reqs2.size;
17358 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17359 if (!pass) {
17360 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17361 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17362 return;
17363 }
17364
17365 VkDeviceMemory mem1;
17366 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17367 ASSERT_VK_SUCCESS(err);
17368 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17369 ASSERT_VK_SUCCESS(err);
17370 VkDeviceMemory mem2;
17371 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17372 ASSERT_VK_SUCCESS(err);
17373 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17374 ASSERT_VK_SUCCESS(err);
17375 // Update descriptors
17376 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17377 buff_info[0].buffer = dyub1;
17378 buff_info[0].offset = 0;
17379 buff_info[0].range = 256;
17380 buff_info[1].buffer = dyub1;
17381 buff_info[1].offset = 256;
17382 buff_info[1].range = 512;
17383 buff_info[2].buffer = dyub2;
17384 buff_info[2].offset = 0;
17385 buff_info[2].range = 512;
17386
17387 VkWriteDescriptorSet descriptor_write;
17388 memset(&descriptor_write, 0, sizeof(descriptor_write));
17389 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17390 descriptor_write.dstSet = descriptor_set;
17391 descriptor_write.dstBinding = 0;
17392 descriptor_write.descriptorCount = BINDING_COUNT;
17393 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17394 descriptor_write.pBufferInfo = buff_info;
17395
17396 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17397
Tony Barbour552f6c02016-12-21 14:34:07 -070017398 m_commandBuffer->BeginCommandBuffer();
17399 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017400
17401 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017402 char const *vsSource =
17403 "#version 450\n"
17404 "\n"
17405 "out gl_PerVertex { \n"
17406 " vec4 gl_Position;\n"
17407 "};\n"
17408 "void main(){\n"
17409 " gl_Position = vec4(1);\n"
17410 "}\n";
17411 char const *fsSource =
17412 "#version 450\n"
17413 "\n"
17414 "layout(location=0) out vec4 x;\n"
17415 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17416 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17417 "void main(){\n"
17418 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17419 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070017420 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17421 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17422 VkPipelineObj pipe(m_device);
17423 pipe.SetViewport(m_viewports);
17424 pipe.SetScissor(m_scissors);
17425 pipe.AddShader(&vs);
17426 pipe.AddShader(&fs);
17427 pipe.AddColorAttachment();
17428 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17429
17430 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17431 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17432 // we used to have a bug in this case.
17433 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17434 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17435 &descriptor_set, BINDING_COUNT, dyn_off);
17436 Draw(1, 0, 0, 0);
17437 m_errorMonitor->VerifyNotFound();
17438
17439 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17440 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17441 vkFreeMemory(m_device->device(), mem1, NULL);
17442 vkFreeMemory(m_device->device(), mem2, NULL);
17443
17444 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17445 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17446 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17447}
17448
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017449TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017450 TEST_DESCRIPTION(
17451 "Ensure that validations handling of non-coherent memory "
17452 "mapping while using VK_WHOLE_SIZE does not cause access "
17453 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017454 VkResult err;
17455 uint8_t *pData;
17456 ASSERT_NO_FATAL_FAILURE(InitState());
17457
17458 VkDeviceMemory mem;
17459 VkMemoryRequirements mem_reqs;
17460 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017461 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017462 VkMemoryAllocateInfo alloc_info = {};
17463 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17464 alloc_info.pNext = NULL;
17465 alloc_info.memoryTypeIndex = 0;
17466
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017467 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017468 alloc_info.allocationSize = allocation_size;
17469
17470 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17471 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 -070017472 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017473 if (!pass) {
17474 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017475 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17476 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017477 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017478 pass = m_device->phy().set_memory_type(
17479 mem_reqs.memoryTypeBits, &alloc_info,
17480 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17481 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017482 if (!pass) {
17483 return;
17484 }
17485 }
17486 }
17487
17488 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17489 ASSERT_VK_SUCCESS(err);
17490
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017491 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017492 m_errorMonitor->ExpectSuccess();
17493 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17494 ASSERT_VK_SUCCESS(err);
17495 VkMappedMemoryRange mmr = {};
17496 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17497 mmr.memory = mem;
17498 mmr.offset = 0;
17499 mmr.size = VK_WHOLE_SIZE;
17500 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17501 ASSERT_VK_SUCCESS(err);
17502 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17503 ASSERT_VK_SUCCESS(err);
17504 m_errorMonitor->VerifyNotFound();
17505 vkUnmapMemory(m_device->device(), mem);
17506
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017507 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017508 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017509 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017510 ASSERT_VK_SUCCESS(err);
17511 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17512 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017513 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017514 mmr.size = VK_WHOLE_SIZE;
17515 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17516 ASSERT_VK_SUCCESS(err);
17517 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17518 ASSERT_VK_SUCCESS(err);
17519 m_errorMonitor->VerifyNotFound();
17520 vkUnmapMemory(m_device->device(), mem);
17521
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017522 // Map with offset and size
17523 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017524 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017525 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017526 ASSERT_VK_SUCCESS(err);
17527 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17528 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017529 mmr.offset = 4 * atom_size;
17530 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017531 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17532 ASSERT_VK_SUCCESS(err);
17533 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17534 ASSERT_VK_SUCCESS(err);
17535 m_errorMonitor->VerifyNotFound();
17536 vkUnmapMemory(m_device->device(), mem);
17537
17538 // Map without offset and flush WHOLE_SIZE with two separate offsets
17539 m_errorMonitor->ExpectSuccess();
17540 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17541 ASSERT_VK_SUCCESS(err);
17542 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17543 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017544 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017545 mmr.size = VK_WHOLE_SIZE;
17546 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17547 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017548 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017549 mmr.size = VK_WHOLE_SIZE;
17550 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17551 ASSERT_VK_SUCCESS(err);
17552 m_errorMonitor->VerifyNotFound();
17553 vkUnmapMemory(m_device->device(), mem);
17554
17555 vkFreeMemory(m_device->device(), mem, NULL);
17556}
17557
17558// This is a positive test. We used to expect error in this case but spec now allows it
17559TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17560 m_errorMonitor->ExpectSuccess();
17561 vk_testing::Fence testFence;
17562 VkFenceCreateInfo fenceInfo = {};
17563 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17564 fenceInfo.pNext = NULL;
17565
17566 ASSERT_NO_FATAL_FAILURE(InitState());
17567 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017568 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017569 VkResult result = vkResetFences(m_device->device(), 1, fences);
17570 ASSERT_VK_SUCCESS(result);
17571
17572 m_errorMonitor->VerifyNotFound();
17573}
17574
17575TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17576 m_errorMonitor->ExpectSuccess();
17577
17578 ASSERT_NO_FATAL_FAILURE(InitState());
17579 VkResult err;
17580
17581 // Record (empty!) command buffer that can be submitted multiple times
17582 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017583 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17584 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017585 m_commandBuffer->BeginCommandBuffer(&cbbi);
17586 m_commandBuffer->EndCommandBuffer();
17587
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017588 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017589 VkFence fence;
17590 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17591 ASSERT_VK_SUCCESS(err);
17592
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017593 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017594 VkSemaphore s1, s2;
17595 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17596 ASSERT_VK_SUCCESS(err);
17597 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17598 ASSERT_VK_SUCCESS(err);
17599
17600 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017601 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017602 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17603 ASSERT_VK_SUCCESS(err);
17604
17605 // Submit CB again, signaling s2.
17606 si.pSignalSemaphores = &s2;
17607 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17608 ASSERT_VK_SUCCESS(err);
17609
17610 // Wait for fence.
17611 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17612 ASSERT_VK_SUCCESS(err);
17613
17614 // CB is still in flight from second submission, but semaphore s1 is no
17615 // longer in flight. delete it.
17616 vkDestroySemaphore(m_device->device(), s1, nullptr);
17617
17618 m_errorMonitor->VerifyNotFound();
17619
17620 // Force device idle and clean up remaining objects
17621 vkDeviceWaitIdle(m_device->device());
17622 vkDestroySemaphore(m_device->device(), s2, nullptr);
17623 vkDestroyFence(m_device->device(), fence, nullptr);
17624}
17625
17626TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17627 m_errorMonitor->ExpectSuccess();
17628
17629 ASSERT_NO_FATAL_FAILURE(InitState());
17630 VkResult err;
17631
17632 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017633 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017634 VkFence f1;
17635 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17636 ASSERT_VK_SUCCESS(err);
17637
17638 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017639 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017640 VkFence f2;
17641 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17642 ASSERT_VK_SUCCESS(err);
17643
17644 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017645 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017646 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17647
17648 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017649 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017650 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17651
17652 // Should have both retired!
17653 vkDestroyFence(m_device->device(), f1, nullptr);
17654 vkDestroyFence(m_device->device(), f2, nullptr);
17655
17656 m_errorMonitor->VerifyNotFound();
17657}
17658
17659TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017660 TEST_DESCRIPTION(
17661 "Verify that creating an image view from an image with valid usage "
17662 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017663
17664 ASSERT_NO_FATAL_FAILURE(InitState());
17665
17666 m_errorMonitor->ExpectSuccess();
17667 // Verify that we can create a view with usage INPUT_ATTACHMENT
17668 VkImageObj image(m_device);
17669 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17670 ASSERT_TRUE(image.initialized());
17671 VkImageView imageView;
17672 VkImageViewCreateInfo ivci = {};
17673 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17674 ivci.image = image.handle();
17675 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17676 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17677 ivci.subresourceRange.layerCount = 1;
17678 ivci.subresourceRange.baseMipLevel = 0;
17679 ivci.subresourceRange.levelCount = 1;
17680 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17681
17682 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17683 m_errorMonitor->VerifyNotFound();
17684 vkDestroyImageView(m_device->device(), imageView, NULL);
17685}
17686
17687// This is a positive test. No failures are expected.
17688TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017689 TEST_DESCRIPTION(
17690 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17691 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017692
17693 ASSERT_NO_FATAL_FAILURE(InitState());
17694
17695 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017696 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017697
17698 m_errorMonitor->ExpectSuccess();
17699
17700 VkImage image;
17701 VkImageCreateInfo image_create_info = {};
17702 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17703 image_create_info.pNext = NULL;
17704 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17705 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17706 image_create_info.extent.width = 64;
17707 image_create_info.extent.height = 64;
17708 image_create_info.extent.depth = 1;
17709 image_create_info.mipLevels = 1;
17710 image_create_info.arrayLayers = 1;
17711 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17712 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17713 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17714 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17715 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17716 ASSERT_VK_SUCCESS(err);
17717
17718 VkMemoryRequirements memory_reqs;
17719 VkDeviceMemory memory_one, memory_two;
17720 bool pass;
17721 VkMemoryAllocateInfo memory_info = {};
17722 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17723 memory_info.pNext = NULL;
17724 memory_info.allocationSize = 0;
17725 memory_info.memoryTypeIndex = 0;
17726 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17727 // Find an image big enough to allow sparse mapping of 2 memory regions
17728 // Increase the image size until it is at least twice the
17729 // size of the required alignment, to ensure we can bind both
17730 // allocated memory blocks to the image on aligned offsets.
17731 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17732 vkDestroyImage(m_device->device(), image, nullptr);
17733 image_create_info.extent.width *= 2;
17734 image_create_info.extent.height *= 2;
17735 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17736 ASSERT_VK_SUCCESS(err);
17737 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17738 }
17739 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17740 // at the end of the first
17741 memory_info.allocationSize = memory_reqs.alignment;
17742 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17743 ASSERT_TRUE(pass);
17744 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17745 ASSERT_VK_SUCCESS(err);
17746 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17747 ASSERT_VK_SUCCESS(err);
17748 VkSparseMemoryBind binds[2];
17749 binds[0].flags = 0;
17750 binds[0].memory = memory_one;
17751 binds[0].memoryOffset = 0;
17752 binds[0].resourceOffset = 0;
17753 binds[0].size = memory_info.allocationSize;
17754 binds[1].flags = 0;
17755 binds[1].memory = memory_two;
17756 binds[1].memoryOffset = 0;
17757 binds[1].resourceOffset = memory_info.allocationSize;
17758 binds[1].size = memory_info.allocationSize;
17759
17760 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17761 opaqueBindInfo.image = image;
17762 opaqueBindInfo.bindCount = 2;
17763 opaqueBindInfo.pBinds = binds;
17764
17765 VkFence fence = VK_NULL_HANDLE;
17766 VkBindSparseInfo bindSparseInfo = {};
17767 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17768 bindSparseInfo.imageOpaqueBindCount = 1;
17769 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17770
17771 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17772 vkQueueWaitIdle(m_device->m_queue);
17773 vkDestroyImage(m_device->device(), image, NULL);
17774 vkFreeMemory(m_device->device(), memory_one, NULL);
17775 vkFreeMemory(m_device->device(), memory_two, NULL);
17776 m_errorMonitor->VerifyNotFound();
17777}
17778
17779TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017780 TEST_DESCRIPTION(
17781 "Ensure that CmdBeginRenderPass with an attachment's "
17782 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17783 "the command buffer has prior knowledge of that "
17784 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017785
17786 m_errorMonitor->ExpectSuccess();
17787
17788 ASSERT_NO_FATAL_FAILURE(InitState());
17789
17790 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017791 VkAttachmentDescription attachment = {0,
17792 VK_FORMAT_R8G8B8A8_UNORM,
17793 VK_SAMPLE_COUNT_1_BIT,
17794 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17795 VK_ATTACHMENT_STORE_OP_STORE,
17796 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17797 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17798 VK_IMAGE_LAYOUT_UNDEFINED,
17799 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017800
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017801 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017802
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017803 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017804
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017805 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017806
17807 VkRenderPass rp;
17808 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17809 ASSERT_VK_SUCCESS(err);
17810
17811 // A compatible framebuffer.
17812 VkImageObj image(m_device);
17813 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17814 ASSERT_TRUE(image.initialized());
17815
17816 VkImageViewCreateInfo ivci = {
17817 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17818 nullptr,
17819 0,
17820 image.handle(),
17821 VK_IMAGE_VIEW_TYPE_2D,
17822 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017823 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17824 VK_COMPONENT_SWIZZLE_IDENTITY},
17825 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017826 };
17827 VkImageView view;
17828 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17829 ASSERT_VK_SUCCESS(err);
17830
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017831 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017832 VkFramebuffer fb;
17833 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17834 ASSERT_VK_SUCCESS(err);
17835
17836 // Record a single command buffer which uses this renderpass twice. The
17837 // bug is triggered at the beginning of the second renderpass, when the
17838 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017839 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 -070017840 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017841 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17842 vkCmdEndRenderPass(m_commandBuffer->handle());
17843 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17844
17845 m_errorMonitor->VerifyNotFound();
17846
17847 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017848 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017849
17850 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17851 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17852 vkDestroyImageView(m_device->device(), view, nullptr);
17853}
17854
17855TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017856 TEST_DESCRIPTION(
17857 "This test should pass. Create a Framebuffer and "
17858 "command buffer, bind them together, then destroy "
17859 "command pool and framebuffer and verify there are no "
17860 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017861
17862 m_errorMonitor->ExpectSuccess();
17863
17864 ASSERT_NO_FATAL_FAILURE(InitState());
17865
17866 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017867 VkAttachmentDescription attachment = {0,
17868 VK_FORMAT_R8G8B8A8_UNORM,
17869 VK_SAMPLE_COUNT_1_BIT,
17870 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17871 VK_ATTACHMENT_STORE_OP_STORE,
17872 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17873 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17874 VK_IMAGE_LAYOUT_UNDEFINED,
17875 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017876
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017877 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017878
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017879 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017880
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017881 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017882
17883 VkRenderPass rp;
17884 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17885 ASSERT_VK_SUCCESS(err);
17886
17887 // A compatible framebuffer.
17888 VkImageObj image(m_device);
17889 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17890 ASSERT_TRUE(image.initialized());
17891
17892 VkImageViewCreateInfo ivci = {
17893 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17894 nullptr,
17895 0,
17896 image.handle(),
17897 VK_IMAGE_VIEW_TYPE_2D,
17898 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017899 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17900 VK_COMPONENT_SWIZZLE_IDENTITY},
17901 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017902 };
17903 VkImageView view;
17904 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17905 ASSERT_VK_SUCCESS(err);
17906
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017907 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017908 VkFramebuffer fb;
17909 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17910 ASSERT_VK_SUCCESS(err);
17911
17912 // Explicitly create a command buffer to bind the FB to so that we can then
17913 // destroy the command pool in order to implicitly free command buffer
17914 VkCommandPool command_pool;
17915 VkCommandPoolCreateInfo pool_create_info{};
17916 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17917 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17918 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17919 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17920
17921 VkCommandBuffer command_buffer;
17922 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17923 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17924 command_buffer_allocate_info.commandPool = command_pool;
17925 command_buffer_allocate_info.commandBufferCount = 1;
17926 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17927 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17928
17929 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017930 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 -060017931 VkCommandBufferBeginInfo begin_info{};
17932 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17933 vkBeginCommandBuffer(command_buffer, &begin_info);
17934
17935 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17936 vkCmdEndRenderPass(command_buffer);
17937 vkEndCommandBuffer(command_buffer);
17938 vkDestroyImageView(m_device->device(), view, nullptr);
17939 // Destroy command pool to implicitly free command buffer
17940 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17941 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17942 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17943 m_errorMonitor->VerifyNotFound();
17944}
17945
17946TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017947 TEST_DESCRIPTION(
17948 "Ensure that CmdBeginRenderPass applies the layout "
17949 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017950
17951 m_errorMonitor->ExpectSuccess();
17952
17953 ASSERT_NO_FATAL_FAILURE(InitState());
17954
17955 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017956 VkAttachmentDescription attachment = {0,
17957 VK_FORMAT_R8G8B8A8_UNORM,
17958 VK_SAMPLE_COUNT_1_BIT,
17959 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17960 VK_ATTACHMENT_STORE_OP_STORE,
17961 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17962 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17963 VK_IMAGE_LAYOUT_UNDEFINED,
17964 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017965
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017966 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017967
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017968 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017969
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017970 VkSubpassDependency dep = {0,
17971 0,
17972 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17973 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17974 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17975 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17976 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017977
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017978 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017979
17980 VkResult err;
17981 VkRenderPass rp;
17982 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17983 ASSERT_VK_SUCCESS(err);
17984
17985 // A compatible framebuffer.
17986 VkImageObj image(m_device);
17987 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17988 ASSERT_TRUE(image.initialized());
17989
17990 VkImageViewCreateInfo ivci = {
17991 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17992 nullptr,
17993 0,
17994 image.handle(),
17995 VK_IMAGE_VIEW_TYPE_2D,
17996 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017997 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17998 VK_COMPONENT_SWIZZLE_IDENTITY},
17999 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018000 };
18001 VkImageView view;
18002 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18003 ASSERT_VK_SUCCESS(err);
18004
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018005 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018006 VkFramebuffer fb;
18007 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18008 ASSERT_VK_SUCCESS(err);
18009
18010 // Record a single command buffer which issues a pipeline barrier w/
18011 // image memory barrier for the attachment. This detects the previously
18012 // missing tracking of the subpass layout by throwing a validation error
18013 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018014 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 -070018015 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018016 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18017
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018018 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
18019 nullptr,
18020 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18021 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18022 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18023 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18024 VK_QUEUE_FAMILY_IGNORED,
18025 VK_QUEUE_FAMILY_IGNORED,
18026 image.handle(),
18027 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018028 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018029 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18030 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018031
18032 vkCmdEndRenderPass(m_commandBuffer->handle());
18033 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018034 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018035
18036 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18037 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18038 vkDestroyImageView(m_device->device(), view, nullptr);
18039}
18040
18041TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018042 TEST_DESCRIPTION(
18043 "Validate that when an imageView of a depth/stencil image "
18044 "is used as a depth/stencil framebuffer attachment, the "
18045 "aspectMask is ignored and both depth and stencil image "
18046 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018047
18048 VkFormatProperties format_properties;
18049 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
18050 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
18051 return;
18052 }
18053
18054 m_errorMonitor->ExpectSuccess();
18055
18056 ASSERT_NO_FATAL_FAILURE(InitState());
18057
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018058 VkAttachmentDescription attachment = {0,
18059 VK_FORMAT_D32_SFLOAT_S8_UINT,
18060 VK_SAMPLE_COUNT_1_BIT,
18061 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18062 VK_ATTACHMENT_STORE_OP_STORE,
18063 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18064 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18065 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
18066 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018067
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018068 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018069
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018070 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018071
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018072 VkSubpassDependency dep = {0,
18073 0,
18074 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18075 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18076 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18077 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18078 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018079
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018080 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018081
18082 VkResult err;
18083 VkRenderPass rp;
18084 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18085 ASSERT_VK_SUCCESS(err);
18086
18087 VkImageObj image(m_device);
18088 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018089 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018090 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018091 ASSERT_TRUE(image.initialized());
18092 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
18093
18094 VkImageViewCreateInfo ivci = {
18095 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18096 nullptr,
18097 0,
18098 image.handle(),
18099 VK_IMAGE_VIEW_TYPE_2D,
18100 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018101 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
18102 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018103 };
18104 VkImageView view;
18105 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18106 ASSERT_VK_SUCCESS(err);
18107
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018108 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018109 VkFramebuffer fb;
18110 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18111 ASSERT_VK_SUCCESS(err);
18112
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018113 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 -070018114 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018115 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18116
18117 VkImageMemoryBarrier imb = {};
18118 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18119 imb.pNext = nullptr;
18120 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18121 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18122 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18123 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18124 imb.srcQueueFamilyIndex = 0;
18125 imb.dstQueueFamilyIndex = 0;
18126 imb.image = image.handle();
18127 imb.subresourceRange.aspectMask = 0x6;
18128 imb.subresourceRange.baseMipLevel = 0;
18129 imb.subresourceRange.levelCount = 0x1;
18130 imb.subresourceRange.baseArrayLayer = 0;
18131 imb.subresourceRange.layerCount = 0x1;
18132
18133 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018134 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18135 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018136
18137 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018138 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018139 QueueCommandBuffer(false);
18140 m_errorMonitor->VerifyNotFound();
18141
18142 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18143 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18144 vkDestroyImageView(m_device->device(), view, nullptr);
18145}
18146
18147TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018148 TEST_DESCRIPTION(
18149 "Ensure that layout transitions work correctly without "
18150 "errors, when an attachment reference is "
18151 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018152
18153 m_errorMonitor->ExpectSuccess();
18154
18155 ASSERT_NO_FATAL_FAILURE(InitState());
18156
18157 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018158 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018159
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018160 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018161
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018162 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018163
18164 VkRenderPass rp;
18165 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18166 ASSERT_VK_SUCCESS(err);
18167
18168 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018169 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018170 VkFramebuffer fb;
18171 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18172 ASSERT_VK_SUCCESS(err);
18173
18174 // Record a command buffer which just begins and ends the renderpass. The
18175 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018176 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 -070018177 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018178 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18179 vkCmdEndRenderPass(m_commandBuffer->handle());
18180 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018181 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018182
18183 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18184 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18185}
18186
18187// This is a positive test. No errors are expected.
18188TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018189 TEST_DESCRIPTION(
18190 "Create a stencil-only attachment with a LOAD_OP set to "
18191 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018192 VkResult result = VK_SUCCESS;
18193 VkImageFormatProperties formatProps;
18194 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018195 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
18196 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018197 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
18198 return;
18199 }
18200
18201 ASSERT_NO_FATAL_FAILURE(InitState());
18202 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
18203 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018204 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018205 VkAttachmentDescription att = {};
18206 VkAttachmentReference ref = {};
18207 att.format = depth_stencil_fmt;
18208 att.samples = VK_SAMPLE_COUNT_1_BIT;
18209 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
18210 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18211 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18212 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
18213 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18214 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18215
18216 VkClearValue clear;
18217 clear.depthStencil.depth = 1.0;
18218 clear.depthStencil.stencil = 0;
18219 ref.attachment = 0;
18220 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18221
18222 VkSubpassDescription subpass = {};
18223 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
18224 subpass.flags = 0;
18225 subpass.inputAttachmentCount = 0;
18226 subpass.pInputAttachments = NULL;
18227 subpass.colorAttachmentCount = 0;
18228 subpass.pColorAttachments = NULL;
18229 subpass.pResolveAttachments = NULL;
18230 subpass.pDepthStencilAttachment = &ref;
18231 subpass.preserveAttachmentCount = 0;
18232 subpass.pPreserveAttachments = NULL;
18233
18234 VkRenderPass rp;
18235 VkRenderPassCreateInfo rp_info = {};
18236 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18237 rp_info.attachmentCount = 1;
18238 rp_info.pAttachments = &att;
18239 rp_info.subpassCount = 1;
18240 rp_info.pSubpasses = &subpass;
18241 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
18242 ASSERT_VK_SUCCESS(result);
18243
18244 VkImageView *depthView = m_depthStencil->BindInfo();
18245 VkFramebufferCreateInfo fb_info = {};
18246 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
18247 fb_info.pNext = NULL;
18248 fb_info.renderPass = rp;
18249 fb_info.attachmentCount = 1;
18250 fb_info.pAttachments = depthView;
18251 fb_info.width = 100;
18252 fb_info.height = 100;
18253 fb_info.layers = 1;
18254 VkFramebuffer fb;
18255 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
18256 ASSERT_VK_SUCCESS(result);
18257
18258 VkRenderPassBeginInfo rpbinfo = {};
18259 rpbinfo.clearValueCount = 1;
18260 rpbinfo.pClearValues = &clear;
18261 rpbinfo.pNext = NULL;
18262 rpbinfo.renderPass = rp;
18263 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
18264 rpbinfo.renderArea.extent.width = 100;
18265 rpbinfo.renderArea.extent.height = 100;
18266 rpbinfo.renderArea.offset.x = 0;
18267 rpbinfo.renderArea.offset.y = 0;
18268 rpbinfo.framebuffer = fb;
18269
18270 VkFence fence = {};
18271 VkFenceCreateInfo fence_ci = {};
18272 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18273 fence_ci.pNext = nullptr;
18274 fence_ci.flags = 0;
18275 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
18276 ASSERT_VK_SUCCESS(result);
18277
18278 m_commandBuffer->BeginCommandBuffer();
18279 m_commandBuffer->BeginRenderPass(rpbinfo);
18280 m_commandBuffer->EndRenderPass();
18281 m_commandBuffer->EndCommandBuffer();
18282 m_commandBuffer->QueueCommandBuffer(fence);
18283
18284 VkImageObj destImage(m_device);
18285 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 -070018286 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018287 VkImageMemoryBarrier barrier = {};
18288 VkImageSubresourceRange range;
18289 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18290 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18291 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
18292 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18293 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18294 barrier.image = m_depthStencil->handle();
18295 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18296 range.baseMipLevel = 0;
18297 range.levelCount = 1;
18298 range.baseArrayLayer = 0;
18299 range.layerCount = 1;
18300 barrier.subresourceRange = range;
18301 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18302 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18303 cmdbuf.BeginCommandBuffer();
18304 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 -070018305 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018306 barrier.srcAccessMask = 0;
18307 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18308 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18309 barrier.image = destImage.handle();
18310 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18311 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 -070018312 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018313 VkImageCopy cregion;
18314 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18315 cregion.srcSubresource.mipLevel = 0;
18316 cregion.srcSubresource.baseArrayLayer = 0;
18317 cregion.srcSubresource.layerCount = 1;
18318 cregion.srcOffset.x = 0;
18319 cregion.srcOffset.y = 0;
18320 cregion.srcOffset.z = 0;
18321 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18322 cregion.dstSubresource.mipLevel = 0;
18323 cregion.dstSubresource.baseArrayLayer = 0;
18324 cregion.dstSubresource.layerCount = 1;
18325 cregion.dstOffset.x = 0;
18326 cregion.dstOffset.y = 0;
18327 cregion.dstOffset.z = 0;
18328 cregion.extent.width = 100;
18329 cregion.extent.height = 100;
18330 cregion.extent.depth = 1;
18331 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018332 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018333 cmdbuf.EndCommandBuffer();
18334
18335 VkSubmitInfo submit_info;
18336 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18337 submit_info.pNext = NULL;
18338 submit_info.waitSemaphoreCount = 0;
18339 submit_info.pWaitSemaphores = NULL;
18340 submit_info.pWaitDstStageMask = NULL;
18341 submit_info.commandBufferCount = 1;
18342 submit_info.pCommandBuffers = &cmdbuf.handle();
18343 submit_info.signalSemaphoreCount = 0;
18344 submit_info.pSignalSemaphores = NULL;
18345
18346 m_errorMonitor->ExpectSuccess();
18347 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18348 m_errorMonitor->VerifyNotFound();
18349
18350 vkQueueWaitIdle(m_device->m_queue);
18351 vkDestroyFence(m_device->device(), fence, nullptr);
18352 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18353 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18354}
18355
18356// This is a positive test. No errors should be generated.
18357TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18358 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18359
18360 m_errorMonitor->ExpectSuccess();
18361 ASSERT_NO_FATAL_FAILURE(InitState());
18362
18363 VkEvent event;
18364 VkEventCreateInfo event_create_info{};
18365 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18366 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18367
18368 VkCommandPool command_pool;
18369 VkCommandPoolCreateInfo pool_create_info{};
18370 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18371 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18372 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18373 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18374
18375 VkCommandBuffer command_buffer;
18376 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18377 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18378 command_buffer_allocate_info.commandPool = command_pool;
18379 command_buffer_allocate_info.commandBufferCount = 1;
18380 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18381 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18382
18383 VkQueue queue = VK_NULL_HANDLE;
18384 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18385
18386 {
18387 VkCommandBufferBeginInfo begin_info{};
18388 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18389 vkBeginCommandBuffer(command_buffer, &begin_info);
18390
18391 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 -070018392 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018393 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18394 vkEndCommandBuffer(command_buffer);
18395 }
18396 {
18397 VkSubmitInfo submit_info{};
18398 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18399 submit_info.commandBufferCount = 1;
18400 submit_info.pCommandBuffers = &command_buffer;
18401 submit_info.signalSemaphoreCount = 0;
18402 submit_info.pSignalSemaphores = nullptr;
18403 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18404 }
18405 { vkSetEvent(m_device->device(), event); }
18406
18407 vkQueueWaitIdle(queue);
18408
18409 vkDestroyEvent(m_device->device(), event, nullptr);
18410 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18411 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18412
18413 m_errorMonitor->VerifyNotFound();
18414}
18415// This is a positive test. No errors should be generated.
18416TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18417 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18418
18419 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018420 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018421
18422 m_errorMonitor->ExpectSuccess();
18423
18424 VkQueryPool query_pool;
18425 VkQueryPoolCreateInfo query_pool_create_info{};
18426 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18427 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18428 query_pool_create_info.queryCount = 1;
18429 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18430
18431 VkCommandPool command_pool;
18432 VkCommandPoolCreateInfo pool_create_info{};
18433 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18434 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18435 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18436 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18437
18438 VkCommandBuffer command_buffer;
18439 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18440 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18441 command_buffer_allocate_info.commandPool = command_pool;
18442 command_buffer_allocate_info.commandBufferCount = 1;
18443 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18444 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18445
18446 VkCommandBuffer secondary_command_buffer;
18447 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18448 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18449
18450 VkQueue queue = VK_NULL_HANDLE;
18451 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18452
18453 uint32_t qfi = 0;
18454 VkBufferCreateInfo buff_create_info = {};
18455 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18456 buff_create_info.size = 1024;
18457 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18458 buff_create_info.queueFamilyIndexCount = 1;
18459 buff_create_info.pQueueFamilyIndices = &qfi;
18460
18461 VkResult err;
18462 VkBuffer buffer;
18463 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18464 ASSERT_VK_SUCCESS(err);
18465 VkMemoryAllocateInfo mem_alloc = {};
18466 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18467 mem_alloc.pNext = NULL;
18468 mem_alloc.allocationSize = 1024;
18469 mem_alloc.memoryTypeIndex = 0;
18470
18471 VkMemoryRequirements memReqs;
18472 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18473 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18474 if (!pass) {
18475 vkDestroyBuffer(m_device->device(), buffer, NULL);
18476 return;
18477 }
18478
18479 VkDeviceMemory mem;
18480 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18481 ASSERT_VK_SUCCESS(err);
18482 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18483 ASSERT_VK_SUCCESS(err);
18484
18485 VkCommandBufferInheritanceInfo hinfo = {};
18486 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18487 hinfo.renderPass = VK_NULL_HANDLE;
18488 hinfo.subpass = 0;
18489 hinfo.framebuffer = VK_NULL_HANDLE;
18490 hinfo.occlusionQueryEnable = VK_FALSE;
18491 hinfo.queryFlags = 0;
18492 hinfo.pipelineStatistics = 0;
18493
18494 {
18495 VkCommandBufferBeginInfo begin_info{};
18496 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18497 begin_info.pInheritanceInfo = &hinfo;
18498 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18499
18500 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18501 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18502
18503 vkEndCommandBuffer(secondary_command_buffer);
18504
18505 begin_info.pInheritanceInfo = nullptr;
18506 vkBeginCommandBuffer(command_buffer, &begin_info);
18507
18508 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18509 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18510
18511 vkEndCommandBuffer(command_buffer);
18512 }
18513 {
18514 VkSubmitInfo submit_info{};
18515 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18516 submit_info.commandBufferCount = 1;
18517 submit_info.pCommandBuffers = &command_buffer;
18518 submit_info.signalSemaphoreCount = 0;
18519 submit_info.pSignalSemaphores = nullptr;
18520 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18521 }
18522
18523 vkQueueWaitIdle(queue);
18524
18525 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18526 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18527 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18528 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18529 vkDestroyBuffer(m_device->device(), buffer, NULL);
18530 vkFreeMemory(m_device->device(), mem, NULL);
18531
18532 m_errorMonitor->VerifyNotFound();
18533}
18534
18535// This is a positive test. No errors should be generated.
18536TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18537 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18538
18539 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018540 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018541
18542 m_errorMonitor->ExpectSuccess();
18543
18544 VkQueryPool query_pool;
18545 VkQueryPoolCreateInfo query_pool_create_info{};
18546 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18547 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18548 query_pool_create_info.queryCount = 1;
18549 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18550
18551 VkCommandPool command_pool;
18552 VkCommandPoolCreateInfo pool_create_info{};
18553 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18554 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18555 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18556 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18557
18558 VkCommandBuffer command_buffer[2];
18559 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18560 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18561 command_buffer_allocate_info.commandPool = command_pool;
18562 command_buffer_allocate_info.commandBufferCount = 2;
18563 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18564 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18565
18566 VkQueue queue = VK_NULL_HANDLE;
18567 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18568
18569 uint32_t qfi = 0;
18570 VkBufferCreateInfo buff_create_info = {};
18571 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18572 buff_create_info.size = 1024;
18573 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18574 buff_create_info.queueFamilyIndexCount = 1;
18575 buff_create_info.pQueueFamilyIndices = &qfi;
18576
18577 VkResult err;
18578 VkBuffer buffer;
18579 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18580 ASSERT_VK_SUCCESS(err);
18581 VkMemoryAllocateInfo mem_alloc = {};
18582 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18583 mem_alloc.pNext = NULL;
18584 mem_alloc.allocationSize = 1024;
18585 mem_alloc.memoryTypeIndex = 0;
18586
18587 VkMemoryRequirements memReqs;
18588 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18589 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18590 if (!pass) {
18591 vkDestroyBuffer(m_device->device(), buffer, NULL);
18592 return;
18593 }
18594
18595 VkDeviceMemory mem;
18596 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18597 ASSERT_VK_SUCCESS(err);
18598 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18599 ASSERT_VK_SUCCESS(err);
18600
18601 {
18602 VkCommandBufferBeginInfo begin_info{};
18603 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18604 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18605
18606 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18607 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18608
18609 vkEndCommandBuffer(command_buffer[0]);
18610
18611 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18612
18613 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18614
18615 vkEndCommandBuffer(command_buffer[1]);
18616 }
18617 {
18618 VkSubmitInfo submit_info{};
18619 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18620 submit_info.commandBufferCount = 2;
18621 submit_info.pCommandBuffers = command_buffer;
18622 submit_info.signalSemaphoreCount = 0;
18623 submit_info.pSignalSemaphores = nullptr;
18624 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18625 }
18626
18627 vkQueueWaitIdle(queue);
18628
18629 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18630 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18631 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18632 vkDestroyBuffer(m_device->device(), buffer, NULL);
18633 vkFreeMemory(m_device->device(), mem, NULL);
18634
18635 m_errorMonitor->VerifyNotFound();
18636}
18637
Tony Barbourc46924f2016-11-04 11:49:52 -060018638TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018639 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18640
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018641 ASSERT_NO_FATAL_FAILURE(InitState());
18642 VkEvent event;
18643 VkEventCreateInfo event_create_info{};
18644 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18645 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18646
18647 VkCommandPool command_pool;
18648 VkCommandPoolCreateInfo pool_create_info{};
18649 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18650 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18651 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18652 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18653
18654 VkCommandBuffer command_buffer;
18655 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18656 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18657 command_buffer_allocate_info.commandPool = command_pool;
18658 command_buffer_allocate_info.commandBufferCount = 1;
18659 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18660 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18661
18662 VkQueue queue = VK_NULL_HANDLE;
18663 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18664
18665 {
18666 VkCommandBufferBeginInfo begin_info{};
18667 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18668 vkBeginCommandBuffer(command_buffer, &begin_info);
18669
18670 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018671 vkEndCommandBuffer(command_buffer);
18672 }
18673 {
18674 VkSubmitInfo submit_info{};
18675 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18676 submit_info.commandBufferCount = 1;
18677 submit_info.pCommandBuffers = &command_buffer;
18678 submit_info.signalSemaphoreCount = 0;
18679 submit_info.pSignalSemaphores = nullptr;
18680 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18681 }
18682 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18684 "that is already in use by a "
18685 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018686 vkSetEvent(m_device->device(), event);
18687 m_errorMonitor->VerifyFound();
18688 }
18689
18690 vkQueueWaitIdle(queue);
18691
18692 vkDestroyEvent(m_device->device(), event, nullptr);
18693 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18694 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18695}
18696
18697// This is a positive test. No errors should be generated.
18698TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018699 TEST_DESCRIPTION(
18700 "Two command buffers with two separate fences are each "
18701 "run through a Submit & WaitForFences cycle 3 times. This "
18702 "previously revealed a bug so running this positive test "
18703 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018704 m_errorMonitor->ExpectSuccess();
18705
18706 ASSERT_NO_FATAL_FAILURE(InitState());
18707 VkQueue queue = VK_NULL_HANDLE;
18708 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18709
18710 static const uint32_t NUM_OBJECTS = 2;
18711 static const uint32_t NUM_FRAMES = 3;
18712 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18713 VkFence fences[NUM_OBJECTS] = {};
18714
18715 VkCommandPool cmd_pool;
18716 VkCommandPoolCreateInfo cmd_pool_ci = {};
18717 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18718 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18719 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18720 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18721 ASSERT_VK_SUCCESS(err);
18722
18723 VkCommandBufferAllocateInfo cmd_buf_info = {};
18724 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18725 cmd_buf_info.commandPool = cmd_pool;
18726 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18727 cmd_buf_info.commandBufferCount = 1;
18728
18729 VkFenceCreateInfo fence_ci = {};
18730 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18731 fence_ci.pNext = nullptr;
18732 fence_ci.flags = 0;
18733
18734 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18735 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18736 ASSERT_VK_SUCCESS(err);
18737 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18738 ASSERT_VK_SUCCESS(err);
18739 }
18740
18741 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18742 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18743 // Create empty cmd buffer
18744 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18745 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18746
18747 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18748 ASSERT_VK_SUCCESS(err);
18749 err = vkEndCommandBuffer(cmd_buffers[obj]);
18750 ASSERT_VK_SUCCESS(err);
18751
18752 VkSubmitInfo submit_info = {};
18753 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18754 submit_info.commandBufferCount = 1;
18755 submit_info.pCommandBuffers = &cmd_buffers[obj];
18756 // Submit cmd buffer and wait for fence
18757 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18758 ASSERT_VK_SUCCESS(err);
18759 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18760 ASSERT_VK_SUCCESS(err);
18761 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18762 ASSERT_VK_SUCCESS(err);
18763 }
18764 }
18765 m_errorMonitor->VerifyNotFound();
18766 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18767 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18768 vkDestroyFence(m_device->device(), fences[i], nullptr);
18769 }
18770}
18771// This is a positive test. No errors should be generated.
18772TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018773 TEST_DESCRIPTION(
18774 "Two command buffers, each in a separate QueueSubmit call "
18775 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018776
18777 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018778 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018779
18780 m_errorMonitor->ExpectSuccess();
18781
18782 VkSemaphore semaphore;
18783 VkSemaphoreCreateInfo semaphore_create_info{};
18784 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18785 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18786
18787 VkCommandPool command_pool;
18788 VkCommandPoolCreateInfo pool_create_info{};
18789 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18790 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18791 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18792 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18793
18794 VkCommandBuffer command_buffer[2];
18795 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18796 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18797 command_buffer_allocate_info.commandPool = command_pool;
18798 command_buffer_allocate_info.commandBufferCount = 2;
18799 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18800 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18801
18802 VkQueue queue = VK_NULL_HANDLE;
18803 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18804
18805 {
18806 VkCommandBufferBeginInfo begin_info{};
18807 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18808 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18809
18810 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 -070018811 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018812
18813 VkViewport viewport{};
18814 viewport.maxDepth = 1.0f;
18815 viewport.minDepth = 0.0f;
18816 viewport.width = 512;
18817 viewport.height = 512;
18818 viewport.x = 0;
18819 viewport.y = 0;
18820 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18821 vkEndCommandBuffer(command_buffer[0]);
18822 }
18823 {
18824 VkCommandBufferBeginInfo begin_info{};
18825 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18826 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18827
18828 VkViewport viewport{};
18829 viewport.maxDepth = 1.0f;
18830 viewport.minDepth = 0.0f;
18831 viewport.width = 512;
18832 viewport.height = 512;
18833 viewport.x = 0;
18834 viewport.y = 0;
18835 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18836 vkEndCommandBuffer(command_buffer[1]);
18837 }
18838 {
18839 VkSubmitInfo submit_info{};
18840 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18841 submit_info.commandBufferCount = 1;
18842 submit_info.pCommandBuffers = &command_buffer[0];
18843 submit_info.signalSemaphoreCount = 1;
18844 submit_info.pSignalSemaphores = &semaphore;
18845 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18846 }
18847 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018848 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018849 VkSubmitInfo submit_info{};
18850 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18851 submit_info.commandBufferCount = 1;
18852 submit_info.pCommandBuffers = &command_buffer[1];
18853 submit_info.waitSemaphoreCount = 1;
18854 submit_info.pWaitSemaphores = &semaphore;
18855 submit_info.pWaitDstStageMask = flags;
18856 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18857 }
18858
18859 vkQueueWaitIdle(m_device->m_queue);
18860
18861 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18862 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18863 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18864
18865 m_errorMonitor->VerifyNotFound();
18866}
18867
18868// This is a positive test. No errors should be generated.
18869TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018870 TEST_DESCRIPTION(
18871 "Two command buffers, each in a separate QueueSubmit call "
18872 "submitted on separate queues, the second having a fence"
18873 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018874
18875 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018876 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018877
18878 m_errorMonitor->ExpectSuccess();
18879
18880 VkFence fence;
18881 VkFenceCreateInfo fence_create_info{};
18882 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18883 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18884
18885 VkSemaphore semaphore;
18886 VkSemaphoreCreateInfo semaphore_create_info{};
18887 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18888 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18889
18890 VkCommandPool command_pool;
18891 VkCommandPoolCreateInfo pool_create_info{};
18892 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18893 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18894 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18895 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18896
18897 VkCommandBuffer command_buffer[2];
18898 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18899 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18900 command_buffer_allocate_info.commandPool = command_pool;
18901 command_buffer_allocate_info.commandBufferCount = 2;
18902 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18903 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18904
18905 VkQueue queue = VK_NULL_HANDLE;
18906 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18907
18908 {
18909 VkCommandBufferBeginInfo begin_info{};
18910 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18911 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18912
18913 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 -070018914 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018915
18916 VkViewport viewport{};
18917 viewport.maxDepth = 1.0f;
18918 viewport.minDepth = 0.0f;
18919 viewport.width = 512;
18920 viewport.height = 512;
18921 viewport.x = 0;
18922 viewport.y = 0;
18923 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18924 vkEndCommandBuffer(command_buffer[0]);
18925 }
18926 {
18927 VkCommandBufferBeginInfo begin_info{};
18928 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18929 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18930
18931 VkViewport viewport{};
18932 viewport.maxDepth = 1.0f;
18933 viewport.minDepth = 0.0f;
18934 viewport.width = 512;
18935 viewport.height = 512;
18936 viewport.x = 0;
18937 viewport.y = 0;
18938 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18939 vkEndCommandBuffer(command_buffer[1]);
18940 }
18941 {
18942 VkSubmitInfo submit_info{};
18943 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18944 submit_info.commandBufferCount = 1;
18945 submit_info.pCommandBuffers = &command_buffer[0];
18946 submit_info.signalSemaphoreCount = 1;
18947 submit_info.pSignalSemaphores = &semaphore;
18948 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18949 }
18950 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018951 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018952 VkSubmitInfo submit_info{};
18953 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18954 submit_info.commandBufferCount = 1;
18955 submit_info.pCommandBuffers = &command_buffer[1];
18956 submit_info.waitSemaphoreCount = 1;
18957 submit_info.pWaitSemaphores = &semaphore;
18958 submit_info.pWaitDstStageMask = flags;
18959 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18960 }
18961
18962 vkQueueWaitIdle(m_device->m_queue);
18963
18964 vkDestroyFence(m_device->device(), fence, nullptr);
18965 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18966 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18967 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18968
18969 m_errorMonitor->VerifyNotFound();
18970}
18971
18972// This is a positive test. No errors should be generated.
18973TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018974 TEST_DESCRIPTION(
18975 "Two command buffers, each in a separate QueueSubmit call "
18976 "submitted on separate queues, the second having a fence"
18977 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018978
18979 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018980 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018981
18982 m_errorMonitor->ExpectSuccess();
18983
18984 VkFence fence;
18985 VkFenceCreateInfo fence_create_info{};
18986 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18987 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18988
18989 VkSemaphore semaphore;
18990 VkSemaphoreCreateInfo semaphore_create_info{};
18991 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18992 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18993
18994 VkCommandPool command_pool;
18995 VkCommandPoolCreateInfo pool_create_info{};
18996 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18997 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18998 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18999 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19000
19001 VkCommandBuffer command_buffer[2];
19002 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19003 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19004 command_buffer_allocate_info.commandPool = command_pool;
19005 command_buffer_allocate_info.commandBufferCount = 2;
19006 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19007 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19008
19009 VkQueue queue = VK_NULL_HANDLE;
19010 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19011
19012 {
19013 VkCommandBufferBeginInfo begin_info{};
19014 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19015 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19016
19017 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 -070019018 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019019
19020 VkViewport viewport{};
19021 viewport.maxDepth = 1.0f;
19022 viewport.minDepth = 0.0f;
19023 viewport.width = 512;
19024 viewport.height = 512;
19025 viewport.x = 0;
19026 viewport.y = 0;
19027 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19028 vkEndCommandBuffer(command_buffer[0]);
19029 }
19030 {
19031 VkCommandBufferBeginInfo begin_info{};
19032 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19033 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19034
19035 VkViewport viewport{};
19036 viewport.maxDepth = 1.0f;
19037 viewport.minDepth = 0.0f;
19038 viewport.width = 512;
19039 viewport.height = 512;
19040 viewport.x = 0;
19041 viewport.y = 0;
19042 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19043 vkEndCommandBuffer(command_buffer[1]);
19044 }
19045 {
19046 VkSubmitInfo submit_info{};
19047 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19048 submit_info.commandBufferCount = 1;
19049 submit_info.pCommandBuffers = &command_buffer[0];
19050 submit_info.signalSemaphoreCount = 1;
19051 submit_info.pSignalSemaphores = &semaphore;
19052 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19053 }
19054 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019055 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019056 VkSubmitInfo submit_info{};
19057 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19058 submit_info.commandBufferCount = 1;
19059 submit_info.pCommandBuffers = &command_buffer[1];
19060 submit_info.waitSemaphoreCount = 1;
19061 submit_info.pWaitSemaphores = &semaphore;
19062 submit_info.pWaitDstStageMask = flags;
19063 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19064 }
19065
19066 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19067 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19068
19069 vkDestroyFence(m_device->device(), fence, nullptr);
19070 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19071 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19072 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19073
19074 m_errorMonitor->VerifyNotFound();
19075}
19076
19077TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019078 ASSERT_NO_FATAL_FAILURE(InitState());
19079 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
19080 printf("Test requires two queues, skipping\n");
19081 return;
19082 }
19083
19084 VkResult err;
19085
19086 m_errorMonitor->ExpectSuccess();
19087
19088 VkQueue q0 = m_device->m_queue;
19089 VkQueue q1 = nullptr;
19090 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
19091 ASSERT_NE(q1, nullptr);
19092
19093 // An (empty) command buffer. We must have work in the first submission --
19094 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019095 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019096 VkCommandPool pool;
19097 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
19098 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019099 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
19100 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019101 VkCommandBuffer cb;
19102 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
19103 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019104 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019105 err = vkBeginCommandBuffer(cb, &cbbi);
19106 ASSERT_VK_SUCCESS(err);
19107 err = vkEndCommandBuffer(cb);
19108 ASSERT_VK_SUCCESS(err);
19109
19110 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019111 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019112 VkSemaphore s;
19113 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
19114 ASSERT_VK_SUCCESS(err);
19115
19116 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019117 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019118
19119 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
19120 ASSERT_VK_SUCCESS(err);
19121
19122 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019123 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019124 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019125
19126 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
19127 ASSERT_VK_SUCCESS(err);
19128
19129 // Wait for q0 idle
19130 err = vkQueueWaitIdle(q0);
19131 ASSERT_VK_SUCCESS(err);
19132
19133 // Command buffer should have been completed (it was on q0); reset the pool.
19134 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
19135
19136 m_errorMonitor->VerifyNotFound();
19137
19138 // Force device completely idle and clean up resources
19139 vkDeviceWaitIdle(m_device->device());
19140 vkDestroyCommandPool(m_device->device(), pool, nullptr);
19141 vkDestroySemaphore(m_device->device(), s, nullptr);
19142}
19143
19144// This is a positive test. No errors should be generated.
19145TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019146 TEST_DESCRIPTION(
19147 "Two command buffers, each in a separate QueueSubmit call "
19148 "submitted on separate queues, the second having a fence, "
19149 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019150
19151 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019152 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019153
19154 m_errorMonitor->ExpectSuccess();
19155
19156 ASSERT_NO_FATAL_FAILURE(InitState());
19157 VkFence fence;
19158 VkFenceCreateInfo fence_create_info{};
19159 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19160 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19161
19162 VkSemaphore semaphore;
19163 VkSemaphoreCreateInfo semaphore_create_info{};
19164 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19165 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19166
19167 VkCommandPool command_pool;
19168 VkCommandPoolCreateInfo pool_create_info{};
19169 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19170 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19171 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19172 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19173
19174 VkCommandBuffer command_buffer[2];
19175 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19176 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19177 command_buffer_allocate_info.commandPool = command_pool;
19178 command_buffer_allocate_info.commandBufferCount = 2;
19179 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19180 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19181
19182 VkQueue queue = VK_NULL_HANDLE;
19183 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19184
19185 {
19186 VkCommandBufferBeginInfo begin_info{};
19187 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19188 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19189
19190 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 -070019191 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019192
19193 VkViewport viewport{};
19194 viewport.maxDepth = 1.0f;
19195 viewport.minDepth = 0.0f;
19196 viewport.width = 512;
19197 viewport.height = 512;
19198 viewport.x = 0;
19199 viewport.y = 0;
19200 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19201 vkEndCommandBuffer(command_buffer[0]);
19202 }
19203 {
19204 VkCommandBufferBeginInfo begin_info{};
19205 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19206 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19207
19208 VkViewport viewport{};
19209 viewport.maxDepth = 1.0f;
19210 viewport.minDepth = 0.0f;
19211 viewport.width = 512;
19212 viewport.height = 512;
19213 viewport.x = 0;
19214 viewport.y = 0;
19215 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19216 vkEndCommandBuffer(command_buffer[1]);
19217 }
19218 {
19219 VkSubmitInfo submit_info{};
19220 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19221 submit_info.commandBufferCount = 1;
19222 submit_info.pCommandBuffers = &command_buffer[0];
19223 submit_info.signalSemaphoreCount = 1;
19224 submit_info.pSignalSemaphores = &semaphore;
19225 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19226 }
19227 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019228 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019229 VkSubmitInfo submit_info{};
19230 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19231 submit_info.commandBufferCount = 1;
19232 submit_info.pCommandBuffers = &command_buffer[1];
19233 submit_info.waitSemaphoreCount = 1;
19234 submit_info.pWaitSemaphores = &semaphore;
19235 submit_info.pWaitDstStageMask = flags;
19236 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19237 }
19238
19239 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19240
19241 vkDestroyFence(m_device->device(), fence, nullptr);
19242 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19243 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19244 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19245
19246 m_errorMonitor->VerifyNotFound();
19247}
19248
19249// This is a positive test. No errors should be generated.
19250TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019251 TEST_DESCRIPTION(
19252 "Two command buffers, each in a separate QueueSubmit call "
19253 "on the same queue, sharing a signal/wait semaphore, the "
19254 "second having a fence, "
19255 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019256
19257 m_errorMonitor->ExpectSuccess();
19258
19259 ASSERT_NO_FATAL_FAILURE(InitState());
19260 VkFence fence;
19261 VkFenceCreateInfo fence_create_info{};
19262 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19263 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19264
19265 VkSemaphore semaphore;
19266 VkSemaphoreCreateInfo semaphore_create_info{};
19267 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19268 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19269
19270 VkCommandPool command_pool;
19271 VkCommandPoolCreateInfo pool_create_info{};
19272 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19273 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19274 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19275 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19276
19277 VkCommandBuffer command_buffer[2];
19278 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19279 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19280 command_buffer_allocate_info.commandPool = command_pool;
19281 command_buffer_allocate_info.commandBufferCount = 2;
19282 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19283 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19284
19285 {
19286 VkCommandBufferBeginInfo begin_info{};
19287 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19288 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19289
19290 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 -070019291 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019292
19293 VkViewport viewport{};
19294 viewport.maxDepth = 1.0f;
19295 viewport.minDepth = 0.0f;
19296 viewport.width = 512;
19297 viewport.height = 512;
19298 viewport.x = 0;
19299 viewport.y = 0;
19300 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19301 vkEndCommandBuffer(command_buffer[0]);
19302 }
19303 {
19304 VkCommandBufferBeginInfo begin_info{};
19305 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19306 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19307
19308 VkViewport viewport{};
19309 viewport.maxDepth = 1.0f;
19310 viewport.minDepth = 0.0f;
19311 viewport.width = 512;
19312 viewport.height = 512;
19313 viewport.x = 0;
19314 viewport.y = 0;
19315 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19316 vkEndCommandBuffer(command_buffer[1]);
19317 }
19318 {
19319 VkSubmitInfo submit_info{};
19320 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19321 submit_info.commandBufferCount = 1;
19322 submit_info.pCommandBuffers = &command_buffer[0];
19323 submit_info.signalSemaphoreCount = 1;
19324 submit_info.pSignalSemaphores = &semaphore;
19325 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19326 }
19327 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019328 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019329 VkSubmitInfo submit_info{};
19330 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19331 submit_info.commandBufferCount = 1;
19332 submit_info.pCommandBuffers = &command_buffer[1];
19333 submit_info.waitSemaphoreCount = 1;
19334 submit_info.pWaitSemaphores = &semaphore;
19335 submit_info.pWaitDstStageMask = flags;
19336 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19337 }
19338
19339 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19340
19341 vkDestroyFence(m_device->device(), fence, nullptr);
19342 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19343 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19344 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19345
19346 m_errorMonitor->VerifyNotFound();
19347}
19348
19349// This is a positive test. No errors should be generated.
19350TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019351 TEST_DESCRIPTION(
19352 "Two command buffers, each in a separate QueueSubmit call "
19353 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19354 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019355
19356 m_errorMonitor->ExpectSuccess();
19357
19358 ASSERT_NO_FATAL_FAILURE(InitState());
19359 VkFence fence;
19360 VkFenceCreateInfo fence_create_info{};
19361 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19362 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19363
19364 VkCommandPool command_pool;
19365 VkCommandPoolCreateInfo pool_create_info{};
19366 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19367 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19368 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19369 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19370
19371 VkCommandBuffer command_buffer[2];
19372 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19373 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19374 command_buffer_allocate_info.commandPool = command_pool;
19375 command_buffer_allocate_info.commandBufferCount = 2;
19376 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19377 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19378
19379 {
19380 VkCommandBufferBeginInfo begin_info{};
19381 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19382 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19383
19384 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 -070019385 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019386
19387 VkViewport viewport{};
19388 viewport.maxDepth = 1.0f;
19389 viewport.minDepth = 0.0f;
19390 viewport.width = 512;
19391 viewport.height = 512;
19392 viewport.x = 0;
19393 viewport.y = 0;
19394 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19395 vkEndCommandBuffer(command_buffer[0]);
19396 }
19397 {
19398 VkCommandBufferBeginInfo begin_info{};
19399 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19400 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19401
19402 VkViewport viewport{};
19403 viewport.maxDepth = 1.0f;
19404 viewport.minDepth = 0.0f;
19405 viewport.width = 512;
19406 viewport.height = 512;
19407 viewport.x = 0;
19408 viewport.y = 0;
19409 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19410 vkEndCommandBuffer(command_buffer[1]);
19411 }
19412 {
19413 VkSubmitInfo submit_info{};
19414 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19415 submit_info.commandBufferCount = 1;
19416 submit_info.pCommandBuffers = &command_buffer[0];
19417 submit_info.signalSemaphoreCount = 0;
19418 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19419 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19420 }
19421 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019422 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019423 VkSubmitInfo submit_info{};
19424 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19425 submit_info.commandBufferCount = 1;
19426 submit_info.pCommandBuffers = &command_buffer[1];
19427 submit_info.waitSemaphoreCount = 0;
19428 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19429 submit_info.pWaitDstStageMask = flags;
19430 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19431 }
19432
19433 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19434
19435 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19436 ASSERT_VK_SUCCESS(err);
19437
19438 vkDestroyFence(m_device->device(), fence, nullptr);
19439 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19440 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19441
19442 m_errorMonitor->VerifyNotFound();
19443}
19444
19445// This is a positive test. No errors should be generated.
19446TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019447 TEST_DESCRIPTION(
19448 "Two command buffers, each in a separate QueueSubmit call "
19449 "on the same queue, the second having a fence, followed "
19450 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019451
19452 m_errorMonitor->ExpectSuccess();
19453
19454 ASSERT_NO_FATAL_FAILURE(InitState());
19455 VkFence fence;
19456 VkFenceCreateInfo fence_create_info{};
19457 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19458 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19459
19460 VkCommandPool command_pool;
19461 VkCommandPoolCreateInfo pool_create_info{};
19462 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19463 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19464 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19465 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19466
19467 VkCommandBuffer command_buffer[2];
19468 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19469 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19470 command_buffer_allocate_info.commandPool = command_pool;
19471 command_buffer_allocate_info.commandBufferCount = 2;
19472 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19473 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19474
19475 {
19476 VkCommandBufferBeginInfo begin_info{};
19477 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19478 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19479
19480 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 -070019481 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019482
19483 VkViewport viewport{};
19484 viewport.maxDepth = 1.0f;
19485 viewport.minDepth = 0.0f;
19486 viewport.width = 512;
19487 viewport.height = 512;
19488 viewport.x = 0;
19489 viewport.y = 0;
19490 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19491 vkEndCommandBuffer(command_buffer[0]);
19492 }
19493 {
19494 VkCommandBufferBeginInfo begin_info{};
19495 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19496 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19497
19498 VkViewport viewport{};
19499 viewport.maxDepth = 1.0f;
19500 viewport.minDepth = 0.0f;
19501 viewport.width = 512;
19502 viewport.height = 512;
19503 viewport.x = 0;
19504 viewport.y = 0;
19505 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19506 vkEndCommandBuffer(command_buffer[1]);
19507 }
19508 {
19509 VkSubmitInfo submit_info{};
19510 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19511 submit_info.commandBufferCount = 1;
19512 submit_info.pCommandBuffers = &command_buffer[0];
19513 submit_info.signalSemaphoreCount = 0;
19514 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19515 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19516 }
19517 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019518 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019519 VkSubmitInfo submit_info{};
19520 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19521 submit_info.commandBufferCount = 1;
19522 submit_info.pCommandBuffers = &command_buffer[1];
19523 submit_info.waitSemaphoreCount = 0;
19524 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19525 submit_info.pWaitDstStageMask = flags;
19526 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19527 }
19528
19529 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19530
19531 vkDestroyFence(m_device->device(), fence, nullptr);
19532 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19533 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19534
19535 m_errorMonitor->VerifyNotFound();
19536}
19537
19538// This is a positive test. No errors should be generated.
19539TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019540 TEST_DESCRIPTION(
19541 "Two command buffers each in a separate SubmitInfo sent in a single "
19542 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019543 ASSERT_NO_FATAL_FAILURE(InitState());
19544
19545 m_errorMonitor->ExpectSuccess();
19546
19547 VkFence fence;
19548 VkFenceCreateInfo fence_create_info{};
19549 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19550 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19551
19552 VkSemaphore semaphore;
19553 VkSemaphoreCreateInfo semaphore_create_info{};
19554 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19555 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19556
19557 VkCommandPool command_pool;
19558 VkCommandPoolCreateInfo pool_create_info{};
19559 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19560 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19561 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19562 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19563
19564 VkCommandBuffer command_buffer[2];
19565 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19566 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19567 command_buffer_allocate_info.commandPool = command_pool;
19568 command_buffer_allocate_info.commandBufferCount = 2;
19569 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19570 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19571
19572 {
19573 VkCommandBufferBeginInfo begin_info{};
19574 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19575 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19576
19577 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 -070019578 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019579
19580 VkViewport viewport{};
19581 viewport.maxDepth = 1.0f;
19582 viewport.minDepth = 0.0f;
19583 viewport.width = 512;
19584 viewport.height = 512;
19585 viewport.x = 0;
19586 viewport.y = 0;
19587 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19588 vkEndCommandBuffer(command_buffer[0]);
19589 }
19590 {
19591 VkCommandBufferBeginInfo begin_info{};
19592 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19593 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19594
19595 VkViewport viewport{};
19596 viewport.maxDepth = 1.0f;
19597 viewport.minDepth = 0.0f;
19598 viewport.width = 512;
19599 viewport.height = 512;
19600 viewport.x = 0;
19601 viewport.y = 0;
19602 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19603 vkEndCommandBuffer(command_buffer[1]);
19604 }
19605 {
19606 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019607 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019608
19609 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19610 submit_info[0].pNext = NULL;
19611 submit_info[0].commandBufferCount = 1;
19612 submit_info[0].pCommandBuffers = &command_buffer[0];
19613 submit_info[0].signalSemaphoreCount = 1;
19614 submit_info[0].pSignalSemaphores = &semaphore;
19615 submit_info[0].waitSemaphoreCount = 0;
19616 submit_info[0].pWaitSemaphores = NULL;
19617 submit_info[0].pWaitDstStageMask = 0;
19618
19619 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19620 submit_info[1].pNext = NULL;
19621 submit_info[1].commandBufferCount = 1;
19622 submit_info[1].pCommandBuffers = &command_buffer[1];
19623 submit_info[1].waitSemaphoreCount = 1;
19624 submit_info[1].pWaitSemaphores = &semaphore;
19625 submit_info[1].pWaitDstStageMask = flags;
19626 submit_info[1].signalSemaphoreCount = 0;
19627 submit_info[1].pSignalSemaphores = NULL;
19628 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19629 }
19630
19631 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19632
19633 vkDestroyFence(m_device->device(), fence, nullptr);
19634 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19635 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19636 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19637
19638 m_errorMonitor->VerifyNotFound();
19639}
19640
19641TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19642 m_errorMonitor->ExpectSuccess();
19643
19644 ASSERT_NO_FATAL_FAILURE(InitState());
19645 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19646
Tony Barbour552f6c02016-12-21 14:34:07 -070019647 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019648
19649 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19650 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19651 m_errorMonitor->VerifyNotFound();
19652 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19653 m_errorMonitor->VerifyNotFound();
19654 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19655 m_errorMonitor->VerifyNotFound();
19656
19657 m_commandBuffer->EndCommandBuffer();
19658 m_errorMonitor->VerifyNotFound();
19659}
19660
19661TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019662 TEST_DESCRIPTION(
19663 "Positive test where we create a renderpass with an "
19664 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19665 "has a valid layout, and a second subpass then uses a "
19666 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019667 m_errorMonitor->ExpectSuccess();
19668 ASSERT_NO_FATAL_FAILURE(InitState());
19669
19670 VkAttachmentReference attach[2] = {};
19671 attach[0].attachment = 0;
19672 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19673 attach[1].attachment = 0;
19674 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19675 VkSubpassDescription subpasses[2] = {};
19676 // First subpass clears DS attach on load
19677 subpasses[0].pDepthStencilAttachment = &attach[0];
19678 // 2nd subpass reads in DS as input attachment
19679 subpasses[1].inputAttachmentCount = 1;
19680 subpasses[1].pInputAttachments = &attach[1];
19681 VkAttachmentDescription attach_desc = {};
19682 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19683 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19684 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19685 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19686 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19687 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19688 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19689 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19690 VkRenderPassCreateInfo rpci = {};
19691 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19692 rpci.attachmentCount = 1;
19693 rpci.pAttachments = &attach_desc;
19694 rpci.subpassCount = 2;
19695 rpci.pSubpasses = subpasses;
19696
19697 // Now create RenderPass and verify no errors
19698 VkRenderPass rp;
19699 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19700 m_errorMonitor->VerifyNotFound();
19701
19702 vkDestroyRenderPass(m_device->device(), rp, NULL);
19703}
19704
19705TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019706 TEST_DESCRIPTION(
19707 "Test that pipeline validation accepts matrices passed "
19708 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019709 m_errorMonitor->ExpectSuccess();
19710
19711 ASSERT_NO_FATAL_FAILURE(InitState());
19712 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19713
19714 VkVertexInputBindingDescription input_binding;
19715 memset(&input_binding, 0, sizeof(input_binding));
19716
19717 VkVertexInputAttributeDescription input_attribs[2];
19718 memset(input_attribs, 0, sizeof(input_attribs));
19719
19720 for (int i = 0; i < 2; i++) {
19721 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19722 input_attribs[i].location = i;
19723 }
19724
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019725 char const *vsSource =
19726 "#version 450\n"
19727 "\n"
19728 "layout(location=0) in mat2x4 x;\n"
19729 "out gl_PerVertex {\n"
19730 " vec4 gl_Position;\n"
19731 "};\n"
19732 "void main(){\n"
19733 " gl_Position = x[0] + x[1];\n"
19734 "}\n";
19735 char const *fsSource =
19736 "#version 450\n"
19737 "\n"
19738 "layout(location=0) out vec4 color;\n"
19739 "void main(){\n"
19740 " color = vec4(1);\n"
19741 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019742
19743 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19744 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19745
19746 VkPipelineObj pipe(m_device);
19747 pipe.AddColorAttachment();
19748 pipe.AddShader(&vs);
19749 pipe.AddShader(&fs);
19750
19751 pipe.AddVertexInputBindings(&input_binding, 1);
19752 pipe.AddVertexInputAttribs(input_attribs, 2);
19753
19754 VkDescriptorSetObj descriptorSet(m_device);
19755 descriptorSet.AppendDummy();
19756 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19757
19758 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19759
19760 /* expect success */
19761 m_errorMonitor->VerifyNotFound();
19762}
19763
19764TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19765 m_errorMonitor->ExpectSuccess();
19766
19767 ASSERT_NO_FATAL_FAILURE(InitState());
19768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19769
19770 VkVertexInputBindingDescription input_binding;
19771 memset(&input_binding, 0, sizeof(input_binding));
19772
19773 VkVertexInputAttributeDescription input_attribs[2];
19774 memset(input_attribs, 0, sizeof(input_attribs));
19775
19776 for (int i = 0; i < 2; i++) {
19777 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19778 input_attribs[i].location = i;
19779 }
19780
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019781 char const *vsSource =
19782 "#version 450\n"
19783 "\n"
19784 "layout(location=0) in vec4 x[2];\n"
19785 "out gl_PerVertex {\n"
19786 " vec4 gl_Position;\n"
19787 "};\n"
19788 "void main(){\n"
19789 " gl_Position = x[0] + x[1];\n"
19790 "}\n";
19791 char const *fsSource =
19792 "#version 450\n"
19793 "\n"
19794 "layout(location=0) out vec4 color;\n"
19795 "void main(){\n"
19796 " color = vec4(1);\n"
19797 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019798
19799 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19800 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19801
19802 VkPipelineObj pipe(m_device);
19803 pipe.AddColorAttachment();
19804 pipe.AddShader(&vs);
19805 pipe.AddShader(&fs);
19806
19807 pipe.AddVertexInputBindings(&input_binding, 1);
19808 pipe.AddVertexInputAttribs(input_attribs, 2);
19809
19810 VkDescriptorSetObj descriptorSet(m_device);
19811 descriptorSet.AppendDummy();
19812 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19813
19814 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19815
19816 m_errorMonitor->VerifyNotFound();
19817}
19818
19819TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019820 TEST_DESCRIPTION(
19821 "Test that pipeline validation accepts consuming a vertex attribute "
19822 "through multiple vertex shader inputs, each consuming a different "
19823 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019824 m_errorMonitor->ExpectSuccess();
19825
19826 ASSERT_NO_FATAL_FAILURE(InitState());
19827 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19828
19829 VkVertexInputBindingDescription input_binding;
19830 memset(&input_binding, 0, sizeof(input_binding));
19831
19832 VkVertexInputAttributeDescription input_attribs[3];
19833 memset(input_attribs, 0, sizeof(input_attribs));
19834
19835 for (int i = 0; i < 3; i++) {
19836 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19837 input_attribs[i].location = i;
19838 }
19839
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019840 char const *vsSource =
19841 "#version 450\n"
19842 "\n"
19843 "layout(location=0) in vec4 x;\n"
19844 "layout(location=1) in vec3 y1;\n"
19845 "layout(location=1, component=3) in float y2;\n"
19846 "layout(location=2) in vec4 z;\n"
19847 "out gl_PerVertex {\n"
19848 " vec4 gl_Position;\n"
19849 "};\n"
19850 "void main(){\n"
19851 " gl_Position = x + vec4(y1, y2) + z;\n"
19852 "}\n";
19853 char const *fsSource =
19854 "#version 450\n"
19855 "\n"
19856 "layout(location=0) out vec4 color;\n"
19857 "void main(){\n"
19858 " color = vec4(1);\n"
19859 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019860
19861 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19862 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19863
19864 VkPipelineObj pipe(m_device);
19865 pipe.AddColorAttachment();
19866 pipe.AddShader(&vs);
19867 pipe.AddShader(&fs);
19868
19869 pipe.AddVertexInputBindings(&input_binding, 1);
19870 pipe.AddVertexInputAttribs(input_attribs, 3);
19871
19872 VkDescriptorSetObj descriptorSet(m_device);
19873 descriptorSet.AppendDummy();
19874 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19875
19876 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19877
19878 m_errorMonitor->VerifyNotFound();
19879}
19880
19881TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19882 m_errorMonitor->ExpectSuccess();
19883
19884 ASSERT_NO_FATAL_FAILURE(InitState());
19885 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19886
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019887 char const *vsSource =
19888 "#version 450\n"
19889 "out gl_PerVertex {\n"
19890 " vec4 gl_Position;\n"
19891 "};\n"
19892 "void main(){\n"
19893 " gl_Position = vec4(0);\n"
19894 "}\n";
19895 char const *fsSource =
19896 "#version 450\n"
19897 "\n"
19898 "layout(location=0) out vec4 color;\n"
19899 "void main(){\n"
19900 " color = vec4(1);\n"
19901 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019902
19903 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19904 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19905
19906 VkPipelineObj pipe(m_device);
19907 pipe.AddColorAttachment();
19908 pipe.AddShader(&vs);
19909 pipe.AddShader(&fs);
19910
19911 VkDescriptorSetObj descriptorSet(m_device);
19912 descriptorSet.AppendDummy();
19913 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19914
19915 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19916
19917 m_errorMonitor->VerifyNotFound();
19918}
19919
19920TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019921 TEST_DESCRIPTION(
19922 "Test that pipeline validation accepts the relaxed type matching rules "
19923 "set out in 14.1.3: fundamental type must match, and producer side must "
19924 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019925 m_errorMonitor->ExpectSuccess();
19926
19927 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19928
19929 ASSERT_NO_FATAL_FAILURE(InitState());
19930 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19931
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019932 char const *vsSource =
19933 "#version 450\n"
19934 "out gl_PerVertex {\n"
19935 " vec4 gl_Position;\n"
19936 "};\n"
19937 "layout(location=0) out vec3 x;\n"
19938 "layout(location=1) out ivec3 y;\n"
19939 "layout(location=2) out vec3 z;\n"
19940 "void main(){\n"
19941 " gl_Position = vec4(0);\n"
19942 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19943 "}\n";
19944 char const *fsSource =
19945 "#version 450\n"
19946 "\n"
19947 "layout(location=0) out vec4 color;\n"
19948 "layout(location=0) in float x;\n"
19949 "layout(location=1) flat in int y;\n"
19950 "layout(location=2) in vec2 z;\n"
19951 "void main(){\n"
19952 " color = vec4(1 + x + y + z.x);\n"
19953 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019954
19955 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19956 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19957
19958 VkPipelineObj pipe(m_device);
19959 pipe.AddColorAttachment();
19960 pipe.AddShader(&vs);
19961 pipe.AddShader(&fs);
19962
19963 VkDescriptorSetObj descriptorSet(m_device);
19964 descriptorSet.AppendDummy();
19965 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19966
19967 VkResult err = VK_SUCCESS;
19968 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19969 ASSERT_VK_SUCCESS(err);
19970
19971 m_errorMonitor->VerifyNotFound();
19972}
19973
19974TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019975 TEST_DESCRIPTION(
19976 "Test that pipeline validation accepts per-vertex variables "
19977 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019978 m_errorMonitor->ExpectSuccess();
19979
19980 ASSERT_NO_FATAL_FAILURE(InitState());
19981 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19982
19983 if (!m_device->phy().features().tessellationShader) {
19984 printf("Device does not support tessellation shaders; skipped.\n");
19985 return;
19986 }
19987
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019988 char const *vsSource =
19989 "#version 450\n"
19990 "void main(){}\n";
19991 char const *tcsSource =
19992 "#version 450\n"
19993 "layout(location=0) out int x[];\n"
19994 "layout(vertices=3) out;\n"
19995 "void main(){\n"
19996 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19997 " gl_TessLevelInner[0] = 1;\n"
19998 " x[gl_InvocationID] = gl_InvocationID;\n"
19999 "}\n";
20000 char const *tesSource =
20001 "#version 450\n"
20002 "layout(triangles, equal_spacing, cw) in;\n"
20003 "layout(location=0) in int x[];\n"
20004 "out gl_PerVertex { vec4 gl_Position; };\n"
20005 "void main(){\n"
20006 " gl_Position.xyz = gl_TessCoord;\n"
20007 " gl_Position.w = x[0] + x[1] + x[2];\n"
20008 "}\n";
20009 char const *fsSource =
20010 "#version 450\n"
20011 "layout(location=0) out vec4 color;\n"
20012 "void main(){\n"
20013 " color = vec4(1);\n"
20014 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020015
20016 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20017 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
20018 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
20019 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20020
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020021 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
20022 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020023
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020024 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020025
20026 VkPipelineObj pipe(m_device);
20027 pipe.SetInputAssembly(&iasci);
20028 pipe.SetTessellation(&tsci);
20029 pipe.AddColorAttachment();
20030 pipe.AddShader(&vs);
20031 pipe.AddShader(&tcs);
20032 pipe.AddShader(&tes);
20033 pipe.AddShader(&fs);
20034
20035 VkDescriptorSetObj descriptorSet(m_device);
20036 descriptorSet.AppendDummy();
20037 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20038
20039 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20040
20041 m_errorMonitor->VerifyNotFound();
20042}
20043
20044TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020045 TEST_DESCRIPTION(
20046 "Test that pipeline validation accepts a user-defined "
20047 "interface block passed into the geometry shader. This "
20048 "is interesting because the 'extra' array level is not "
20049 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020050 m_errorMonitor->ExpectSuccess();
20051
20052 ASSERT_NO_FATAL_FAILURE(InitState());
20053 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20054
20055 if (!m_device->phy().features().geometryShader) {
20056 printf("Device does not support geometry shaders; skipped.\n");
20057 return;
20058 }
20059
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020060 char const *vsSource =
20061 "#version 450\n"
20062 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
20063 "void main(){\n"
20064 " vs_out.x = vec4(1);\n"
20065 "}\n";
20066 char const *gsSource =
20067 "#version 450\n"
20068 "layout(triangles) in;\n"
20069 "layout(triangle_strip, max_vertices=3) out;\n"
20070 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
20071 "out gl_PerVertex { vec4 gl_Position; };\n"
20072 "void main() {\n"
20073 " gl_Position = gs_in[0].x;\n"
20074 " EmitVertex();\n"
20075 "}\n";
20076 char const *fsSource =
20077 "#version 450\n"
20078 "layout(location=0) out vec4 color;\n"
20079 "void main(){\n"
20080 " color = vec4(1);\n"
20081 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020082
20083 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20084 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
20085 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20086
20087 VkPipelineObj pipe(m_device);
20088 pipe.AddColorAttachment();
20089 pipe.AddShader(&vs);
20090 pipe.AddShader(&gs);
20091 pipe.AddShader(&fs);
20092
20093 VkDescriptorSetObj descriptorSet(m_device);
20094 descriptorSet.AppendDummy();
20095 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20096
20097 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20098
20099 m_errorMonitor->VerifyNotFound();
20100}
20101
20102TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020103 TEST_DESCRIPTION(
20104 "Test that pipeline validation accepts basic use of 64bit vertex "
20105 "attributes. This is interesting because they consume multiple "
20106 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020107 m_errorMonitor->ExpectSuccess();
20108
20109 ASSERT_NO_FATAL_FAILURE(InitState());
20110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20111
20112 if (!m_device->phy().features().shaderFloat64) {
20113 printf("Device does not support 64bit vertex attributes; skipped.\n");
20114 return;
20115 }
20116
20117 VkVertexInputBindingDescription input_bindings[1];
20118 memset(input_bindings, 0, sizeof(input_bindings));
20119
20120 VkVertexInputAttributeDescription input_attribs[4];
20121 memset(input_attribs, 0, sizeof(input_attribs));
20122 input_attribs[0].location = 0;
20123 input_attribs[0].offset = 0;
20124 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20125 input_attribs[1].location = 2;
20126 input_attribs[1].offset = 32;
20127 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20128 input_attribs[2].location = 4;
20129 input_attribs[2].offset = 64;
20130 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20131 input_attribs[3].location = 6;
20132 input_attribs[3].offset = 96;
20133 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020135 char const *vsSource =
20136 "#version 450\n"
20137 "\n"
20138 "layout(location=0) in dmat4 x;\n"
20139 "out gl_PerVertex {\n"
20140 " vec4 gl_Position;\n"
20141 "};\n"
20142 "void main(){\n"
20143 " gl_Position = vec4(x[0][0]);\n"
20144 "}\n";
20145 char const *fsSource =
20146 "#version 450\n"
20147 "\n"
20148 "layout(location=0) out vec4 color;\n"
20149 "void main(){\n"
20150 " color = vec4(1);\n"
20151 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020152
20153 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20154 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20155
20156 VkPipelineObj pipe(m_device);
20157 pipe.AddColorAttachment();
20158 pipe.AddShader(&vs);
20159 pipe.AddShader(&fs);
20160
20161 pipe.AddVertexInputBindings(input_bindings, 1);
20162 pipe.AddVertexInputAttribs(input_attribs, 4);
20163
20164 VkDescriptorSetObj descriptorSet(m_device);
20165 descriptorSet.AppendDummy();
20166 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20167
20168 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20169
20170 m_errorMonitor->VerifyNotFound();
20171}
20172
20173TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
20174 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
20175 m_errorMonitor->ExpectSuccess();
20176
20177 ASSERT_NO_FATAL_FAILURE(InitState());
20178
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020179 char const *vsSource =
20180 "#version 450\n"
20181 "\n"
20182 "out gl_PerVertex {\n"
20183 " vec4 gl_Position;\n"
20184 "};\n"
20185 "void main(){\n"
20186 " gl_Position = vec4(1);\n"
20187 "}\n";
20188 char const *fsSource =
20189 "#version 450\n"
20190 "\n"
20191 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
20192 "layout(location=0) out vec4 color;\n"
20193 "void main() {\n"
20194 " color = subpassLoad(x);\n"
20195 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020196
20197 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20198 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20199
20200 VkPipelineObj pipe(m_device);
20201 pipe.AddShader(&vs);
20202 pipe.AddShader(&fs);
20203 pipe.AddColorAttachment();
20204 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20205
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020206 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
20207 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020208 VkDescriptorSetLayout dsl;
20209 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20210 ASSERT_VK_SUCCESS(err);
20211
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020212 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020213 VkPipelineLayout pl;
20214 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20215 ASSERT_VK_SUCCESS(err);
20216
20217 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020218 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20219 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20220 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
20221 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20222 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 -060020223 };
20224 VkAttachmentReference color = {
20225 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20226 };
20227 VkAttachmentReference input = {
20228 1, VK_IMAGE_LAYOUT_GENERAL,
20229 };
20230
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020231 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020232
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020233 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020234 VkRenderPass rp;
20235 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20236 ASSERT_VK_SUCCESS(err);
20237
20238 // should be OK. would go wrong here if it's going to...
20239 pipe.CreateVKPipeline(pl, rp);
20240
20241 m_errorMonitor->VerifyNotFound();
20242
20243 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20244 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20245 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20246}
20247
20248TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020249 TEST_DESCRIPTION(
20250 "Test that pipeline validation accepts a compute pipeline which declares a "
20251 "descriptor-backed resource which is not provided, but the shader does not "
20252 "statically use it. This is interesting because it requires compute pipelines "
20253 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020254 m_errorMonitor->ExpectSuccess();
20255
20256 ASSERT_NO_FATAL_FAILURE(InitState());
20257
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020258 char const *csSource =
20259 "#version 450\n"
20260 "\n"
20261 "layout(local_size_x=1) in;\n"
20262 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
20263 "void main(){\n"
20264 " // x is not used.\n"
20265 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020266
20267 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20268
20269 VkDescriptorSetObj descriptorSet(m_device);
20270 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20271
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020272 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20273 nullptr,
20274 0,
20275 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20276 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20277 descriptorSet.GetPipelineLayout(),
20278 VK_NULL_HANDLE,
20279 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020280
20281 VkPipeline pipe;
20282 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20283
20284 m_errorMonitor->VerifyNotFound();
20285
20286 if (err == VK_SUCCESS) {
20287 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20288 }
20289}
20290
20291TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020292 TEST_DESCRIPTION(
20293 "Test that pipeline validation accepts a shader consuming only the "
20294 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020295 m_errorMonitor->ExpectSuccess();
20296
20297 ASSERT_NO_FATAL_FAILURE(InitState());
20298
20299 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020300 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20301 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20302 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020303 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020304 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020305 VkDescriptorSetLayout dsl;
20306 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20307 ASSERT_VK_SUCCESS(err);
20308
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020309 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020310 VkPipelineLayout pl;
20311 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20312 ASSERT_VK_SUCCESS(err);
20313
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020314 char const *csSource =
20315 "#version 450\n"
20316 "\n"
20317 "layout(local_size_x=1) in;\n"
20318 "layout(set=0, binding=0) uniform sampler s;\n"
20319 "layout(set=0, binding=1) uniform texture2D t;\n"
20320 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20321 "void main() {\n"
20322 " x = texture(sampler2D(t, s), vec2(0));\n"
20323 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020324 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20325
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020326 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20327 nullptr,
20328 0,
20329 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20330 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20331 pl,
20332 VK_NULL_HANDLE,
20333 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020334
20335 VkPipeline pipe;
20336 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20337
20338 m_errorMonitor->VerifyNotFound();
20339
20340 if (err == VK_SUCCESS) {
20341 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20342 }
20343
20344 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20345 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20346}
20347
20348TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020349 TEST_DESCRIPTION(
20350 "Test that pipeline validation accepts a shader consuming only the "
20351 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020352 m_errorMonitor->ExpectSuccess();
20353
20354 ASSERT_NO_FATAL_FAILURE(InitState());
20355
20356 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020357 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20358 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20359 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020360 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020361 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020362 VkDescriptorSetLayout dsl;
20363 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20364 ASSERT_VK_SUCCESS(err);
20365
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020366 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020367 VkPipelineLayout pl;
20368 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20369 ASSERT_VK_SUCCESS(err);
20370
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020371 char const *csSource =
20372 "#version 450\n"
20373 "\n"
20374 "layout(local_size_x=1) in;\n"
20375 "layout(set=0, binding=0) uniform texture2D t;\n"
20376 "layout(set=0, binding=1) uniform sampler s;\n"
20377 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20378 "void main() {\n"
20379 " x = texture(sampler2D(t, s), vec2(0));\n"
20380 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020381 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20382
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020383 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20384 nullptr,
20385 0,
20386 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20387 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20388 pl,
20389 VK_NULL_HANDLE,
20390 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020391
20392 VkPipeline pipe;
20393 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20394
20395 m_errorMonitor->VerifyNotFound();
20396
20397 if (err == VK_SUCCESS) {
20398 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20399 }
20400
20401 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20402 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20403}
20404
20405TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020406 TEST_DESCRIPTION(
20407 "Test that pipeline validation accepts a shader consuming "
20408 "both the sampler and the image of a combined image+sampler "
20409 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020410 m_errorMonitor->ExpectSuccess();
20411
20412 ASSERT_NO_FATAL_FAILURE(InitState());
20413
20414 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020415 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20416 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020417 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020418 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020419 VkDescriptorSetLayout dsl;
20420 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20421 ASSERT_VK_SUCCESS(err);
20422
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020423 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020424 VkPipelineLayout pl;
20425 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20426 ASSERT_VK_SUCCESS(err);
20427
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020428 char const *csSource =
20429 "#version 450\n"
20430 "\n"
20431 "layout(local_size_x=1) in;\n"
20432 "layout(set=0, binding=0) uniform texture2D t;\n"
20433 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20434 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20435 "void main() {\n"
20436 " x = texture(sampler2D(t, s), vec2(0));\n"
20437 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020438 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20439
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020440 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20441 nullptr,
20442 0,
20443 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20444 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20445 pl,
20446 VK_NULL_HANDLE,
20447 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020448
20449 VkPipeline pipe;
20450 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20451
20452 m_errorMonitor->VerifyNotFound();
20453
20454 if (err == VK_SUCCESS) {
20455 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20456 }
20457
20458 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20459 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20460}
20461
20462TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20463 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20464
20465 ASSERT_NO_FATAL_FAILURE(InitState());
20466
20467 // Positive test to check parameter_validation and unique_objects support
20468 // for NV_dedicated_allocation
20469 uint32_t extension_count = 0;
20470 bool supports_nv_dedicated_allocation = false;
20471 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20472 ASSERT_VK_SUCCESS(err);
20473
20474 if (extension_count > 0) {
20475 std::vector<VkExtensionProperties> available_extensions(extension_count);
20476
20477 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20478 ASSERT_VK_SUCCESS(err);
20479
20480 for (const auto &extension_props : available_extensions) {
20481 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20482 supports_nv_dedicated_allocation = true;
20483 }
20484 }
20485 }
20486
20487 if (supports_nv_dedicated_allocation) {
20488 m_errorMonitor->ExpectSuccess();
20489
20490 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20491 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20492 dedicated_buffer_create_info.pNext = nullptr;
20493 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20494
20495 uint32_t queue_family_index = 0;
20496 VkBufferCreateInfo buffer_create_info = {};
20497 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20498 buffer_create_info.pNext = &dedicated_buffer_create_info;
20499 buffer_create_info.size = 1024;
20500 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20501 buffer_create_info.queueFamilyIndexCount = 1;
20502 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20503
20504 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070020505 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020506 ASSERT_VK_SUCCESS(err);
20507
20508 VkMemoryRequirements memory_reqs;
20509 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20510
20511 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20512 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20513 dedicated_memory_info.pNext = nullptr;
20514 dedicated_memory_info.buffer = buffer;
20515 dedicated_memory_info.image = VK_NULL_HANDLE;
20516
20517 VkMemoryAllocateInfo memory_info = {};
20518 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20519 memory_info.pNext = &dedicated_memory_info;
20520 memory_info.allocationSize = memory_reqs.size;
20521
20522 bool pass;
20523 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20524 ASSERT_TRUE(pass);
20525
20526 VkDeviceMemory buffer_memory;
20527 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20528 ASSERT_VK_SUCCESS(err);
20529
20530 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20531 ASSERT_VK_SUCCESS(err);
20532
20533 vkDestroyBuffer(m_device->device(), buffer, NULL);
20534 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20535
20536 m_errorMonitor->VerifyNotFound();
20537 }
20538}
20539
20540TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20541 VkResult err;
20542
20543 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20544
20545 ASSERT_NO_FATAL_FAILURE(InitState());
20546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20547
20548 std::vector<const char *> device_extension_names;
20549 auto features = m_device->phy().features();
20550 // Artificially disable support for non-solid fill modes
20551 features.fillModeNonSolid = false;
20552 // The sacrificial device object
20553 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20554
20555 VkRenderpassObj render_pass(&test_device);
20556
20557 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20558 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20559 pipeline_layout_ci.setLayoutCount = 0;
20560 pipeline_layout_ci.pSetLayouts = NULL;
20561
20562 VkPipelineLayout pipeline_layout;
20563 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20564 ASSERT_VK_SUCCESS(err);
20565
20566 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20567 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20568 rs_ci.pNext = nullptr;
20569 rs_ci.lineWidth = 1.0f;
20570 rs_ci.rasterizerDiscardEnable = true;
20571
20572 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20573 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20574
20575 // Set polygonMode=FILL. No error is expected
20576 m_errorMonitor->ExpectSuccess();
20577 {
20578 VkPipelineObj pipe(&test_device);
20579 pipe.AddShader(&vs);
20580 pipe.AddShader(&fs);
20581 pipe.AddColorAttachment();
20582 // Set polygonMode to a good value
20583 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20584 pipe.SetRasterization(&rs_ci);
20585 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20586 }
20587 m_errorMonitor->VerifyNotFound();
20588
20589 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20590}
20591
20592TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20593 VkResult err;
20594 ASSERT_NO_FATAL_FAILURE(InitState());
20595 ASSERT_NO_FATAL_FAILURE(InitViewport());
20596 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20597
20598 VkPipelineLayout pipeline_layout;
20599 VkPushConstantRange pc_range = {};
20600 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20601 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20602 pipeline_layout_ci.pushConstantRangeCount = 1;
20603 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20604
20605 //
20606 // Check for invalid push constant ranges in pipeline layouts.
20607 //
20608 struct PipelineLayoutTestCase {
20609 VkPushConstantRange const range;
20610 char const *msg;
20611 };
20612
20613 // Check for overlapping ranges
20614 const uint32_t ranges_per_test = 5;
20615 struct OverlappingRangeTestCase {
20616 VkPushConstantRange const ranges[ranges_per_test];
20617 char const *msg;
20618 };
20619
20620 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020621 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
20622 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
20623 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
20624 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
20625 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
20626 ""},
20627 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
20628 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
20629 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
20630 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
20631 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
20632 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020633 for (const auto &iter : overlapping_range_tests_pos) {
20634 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20635 m_errorMonitor->ExpectSuccess();
20636 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20637 m_errorMonitor->VerifyNotFound();
20638 if (VK_SUCCESS == err) {
20639 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20640 }
20641 }
20642
20643 //
20644 // CmdPushConstants tests
20645 //
20646 const uint8_t dummy_values[100] = {};
20647
Tony Barbour552f6c02016-12-21 14:34:07 -070020648 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020649
20650 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020651 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
20652 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
20653 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
20654 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
20655 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
20656 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020657
20658 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20659 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020660 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
20661 {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 -060020662 };
20663
20664 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20665 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20666 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20667 ASSERT_VK_SUCCESS(err);
20668 for (const auto &iter : cmd_overlap_tests_pos) {
20669 m_errorMonitor->ExpectSuccess();
20670 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020671 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020672 m_errorMonitor->VerifyNotFound();
20673 }
20674 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20675
Tony Barbour552f6c02016-12-21 14:34:07 -070020676 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020677}
20678
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020679#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020680TEST_F(VkPositiveLayerTest, LongFenceChain)
20681{
20682 m_errorMonitor->ExpectSuccess();
20683
20684 ASSERT_NO_FATAL_FAILURE(InitState());
20685 VkResult err;
20686
20687 std::vector<VkFence> fences;
20688
20689 const int chainLength = 32768;
20690
20691 for (int i = 0; i < chainLength; i++) {
20692 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20693 VkFence fence;
20694 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20695 ASSERT_VK_SUCCESS(err);
20696
20697 fences.push_back(fence);
20698
20699 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20700 0, nullptr, 0, nullptr };
20701 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20702 ASSERT_VK_SUCCESS(err);
20703
20704 }
20705
20706 // BOOM, stack overflow.
20707 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20708
20709 for (auto fence : fences)
20710 vkDestroyFence(m_device->device(), fence, nullptr);
20711
20712 m_errorMonitor->VerifyNotFound();
20713}
20714#endif
20715
Cody Northrop1242dfd2016-07-13 17:24:59 -060020716#if defined(ANDROID) && defined(VALIDATION_APK)
20717static bool initialized = false;
20718static bool active = false;
20719
20720// Convert Intents to argv
20721// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020722std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020723 std::vector<std::string> args;
20724 JavaVM &vm = *app.activity->vm;
20725 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020726 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020727
20728 JNIEnv &env = *p_env;
20729 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020730 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020731 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020732 jmethodID get_string_extra_method =
20733 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020734 jvalue get_string_extra_args;
20735 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020736 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020737
20738 std::string args_str;
20739 if (extra_str) {
20740 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20741 args_str = extra_utf;
20742 env.ReleaseStringUTFChars(extra_str, extra_utf);
20743 env.DeleteLocalRef(extra_str);
20744 }
20745
20746 env.DeleteLocalRef(get_string_extra_args.l);
20747 env.DeleteLocalRef(intent);
20748 vm.DetachCurrentThread();
20749
20750 // split args_str
20751 std::stringstream ss(args_str);
20752 std::string arg;
20753 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020754 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020755 }
20756
20757 return args;
20758}
20759
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020760static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020761
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020762static void processCommand(struct android_app *app, int32_t cmd) {
20763 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020764 case APP_CMD_INIT_WINDOW: {
20765 if (app->window) {
20766 initialized = true;
20767 }
20768 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020769 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020770 case APP_CMD_GAINED_FOCUS: {
20771 active = true;
20772 break;
20773 }
20774 case APP_CMD_LOST_FOCUS: {
20775 active = false;
20776 break;
20777 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020778 }
20779}
20780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020781void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020782 app_dummy();
20783
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020784 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020785
20786 int vulkanSupport = InitVulkan();
20787 if (vulkanSupport == 0) {
20788 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20789 return;
20790 }
20791
20792 app->onAppCmd = processCommand;
20793 app->onInputEvent = processInput;
20794
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020795 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020796 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020797 struct android_poll_source *source;
20798 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020799 if (source) {
20800 source->process(app, source);
20801 }
20802
20803 if (app->destroyRequested != 0) {
20804 VkTestFramework::Finish();
20805 return;
20806 }
20807 }
20808
20809 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020810 // Use the following key to send arguments to gtest, i.e.
20811 // --es args "--gtest_filter=-VkLayerTest.foo"
20812 const char key[] = "args";
20813 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020814
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020815 std::string filter = "";
20816 if (args.size() > 0) {
20817 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20818 filter += args[0];
20819 } else {
20820 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20821 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020822
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020823 int argc = 2;
20824 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20825 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020826
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020827 // Route output to files until we can override the gtest output
20828 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20829 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020830
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020831 ::testing::InitGoogleTest(&argc, argv);
20832 VkTestFramework::InitArgs(&argc, argv);
20833 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020835 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020837 if (result != 0) {
20838 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20839 } else {
20840 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20841 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020842
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020843 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020844
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020845 fclose(stdout);
20846 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020847
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020848 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020849
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020850 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020851 }
20852 }
20853}
20854#endif
20855
Tony Barbour300a6082015-04-07 13:44:53 -060020856int main(int argc, char **argv) {
20857 int result;
20858
Cody Northrop8e54a402016-03-08 22:25:52 -070020859#ifdef ANDROID
20860 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020861 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070020862#endif
20863
Tony Barbour300a6082015-04-07 13:44:53 -060020864 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020865 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020866
20867 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20868
20869 result = RUN_ALL_TESTS();
20870
Tony Barbour6918cd52015-04-09 12:58:51 -060020871 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020872 return result;
20873}