blob: bac4c3ec0ad176c83530123d0e8dfce806c4ad5f [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;
2644 VkMemoryPropertyFlags reqs = 0;
2645 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2646 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002647 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002648 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002649 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002650 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2652 "was created with a sample count "
2653 "of VK_SAMPLE_COUNT_8_BIT but "
2654 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002655 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2656 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002657 m_errorMonitor->VerifyFound();
2658 m_commandBuffer->EndCommandBuffer();
2659 }
2660
2661 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2662 // image to buffer
2663 {
2664 vk_testing::Buffer dst_buffer;
2665 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2666 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002667 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002668 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002669 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002670 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2672 "was created with a sample count "
2673 "of VK_SAMPLE_COUNT_2_BIT but "
2674 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002675 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002676 dst_buffer.handle(), 1, &copy_region);
2677 m_errorMonitor->VerifyFound();
2678 m_commandBuffer->EndCommandBuffer();
2679 }
2680}
2681
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002682TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002683 ASSERT_NO_FATAL_FAILURE(InitState());
2684
2685 VkImageObj src_image(m_device);
2686 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2687 VkImageObj dst_image(m_device);
2688 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2689 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002690 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 -06002691
2692 VkImageBlit blitRegion = {};
2693 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2694 blitRegion.srcSubresource.baseArrayLayer = 0;
2695 blitRegion.srcSubresource.layerCount = 1;
2696 blitRegion.srcSubresource.mipLevel = 0;
2697 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2698 blitRegion.dstSubresource.baseArrayLayer = 0;
2699 blitRegion.dstSubresource.layerCount = 1;
2700 blitRegion.dstSubresource.mipLevel = 0;
2701
Dave Houlton34df4cb2016-12-01 16:43:06 -07002702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
2703
2704 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
2705 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002706
2707 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07002708 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002709 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
2710 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002711
2712 m_errorMonitor->VerifyFound();
2713
Dave Houlton34df4cb2016-12-01 16:43:06 -07002714 // Test should generate 2 VU failures
2715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
2716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002717
2718 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002719 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
2720 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002721
Dave Houlton34df4cb2016-12-01 16:43:06 -07002722 // TODO: Note that this only verifies that at least one of the VU enums was found
2723 // 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 -06002724 m_errorMonitor->VerifyFound();
2725
Tony Barbour552f6c02016-12-21 14:34:07 -07002726 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002727}
2728
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002729TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2730 VkResult err;
2731 bool pass;
2732
2733 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2734 ASSERT_NO_FATAL_FAILURE(InitState());
2735
2736 // If w/d/h granularity is 1, test is not meaningful
2737 // TODO: When virtual device limits are available, create a set of limits for this test that
2738 // will always have a granularity of > 1 for w, h, and d
2739 auto index = m_device->graphics_queue_node_index_;
2740 auto queue_family_properties = m_device->phy().queue_properties();
2741
2742 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2743 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2744 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2745 return;
2746 }
2747
2748 // Create two images of different types and try to copy between them
2749 VkImage srcImage;
2750 VkImage dstImage;
2751 VkDeviceMemory srcMem;
2752 VkDeviceMemory destMem;
2753 VkMemoryRequirements memReqs;
2754
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002755 VkImageCreateInfo image_create_info = {};
2756 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2757 image_create_info.pNext = NULL;
2758 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2759 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2760 image_create_info.extent.width = 32;
2761 image_create_info.extent.height = 32;
2762 image_create_info.extent.depth = 1;
2763 image_create_info.mipLevels = 1;
2764 image_create_info.arrayLayers = 4;
2765 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2766 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2767 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2768 image_create_info.flags = 0;
2769
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002770 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002771 ASSERT_VK_SUCCESS(err);
2772
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002773 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002774 ASSERT_VK_SUCCESS(err);
2775
2776 // Allocate memory
2777 VkMemoryAllocateInfo memAlloc = {};
2778 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2779 memAlloc.pNext = NULL;
2780 memAlloc.allocationSize = 0;
2781 memAlloc.memoryTypeIndex = 0;
2782
2783 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2784 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002785 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002786 ASSERT_TRUE(pass);
2787 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2788 ASSERT_VK_SUCCESS(err);
2789
2790 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2791 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002792 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002793 ASSERT_VK_SUCCESS(err);
2794 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2795 ASSERT_VK_SUCCESS(err);
2796
2797 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2798 ASSERT_VK_SUCCESS(err);
2799 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2800 ASSERT_VK_SUCCESS(err);
2801
Tony Barbour552f6c02016-12-21 14:34:07 -07002802 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002803 VkImageCopy copyRegion;
2804 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2805 copyRegion.srcSubresource.mipLevel = 0;
2806 copyRegion.srcSubresource.baseArrayLayer = 0;
2807 copyRegion.srcSubresource.layerCount = 1;
2808 copyRegion.srcOffset.x = 0;
2809 copyRegion.srcOffset.y = 0;
2810 copyRegion.srcOffset.z = 0;
2811 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2812 copyRegion.dstSubresource.mipLevel = 0;
2813 copyRegion.dstSubresource.baseArrayLayer = 0;
2814 copyRegion.dstSubresource.layerCount = 1;
2815 copyRegion.dstOffset.x = 0;
2816 copyRegion.dstOffset.y = 0;
2817 copyRegion.dstOffset.z = 0;
2818 copyRegion.extent.width = 1;
2819 copyRegion.extent.height = 1;
2820 copyRegion.extent.depth = 1;
2821
2822 // Introduce failure by setting srcOffset to a bad granularity value
2823 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2825 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002826 m_errorMonitor->VerifyFound();
2827
2828 // Introduce failure by setting extent to a bad granularity value
2829 copyRegion.srcOffset.y = 0;
2830 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2832 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002833 m_errorMonitor->VerifyFound();
2834
2835 // Now do some buffer/image copies
2836 vk_testing::Buffer buffer;
2837 VkMemoryPropertyFlags reqs = 0;
2838 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2839 VkBufferImageCopy region = {};
2840 region.bufferOffset = 0;
2841 region.bufferRowLength = 3;
2842 region.bufferImageHeight = 128;
2843 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2844 region.imageSubresource.layerCount = 1;
2845 region.imageExtent.height = 16;
2846 region.imageExtent.width = 16;
2847 region.imageExtent.depth = 1;
2848 region.imageOffset.x = 0;
2849 region.imageOffset.y = 0;
2850 region.imageOffset.z = 0;
2851
2852 // Introduce failure by setting bufferRowLength to a bad granularity value
2853 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2855 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2856 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002857 m_errorMonitor->VerifyFound();
2858 region.bufferRowLength = 128;
2859
2860 // Introduce failure by setting bufferOffset to a bad granularity value
2861 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2863 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2864 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002865 m_errorMonitor->VerifyFound();
2866 region.bufferOffset = 0;
2867
2868 // Introduce failure by setting bufferImageHeight to a bad granularity value
2869 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2871 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2872 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002873 m_errorMonitor->VerifyFound();
2874 region.bufferImageHeight = 128;
2875
2876 // Introduce failure by setting imageExtent to a bad granularity value
2877 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2879 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2880 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002881 m_errorMonitor->VerifyFound();
2882 region.imageExtent.width = 16;
2883
2884 // Introduce failure by setting imageOffset to a bad granularity value
2885 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002886 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2887 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2888 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002889 m_errorMonitor->VerifyFound();
2890
Tony Barbour552f6c02016-12-21 14:34:07 -07002891 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002892
2893 vkDestroyImage(m_device->device(), srcImage, NULL);
2894 vkDestroyImage(m_device->device(), dstImage, NULL);
2895 vkFreeMemory(m_device->device(), srcMem, NULL);
2896 vkFreeMemory(m_device->device(), destMem, NULL);
2897}
2898
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002899TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002900 TEST_DESCRIPTION(
2901 "Submit command buffer created using one queue family and "
2902 "attempt to submit them on a queue created in a different "
2903 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002904
Cody Northropc31a84f2016-08-22 10:41:47 -06002905 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002906 // This test is meaningless unless we have multiple queue families
2907 auto queue_family_properties = m_device->phy().queue_properties();
2908 if (queue_family_properties.size() < 2) {
2909 return;
2910 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002912 // Get safe index of another queue family
2913 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2914 ASSERT_NO_FATAL_FAILURE(InitState());
2915 // Create a second queue using a different queue family
2916 VkQueue other_queue;
2917 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2918
2919 // Record an empty cmd buffer
2920 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2921 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2922 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2923 vkEndCommandBuffer(m_commandBuffer->handle());
2924
2925 // And submit on the wrong queue
2926 VkSubmitInfo submit_info = {};
2927 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2928 submit_info.commandBufferCount = 1;
2929 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002930 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002931
2932 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002933}
2934
Chris Forbes4c24a922016-11-16 08:59:10 +13002935TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2936 ASSERT_NO_FATAL_FAILURE(InitState());
2937
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002938 // There are no attachments, but refer to attachment 0.
2939 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002940 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002941 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002942 };
2943
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002944 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002945 VkRenderPass rp;
2946
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002947 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002949 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2950 m_errorMonitor->VerifyFound();
2951}
2952
Chris Forbesa58c4522016-09-28 15:19:39 +13002953TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2954 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2955 ASSERT_NO_FATAL_FAILURE(InitState());
2956
2957 // A renderpass with two subpasses, both writing the same attachment.
2958 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002959 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2960 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
2961 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13002962 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002963 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13002964 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002965 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
2966 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13002967 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002968 VkSubpassDependency dep = {0,
2969 1,
2970 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2971 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2972 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2973 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2974 VK_DEPENDENCY_BY_REGION_BIT};
2975 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13002976 VkRenderPass rp;
2977 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2978 ASSERT_VK_SUCCESS(err);
2979
2980 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002981 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 +13002982 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2983
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002984 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13002985 VkFramebuffer fb;
2986 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2987 ASSERT_VK_SUCCESS(err);
2988
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002989 char const *vsSource =
2990 "#version 450\n"
2991 "void main() { gl_Position = vec4(1); }\n";
2992 char const *fsSource =
2993 "#version 450\n"
2994 "layout(location=0) out vec4 color;\n"
2995 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13002996
2997 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2998 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2999 VkPipelineObj pipe(m_device);
3000 pipe.AddColorAttachment();
3001 pipe.AddShader(&vs);
3002 pipe.AddShader(&fs);
3003 VkViewport view_port = {};
3004 m_viewports.push_back(view_port);
3005 pipe.SetViewport(m_viewports);
3006 VkRect2D rect = {};
3007 m_scissors.push_back(rect);
3008 pipe.SetScissor(m_scissors);
3009
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003010 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003011 VkPipelineLayout pl;
3012 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3013 ASSERT_VK_SUCCESS(err);
3014 pipe.CreateVKPipeline(pl, rp);
3015
Tony Barbour552f6c02016-12-21 14:34:07 -07003016 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003017
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003018 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3019 nullptr,
3020 rp,
3021 fb,
3022 {{
3023 0, 0,
3024 },
3025 {32, 32}},
3026 0,
3027 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003028
3029 // subtest 1: bind in the wrong subpass
3030 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3031 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003032 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 +13003033 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3034 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3035 m_errorMonitor->VerifyFound();
3036
3037 vkCmdEndRenderPass(m_commandBuffer->handle());
3038
3039 // subtest 2: bind in correct subpass, then transition to next subpass
3040 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3041 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3042 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003043 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 +13003044 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3045 m_errorMonitor->VerifyFound();
3046
3047 vkCmdEndRenderPass(m_commandBuffer->handle());
3048
Tony Barbour552f6c02016-12-21 14:34:07 -07003049 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003050
3051 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3052 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3053 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3054}
3055
Tony Barbour4e919972016-08-09 13:27:40 -06003056TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003057 TEST_DESCRIPTION(
3058 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3059 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003060 ASSERT_NO_FATAL_FAILURE(InitState());
3061 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3062
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3064 "Cannot execute a render pass with renderArea "
3065 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003066
3067 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3068 m_renderPassBeginInfo.renderArea.extent.width = 257;
3069 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003070 m_commandBuffer->BeginCommandBuffer();
3071 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003072 m_errorMonitor->VerifyFound();
3073}
3074
3075TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003076 TEST_DESCRIPTION(
3077 "Generate INDEPENDENT_BLEND by disabling independent "
3078 "blend and then specifying different blend states for two "
3079 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003080 VkPhysicalDeviceFeatures features = {};
3081 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003082 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003083
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3085 "Invalid Pipeline CreateInfo: If independent blend feature not "
3086 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003087
Cody Northropc31a84f2016-08-22 10:41:47 -06003088 VkDescriptorSetObj descriptorSet(m_device);
3089 descriptorSet.AppendDummy();
3090 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003091
Cody Northropc31a84f2016-08-22 10:41:47 -06003092 VkPipelineObj pipeline(m_device);
3093 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003094 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003095 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003096
Cody Northropc31a84f2016-08-22 10:41:47 -06003097 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3098 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3099 att_state1.blendEnable = VK_TRUE;
3100 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3101 att_state2.blendEnable = VK_FALSE;
3102 pipeline.AddColorAttachment(0, &att_state1);
3103 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003104 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003105 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003106}
3107
Chris Forbes26ec2122016-11-29 08:58:33 +13003108#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003109TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3110 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3111 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003112 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003113
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3115 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003116
3117 // Create a renderPass with a single color attachment
3118 VkAttachmentReference attach = {};
3119 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3120 VkSubpassDescription subpass = {};
3121 VkRenderPassCreateInfo rpci = {};
3122 rpci.subpassCount = 1;
3123 rpci.pSubpasses = &subpass;
3124 rpci.attachmentCount = 1;
3125 VkAttachmentDescription attach_desc = {};
3126 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3127 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3128 rpci.pAttachments = &attach_desc;
3129 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3130 VkRenderPass rp;
3131 subpass.pDepthStencilAttachment = &attach;
3132 subpass.pColorAttachments = NULL;
3133 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3134 m_errorMonitor->VerifyFound();
3135}
Chris Forbes26ec2122016-11-29 08:58:33 +13003136#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003137
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003138TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003139 TEST_DESCRIPTION(
3140 "Create a framebuffer where a subpass has a preserve "
3141 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003142
3143 ASSERT_NO_FATAL_FAILURE(InitState());
3144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3145
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003147
3148 VkAttachmentReference color_attach = {};
3149 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3150 color_attach.attachment = 0;
3151 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3152 VkSubpassDescription subpass = {};
3153 subpass.colorAttachmentCount = 1;
3154 subpass.pColorAttachments = &color_attach;
3155 subpass.preserveAttachmentCount = 1;
3156 subpass.pPreserveAttachments = &preserve_attachment;
3157
3158 VkRenderPassCreateInfo rpci = {};
3159 rpci.subpassCount = 1;
3160 rpci.pSubpasses = &subpass;
3161 rpci.attachmentCount = 1;
3162 VkAttachmentDescription attach_desc = {};
3163 attach_desc.format = VK_FORMAT_UNDEFINED;
3164 rpci.pAttachments = &attach_desc;
3165 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3166 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003167 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003168
3169 m_errorMonitor->VerifyFound();
3170
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003171 if (result == VK_SUCCESS) {
3172 vkDestroyRenderPass(m_device->device(), rp, NULL);
3173 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003174}
3175
Chris Forbesc5389742016-06-29 11:49:23 +12003176TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003177 TEST_DESCRIPTION(
3178 "Ensure that CreateRenderPass produces a validation error "
3179 "when the source of a subpass multisample resolve "
3180 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003181
Chris Forbesc5389742016-06-29 11:49:23 +12003182 ASSERT_NO_FATAL_FAILURE(InitState());
3183
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003184 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3185 "Subpass 0 requests multisample resolve from attachment 0 which has "
3186 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003187
3188 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003189 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3190 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3191 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3192 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3193 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3194 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003195 };
3196
3197 VkAttachmentReference color = {
3198 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3199 };
3200
3201 VkAttachmentReference resolve = {
3202 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3203 };
3204
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003205 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003206
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003207 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003208
3209 VkRenderPass rp;
3210 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3211
3212 m_errorMonitor->VerifyFound();
3213
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003214 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003215}
3216
3217TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003218 TEST_DESCRIPTION(
3219 "Ensure CreateRenderPass produces a validation error "
3220 "when a subpass multisample resolve operation is "
3221 "requested, and the destination of that resolve has "
3222 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003223
Chris Forbesc5389742016-06-29 11:49:23 +12003224 ASSERT_NO_FATAL_FAILURE(InitState());
3225
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3227 "Subpass 0 requests multisample resolve into attachment 1, which "
3228 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003229
3230 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003231 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3232 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3233 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3234 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3235 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3236 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003237 };
3238
3239 VkAttachmentReference color = {
3240 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3241 };
3242
3243 VkAttachmentReference resolve = {
3244 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3245 };
3246
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003247 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003248
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003249 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003250
3251 VkRenderPass rp;
3252 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3253
3254 m_errorMonitor->VerifyFound();
3255
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003256 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003257}
3258
Chris Forbes3f128ef2016-06-29 14:58:53 +12003259TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003260 TEST_DESCRIPTION(
3261 "Ensure CreateRenderPass produces a validation error "
3262 "when the color and depth attachments used by a subpass "
3263 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003264
Chris Forbes3f128ef2016-06-29 14:58:53 +12003265 ASSERT_NO_FATAL_FAILURE(InitState());
3266
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3268 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003269
3270 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003271 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3272 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3273 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3274 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3275 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3276 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003277 };
3278
3279 VkAttachmentReference color[] = {
3280 {
3281 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3282 },
3283 {
3284 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3285 },
3286 };
3287
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003288 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003289
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003290 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003291
3292 VkRenderPass rp;
3293 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3294
3295 m_errorMonitor->VerifyFound();
3296
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003297 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003298}
3299
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003300TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003301 TEST_DESCRIPTION(
3302 "Hit errors when attempting to create a framebuffer :\n"
3303 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3304 " 2. Use a color image as depthStencil attachment\n"
3305 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3306 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3307 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3308 " 6. Framebuffer attachment where dimensions don't match\n"
3309 " 7. Framebuffer attachment w/o identity swizzle\n"
3310 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003311
3312 ASSERT_NO_FATAL_FAILURE(InitState());
3313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3314
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3316 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3317 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003318
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003319 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003320 VkAttachmentReference attach = {};
3321 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3322 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003323 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003324 VkRenderPassCreateInfo rpci = {};
3325 rpci.subpassCount = 1;
3326 rpci.pSubpasses = &subpass;
3327 rpci.attachmentCount = 1;
3328 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003329 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003330 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003331 rpci.pAttachments = &attach_desc;
3332 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3333 VkRenderPass rp;
3334 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3335 ASSERT_VK_SUCCESS(err);
3336
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003337 VkImageView ivs[2];
3338 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3339 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003340 VkFramebufferCreateInfo fb_info = {};
3341 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3342 fb_info.pNext = NULL;
3343 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003344 // Set mis-matching attachmentCount
3345 fb_info.attachmentCount = 2;
3346 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003347 fb_info.width = 100;
3348 fb_info.height = 100;
3349 fb_info.layers = 1;
3350
3351 VkFramebuffer fb;
3352 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3353
3354 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003355 if (err == VK_SUCCESS) {
3356 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3357 }
3358 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003359
3360 // Create a renderPass with a depth-stencil attachment created with
3361 // IMAGE_USAGE_COLOR_ATTACHMENT
3362 // Add our color attachment to pDepthStencilAttachment
3363 subpass.pDepthStencilAttachment = &attach;
3364 subpass.pColorAttachments = NULL;
3365 VkRenderPass rp_ds;
3366 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3367 ASSERT_VK_SUCCESS(err);
3368 // Set correct attachment count, but attachment has COLOR usage bit set
3369 fb_info.attachmentCount = 1;
3370 fb_info.renderPass = rp_ds;
3371
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003373 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3374
3375 m_errorMonitor->VerifyFound();
3376 if (err == VK_SUCCESS) {
3377 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3378 }
3379 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003380
3381 // Create new renderpass with alternate attachment format from fb
3382 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3383 subpass.pDepthStencilAttachment = NULL;
3384 subpass.pColorAttachments = &attach;
3385 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3386 ASSERT_VK_SUCCESS(err);
3387
3388 // Cause error due to mis-matched formats between rp & fb
3389 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3390 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3392 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003393 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3394
3395 m_errorMonitor->VerifyFound();
3396 if (err == VK_SUCCESS) {
3397 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3398 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003399 vkDestroyRenderPass(m_device->device(), rp, NULL);
3400
3401 // Create new renderpass with alternate sample count from fb
3402 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3403 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3404 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3405 ASSERT_VK_SUCCESS(err);
3406
3407 // Cause error due to mis-matched sample count between rp & fb
3408 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3410 " has VK_SAMPLE_COUNT_1_BIT samples "
3411 "that do not match the "
3412 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003413 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3414
3415 m_errorMonitor->VerifyFound();
3416 if (err == VK_SUCCESS) {
3417 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3418 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003419
3420 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003421
3422 // Create a custom imageView with non-1 mip levels
3423 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003424 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 -06003425 ASSERT_TRUE(image.initialized());
3426
3427 VkImageView view;
3428 VkImageViewCreateInfo ivci = {};
3429 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3430 ivci.image = image.handle();
3431 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3432 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3433 ivci.subresourceRange.layerCount = 1;
3434 ivci.subresourceRange.baseMipLevel = 0;
3435 // Set level count 2 (only 1 is allowed for FB attachment)
3436 ivci.subresourceRange.levelCount = 2;
3437 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3438 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3439 ASSERT_VK_SUCCESS(err);
3440 // Re-create renderpass to have matching sample count
3441 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3442 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3443 ASSERT_VK_SUCCESS(err);
3444
3445 fb_info.renderPass = rp;
3446 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003448 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3449
3450 m_errorMonitor->VerifyFound();
3451 if (err == VK_SUCCESS) {
3452 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3453 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003454 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003455 // Update view to original color buffer and grow FB dimensions too big
3456 fb_info.pAttachments = ivs;
3457 fb_info.height = 1024;
3458 fb_info.width = 1024;
3459 fb_info.layers = 2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3461 " Attachment dimensions must be at "
3462 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003463 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3464
3465 m_errorMonitor->VerifyFound();
3466 if (err == VK_SUCCESS) {
3467 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3468 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003469 // Create view attachment with non-identity swizzle
3470 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3471 ivci.image = image.handle();
3472 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3473 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3474 ivci.subresourceRange.layerCount = 1;
3475 ivci.subresourceRange.baseMipLevel = 0;
3476 ivci.subresourceRange.levelCount = 1;
3477 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3478 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3479 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3480 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3481 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3482 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3483 ASSERT_VK_SUCCESS(err);
3484
3485 fb_info.pAttachments = &view;
3486 fb_info.height = 100;
3487 fb_info.width = 100;
3488 fb_info.layers = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3490 " has non-identy swizzle. All "
3491 "framebuffer attachments must have "
3492 "been created with the identity "
3493 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003494 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3495
3496 m_errorMonitor->VerifyFound();
3497 if (err == VK_SUCCESS) {
3498 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3499 }
3500 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003501 // reset attachment to color attachment
3502 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003503
3504 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003505 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003506 fb_info.height = 100;
3507 fb_info.layers = 1;
3508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
3509 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3510
3511 m_errorMonitor->VerifyFound();
3512 if (err == VK_SUCCESS) {
3513 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3514 }
3515
3516 // Request fb that exceeds max height
3517 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003518 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003519 fb_info.layers = 1;
3520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
3521 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3522
3523 m_errorMonitor->VerifyFound();
3524 if (err == VK_SUCCESS) {
3525 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3526 }
3527
3528 // Request fb that exceeds max layers
3529 fb_info.width = 100;
3530 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003531 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003533 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3534
3535 m_errorMonitor->VerifyFound();
3536 if (err == VK_SUCCESS) {
3537 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3538 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003539
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003540 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003541}
3542
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003543TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003544 TEST_DESCRIPTION(
3545 "Run a simple draw calls to validate failure when Depth Bias dynamic "
3546 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003547
Cody Northropc31a84f2016-08-22 10:41:47 -06003548 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003549 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3551 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003552 m_errorMonitor->VerifyFound();
3553}
3554
3555TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003556 TEST_DESCRIPTION(
3557 "Run a simple draw calls to validate failure when Line Width dynamic "
3558 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003559
Cody Northropc31a84f2016-08-22 10:41:47 -06003560 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003561 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3563 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003564 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003565}
3566
3567TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003568 TEST_DESCRIPTION(
3569 "Run a simple draw calls to validate failure when Viewport dynamic "
3570 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003571
Cody Northropc31a84f2016-08-22 10:41:47 -06003572 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003573 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3575 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003576 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003577 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003578}
3579
3580TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003581 TEST_DESCRIPTION(
3582 "Run a simple draw calls to validate failure when Scissor dynamic "
3583 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003584
Cody Northropc31a84f2016-08-22 10:41:47 -06003585 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003586 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3588 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003589 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003590 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003591}
3592
Cortd713fe82016-07-27 09:51:27 -07003593TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003594 TEST_DESCRIPTION(
3595 "Run a simple draw calls to validate failure when Blend Constants "
3596 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003597
3598 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003599 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3601 "Dynamic blend constants state not set for this command buffer");
3602 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003603 m_errorMonitor->VerifyFound();
3604}
3605
3606TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003607 TEST_DESCRIPTION(
3608 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
3609 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003610
3611 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003612 if (!m_device->phy().features().depthBounds) {
3613 printf("Device does not support depthBounds test; skipped.\n");
3614 return;
3615 }
3616 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3618 "Dynamic depth bounds state not set for this command buffer");
3619 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003620 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003621}
3622
3623TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003624 TEST_DESCRIPTION(
3625 "Run a simple draw calls to validate failure when Stencil Read dynamic "
3626 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003627
3628 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003629 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003630 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3631 "Dynamic stencil read mask state not set for this command buffer");
3632 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003633 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003634}
3635
3636TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003637 TEST_DESCRIPTION(
3638 "Run a simple draw calls to validate failure when Stencil Write dynamic"
3639 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003640
3641 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003642 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3644 "Dynamic stencil write mask state not set for this command buffer");
3645 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003646 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003647}
3648
3649TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003650 TEST_DESCRIPTION(
3651 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
3652 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003653
3654 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003655 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3657 "Dynamic stencil reference state not set for this command buffer");
3658 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003659 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003660}
3661
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003662TEST_F(VkLayerTest, IndexBufferNotBound) {
3663 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003664
3665 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3667 "Index buffer object not bound to this command buffer when Indexed ");
3668 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003669 m_errorMonitor->VerifyFound();
3670}
3671
Karl Schultz6addd812016-02-02 17:17:23 -07003672TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3674 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3675 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003676
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003677 ASSERT_NO_FATAL_FAILURE(InitState());
3678 ASSERT_NO_FATAL_FAILURE(InitViewport());
3679 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3680
Karl Schultz6addd812016-02-02 17:17:23 -07003681 // We luck out b/c by default the framework creates CB w/ the
3682 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07003683 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003684 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07003685 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003686
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003687 // Bypass framework since it does the waits automatically
3688 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003689 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003690 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3691 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003692 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003693 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003694 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003695 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003696 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003697 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003698 submit_info.pSignalSemaphores = NULL;
3699
Chris Forbes40028e22016-06-13 09:59:34 +12003700 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003701 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003702 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003703
Karl Schultz6addd812016-02-02 17:17:23 -07003704 // Cause validation error by re-submitting cmd buffer that should only be
3705 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003706 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003707 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003708
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003709 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003710}
3711
Karl Schultz6addd812016-02-02 17:17:23 -07003712TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003713 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003714 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003715
3716 ASSERT_NO_FATAL_FAILURE(InitState());
3717 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003718
Karl Schultz6addd812016-02-02 17:17:23 -07003719 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3720 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003721 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003722 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003723 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003724
3725 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003726 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3727 ds_pool_ci.pNext = NULL;
3728 ds_pool_ci.flags = 0;
3729 ds_pool_ci.maxSets = 1;
3730 ds_pool_ci.poolSizeCount = 1;
3731 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003732
3733 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003734 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003735 ASSERT_VK_SUCCESS(err);
3736
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003737 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3738 dsl_binding_samp.binding = 0;
3739 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3740 dsl_binding_samp.descriptorCount = 1;
3741 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3742 dsl_binding_samp.pImmutableSamplers = NULL;
3743
3744 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3745 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3746 ds_layout_ci.pNext = NULL;
3747 ds_layout_ci.bindingCount = 1;
3748 ds_layout_ci.pBindings = &dsl_binding_samp;
3749
3750 VkDescriptorSetLayout ds_layout_samp;
3751 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3752 ASSERT_VK_SUCCESS(err);
3753
3754 // Try to allocate 2 sets when pool only has 1 set
3755 VkDescriptorSet descriptor_sets[2];
3756 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3757 VkDescriptorSetAllocateInfo alloc_info = {};
3758 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3759 alloc_info.descriptorSetCount = 2;
3760 alloc_info.descriptorPool = ds_pool;
3761 alloc_info.pSetLayouts = set_layouts;
3762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3763 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3764 m_errorMonitor->VerifyFound();
3765
3766 alloc_info.descriptorSetCount = 1;
3767 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003768 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003769 dsl_binding.binding = 0;
3770 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3771 dsl_binding.descriptorCount = 1;
3772 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3773 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003774
Karl Schultz6addd812016-02-02 17:17:23 -07003775 ds_layout_ci.bindingCount = 1;
3776 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003777
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003778 VkDescriptorSetLayout ds_layout_ub;
3779 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003780 ASSERT_VK_SUCCESS(err);
3781
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003782 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003783 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003784 alloc_info.pSetLayouts = &ds_layout_ub;
3785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3786 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003787
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003788 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003789
Karl Schultz2825ab92016-12-02 08:23:14 -07003790 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003791 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003792 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003793}
3794
Karl Schultz6addd812016-02-02 17:17:23 -07003795TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3796 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003797
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07003798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003799
Tobin Ehlise735c692015-10-08 13:13:50 -06003800 ASSERT_NO_FATAL_FAILURE(InitState());
3801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003802
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003803 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003804 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3805 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003806
3807 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003808 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3809 ds_pool_ci.pNext = NULL;
3810 ds_pool_ci.maxSets = 1;
3811 ds_pool_ci.poolSizeCount = 1;
3812 ds_pool_ci.flags = 0;
3813 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3814 // app can only call vkResetDescriptorPool on this pool.;
3815 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003816
3817 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003818 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003819 ASSERT_VK_SUCCESS(err);
3820
3821 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003822 dsl_binding.binding = 0;
3823 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3824 dsl_binding.descriptorCount = 1;
3825 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3826 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003827
3828 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003829 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3830 ds_layout_ci.pNext = NULL;
3831 ds_layout_ci.bindingCount = 1;
3832 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003833
3834 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003835 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003836 ASSERT_VK_SUCCESS(err);
3837
3838 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003839 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003840 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003841 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003842 alloc_info.descriptorPool = ds_pool;
3843 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003844 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003845 ASSERT_VK_SUCCESS(err);
3846
3847 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003848 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003849
Chia-I Wuf7458c52015-10-26 21:10:41 +08003850 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3851 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003852}
3853
Karl Schultz6addd812016-02-02 17:17:23 -07003854TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003855 // Attempt to clear Descriptor Pool with bad object.
3856 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003857
3858 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003860 uint64_t fake_pool_handle = 0xbaad6001;
3861 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3862 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003863 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003864}
3865
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003866TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003867 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3868 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003869 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003870 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003871
3872 uint64_t fake_set_handle = 0xbaad6001;
3873 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003874 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003876
3877 ASSERT_NO_FATAL_FAILURE(InitState());
3878
3879 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3880 layout_bindings[0].binding = 0;
3881 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3882 layout_bindings[0].descriptorCount = 1;
3883 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3884 layout_bindings[0].pImmutableSamplers = NULL;
3885
3886 VkDescriptorSetLayout descriptor_set_layout;
3887 VkDescriptorSetLayoutCreateInfo dslci = {};
3888 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3889 dslci.pNext = NULL;
3890 dslci.bindingCount = 1;
3891 dslci.pBindings = layout_bindings;
3892 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003893 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003894
3895 VkPipelineLayout pipeline_layout;
3896 VkPipelineLayoutCreateInfo plci = {};
3897 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3898 plci.pNext = NULL;
3899 plci.setLayoutCount = 1;
3900 plci.pSetLayouts = &descriptor_set_layout;
3901 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003902 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003903
Tony Barbour552f6c02016-12-21 14:34:07 -07003904 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003905 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3906 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003907 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07003908 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06003909 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3910 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003911}
3912
Karl Schultz6addd812016-02-02 17:17:23 -07003913TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003914 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3915 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003916 uint64_t fake_layout_handle = 0xbaad6001;
3917 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003919 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003920 VkPipelineLayout pipeline_layout;
3921 VkPipelineLayoutCreateInfo plci = {};
3922 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3923 plci.pNext = NULL;
3924 plci.setLayoutCount = 1;
3925 plci.pSetLayouts = &bad_layout;
3926 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3927
3928 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003929}
3930
Mark Muellerd4914412016-06-13 17:52:06 -06003931TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003932 TEST_DESCRIPTION(
3933 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3934 "1) A uniform buffer update must have a valid buffer index."
3935 "2) When using an array of descriptors in a single WriteDescriptor,"
3936 " the descriptor types and stageflags must all be the same."
3937 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06003938
Mike Weiblena6666382017-01-05 15:16:11 -07003939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06003940
3941 ASSERT_NO_FATAL_FAILURE(InitState());
3942 VkDescriptorPoolSize ds_type_count[4] = {};
3943 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3944 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003945 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003946 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003947 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003948 ds_type_count[2].descriptorCount = 1;
3949 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3950 ds_type_count[3].descriptorCount = 1;
3951
3952 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3953 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3954 ds_pool_ci.maxSets = 1;
3955 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3956 ds_pool_ci.pPoolSizes = ds_type_count;
3957
3958 VkDescriptorPool ds_pool;
3959 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3960 ASSERT_VK_SUCCESS(err);
3961
Mark Muellerb9896722016-06-16 09:54:29 -06003962 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003963 layout_binding[0].binding = 0;
3964 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3965 layout_binding[0].descriptorCount = 1;
3966 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3967 layout_binding[0].pImmutableSamplers = NULL;
3968
3969 layout_binding[1].binding = 1;
3970 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3971 layout_binding[1].descriptorCount = 1;
3972 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3973 layout_binding[1].pImmutableSamplers = NULL;
3974
3975 VkSamplerCreateInfo sampler_ci = {};
3976 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3977 sampler_ci.pNext = NULL;
3978 sampler_ci.magFilter = VK_FILTER_NEAREST;
3979 sampler_ci.minFilter = VK_FILTER_NEAREST;
3980 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3981 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3982 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3983 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3984 sampler_ci.mipLodBias = 1.0;
3985 sampler_ci.anisotropyEnable = VK_FALSE;
3986 sampler_ci.maxAnisotropy = 1;
3987 sampler_ci.compareEnable = VK_FALSE;
3988 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3989 sampler_ci.minLod = 1.0;
3990 sampler_ci.maxLod = 1.0;
3991 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3992 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3993 VkSampler sampler;
3994
3995 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3996 ASSERT_VK_SUCCESS(err);
3997
3998 layout_binding[2].binding = 2;
3999 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4000 layout_binding[2].descriptorCount = 1;
4001 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4002 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4003
Mark Muellerd4914412016-06-13 17:52:06 -06004004 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4005 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4006 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4007 ds_layout_ci.pBindings = layout_binding;
4008 VkDescriptorSetLayout ds_layout;
4009 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4010 ASSERT_VK_SUCCESS(err);
4011
4012 VkDescriptorSetAllocateInfo alloc_info = {};
4013 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4014 alloc_info.descriptorSetCount = 1;
4015 alloc_info.descriptorPool = ds_pool;
4016 alloc_info.pSetLayouts = &ds_layout;
4017 VkDescriptorSet descriptorSet;
4018 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4019 ASSERT_VK_SUCCESS(err);
4020
4021 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4022 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4023 pipeline_layout_ci.pNext = NULL;
4024 pipeline_layout_ci.setLayoutCount = 1;
4025 pipeline_layout_ci.pSetLayouts = &ds_layout;
4026
4027 VkPipelineLayout pipeline_layout;
4028 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4029 ASSERT_VK_SUCCESS(err);
4030
Mark Mueller5c838ce2016-06-16 09:54:29 -06004031 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004032 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4033 descriptor_write.dstSet = descriptorSet;
4034 descriptor_write.dstBinding = 0;
4035 descriptor_write.descriptorCount = 1;
4036 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4037
Mark Mueller5c838ce2016-06-16 09:54:29 -06004038 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004039 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4040 m_errorMonitor->VerifyFound();
4041
4042 // Create a buffer to update the descriptor with
4043 uint32_t qfi = 0;
4044 VkBufferCreateInfo buffCI = {};
4045 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4046 buffCI.size = 1024;
4047 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4048 buffCI.queueFamilyIndexCount = 1;
4049 buffCI.pQueueFamilyIndices = &qfi;
4050
4051 VkBuffer dyub;
4052 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4053 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004054
Tony Barboure132c5f2016-12-12 11:50:20 -07004055 VkDeviceMemory mem;
4056 VkMemoryRequirements mem_reqs;
4057 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4058
4059 VkMemoryAllocateInfo mem_alloc_info = {};
4060 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4061 mem_alloc_info.allocationSize = mem_reqs.size;
4062 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4063 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4064 ASSERT_VK_SUCCESS(err);
4065
4066 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4067 ASSERT_VK_SUCCESS(err);
4068
4069 VkDescriptorBufferInfo buffInfo[2] = {};
4070 buffInfo[0].buffer = dyub;
4071 buffInfo[0].offset = 0;
4072 buffInfo[0].range = 1024;
4073 buffInfo[1].buffer = dyub;
4074 buffInfo[1].offset = 0;
4075 buffInfo[1].range = 1024;
4076 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004077 descriptor_write.descriptorCount = 2;
4078
Mark Mueller5c838ce2016-06-16 09:54:29 -06004079 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004081 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4082 m_errorMonitor->VerifyFound();
4083
Mark Mueller5c838ce2016-06-16 09:54:29 -06004084 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4085 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004086 descriptor_write.dstBinding = 1;
4087 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004088
Mark Mueller5c838ce2016-06-16 09:54:29 -06004089 // Make pImageInfo index non-null to avoid complaints of it missing
4090 VkDescriptorImageInfo imageInfo = {};
4091 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4092 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004094 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4095 m_errorMonitor->VerifyFound();
4096
Mark Muellerd4914412016-06-13 17:52:06 -06004097 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004098 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004099 vkDestroySampler(m_device->device(), sampler, NULL);
4100 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4101 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4102 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4103}
4104
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004105TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004106 TEST_DESCRIPTION(
4107 "Attempt to draw with a command buffer that is invalid "
4108 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004109 ASSERT_NO_FATAL_FAILURE(InitState());
4110
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004111 VkBuffer buffer;
4112 VkDeviceMemory mem;
4113 VkMemoryRequirements mem_reqs;
4114
4115 VkBufferCreateInfo buf_info = {};
4116 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004117 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004118 buf_info.size = 256;
4119 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4120 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4121 ASSERT_VK_SUCCESS(err);
4122
4123 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4124
4125 VkMemoryAllocateInfo alloc_info = {};
4126 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4127 alloc_info.allocationSize = 256;
4128 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004129 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 -06004130 if (!pass) {
4131 vkDestroyBuffer(m_device->device(), buffer, NULL);
4132 return;
4133 }
4134 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4135 ASSERT_VK_SUCCESS(err);
4136
4137 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4138 ASSERT_VK_SUCCESS(err);
4139
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004140 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004141 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004142 m_commandBuffer->EndCommandBuffer();
4143
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004145 // Destroy buffer dependency prior to submit to cause ERROR
4146 vkDestroyBuffer(m_device->device(), buffer, NULL);
4147
4148 VkSubmitInfo submit_info = {};
4149 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4150 submit_info.commandBufferCount = 1;
4151 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4152 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4153
4154 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004155 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004156 vkFreeMemory(m_device->handle(), mem, NULL);
4157}
4158
Tobin Ehlisea413442016-09-28 10:23:59 -06004159TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4160 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4161
4162 ASSERT_NO_FATAL_FAILURE(InitState());
4163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4164
4165 VkDescriptorPoolSize ds_type_count;
4166 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4167 ds_type_count.descriptorCount = 1;
4168
4169 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4170 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4171 ds_pool_ci.maxSets = 1;
4172 ds_pool_ci.poolSizeCount = 1;
4173 ds_pool_ci.pPoolSizes = &ds_type_count;
4174
4175 VkDescriptorPool ds_pool;
4176 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4177 ASSERT_VK_SUCCESS(err);
4178
4179 VkDescriptorSetLayoutBinding layout_binding;
4180 layout_binding.binding = 0;
4181 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4182 layout_binding.descriptorCount = 1;
4183 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4184 layout_binding.pImmutableSamplers = NULL;
4185
4186 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4187 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4188 ds_layout_ci.bindingCount = 1;
4189 ds_layout_ci.pBindings = &layout_binding;
4190 VkDescriptorSetLayout ds_layout;
4191 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4192 ASSERT_VK_SUCCESS(err);
4193
4194 VkDescriptorSetAllocateInfo alloc_info = {};
4195 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4196 alloc_info.descriptorSetCount = 1;
4197 alloc_info.descriptorPool = ds_pool;
4198 alloc_info.pSetLayouts = &ds_layout;
4199 VkDescriptorSet descriptor_set;
4200 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4201 ASSERT_VK_SUCCESS(err);
4202
4203 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4204 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4205 pipeline_layout_ci.pNext = NULL;
4206 pipeline_layout_ci.setLayoutCount = 1;
4207 pipeline_layout_ci.pSetLayouts = &ds_layout;
4208
4209 VkPipelineLayout pipeline_layout;
4210 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4211 ASSERT_VK_SUCCESS(err);
4212
4213 VkBuffer buffer;
4214 uint32_t queue_family_index = 0;
4215 VkBufferCreateInfo buffer_create_info = {};
4216 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4217 buffer_create_info.size = 1024;
4218 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4219 buffer_create_info.queueFamilyIndexCount = 1;
4220 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4221
4222 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4223 ASSERT_VK_SUCCESS(err);
4224
4225 VkMemoryRequirements memory_reqs;
4226 VkDeviceMemory buffer_memory;
4227
4228 VkMemoryAllocateInfo memory_info = {};
4229 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4230 memory_info.allocationSize = 0;
4231 memory_info.memoryTypeIndex = 0;
4232
4233 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4234 memory_info.allocationSize = memory_reqs.size;
4235 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4236 ASSERT_TRUE(pass);
4237
4238 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4239 ASSERT_VK_SUCCESS(err);
4240 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4241 ASSERT_VK_SUCCESS(err);
4242
4243 VkBufferView view;
4244 VkBufferViewCreateInfo bvci = {};
4245 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4246 bvci.buffer = buffer;
4247 bvci.format = VK_FORMAT_R8_UNORM;
4248 bvci.range = VK_WHOLE_SIZE;
4249
4250 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4251 ASSERT_VK_SUCCESS(err);
4252
4253 VkWriteDescriptorSet descriptor_write = {};
4254 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4255 descriptor_write.dstSet = descriptor_set;
4256 descriptor_write.dstBinding = 0;
4257 descriptor_write.descriptorCount = 1;
4258 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4259 descriptor_write.pTexelBufferView = &view;
4260
4261 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4262
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004263 char const *vsSource =
4264 "#version 450\n"
4265 "\n"
4266 "out gl_PerVertex { \n"
4267 " vec4 gl_Position;\n"
4268 "};\n"
4269 "void main(){\n"
4270 " gl_Position = vec4(1);\n"
4271 "}\n";
4272 char const *fsSource =
4273 "#version 450\n"
4274 "\n"
4275 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4276 "layout(location=0) out vec4 x;\n"
4277 "void main(){\n"
4278 " x = imageLoad(s, 0);\n"
4279 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004280 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4281 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4282 VkPipelineObj pipe(m_device);
4283 pipe.AddShader(&vs);
4284 pipe.AddShader(&fs);
4285 pipe.AddColorAttachment();
4286 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4287
4288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4290
Tony Barbour552f6c02016-12-21 14:34:07 -07004291 m_commandBuffer->BeginCommandBuffer();
4292 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4293
Tobin Ehlisea413442016-09-28 10:23:59 -06004294 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4295 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4296 VkRect2D scissor = {{0, 0}, {16, 16}};
4297 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4298 // Bind pipeline to cmd buffer
4299 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4300 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4301 &descriptor_set, 0, nullptr);
4302 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004303 m_commandBuffer->EndRenderPass();
4304 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004305
4306 // Delete BufferView in order to invalidate cmd buffer
4307 vkDestroyBufferView(m_device->device(), view, NULL);
4308 // Now attempt submit of cmd buffer
4309 VkSubmitInfo submit_info = {};
4310 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4311 submit_info.commandBufferCount = 1;
4312 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4313 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4314 m_errorMonitor->VerifyFound();
4315
4316 // Clean-up
4317 vkDestroyBuffer(m_device->device(), buffer, NULL);
4318 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4319 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4320 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4321 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4322}
4323
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004324TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004325 TEST_DESCRIPTION(
4326 "Attempt to draw with a command buffer that is invalid "
4327 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004328 ASSERT_NO_FATAL_FAILURE(InitState());
4329
4330 VkImage image;
4331 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4332 VkImageCreateInfo image_create_info = {};
4333 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4334 image_create_info.pNext = NULL;
4335 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4336 image_create_info.format = tex_format;
4337 image_create_info.extent.width = 32;
4338 image_create_info.extent.height = 32;
4339 image_create_info.extent.depth = 1;
4340 image_create_info.mipLevels = 1;
4341 image_create_info.arrayLayers = 1;
4342 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4343 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004344 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004345 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004346 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004347 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004348 // Have to bind memory to image before recording cmd in cmd buffer using it
4349 VkMemoryRequirements mem_reqs;
4350 VkDeviceMemory image_mem;
4351 bool pass;
4352 VkMemoryAllocateInfo mem_alloc = {};
4353 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4354 mem_alloc.pNext = NULL;
4355 mem_alloc.memoryTypeIndex = 0;
4356 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4357 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004358 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004359 ASSERT_TRUE(pass);
4360 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4361 ASSERT_VK_SUCCESS(err);
4362 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4363 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004364
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004365 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004366 VkClearColorValue ccv;
4367 ccv.float32[0] = 1.0f;
4368 ccv.float32[1] = 1.0f;
4369 ccv.float32[2] = 1.0f;
4370 ccv.float32[3] = 1.0f;
4371 VkImageSubresourceRange isr = {};
4372 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004373 isr.baseArrayLayer = 0;
4374 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004375 isr.layerCount = 1;
4376 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004377 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004378 m_commandBuffer->EndCommandBuffer();
4379
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004381 // Destroy image dependency prior to submit to cause ERROR
4382 vkDestroyImage(m_device->device(), image, NULL);
4383
4384 VkSubmitInfo submit_info = {};
4385 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4386 submit_info.commandBufferCount = 1;
4387 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4388 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4389
4390 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004391 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004392}
4393
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004394TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004395 TEST_DESCRIPTION(
4396 "Attempt to draw with a command buffer that is invalid "
4397 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004398 VkFormatProperties format_properties;
4399 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004400 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4401 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004402 return;
4403 }
4404
4405 ASSERT_NO_FATAL_FAILURE(InitState());
4406 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4407
4408 VkImageCreateInfo image_ci = {};
4409 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4410 image_ci.pNext = NULL;
4411 image_ci.imageType = VK_IMAGE_TYPE_2D;
4412 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4413 image_ci.extent.width = 32;
4414 image_ci.extent.height = 32;
4415 image_ci.extent.depth = 1;
4416 image_ci.mipLevels = 1;
4417 image_ci.arrayLayers = 1;
4418 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4419 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004420 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004421 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4422 image_ci.flags = 0;
4423 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004424 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004425
4426 VkMemoryRequirements memory_reqs;
4427 VkDeviceMemory image_memory;
4428 bool pass;
4429 VkMemoryAllocateInfo memory_info = {};
4430 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4431 memory_info.pNext = NULL;
4432 memory_info.allocationSize = 0;
4433 memory_info.memoryTypeIndex = 0;
4434 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4435 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004436 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004437 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004438 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004439 ASSERT_VK_SUCCESS(err);
4440 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4441 ASSERT_VK_SUCCESS(err);
4442
4443 VkImageViewCreateInfo ivci = {
4444 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4445 nullptr,
4446 0,
4447 image,
4448 VK_IMAGE_VIEW_TYPE_2D,
4449 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004450 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004451 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4452 };
4453 VkImageView view;
4454 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4455 ASSERT_VK_SUCCESS(err);
4456
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004457 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004458 VkFramebuffer fb;
4459 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4460 ASSERT_VK_SUCCESS(err);
4461
4462 // Just use default renderpass with our framebuffer
4463 m_renderPassBeginInfo.framebuffer = fb;
4464 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004465 m_commandBuffer->BeginCommandBuffer();
4466 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4467 m_commandBuffer->EndRenderPass();
4468 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004469 // Destroy image attached to framebuffer to invalidate cmd buffer
4470 vkDestroyImage(m_device->device(), image, NULL);
4471 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004473 QueueCommandBuffer(false);
4474 m_errorMonitor->VerifyFound();
4475
4476 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4477 vkDestroyImageView(m_device->device(), view, nullptr);
4478 vkFreeMemory(m_device->device(), image_memory, nullptr);
4479}
4480
Tobin Ehlisb329f992016-10-12 13:20:29 -06004481TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4482 TEST_DESCRIPTION("Delete in-use framebuffer.");
4483 VkFormatProperties format_properties;
4484 VkResult err = VK_SUCCESS;
4485 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4486
4487 ASSERT_NO_FATAL_FAILURE(InitState());
4488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4489
4490 VkImageObj image(m_device);
4491 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4492 ASSERT_TRUE(image.initialized());
4493 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4494
4495 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4496 VkFramebuffer fb;
4497 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4498 ASSERT_VK_SUCCESS(err);
4499
4500 // Just use default renderpass with our framebuffer
4501 m_renderPassBeginInfo.framebuffer = fb;
4502 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004503 m_commandBuffer->BeginCommandBuffer();
4504 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4505 m_commandBuffer->EndRenderPass();
4506 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06004507 // Submit cmd buffer to put it in-flight
4508 VkSubmitInfo submit_info = {};
4509 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4510 submit_info.commandBufferCount = 1;
4511 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4512 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4513 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06004515 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4516 m_errorMonitor->VerifyFound();
4517 // Wait for queue to complete so we can safely destroy everything
4518 vkQueueWaitIdle(m_device->m_queue);
4519 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4520}
4521
Tobin Ehlis88becd72016-09-21 14:33:41 -06004522TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4523 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4524 VkFormatProperties format_properties;
4525 VkResult err = VK_SUCCESS;
4526 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004527
4528 ASSERT_NO_FATAL_FAILURE(InitState());
4529 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4530
4531 VkImageCreateInfo image_ci = {};
4532 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4533 image_ci.pNext = NULL;
4534 image_ci.imageType = VK_IMAGE_TYPE_2D;
4535 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4536 image_ci.extent.width = 256;
4537 image_ci.extent.height = 256;
4538 image_ci.extent.depth = 1;
4539 image_ci.mipLevels = 1;
4540 image_ci.arrayLayers = 1;
4541 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4542 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004543 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004544 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4545 image_ci.flags = 0;
4546 VkImage image;
4547 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4548
4549 VkMemoryRequirements memory_reqs;
4550 VkDeviceMemory image_memory;
4551 bool pass;
4552 VkMemoryAllocateInfo memory_info = {};
4553 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4554 memory_info.pNext = NULL;
4555 memory_info.allocationSize = 0;
4556 memory_info.memoryTypeIndex = 0;
4557 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4558 memory_info.allocationSize = memory_reqs.size;
4559 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4560 ASSERT_TRUE(pass);
4561 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4562 ASSERT_VK_SUCCESS(err);
4563 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4564 ASSERT_VK_SUCCESS(err);
4565
4566 VkImageViewCreateInfo ivci = {
4567 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4568 nullptr,
4569 0,
4570 image,
4571 VK_IMAGE_VIEW_TYPE_2D,
4572 VK_FORMAT_B8G8R8A8_UNORM,
4573 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4574 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4575 };
4576 VkImageView view;
4577 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4578 ASSERT_VK_SUCCESS(err);
4579
4580 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4581 VkFramebuffer fb;
4582 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4583 ASSERT_VK_SUCCESS(err);
4584
4585 // Just use default renderpass with our framebuffer
4586 m_renderPassBeginInfo.framebuffer = fb;
4587 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004588 m_commandBuffer->BeginCommandBuffer();
4589 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4590 m_commandBuffer->EndRenderPass();
4591 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06004592 // Submit cmd buffer to put it (and attached imageView) in-flight
4593 VkSubmitInfo submit_info = {};
4594 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4595 submit_info.commandBufferCount = 1;
4596 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4597 // Submit cmd buffer to put framebuffer and children in-flight
4598 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4599 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004601 vkDestroyImage(m_device->device(), image, NULL);
4602 m_errorMonitor->VerifyFound();
4603 // Wait for queue to complete so we can safely destroy image and other objects
4604 vkQueueWaitIdle(m_device->m_queue);
4605 vkDestroyImage(m_device->device(), image, NULL);
4606 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4607 vkDestroyImageView(m_device->device(), view, nullptr);
4608 vkFreeMemory(m_device->device(), image_memory, nullptr);
4609}
4610
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004611TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4612 TEST_DESCRIPTION("Delete in-use renderPass.");
4613
4614 ASSERT_NO_FATAL_FAILURE(InitState());
4615 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4616
4617 // Create simple renderpass
4618 VkAttachmentReference attach = {};
4619 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4620 VkSubpassDescription subpass = {};
4621 subpass.pColorAttachments = &attach;
4622 VkRenderPassCreateInfo rpci = {};
4623 rpci.subpassCount = 1;
4624 rpci.pSubpasses = &subpass;
4625 rpci.attachmentCount = 1;
4626 VkAttachmentDescription attach_desc = {};
4627 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4628 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4629 rpci.pAttachments = &attach_desc;
4630 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4631 VkRenderPass rp;
4632 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4633 ASSERT_VK_SUCCESS(err);
4634
4635 // Create a pipeline that uses the given renderpass
4636 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4637 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4638
4639 VkPipelineLayout pipeline_layout;
4640 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4641 ASSERT_VK_SUCCESS(err);
4642
4643 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4644 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4645 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004646 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004647 vp_state_ci.pViewports = &vp;
4648 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004649 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004650 vp_state_ci.pScissors = &scissors;
4651
4652 VkPipelineShaderStageCreateInfo shaderStages[2];
4653 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4654
4655 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004656 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 -06004657 // but add it to be able to run on more devices
4658 shaderStages[0] = vs.GetStageCreateInfo();
4659 shaderStages[1] = fs.GetStageCreateInfo();
4660
4661 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4662 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4663
4664 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4665 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4666 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4667
4668 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4669 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4670 rs_ci.rasterizerDiscardEnable = true;
4671 rs_ci.lineWidth = 1.0f;
4672
4673 VkPipelineColorBlendAttachmentState att = {};
4674 att.blendEnable = VK_FALSE;
4675 att.colorWriteMask = 0xf;
4676
4677 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4678 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4679 cb_ci.attachmentCount = 1;
4680 cb_ci.pAttachments = &att;
4681
4682 VkGraphicsPipelineCreateInfo gp_ci = {};
4683 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4684 gp_ci.stageCount = 2;
4685 gp_ci.pStages = shaderStages;
4686 gp_ci.pVertexInputState = &vi_ci;
4687 gp_ci.pInputAssemblyState = &ia_ci;
4688 gp_ci.pViewportState = &vp_state_ci;
4689 gp_ci.pRasterizationState = &rs_ci;
4690 gp_ci.pColorBlendState = &cb_ci;
4691 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4692 gp_ci.layout = pipeline_layout;
4693 gp_ci.renderPass = rp;
4694
4695 VkPipelineCacheCreateInfo pc_ci = {};
4696 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4697
4698 VkPipeline pipeline;
4699 VkPipelineCache pipe_cache;
4700 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4701 ASSERT_VK_SUCCESS(err);
4702
4703 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4704 ASSERT_VK_SUCCESS(err);
4705 // Bind pipeline to cmd buffer, will also bind renderpass
4706 m_commandBuffer->BeginCommandBuffer();
4707 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4708 m_commandBuffer->EndCommandBuffer();
4709
4710 VkSubmitInfo submit_info = {};
4711 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4712 submit_info.commandBufferCount = 1;
4713 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4714 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4715
4716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4717 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4718 m_errorMonitor->VerifyFound();
4719
4720 // Wait for queue to complete so we can safely destroy everything
4721 vkQueueWaitIdle(m_device->m_queue);
4722 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4723 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4724 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4725 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4726}
4727
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004728TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004729 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004730 ASSERT_NO_FATAL_FAILURE(InitState());
4731
4732 VkImage image;
4733 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4734 VkImageCreateInfo image_create_info = {};
4735 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4736 image_create_info.pNext = NULL;
4737 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4738 image_create_info.format = tex_format;
4739 image_create_info.extent.width = 32;
4740 image_create_info.extent.height = 32;
4741 image_create_info.extent.depth = 1;
4742 image_create_info.mipLevels = 1;
4743 image_create_info.arrayLayers = 1;
4744 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4745 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004746 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004747 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004748 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004749 ASSERT_VK_SUCCESS(err);
4750 // Have to bind memory to image before recording cmd in cmd buffer using it
4751 VkMemoryRequirements mem_reqs;
4752 VkDeviceMemory image_mem;
4753 bool pass;
4754 VkMemoryAllocateInfo mem_alloc = {};
4755 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4756 mem_alloc.pNext = NULL;
4757 mem_alloc.memoryTypeIndex = 0;
4758 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4759 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004760 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004761 ASSERT_TRUE(pass);
4762 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4763 ASSERT_VK_SUCCESS(err);
4764
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004765 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004767 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004768
4769 m_commandBuffer->BeginCommandBuffer();
4770 VkClearColorValue ccv;
4771 ccv.float32[0] = 1.0f;
4772 ccv.float32[1] = 1.0f;
4773 ccv.float32[2] = 1.0f;
4774 ccv.float32[3] = 1.0f;
4775 VkImageSubresourceRange isr = {};
4776 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4777 isr.baseArrayLayer = 0;
4778 isr.baseMipLevel = 0;
4779 isr.layerCount = 1;
4780 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004781 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004782 m_commandBuffer->EndCommandBuffer();
4783
4784 m_errorMonitor->VerifyFound();
4785 vkDestroyImage(m_device->device(), image, NULL);
4786 vkFreeMemory(m_device->device(), image_mem, nullptr);
4787}
4788
4789TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004790 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004791 ASSERT_NO_FATAL_FAILURE(InitState());
4792
4793 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004794 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 -06004795 VK_IMAGE_TILING_OPTIMAL, 0);
4796 ASSERT_TRUE(image.initialized());
4797
4798 VkBuffer buffer;
4799 VkDeviceMemory mem;
4800 VkMemoryRequirements mem_reqs;
4801
4802 VkBufferCreateInfo buf_info = {};
4803 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004804 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004805 buf_info.size = 256;
4806 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4807 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4808 ASSERT_VK_SUCCESS(err);
4809
4810 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4811
4812 VkMemoryAllocateInfo alloc_info = {};
4813 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4814 alloc_info.allocationSize = 256;
4815 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004816 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 -06004817 if (!pass) {
4818 vkDestroyBuffer(m_device->device(), buffer, NULL);
4819 return;
4820 }
4821 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4822 ASSERT_VK_SUCCESS(err);
4823
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004824 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004826 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004827 VkBufferImageCopy region = {};
4828 region.bufferRowLength = 128;
4829 region.bufferImageHeight = 128;
4830 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4831
4832 region.imageSubresource.layerCount = 1;
4833 region.imageExtent.height = 4;
4834 region.imageExtent.width = 4;
4835 region.imageExtent.depth = 1;
4836 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004837 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4838 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004839 m_commandBuffer->EndCommandBuffer();
4840
4841 m_errorMonitor->VerifyFound();
4842
4843 vkDestroyBuffer(m_device->device(), buffer, NULL);
4844 vkFreeMemory(m_device->handle(), mem, NULL);
4845}
4846
Tobin Ehlis85940f52016-07-07 16:57:21 -06004847TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004848 TEST_DESCRIPTION(
4849 "Attempt to draw with a command buffer that is invalid "
4850 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004851 ASSERT_NO_FATAL_FAILURE(InitState());
4852
4853 VkEvent event;
4854 VkEventCreateInfo evci = {};
4855 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4856 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4857 ASSERT_VK_SUCCESS(result);
4858
4859 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004860 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004861 m_commandBuffer->EndCommandBuffer();
4862
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004864 // Destroy event dependency prior to submit to cause ERROR
4865 vkDestroyEvent(m_device->device(), event, NULL);
4866
4867 VkSubmitInfo submit_info = {};
4868 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4869 submit_info.commandBufferCount = 1;
4870 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4871 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4872
4873 m_errorMonitor->VerifyFound();
4874}
4875
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004876TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004877 TEST_DESCRIPTION(
4878 "Attempt to draw with a command buffer that is invalid "
4879 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004880 ASSERT_NO_FATAL_FAILURE(InitState());
4881
4882 VkQueryPool query_pool;
4883 VkQueryPoolCreateInfo qpci{};
4884 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4885 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4886 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004887 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004888 ASSERT_VK_SUCCESS(result);
4889
4890 m_commandBuffer->BeginCommandBuffer();
4891 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4892 m_commandBuffer->EndCommandBuffer();
4893
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004895 // Destroy query pool dependency prior to submit to cause ERROR
4896 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4897
4898 VkSubmitInfo submit_info = {};
4899 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4900 submit_info.commandBufferCount = 1;
4901 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4902 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4903
4904 m_errorMonitor->VerifyFound();
4905}
4906
Tobin Ehlis24130d92016-07-08 15:50:53 -06004907TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004908 TEST_DESCRIPTION(
4909 "Attempt to draw with a command buffer that is invalid "
4910 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004911 ASSERT_NO_FATAL_FAILURE(InitState());
4912 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4913
4914 VkResult err;
4915
4916 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4917 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4918
4919 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004920 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004921 ASSERT_VK_SUCCESS(err);
4922
4923 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4924 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4925 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004926 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004927 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004928 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004929 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06004930 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004931
4932 VkPipelineShaderStageCreateInfo shaderStages[2];
4933 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4934
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004935 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004936 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 -06004937 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004938 shaderStages[0] = vs.GetStageCreateInfo();
4939 shaderStages[1] = fs.GetStageCreateInfo();
4940
4941 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4942 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4943
4944 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4945 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4946 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4947
4948 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4949 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004950 rs_ci.rasterizerDiscardEnable = true;
4951 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004952
4953 VkPipelineColorBlendAttachmentState att = {};
4954 att.blendEnable = VK_FALSE;
4955 att.colorWriteMask = 0xf;
4956
4957 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4958 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4959 cb_ci.attachmentCount = 1;
4960 cb_ci.pAttachments = &att;
4961
4962 VkGraphicsPipelineCreateInfo gp_ci = {};
4963 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4964 gp_ci.stageCount = 2;
4965 gp_ci.pStages = shaderStages;
4966 gp_ci.pVertexInputState = &vi_ci;
4967 gp_ci.pInputAssemblyState = &ia_ci;
4968 gp_ci.pViewportState = &vp_state_ci;
4969 gp_ci.pRasterizationState = &rs_ci;
4970 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004971 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4972 gp_ci.layout = pipeline_layout;
4973 gp_ci.renderPass = renderPass();
4974
4975 VkPipelineCacheCreateInfo pc_ci = {};
4976 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4977
4978 VkPipeline pipeline;
4979 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004980 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004981 ASSERT_VK_SUCCESS(err);
4982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004983 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004984 ASSERT_VK_SUCCESS(err);
4985
4986 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004987 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004988 m_commandBuffer->EndCommandBuffer();
4989 // Now destroy pipeline in order to cause error when submitting
4990 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4991
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004993
4994 VkSubmitInfo submit_info = {};
4995 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4996 submit_info.commandBufferCount = 1;
4997 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4998 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4999
5000 m_errorMonitor->VerifyFound();
5001 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5002 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5003}
5004
Tobin Ehlis31289162016-08-17 14:57:58 -06005005TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005006 TEST_DESCRIPTION(
5007 "Attempt to draw with a command buffer that is invalid "
5008 "due to a bound descriptor set with a buffer dependency "
5009 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005010 ASSERT_NO_FATAL_FAILURE(InitState());
5011 ASSERT_NO_FATAL_FAILURE(InitViewport());
5012 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5013
5014 VkDescriptorPoolSize ds_type_count = {};
5015 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5016 ds_type_count.descriptorCount = 1;
5017
5018 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5019 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5020 ds_pool_ci.pNext = NULL;
5021 ds_pool_ci.maxSets = 1;
5022 ds_pool_ci.poolSizeCount = 1;
5023 ds_pool_ci.pPoolSizes = &ds_type_count;
5024
5025 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005026 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005027 ASSERT_VK_SUCCESS(err);
5028
5029 VkDescriptorSetLayoutBinding dsl_binding = {};
5030 dsl_binding.binding = 0;
5031 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5032 dsl_binding.descriptorCount = 1;
5033 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5034 dsl_binding.pImmutableSamplers = NULL;
5035
5036 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5037 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5038 ds_layout_ci.pNext = NULL;
5039 ds_layout_ci.bindingCount = 1;
5040 ds_layout_ci.pBindings = &dsl_binding;
5041 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005042 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005043 ASSERT_VK_SUCCESS(err);
5044
5045 VkDescriptorSet descriptorSet;
5046 VkDescriptorSetAllocateInfo alloc_info = {};
5047 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5048 alloc_info.descriptorSetCount = 1;
5049 alloc_info.descriptorPool = ds_pool;
5050 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005051 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005052 ASSERT_VK_SUCCESS(err);
5053
5054 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5055 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5056 pipeline_layout_ci.pNext = NULL;
5057 pipeline_layout_ci.setLayoutCount = 1;
5058 pipeline_layout_ci.pSetLayouts = &ds_layout;
5059
5060 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005061 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005062 ASSERT_VK_SUCCESS(err);
5063
5064 // Create a buffer to update the descriptor with
5065 uint32_t qfi = 0;
5066 VkBufferCreateInfo buffCI = {};
5067 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5068 buffCI.size = 1024;
5069 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5070 buffCI.queueFamilyIndexCount = 1;
5071 buffCI.pQueueFamilyIndices = &qfi;
5072
5073 VkBuffer buffer;
5074 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5075 ASSERT_VK_SUCCESS(err);
5076 // Allocate memory and bind to buffer so we can make it to the appropriate
5077 // error
5078 VkMemoryAllocateInfo mem_alloc = {};
5079 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5080 mem_alloc.pNext = NULL;
5081 mem_alloc.allocationSize = 1024;
5082 mem_alloc.memoryTypeIndex = 0;
5083
5084 VkMemoryRequirements memReqs;
5085 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005086 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005087 if (!pass) {
5088 vkDestroyBuffer(m_device->device(), buffer, NULL);
5089 return;
5090 }
5091
5092 VkDeviceMemory mem;
5093 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5094 ASSERT_VK_SUCCESS(err);
5095 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5096 ASSERT_VK_SUCCESS(err);
5097 // Correctly update descriptor to avoid "NOT_UPDATED" error
5098 VkDescriptorBufferInfo buffInfo = {};
5099 buffInfo.buffer = buffer;
5100 buffInfo.offset = 0;
5101 buffInfo.range = 1024;
5102
5103 VkWriteDescriptorSet descriptor_write;
5104 memset(&descriptor_write, 0, sizeof(descriptor_write));
5105 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5106 descriptor_write.dstSet = descriptorSet;
5107 descriptor_write.dstBinding = 0;
5108 descriptor_write.descriptorCount = 1;
5109 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5110 descriptor_write.pBufferInfo = &buffInfo;
5111
5112 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5113
5114 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005115 char const *vsSource =
5116 "#version 450\n"
5117 "\n"
5118 "out gl_PerVertex { \n"
5119 " vec4 gl_Position;\n"
5120 "};\n"
5121 "void main(){\n"
5122 " gl_Position = vec4(1);\n"
5123 "}\n";
5124 char const *fsSource =
5125 "#version 450\n"
5126 "\n"
5127 "layout(location=0) out vec4 x;\n"
5128 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5129 "void main(){\n"
5130 " x = vec4(bar.y);\n"
5131 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005132 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5133 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5134 VkPipelineObj pipe(m_device);
5135 pipe.AddShader(&vs);
5136 pipe.AddShader(&fs);
5137 pipe.AddColorAttachment();
5138 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5139
Tony Barbour552f6c02016-12-21 14:34:07 -07005140 m_commandBuffer->BeginCommandBuffer();
5141 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005142 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5143 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5144 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005145
5146 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5147 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5148
Tobin Ehlis31289162016-08-17 14:57:58 -06005149 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005150 m_commandBuffer->EndRenderPass();
5151 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005153 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5154 vkDestroyBuffer(m_device->device(), buffer, NULL);
5155 // Attempt to submit cmd buffer
5156 VkSubmitInfo submit_info = {};
5157 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5158 submit_info.commandBufferCount = 1;
5159 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5160 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5161 m_errorMonitor->VerifyFound();
5162 // Cleanup
5163 vkFreeMemory(m_device->device(), mem, NULL);
5164
5165 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5166 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5167 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5168}
5169
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005170TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005171 TEST_DESCRIPTION(
5172 "Attempt to draw with a command buffer that is invalid "
5173 "due to a bound descriptor sets with a combined image "
5174 "sampler having their image, sampler, and descriptor set "
5175 "each respectively destroyed and then attempting to "
5176 "submit associated cmd buffers. Attempt to destroy a "
5177 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005178 ASSERT_NO_FATAL_FAILURE(InitState());
5179 ASSERT_NO_FATAL_FAILURE(InitViewport());
5180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5181
5182 VkDescriptorPoolSize ds_type_count = {};
5183 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5184 ds_type_count.descriptorCount = 1;
5185
5186 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5187 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5188 ds_pool_ci.pNext = NULL;
5189 ds_pool_ci.maxSets = 1;
5190 ds_pool_ci.poolSizeCount = 1;
5191 ds_pool_ci.pPoolSizes = &ds_type_count;
5192
5193 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005194 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005195 ASSERT_VK_SUCCESS(err);
5196
5197 VkDescriptorSetLayoutBinding dsl_binding = {};
5198 dsl_binding.binding = 0;
5199 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5200 dsl_binding.descriptorCount = 1;
5201 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5202 dsl_binding.pImmutableSamplers = NULL;
5203
5204 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5205 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5206 ds_layout_ci.pNext = NULL;
5207 ds_layout_ci.bindingCount = 1;
5208 ds_layout_ci.pBindings = &dsl_binding;
5209 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005210 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005211 ASSERT_VK_SUCCESS(err);
5212
5213 VkDescriptorSet descriptorSet;
5214 VkDescriptorSetAllocateInfo alloc_info = {};
5215 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5216 alloc_info.descriptorSetCount = 1;
5217 alloc_info.descriptorPool = ds_pool;
5218 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005219 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005220 ASSERT_VK_SUCCESS(err);
5221
5222 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5223 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5224 pipeline_layout_ci.pNext = NULL;
5225 pipeline_layout_ci.setLayoutCount = 1;
5226 pipeline_layout_ci.pSetLayouts = &ds_layout;
5227
5228 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005229 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005230 ASSERT_VK_SUCCESS(err);
5231
5232 // Create images to update the descriptor with
5233 VkImage image;
5234 VkImage image2;
5235 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5236 const int32_t tex_width = 32;
5237 const int32_t tex_height = 32;
5238 VkImageCreateInfo image_create_info = {};
5239 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5240 image_create_info.pNext = NULL;
5241 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5242 image_create_info.format = tex_format;
5243 image_create_info.extent.width = tex_width;
5244 image_create_info.extent.height = tex_height;
5245 image_create_info.extent.depth = 1;
5246 image_create_info.mipLevels = 1;
5247 image_create_info.arrayLayers = 1;
5248 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5249 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5250 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5251 image_create_info.flags = 0;
5252 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5253 ASSERT_VK_SUCCESS(err);
5254 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5255 ASSERT_VK_SUCCESS(err);
5256
5257 VkMemoryRequirements memory_reqs;
5258 VkDeviceMemory image_memory;
5259 bool pass;
5260 VkMemoryAllocateInfo memory_info = {};
5261 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5262 memory_info.pNext = NULL;
5263 memory_info.allocationSize = 0;
5264 memory_info.memoryTypeIndex = 0;
5265 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5266 // Allocate enough memory for both images
5267 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005268 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005269 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005270 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005271 ASSERT_VK_SUCCESS(err);
5272 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5273 ASSERT_VK_SUCCESS(err);
5274 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005275 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005276 ASSERT_VK_SUCCESS(err);
5277
5278 VkImageViewCreateInfo image_view_create_info = {};
5279 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5280 image_view_create_info.image = image;
5281 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5282 image_view_create_info.format = tex_format;
5283 image_view_create_info.subresourceRange.layerCount = 1;
5284 image_view_create_info.subresourceRange.baseMipLevel = 0;
5285 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005286 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005287
5288 VkImageView view;
5289 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005290 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005291 ASSERT_VK_SUCCESS(err);
5292 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005293 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005294 ASSERT_VK_SUCCESS(err);
5295 // Create Samplers
5296 VkSamplerCreateInfo sampler_ci = {};
5297 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5298 sampler_ci.pNext = NULL;
5299 sampler_ci.magFilter = VK_FILTER_NEAREST;
5300 sampler_ci.minFilter = VK_FILTER_NEAREST;
5301 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5302 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5303 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5304 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5305 sampler_ci.mipLodBias = 1.0;
5306 sampler_ci.anisotropyEnable = VK_FALSE;
5307 sampler_ci.maxAnisotropy = 1;
5308 sampler_ci.compareEnable = VK_FALSE;
5309 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5310 sampler_ci.minLod = 1.0;
5311 sampler_ci.maxLod = 1.0;
5312 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5313 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5314 VkSampler sampler;
5315 VkSampler sampler2;
5316 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5317 ASSERT_VK_SUCCESS(err);
5318 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5319 ASSERT_VK_SUCCESS(err);
5320 // Update descriptor with image and sampler
5321 VkDescriptorImageInfo img_info = {};
5322 img_info.sampler = sampler;
5323 img_info.imageView = view;
5324 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5325
5326 VkWriteDescriptorSet descriptor_write;
5327 memset(&descriptor_write, 0, sizeof(descriptor_write));
5328 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5329 descriptor_write.dstSet = descriptorSet;
5330 descriptor_write.dstBinding = 0;
5331 descriptor_write.descriptorCount = 1;
5332 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5333 descriptor_write.pImageInfo = &img_info;
5334
5335 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5336
5337 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005338 char const *vsSource =
5339 "#version 450\n"
5340 "\n"
5341 "out gl_PerVertex { \n"
5342 " vec4 gl_Position;\n"
5343 "};\n"
5344 "void main(){\n"
5345 " gl_Position = vec4(1);\n"
5346 "}\n";
5347 char const *fsSource =
5348 "#version 450\n"
5349 "\n"
5350 "layout(set=0, binding=0) uniform sampler2D s;\n"
5351 "layout(location=0) out vec4 x;\n"
5352 "void main(){\n"
5353 " x = texture(s, vec2(1));\n"
5354 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005355 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5356 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5357 VkPipelineObj pipe(m_device);
5358 pipe.AddShader(&vs);
5359 pipe.AddShader(&fs);
5360 pipe.AddColorAttachment();
5361 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5362
5363 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005364 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005365 m_commandBuffer->BeginCommandBuffer();
5366 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005367 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5368 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5369 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005370 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5371 VkRect2D scissor = {{0, 0}, {16, 16}};
5372 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5373 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005374 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005375 m_commandBuffer->EndRenderPass();
5376 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005377 // Destroy sampler invalidates the cmd buffer, causing error on submit
5378 vkDestroySampler(m_device->device(), sampler, NULL);
5379 // Attempt to submit cmd buffer
5380 VkSubmitInfo submit_info = {};
5381 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5382 submit_info.commandBufferCount = 1;
5383 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5384 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5385 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005386
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005387 // Now re-update descriptor with valid sampler and delete image
5388 img_info.sampler = sampler2;
5389 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005391 m_commandBuffer->BeginCommandBuffer();
5392 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005393 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5394 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5395 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005396 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5397 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005398 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005399 m_commandBuffer->EndRenderPass();
5400 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005401 // Destroy image invalidates the cmd buffer, causing error on submit
5402 vkDestroyImage(m_device->device(), image, NULL);
5403 // Attempt to submit cmd buffer
5404 submit_info = {};
5405 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5406 submit_info.commandBufferCount = 1;
5407 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5408 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5409 m_errorMonitor->VerifyFound();
5410 // Now update descriptor to be valid, but then free descriptor
5411 img_info.imageView = view2;
5412 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07005413 m_commandBuffer->BeginCommandBuffer();
5414 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005415 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5416 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5417 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005418 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5419 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005420 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005421 m_commandBuffer->EndRenderPass();
5422 m_commandBuffer->EndCommandBuffer();
Dave Houltonfbf52152017-01-06 12:55:29 -07005423
5424 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005426 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005427 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005428
5429 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07005430 // 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 -07005431 vkQueueWaitIdle(m_device->m_queue);
5432 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5433
5434 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005435 submit_info = {};
5436 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5437 submit_info.commandBufferCount = 1;
5438 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005440 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5441 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005442
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005443 // Cleanup
5444 vkFreeMemory(m_device->device(), image_memory, NULL);
5445 vkDestroySampler(m_device->device(), sampler2, NULL);
5446 vkDestroyImage(m_device->device(), image2, NULL);
5447 vkDestroyImageView(m_device->device(), view, NULL);
5448 vkDestroyImageView(m_device->device(), view2, NULL);
5449 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5450 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5451 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5452}
5453
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005454TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5455 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5456 ASSERT_NO_FATAL_FAILURE(InitState());
5457 ASSERT_NO_FATAL_FAILURE(InitViewport());
5458 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5459
5460 VkDescriptorPoolSize ds_type_count = {};
5461 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5462 ds_type_count.descriptorCount = 1;
5463
5464 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5465 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5466 ds_pool_ci.pNext = NULL;
5467 ds_pool_ci.maxSets = 1;
5468 ds_pool_ci.poolSizeCount = 1;
5469 ds_pool_ci.pPoolSizes = &ds_type_count;
5470
5471 VkDescriptorPool ds_pool;
5472 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5473 ASSERT_VK_SUCCESS(err);
5474
5475 VkDescriptorSetLayoutBinding dsl_binding = {};
5476 dsl_binding.binding = 0;
5477 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5478 dsl_binding.descriptorCount = 1;
5479 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5480 dsl_binding.pImmutableSamplers = NULL;
5481
5482 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5483 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5484 ds_layout_ci.pNext = NULL;
5485 ds_layout_ci.bindingCount = 1;
5486 ds_layout_ci.pBindings = &dsl_binding;
5487 VkDescriptorSetLayout ds_layout;
5488 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5489 ASSERT_VK_SUCCESS(err);
5490
5491 VkDescriptorSet descriptor_set;
5492 VkDescriptorSetAllocateInfo alloc_info = {};
5493 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5494 alloc_info.descriptorSetCount = 1;
5495 alloc_info.descriptorPool = ds_pool;
5496 alloc_info.pSetLayouts = &ds_layout;
5497 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5498 ASSERT_VK_SUCCESS(err);
5499
5500 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5501 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5502 pipeline_layout_ci.pNext = NULL;
5503 pipeline_layout_ci.setLayoutCount = 1;
5504 pipeline_layout_ci.pSetLayouts = &ds_layout;
5505
5506 VkPipelineLayout pipeline_layout;
5507 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5508 ASSERT_VK_SUCCESS(err);
5509
5510 // Create image to update the descriptor with
5511 VkImageObj image(m_device);
5512 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5513 ASSERT_TRUE(image.initialized());
5514
5515 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5516 // Create Sampler
5517 VkSamplerCreateInfo sampler_ci = {};
5518 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5519 sampler_ci.pNext = NULL;
5520 sampler_ci.magFilter = VK_FILTER_NEAREST;
5521 sampler_ci.minFilter = VK_FILTER_NEAREST;
5522 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5523 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5524 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5525 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5526 sampler_ci.mipLodBias = 1.0;
5527 sampler_ci.anisotropyEnable = VK_FALSE;
5528 sampler_ci.maxAnisotropy = 1;
5529 sampler_ci.compareEnable = VK_FALSE;
5530 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5531 sampler_ci.minLod = 1.0;
5532 sampler_ci.maxLod = 1.0;
5533 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5534 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5535 VkSampler sampler;
5536 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5537 ASSERT_VK_SUCCESS(err);
5538 // Update descriptor with image and sampler
5539 VkDescriptorImageInfo img_info = {};
5540 img_info.sampler = sampler;
5541 img_info.imageView = view;
5542 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5543
5544 VkWriteDescriptorSet descriptor_write;
5545 memset(&descriptor_write, 0, sizeof(descriptor_write));
5546 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5547 descriptor_write.dstSet = descriptor_set;
5548 descriptor_write.dstBinding = 0;
5549 descriptor_write.descriptorCount = 1;
5550 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5551 descriptor_write.pImageInfo = &img_info;
5552
5553 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5554
5555 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005556 char const *vsSource =
5557 "#version 450\n"
5558 "\n"
5559 "out gl_PerVertex { \n"
5560 " vec4 gl_Position;\n"
5561 "};\n"
5562 "void main(){\n"
5563 " gl_Position = vec4(1);\n"
5564 "}\n";
5565 char const *fsSource =
5566 "#version 450\n"
5567 "\n"
5568 "layout(set=0, binding=0) uniform sampler2D s;\n"
5569 "layout(location=0) out vec4 x;\n"
5570 "void main(){\n"
5571 " x = texture(s, vec2(1));\n"
5572 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005573 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5574 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5575 VkPipelineObj pipe(m_device);
5576 pipe.AddShader(&vs);
5577 pipe.AddShader(&fs);
5578 pipe.AddColorAttachment();
5579 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5580
Tony Barbour552f6c02016-12-21 14:34:07 -07005581 m_commandBuffer->BeginCommandBuffer();
5582 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005583 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5584 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5585 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005586
5587 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5588 VkRect2D scissor = {{0, 0}, {16, 16}};
5589 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5590 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
5591
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005592 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005593 m_commandBuffer->EndRenderPass();
5594 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005595 // Submit cmd buffer to put pool in-flight
5596 VkSubmitInfo submit_info = {};
5597 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5598 submit_info.commandBufferCount = 1;
5599 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5600 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5601 // Destroy pool while in-flight, causing error
5602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5603 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5604 m_errorMonitor->VerifyFound();
5605 vkQueueWaitIdle(m_device->m_queue);
5606 // Cleanup
5607 vkDestroySampler(m_device->device(), sampler, NULL);
5608 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5609 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5610 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005611 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005612}
5613
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005614TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5615 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5616 ASSERT_NO_FATAL_FAILURE(InitState());
5617 ASSERT_NO_FATAL_FAILURE(InitViewport());
5618 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5619
5620 VkDescriptorPoolSize ds_type_count = {};
5621 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5622 ds_type_count.descriptorCount = 1;
5623
5624 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5625 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5626 ds_pool_ci.pNext = NULL;
5627 ds_pool_ci.maxSets = 1;
5628 ds_pool_ci.poolSizeCount = 1;
5629 ds_pool_ci.pPoolSizes = &ds_type_count;
5630
5631 VkDescriptorPool ds_pool;
5632 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5633 ASSERT_VK_SUCCESS(err);
5634
5635 VkDescriptorSetLayoutBinding dsl_binding = {};
5636 dsl_binding.binding = 0;
5637 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5638 dsl_binding.descriptorCount = 1;
5639 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5640 dsl_binding.pImmutableSamplers = NULL;
5641
5642 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5643 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5644 ds_layout_ci.pNext = NULL;
5645 ds_layout_ci.bindingCount = 1;
5646 ds_layout_ci.pBindings = &dsl_binding;
5647 VkDescriptorSetLayout ds_layout;
5648 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5649 ASSERT_VK_SUCCESS(err);
5650
5651 VkDescriptorSet descriptorSet;
5652 VkDescriptorSetAllocateInfo alloc_info = {};
5653 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5654 alloc_info.descriptorSetCount = 1;
5655 alloc_info.descriptorPool = ds_pool;
5656 alloc_info.pSetLayouts = &ds_layout;
5657 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5658 ASSERT_VK_SUCCESS(err);
5659
5660 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5661 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5662 pipeline_layout_ci.pNext = NULL;
5663 pipeline_layout_ci.setLayoutCount = 1;
5664 pipeline_layout_ci.pSetLayouts = &ds_layout;
5665
5666 VkPipelineLayout pipeline_layout;
5667 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5668 ASSERT_VK_SUCCESS(err);
5669
5670 // Create images to update the descriptor with
5671 VkImage image;
5672 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5673 const int32_t tex_width = 32;
5674 const int32_t tex_height = 32;
5675 VkImageCreateInfo image_create_info = {};
5676 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5677 image_create_info.pNext = NULL;
5678 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5679 image_create_info.format = tex_format;
5680 image_create_info.extent.width = tex_width;
5681 image_create_info.extent.height = tex_height;
5682 image_create_info.extent.depth = 1;
5683 image_create_info.mipLevels = 1;
5684 image_create_info.arrayLayers = 1;
5685 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5686 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5687 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5688 image_create_info.flags = 0;
5689 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5690 ASSERT_VK_SUCCESS(err);
5691 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5692 VkMemoryRequirements memory_reqs;
5693 VkDeviceMemory image_memory;
5694 bool pass;
5695 VkMemoryAllocateInfo memory_info = {};
5696 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5697 memory_info.pNext = NULL;
5698 memory_info.allocationSize = 0;
5699 memory_info.memoryTypeIndex = 0;
5700 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5701 // Allocate enough memory for image
5702 memory_info.allocationSize = memory_reqs.size;
5703 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5704 ASSERT_TRUE(pass);
5705 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5706 ASSERT_VK_SUCCESS(err);
5707 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5708 ASSERT_VK_SUCCESS(err);
5709
5710 VkImageViewCreateInfo image_view_create_info = {};
5711 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5712 image_view_create_info.image = image;
5713 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5714 image_view_create_info.format = tex_format;
5715 image_view_create_info.subresourceRange.layerCount = 1;
5716 image_view_create_info.subresourceRange.baseMipLevel = 0;
5717 image_view_create_info.subresourceRange.levelCount = 1;
5718 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5719
5720 VkImageView view;
5721 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5722 ASSERT_VK_SUCCESS(err);
5723 // Create Samplers
5724 VkSamplerCreateInfo sampler_ci = {};
5725 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5726 sampler_ci.pNext = NULL;
5727 sampler_ci.magFilter = VK_FILTER_NEAREST;
5728 sampler_ci.minFilter = VK_FILTER_NEAREST;
5729 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5730 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5731 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5732 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5733 sampler_ci.mipLodBias = 1.0;
5734 sampler_ci.anisotropyEnable = VK_FALSE;
5735 sampler_ci.maxAnisotropy = 1;
5736 sampler_ci.compareEnable = VK_FALSE;
5737 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5738 sampler_ci.minLod = 1.0;
5739 sampler_ci.maxLod = 1.0;
5740 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5741 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5742 VkSampler sampler;
5743 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5744 ASSERT_VK_SUCCESS(err);
5745 // Update descriptor with image and sampler
5746 VkDescriptorImageInfo img_info = {};
5747 img_info.sampler = sampler;
5748 img_info.imageView = view;
5749 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5750
5751 VkWriteDescriptorSet descriptor_write;
5752 memset(&descriptor_write, 0, sizeof(descriptor_write));
5753 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5754 descriptor_write.dstSet = descriptorSet;
5755 descriptor_write.dstBinding = 0;
5756 descriptor_write.descriptorCount = 1;
5757 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5758 descriptor_write.pImageInfo = &img_info;
5759 // Break memory binding and attempt update
5760 vkFreeMemory(m_device->device(), image_memory, nullptr);
5761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005762 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5764 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5765 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5766 m_errorMonitor->VerifyFound();
5767 // Cleanup
5768 vkDestroyImage(m_device->device(), image, NULL);
5769 vkDestroySampler(m_device->device(), sampler, NULL);
5770 vkDestroyImageView(m_device->device(), view, NULL);
5771 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5772 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5773 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5774}
5775
Karl Schultz6addd812016-02-02 17:17:23 -07005776TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005777 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5778 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005779 // Create a valid cmd buffer
5780 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005781 uint64_t fake_pipeline_handle = 0xbaad6001;
5782 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005783 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005784 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5785
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07005787 m_commandBuffer->BeginCommandBuffer();
5788 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005789 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005790 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005791
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005792 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 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 -06005794 Draw(1, 0, 0, 0);
5795 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005796
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005797 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005798 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 -07005799 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005800 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5801 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005802}
5803
Karl Schultz6addd812016-02-02 17:17:23 -07005804TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005805 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005806 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005807
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005809
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005810 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005811 ASSERT_NO_FATAL_FAILURE(InitViewport());
5812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005813 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005814 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5815 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005816
5817 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005818 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5819 ds_pool_ci.pNext = NULL;
5820 ds_pool_ci.maxSets = 1;
5821 ds_pool_ci.poolSizeCount = 1;
5822 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005823
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005824 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005825 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005826 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005827
Tony Barboureb254902015-07-15 12:50:33 -06005828 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005829 dsl_binding.binding = 0;
5830 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5831 dsl_binding.descriptorCount = 1;
5832 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5833 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005834
Tony Barboureb254902015-07-15 12:50:33 -06005835 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005836 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5837 ds_layout_ci.pNext = NULL;
5838 ds_layout_ci.bindingCount = 1;
5839 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005840 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005841 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005842 ASSERT_VK_SUCCESS(err);
5843
5844 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005845 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005846 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005847 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005848 alloc_info.descriptorPool = ds_pool;
5849 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005850 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005851 ASSERT_VK_SUCCESS(err);
5852
Tony Barboureb254902015-07-15 12:50:33 -06005853 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005854 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5855 pipeline_layout_ci.pNext = NULL;
5856 pipeline_layout_ci.setLayoutCount = 1;
5857 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005858
5859 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005860 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005861 ASSERT_VK_SUCCESS(err);
5862
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005863 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005864 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005865 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005866 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005867
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005868 VkPipelineObj pipe(m_device);
5869 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005870 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005871 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005872 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005873
Tony Barbour552f6c02016-12-21 14:34:07 -07005874 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005875 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5876 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5877 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005878
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005879 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005880
Chia-I Wuf7458c52015-10-26 21:10:41 +08005881 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5882 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5883 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005884}
5885
Karl Schultz6addd812016-02-02 17:17:23 -07005886TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005887 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005888 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005889
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005891
5892 ASSERT_NO_FATAL_FAILURE(InitState());
5893 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005894 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5895 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005896
5897 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005898 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5899 ds_pool_ci.pNext = NULL;
5900 ds_pool_ci.maxSets = 1;
5901 ds_pool_ci.poolSizeCount = 1;
5902 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005903
5904 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005905 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005906 ASSERT_VK_SUCCESS(err);
5907
5908 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005909 dsl_binding.binding = 0;
5910 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5911 dsl_binding.descriptorCount = 1;
5912 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5913 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005914
5915 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005916 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5917 ds_layout_ci.pNext = NULL;
5918 ds_layout_ci.bindingCount = 1;
5919 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005920 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005921 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005922 ASSERT_VK_SUCCESS(err);
5923
5924 VkDescriptorSet descriptorSet;
5925 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005926 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005927 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005928 alloc_info.descriptorPool = ds_pool;
5929 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005930 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005931 ASSERT_VK_SUCCESS(err);
5932
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005933 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005934 VkWriteDescriptorSet descriptor_write;
5935 memset(&descriptor_write, 0, sizeof(descriptor_write));
5936 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5937 descriptor_write.dstSet = descriptorSet;
5938 descriptor_write.dstBinding = 0;
5939 descriptor_write.descriptorCount = 1;
5940 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5941 descriptor_write.pTexelBufferView = &view;
5942
5943 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5944
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005945 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005946
5947 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5948 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5949}
5950
Mark Youngd339ba32016-05-30 13:28:35 -06005951TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005952 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 -06005953
5954 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005956 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005957
5958 ASSERT_NO_FATAL_FAILURE(InitState());
5959
5960 // Create a buffer with no bound memory and then attempt to create
5961 // a buffer view.
5962 VkBufferCreateInfo buff_ci = {};
5963 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005964 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005965 buff_ci.size = 256;
5966 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5967 VkBuffer buffer;
5968 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5969 ASSERT_VK_SUCCESS(err);
5970
5971 VkBufferViewCreateInfo buff_view_ci = {};
5972 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5973 buff_view_ci.buffer = buffer;
5974 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5975 buff_view_ci.range = VK_WHOLE_SIZE;
5976 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005977 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005978
5979 m_errorMonitor->VerifyFound();
5980 vkDestroyBuffer(m_device->device(), buffer, NULL);
5981 // If last error is success, it still created the view, so delete it.
5982 if (err == VK_SUCCESS) {
5983 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5984 }
5985}
5986
Karl Schultz6addd812016-02-02 17:17:23 -07005987TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5988 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5989 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005990 // 1. No dynamicOffset supplied
5991 // 2. Too many dynamicOffsets supplied
5992 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005993 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5995 " requires 1 dynamicOffsets, but only "
5996 "0 dynamicOffsets are left in "
5997 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005998
5999 ASSERT_NO_FATAL_FAILURE(InitState());
6000 ASSERT_NO_FATAL_FAILURE(InitViewport());
6001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6002
6003 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006004 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6005 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006006
6007 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006008 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6009 ds_pool_ci.pNext = NULL;
6010 ds_pool_ci.maxSets = 1;
6011 ds_pool_ci.poolSizeCount = 1;
6012 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006013
6014 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006015 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006016 ASSERT_VK_SUCCESS(err);
6017
6018 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006019 dsl_binding.binding = 0;
6020 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6021 dsl_binding.descriptorCount = 1;
6022 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6023 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006024
6025 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006026 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6027 ds_layout_ci.pNext = NULL;
6028 ds_layout_ci.bindingCount = 1;
6029 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006030 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006031 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006032 ASSERT_VK_SUCCESS(err);
6033
6034 VkDescriptorSet descriptorSet;
6035 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006036 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006037 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006038 alloc_info.descriptorPool = ds_pool;
6039 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006040 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006041 ASSERT_VK_SUCCESS(err);
6042
6043 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006044 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6045 pipeline_layout_ci.pNext = NULL;
6046 pipeline_layout_ci.setLayoutCount = 1;
6047 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006048
6049 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006050 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006051 ASSERT_VK_SUCCESS(err);
6052
6053 // Create a buffer to update the descriptor with
6054 uint32_t qfi = 0;
6055 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006056 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6057 buffCI.size = 1024;
6058 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6059 buffCI.queueFamilyIndexCount = 1;
6060 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006061
6062 VkBuffer dyub;
6063 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6064 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006065 // Allocate memory and bind to buffer so we can make it to the appropriate
6066 // error
6067 VkMemoryAllocateInfo mem_alloc = {};
6068 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6069 mem_alloc.pNext = NULL;
6070 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006071 mem_alloc.memoryTypeIndex = 0;
6072
6073 VkMemoryRequirements memReqs;
6074 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006075 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006076 if (!pass) {
6077 vkDestroyBuffer(m_device->device(), dyub, NULL);
6078 return;
6079 }
6080
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006081 VkDeviceMemory mem;
6082 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6083 ASSERT_VK_SUCCESS(err);
6084 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6085 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006086 // Correctly update descriptor to avoid "NOT_UPDATED" error
6087 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006088 buffInfo.buffer = dyub;
6089 buffInfo.offset = 0;
6090 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006091
6092 VkWriteDescriptorSet descriptor_write;
6093 memset(&descriptor_write, 0, sizeof(descriptor_write));
6094 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6095 descriptor_write.dstSet = descriptorSet;
6096 descriptor_write.dstBinding = 0;
6097 descriptor_write.descriptorCount = 1;
6098 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6099 descriptor_write.pBufferInfo = &buffInfo;
6100
6101 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6102
Tony Barbour552f6c02016-12-21 14:34:07 -07006103 m_commandBuffer->BeginCommandBuffer();
6104 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006105 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6106 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006107 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006108 uint32_t pDynOff[2] = {512, 756};
6109 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6111 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6112 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6113 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006114 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006115 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6117 " dynamic offset 512 combined with "
6118 "offset 0 and range 1024 that "
6119 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006120 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006121 char const *vsSource =
6122 "#version 450\n"
6123 "\n"
6124 "out gl_PerVertex { \n"
6125 " vec4 gl_Position;\n"
6126 "};\n"
6127 "void main(){\n"
6128 " gl_Position = vec4(1);\n"
6129 "}\n";
6130 char const *fsSource =
6131 "#version 450\n"
6132 "\n"
6133 "layout(location=0) out vec4 x;\n"
6134 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6135 "void main(){\n"
6136 " x = vec4(bar.y);\n"
6137 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006138 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6139 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6140 VkPipelineObj pipe(m_device);
6141 pipe.AddShader(&vs);
6142 pipe.AddShader(&fs);
6143 pipe.AddColorAttachment();
6144 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6145
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006146 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6147 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6148 VkRect2D scissor = {{0, 0}, {16, 16}};
6149 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6150
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006151 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006152 // This update should succeed, but offset size of 512 will overstep buffer
6153 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006154 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6155 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006156 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006157 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006158
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006159 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006160 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006161
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006162 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006163 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006164 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6165}
6166
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006167TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006168 TEST_DESCRIPTION(
6169 "Attempt to update a descriptor with a non-sparse buffer "
6170 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006171 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006173 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6175 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006176
6177 ASSERT_NO_FATAL_FAILURE(InitState());
6178 ASSERT_NO_FATAL_FAILURE(InitViewport());
6179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6180
6181 VkDescriptorPoolSize ds_type_count = {};
6182 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6183 ds_type_count.descriptorCount = 1;
6184
6185 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6186 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6187 ds_pool_ci.pNext = NULL;
6188 ds_pool_ci.maxSets = 1;
6189 ds_pool_ci.poolSizeCount = 1;
6190 ds_pool_ci.pPoolSizes = &ds_type_count;
6191
6192 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006193 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006194 ASSERT_VK_SUCCESS(err);
6195
6196 VkDescriptorSetLayoutBinding dsl_binding = {};
6197 dsl_binding.binding = 0;
6198 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6199 dsl_binding.descriptorCount = 1;
6200 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6201 dsl_binding.pImmutableSamplers = NULL;
6202
6203 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6204 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6205 ds_layout_ci.pNext = NULL;
6206 ds_layout_ci.bindingCount = 1;
6207 ds_layout_ci.pBindings = &dsl_binding;
6208 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006209 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006210 ASSERT_VK_SUCCESS(err);
6211
6212 VkDescriptorSet descriptorSet;
6213 VkDescriptorSetAllocateInfo alloc_info = {};
6214 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6215 alloc_info.descriptorSetCount = 1;
6216 alloc_info.descriptorPool = ds_pool;
6217 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006218 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006219 ASSERT_VK_SUCCESS(err);
6220
6221 // Create a buffer to update the descriptor with
6222 uint32_t qfi = 0;
6223 VkBufferCreateInfo buffCI = {};
6224 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6225 buffCI.size = 1024;
6226 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6227 buffCI.queueFamilyIndexCount = 1;
6228 buffCI.pQueueFamilyIndices = &qfi;
6229
6230 VkBuffer dyub;
6231 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6232 ASSERT_VK_SUCCESS(err);
6233
6234 // Attempt to update descriptor without binding memory to it
6235 VkDescriptorBufferInfo buffInfo = {};
6236 buffInfo.buffer = dyub;
6237 buffInfo.offset = 0;
6238 buffInfo.range = 1024;
6239
6240 VkWriteDescriptorSet descriptor_write;
6241 memset(&descriptor_write, 0, sizeof(descriptor_write));
6242 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6243 descriptor_write.dstSet = descriptorSet;
6244 descriptor_write.dstBinding = 0;
6245 descriptor_write.descriptorCount = 1;
6246 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6247 descriptor_write.pBufferInfo = &buffInfo;
6248
6249 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6250 m_errorMonitor->VerifyFound();
6251
6252 vkDestroyBuffer(m_device->device(), dyub, NULL);
6253 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6254 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6255}
6256
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006257TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006258 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006259 ASSERT_NO_FATAL_FAILURE(InitState());
6260 ASSERT_NO_FATAL_FAILURE(InitViewport());
6261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6262
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006263 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006264 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006265 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6266 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6267 pipeline_layout_ci.pushConstantRangeCount = 1;
6268 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6269
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006270 //
6271 // Check for invalid push constant ranges in pipeline layouts.
6272 //
6273 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006274 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006275 char const *msg;
6276 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006277
Karl Schultzc81037d2016-05-12 08:11:23 -06006278 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6279 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6280 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6281 "vkCreatePipelineLayout() call has push constants index 0 with "
6282 "size 0."},
6283 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6284 "vkCreatePipelineLayout() call has push constants index 0 with "
6285 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006286 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006287 "vkCreatePipelineLayout() call has push constants index 0 with "
6288 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006289 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006290 "vkCreatePipelineLayout() call has push constants index 0 with "
6291 "size 0."},
6292 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6293 "vkCreatePipelineLayout() call has push constants index 0 with "
6294 "offset 1. Offset must"},
6295 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6296 "vkCreatePipelineLayout() call has push constants index 0 "
6297 "with offset "},
6298 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6299 "vkCreatePipelineLayout() call has push constants "
6300 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006301 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006302 "vkCreatePipelineLayout() call has push constants index 0 "
6303 "with offset "},
6304 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6305 "vkCreatePipelineLayout() call has push "
6306 "constants index 0 with offset "},
6307 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6308 "vkCreatePipelineLayout() call has push "
6309 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006310 }};
6311
6312 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006313 for (const auto &iter : range_tests) {
6314 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6316 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006317 m_errorMonitor->VerifyFound();
6318 if (VK_SUCCESS == err) {
6319 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6320 }
6321 }
6322
6323 // Check for invalid stage flag
6324 pc_range.offset = 0;
6325 pc_range.size = 16;
6326 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006327 m_errorMonitor->SetDesiredFailureMsg(
6328 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6329 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006330 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006331 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006332 if (VK_SUCCESS == err) {
6333 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6334 }
6335
6336 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006337 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006338 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006339 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006340 char const *msg;
6341 };
6342
Karl Schultzc81037d2016-05-12 08:11:23 -06006343 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006344 {{{{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},
6348 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006349 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006350 {
6351 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6352 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6353 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6354 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6355 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006356 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006357 },
6358 {
6359 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6360 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6361 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6362 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6363 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006364 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006365 },
6366 {
6367 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6368 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6369 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6370 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6371 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006372 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006373 },
6374 {
6375 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6376 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6377 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6378 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6379 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006380 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006381 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006382
Karl Schultzc81037d2016-05-12 08:11:23 -06006383 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006384 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006385 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6387 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006388 m_errorMonitor->VerifyFound();
6389 if (VK_SUCCESS == err) {
6390 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6391 }
6392 }
6393
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006394 //
6395 // CmdPushConstants tests
6396 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006397 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006398
6399 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006400 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6401 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006402 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006403 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6404 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006405 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006406 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6407 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006408 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006409 "vkCmdPushConstants() call has push constants with offset 1. "
6410 "Offset must be a multiple of 4."},
6411 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6412 "vkCmdPushConstants() call has push constants with offset 1. "
6413 "Offset must be a multiple of 4."},
6414 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6415 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6416 "0x1 not within flag-matching ranges in pipeline layout"},
6417 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6418 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6419 "0x1 not within flag-matching ranges in pipeline layout"},
6420 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6421 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6422 "0x1 not within flag-matching ranges in pipeline layout"},
6423 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6424 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6425 "0x1 not within flag-matching ranges in pipeline layout"},
6426 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6427 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6428 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006429 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006430 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6431 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006432 }};
6433
Tony Barbour552f6c02016-12-21 14:34:07 -07006434 m_commandBuffer->BeginCommandBuffer();
6435 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006436
6437 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006438 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006439 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006440 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006441 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006442 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006444 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006445 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6447 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006448 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006449 m_errorMonitor->VerifyFound();
6450 }
6451
6452 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006454 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006455 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006456 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006457
Karl Schultzc81037d2016-05-12 08:11:23 -06006458 // overlapping range tests with cmd
6459 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6460 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6461 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6462 "0x1 not within flag-matching ranges in pipeline layout"},
6463 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6464 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6465 "0x1 not within flag-matching ranges in pipeline layout"},
6466 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6467 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6468 "0x1 not within flag-matching ranges in pipeline layout"},
6469 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006470 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006471 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006472 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6473 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006474 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006475 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006476 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006477 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006478 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006479 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6481 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006482 iter.range.size, dummy_values);
6483 m_errorMonitor->VerifyFound();
6484 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006485 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6486
Tony Barbour552f6c02016-12-21 14:34:07 -07006487 m_commandBuffer->EndRenderPass();
6488 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006489}
6490
Karl Schultz6addd812016-02-02 17:17:23 -07006491TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006492 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006493 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006494
6495 ASSERT_NO_FATAL_FAILURE(InitState());
6496 ASSERT_NO_FATAL_FAILURE(InitViewport());
6497 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6498
6499 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6500 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006501 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6502 ds_type_count[0].descriptorCount = 10;
6503 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6504 ds_type_count[1].descriptorCount = 2;
6505 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6506 ds_type_count[2].descriptorCount = 2;
6507 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6508 ds_type_count[3].descriptorCount = 5;
6509 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6510 // type
6511 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6512 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6513 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006514
6515 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006516 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6517 ds_pool_ci.pNext = NULL;
6518 ds_pool_ci.maxSets = 5;
6519 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6520 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006521
6522 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006523 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006524 ASSERT_VK_SUCCESS(err);
6525
6526 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6527 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006528 dsl_binding[0].binding = 0;
6529 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6530 dsl_binding[0].descriptorCount = 5;
6531 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6532 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006533
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006534 // Create layout identical to set0 layout but w/ different stageFlags
6535 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006536 dsl_fs_stage_only.binding = 0;
6537 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6538 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006539 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6540 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006541 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006542 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006543 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6544 ds_layout_ci.pNext = NULL;
6545 ds_layout_ci.bindingCount = 1;
6546 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006547 static const uint32_t NUM_LAYOUTS = 4;
6548 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006549 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006550 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6551 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006552 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006553 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006554 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006555 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006556 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006557 dsl_binding[0].binding = 0;
6558 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006559 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006560 dsl_binding[1].binding = 1;
6561 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6562 dsl_binding[1].descriptorCount = 2;
6563 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6564 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006565 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006566 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006567 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006568 ASSERT_VK_SUCCESS(err);
6569 dsl_binding[0].binding = 0;
6570 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006571 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006572 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006573 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006574 ASSERT_VK_SUCCESS(err);
6575 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006576 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006577 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006578 ASSERT_VK_SUCCESS(err);
6579
6580 static const uint32_t NUM_SETS = 4;
6581 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6582 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006583 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006584 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006585 alloc_info.descriptorPool = ds_pool;
6586 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006587 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006588 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006589 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006590 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006591 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006592 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006593 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006594
6595 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006596 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6597 pipeline_layout_ci.pNext = NULL;
6598 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6599 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006600
6601 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006602 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006603 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006604 // Create pipelineLayout with only one setLayout
6605 pipeline_layout_ci.setLayoutCount = 1;
6606 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006607 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006608 ASSERT_VK_SUCCESS(err);
6609 // Create pipelineLayout with 2 descriptor setLayout at index 0
6610 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6611 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006612 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006613 ASSERT_VK_SUCCESS(err);
6614 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6615 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6616 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006617 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006618 ASSERT_VK_SUCCESS(err);
6619 // Create pipelineLayout with UB type, but stageFlags for FS only
6620 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6621 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006622 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006623 ASSERT_VK_SUCCESS(err);
6624 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6625 VkDescriptorSetLayout pl_bad_s0[2] = {};
6626 pl_bad_s0[0] = ds_layout_fs_only;
6627 pl_bad_s0[1] = ds_layout[1];
6628 pipeline_layout_ci.setLayoutCount = 2;
6629 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6630 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006631 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006632 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006633
Tobin Ehlis88452832015-12-03 09:40:56 -07006634 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006635 char const *vsSource =
6636 "#version 450\n"
6637 "\n"
6638 "out gl_PerVertex {\n"
6639 " vec4 gl_Position;\n"
6640 "};\n"
6641 "void main(){\n"
6642 " gl_Position = vec4(1);\n"
6643 "}\n";
6644 char const *fsSource =
6645 "#version 450\n"
6646 "\n"
6647 "layout(location=0) out vec4 x;\n"
6648 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6649 "void main(){\n"
6650 " x = vec4(bar.y);\n"
6651 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006652 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6653 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006654 VkPipelineObj pipe(m_device);
6655 pipe.AddShader(&vs);
6656 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006657 pipe.AddColorAttachment();
6658 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006659
Tony Barbour552f6c02016-12-21 14:34:07 -07006660 m_commandBuffer->BeginCommandBuffer();
6661 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07006662
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006663 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006664 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6665 // of PSO
6666 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6667 // cmd_pipeline.c
6668 // due to the fact that cmd_alloc_dset_data() has not been called in
6669 // cmd_bind_graphics_pipeline()
6670 // TODO : Want to cause various binding incompatibility issues here to test
6671 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006672 // First cause various verify_layout_compatibility() fails
6673 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006674 // verify_set_layout_compatibility fail cases:
6675 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006677 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6678 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006679 m_errorMonitor->VerifyFound();
6680
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006681 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6683 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6684 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006685 m_errorMonitor->VerifyFound();
6686
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006687 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006688 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6689 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6691 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6692 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006693 m_errorMonitor->VerifyFound();
6694
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006695 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6696 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6698 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6699 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006700 m_errorMonitor->VerifyFound();
6701
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006702 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6703 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6705 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6706 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6707 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006708 m_errorMonitor->VerifyFound();
6709
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006710 // Cause INFO messages due to disturbing previously bound Sets
6711 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006712 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6713 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006714 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6716 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6717 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006718 m_errorMonitor->VerifyFound();
6719
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006720 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6721 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006722 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6724 " newly bound as set #0 so set #1 and "
6725 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006726 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6727 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006728 m_errorMonitor->VerifyFound();
6729
Tobin Ehlis10fad692016-07-07 12:00:36 -06006730 // Now that we're done actively using the pipelineLayout that gfx pipeline
6731 // was created with, we should be able to delete it. Do that now to verify
6732 // that validation obeys pipelineLayout lifetime
6733 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6734
Tobin Ehlis88452832015-12-03 09:40:56 -07006735 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006736 // 1. Error due to not binding required set (we actually use same code as
6737 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006738 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6739 &descriptorSet[0], 0, NULL);
6740 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6741 &descriptorSet[1], 0, NULL);
6742 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 -07006743
6744 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6745 VkRect2D scissor = {{0, 0}, {16, 16}};
6746 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6747 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6748
Tobin Ehlis88452832015-12-03 09:40:56 -07006749 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006750 m_errorMonitor->VerifyFound();
6751
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006752 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006753 // 2. Error due to bound set not being compatible with PSO's
6754 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006755 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6756 &descriptorSet[0], 0, NULL);
6757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006758 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006759 m_errorMonitor->VerifyFound();
6760
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006761 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006762 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006763 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6764 }
6765 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006766 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6767 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6768}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006769
Karl Schultz6addd812016-02-02 17:17:23 -07006770TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6772 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006773
6774 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006775 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006776 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006777 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006778
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006779 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006780}
6781
Karl Schultz6addd812016-02-02 17:17:23 -07006782TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6783 VkResult err;
6784 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006785
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006787
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006788 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006789
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006790 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006791 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006792 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006793 cmd.commandPool = m_commandPool;
6794 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006795 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006796
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006797 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006798 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006799
6800 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07006801 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07006802 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
6803
6804 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006805 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006806 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006807 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 -07006808 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006809
6810 // The error should be caught by validation of the BeginCommandBuffer call
6811 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6812
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006813 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006814 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006815}
6816
Karl Schultz6addd812016-02-02 17:17:23 -07006817TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006818 // Cause error due to Begin while recording CB
6819 // Then cause 2 errors for attempting to reset CB w/o having
6820 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6821 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006823
6824 ASSERT_NO_FATAL_FAILURE(InitState());
6825
6826 // Calls AllocateCommandBuffers
6827 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6828
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006829 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07006830 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006831 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
6832 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006833 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6834 cmd_buf_info.pNext = NULL;
6835 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006836 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006837
6838 // Begin CB to transition to recording state
6839 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6840 // Can't re-begin. This should trigger error
6841 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006842 m_errorMonitor->VerifyFound();
6843
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006845 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006846 // Reset attempt will trigger error due to incorrect CommandPool state
6847 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006848 m_errorMonitor->VerifyFound();
6849
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006851 // Transition CB to RECORDED state
6852 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6853 // Now attempting to Begin will implicitly reset, which triggers error
6854 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006855 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006856}
6857
Karl Schultz6addd812016-02-02 17:17:23 -07006858TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006859 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006860 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006861
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07006862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6863 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006864
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006865 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006866 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006867
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006868 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006869 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6870 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006871
6872 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006873 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6874 ds_pool_ci.pNext = NULL;
6875 ds_pool_ci.maxSets = 1;
6876 ds_pool_ci.poolSizeCount = 1;
6877 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006878
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006879 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006880 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006881 ASSERT_VK_SUCCESS(err);
6882
Tony Barboureb254902015-07-15 12:50:33 -06006883 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006884 dsl_binding.binding = 0;
6885 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6886 dsl_binding.descriptorCount = 1;
6887 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6888 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006889
Tony Barboureb254902015-07-15 12:50:33 -06006890 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006891 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6892 ds_layout_ci.pNext = NULL;
6893 ds_layout_ci.bindingCount = 1;
6894 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006895
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006896 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006897 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006898 ASSERT_VK_SUCCESS(err);
6899
6900 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006901 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006902 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006903 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006904 alloc_info.descriptorPool = ds_pool;
6905 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006906 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006907 ASSERT_VK_SUCCESS(err);
6908
Tony Barboureb254902015-07-15 12:50:33 -06006909 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006910 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6911 pipeline_layout_ci.setLayoutCount = 1;
6912 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006913
6914 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006915 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006916 ASSERT_VK_SUCCESS(err);
6917
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006918 VkViewport vp = {}; // Just need dummy vp to point to
6919 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006920
6921 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006922 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
6923 vp_state_ci.scissorCount = 1;
6924 vp_state_ci.pScissors = &sc;
6925 vp_state_ci.viewportCount = 1;
6926 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06006927
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006928 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
6929 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
6930 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
6931 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
6932 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
6933 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07006934 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006935 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07006936 rs_state_ci.lineWidth = 1.0f;
6937
6938 VkPipelineVertexInputStateCreateInfo vi_ci = {};
6939 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
6940 vi_ci.pNext = nullptr;
6941 vi_ci.vertexBindingDescriptionCount = 0;
6942 vi_ci.pVertexBindingDescriptions = nullptr;
6943 vi_ci.vertexAttributeDescriptionCount = 0;
6944 vi_ci.pVertexAttributeDescriptions = nullptr;
6945
6946 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
6947 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
6948 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
6949
6950 VkPipelineShaderStageCreateInfo shaderStages[2];
6951 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
6952
6953 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
6954 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6955 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
6956 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006957
Tony Barboureb254902015-07-15 12:50:33 -06006958 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006959 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6960 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006961 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006962 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6963 gp_ci.layout = pipeline_layout;
6964 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07006965 gp_ci.pVertexInputState = &vi_ci;
6966 gp_ci.pInputAssemblyState = &ia_ci;
6967
6968 gp_ci.stageCount = 1;
6969 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06006970
6971 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006972 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6973 pc_ci.initialDataSize = 0;
6974 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006975
6976 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006977 VkPipelineCache pipelineCache;
6978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006979 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006980 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006981 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006982 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006983
Chia-I Wuf7458c52015-10-26 21:10:41 +08006984 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6985 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6986 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6987 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006988}
Rene Lindsayae4977b2017-01-23 14:55:54 -07006989
Tobin Ehlis912df022015-09-17 08:46:18 -06006990/*// TODO : This test should be good, but needs Tess support in compiler to run
6991TEST_F(VkLayerTest, InvalidPatchControlPoints)
6992{
6993 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006994 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006995
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006997 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6998primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006999
Tobin Ehlis912df022015-09-17 08:46:18 -06007000 ASSERT_NO_FATAL_FAILURE(InitState());
7001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007002
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007003 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007004 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007005 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007006
7007 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7008 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7009 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007010 ds_pool_ci.poolSizeCount = 1;
7011 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007012
7013 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007014 err = vkCreateDescriptorPool(m_device->device(),
7015VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007016 ASSERT_VK_SUCCESS(err);
7017
7018 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007019 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007020 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007021 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007022 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7023 dsl_binding.pImmutableSamplers = NULL;
7024
7025 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007026 ds_layout_ci.sType =
7027VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007028 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007029 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007030 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007031
7032 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007033 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7034&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007035 ASSERT_VK_SUCCESS(err);
7036
7037 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007038 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7039VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007040 ASSERT_VK_SUCCESS(err);
7041
7042 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007043 pipeline_layout_ci.sType =
7044VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007045 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007046 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007047 pipeline_layout_ci.pSetLayouts = &ds_layout;
7048
7049 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007050 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7051&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007052 ASSERT_VK_SUCCESS(err);
7053
7054 VkPipelineShaderStageCreateInfo shaderStages[3];
7055 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7056
Karl Schultz6addd812016-02-02 17:17:23 -07007057 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7058this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007059 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007060 VkShaderObj
7061tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7062this);
7063 VkShaderObj
7064te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7065this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007066
Karl Schultz6addd812016-02-02 17:17:23 -07007067 shaderStages[0].sType =
7068VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007069 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007070 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007071 shaderStages[1].sType =
7072VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007073 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007074 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007075 shaderStages[2].sType =
7076VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007077 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007078 shaderStages[2].shader = te.handle();
7079
7080 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007081 iaCI.sType =
7082VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007083 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007084
7085 VkPipelineTessellationStateCreateInfo tsCI = {};
7086 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7087 tsCI.patchControlPoints = 0; // This will cause an error
7088
7089 VkGraphicsPipelineCreateInfo gp_ci = {};
7090 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7091 gp_ci.pNext = NULL;
7092 gp_ci.stageCount = 3;
7093 gp_ci.pStages = shaderStages;
7094 gp_ci.pVertexInputState = NULL;
7095 gp_ci.pInputAssemblyState = &iaCI;
7096 gp_ci.pTessellationState = &tsCI;
7097 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007098 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007099 gp_ci.pMultisampleState = NULL;
7100 gp_ci.pDepthStencilState = NULL;
7101 gp_ci.pColorBlendState = NULL;
7102 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7103 gp_ci.layout = pipeline_layout;
7104 gp_ci.renderPass = renderPass();
7105
7106 VkPipelineCacheCreateInfo pc_ci = {};
7107 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7108 pc_ci.pNext = NULL;
7109 pc_ci.initialSize = 0;
7110 pc_ci.initialData = 0;
7111 pc_ci.maxSize = 0;
7112
7113 VkPipeline pipeline;
7114 VkPipelineCache pipelineCache;
7115
Karl Schultz6addd812016-02-02 17:17:23 -07007116 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7117&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007118 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007119 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7120&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007121
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007122 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007123
Chia-I Wuf7458c52015-10-26 21:10:41 +08007124 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7125 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7126 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7127 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007128}
7129*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007130
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007131TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007132 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007133
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007134 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007135
Tobin Ehlise68360f2015-10-01 11:15:13 -06007136 ASSERT_NO_FATAL_FAILURE(InitState());
7137 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007138
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007139 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007140 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7141 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007142
7143 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007144 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7145 ds_pool_ci.maxSets = 1;
7146 ds_pool_ci.poolSizeCount = 1;
7147 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007148
7149 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007150 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007151 ASSERT_VK_SUCCESS(err);
7152
7153 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007154 dsl_binding.binding = 0;
7155 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7156 dsl_binding.descriptorCount = 1;
7157 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007158
7159 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007160 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7161 ds_layout_ci.bindingCount = 1;
7162 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007163
7164 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007165 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007166 ASSERT_VK_SUCCESS(err);
7167
7168 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007169 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007170 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007171 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007172 alloc_info.descriptorPool = ds_pool;
7173 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007174 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007175 ASSERT_VK_SUCCESS(err);
7176
7177 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007178 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7179 pipeline_layout_ci.setLayoutCount = 1;
7180 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007181
7182 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007183 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007184 ASSERT_VK_SUCCESS(err);
7185
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007186 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007187 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007188 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007189 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007190 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007191 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007192
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007193 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7194 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7195 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7196 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7197 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7198 rs_state_ci.depthClampEnable = VK_FALSE;
7199 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7200 rs_state_ci.depthBiasEnable = VK_FALSE;
7201
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007202 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7203 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7204 vi_ci.pNext = nullptr;
7205 vi_ci.vertexBindingDescriptionCount = 0;
7206 vi_ci.pVertexBindingDescriptions = nullptr;
7207 vi_ci.vertexAttributeDescriptionCount = 0;
7208 vi_ci.pVertexAttributeDescriptions = nullptr;
7209
7210 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7211 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7212 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7213
7214 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7215 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7216 pipe_ms_state_ci.pNext = NULL;
7217 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7218 pipe_ms_state_ci.sampleShadingEnable = 0;
7219 pipe_ms_state_ci.minSampleShading = 1.0;
7220 pipe_ms_state_ci.pSampleMask = NULL;
7221
Cody Northropeb3a6c12015-10-05 14:44:45 -06007222 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007223 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007224
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007225 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007226 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007227 shaderStages[0] = vs.GetStageCreateInfo();
7228 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007229
7230 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007231 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7232 gp_ci.stageCount = 2;
7233 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007234 gp_ci.pVertexInputState = &vi_ci;
7235 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007236 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007237 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007238 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007239 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7240 gp_ci.layout = pipeline_layout;
7241 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007242
7243 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007244 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007245
7246 VkPipeline pipeline;
7247 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007248 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007249 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007250
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007251 if (!m_device->phy().features().multiViewport) {
7252 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7253
7254 // Check case where multiViewport is disabled and viewport count is not 1
7255 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7258 vp_state_ci.scissorCount = 0;
7259 vp_state_ci.viewportCount = 0;
7260 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7261 m_errorMonitor->VerifyFound();
7262 } else {
7263 if (m_device->props.limits.maxViewports == 1) {
7264 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7265 } else {
7266 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7267
7268 // Check is that viewportcount and scissorcount match
7269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7270 vp_state_ci.scissorCount = 1;
7271 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7272 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7273 m_errorMonitor->VerifyFound();
7274
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007275 // Check case where multiViewport is enabled and viewport count is greater than max
7276 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7279 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7280 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7281 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7282 m_errorMonitor->VerifyFound();
7283 }
7284 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007285
Chia-I Wuf7458c52015-10-26 21:10:41 +08007286 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7287 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7288 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7289 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007290}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007291
7292// 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
7293// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007294TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007295 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007296
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007297 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7298
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007300
Tobin Ehlise68360f2015-10-01 11:15:13 -06007301 ASSERT_NO_FATAL_FAILURE(InitState());
7302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007303
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007304 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007305 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7306 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007307
7308 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007309 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7310 ds_pool_ci.maxSets = 1;
7311 ds_pool_ci.poolSizeCount = 1;
7312 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007313
7314 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007315 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007316 ASSERT_VK_SUCCESS(err);
7317
7318 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007319 dsl_binding.binding = 0;
7320 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7321 dsl_binding.descriptorCount = 1;
7322 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007323
7324 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007325 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7326 ds_layout_ci.bindingCount = 1;
7327 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007328
7329 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007330 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007331 ASSERT_VK_SUCCESS(err);
7332
7333 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007334 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007335 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007336 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007337 alloc_info.descriptorPool = ds_pool;
7338 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007339 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007340 ASSERT_VK_SUCCESS(err);
7341
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007342 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7343 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7344 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7345
7346 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7347 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7348 vi_ci.pNext = nullptr;
7349 vi_ci.vertexBindingDescriptionCount = 0;
7350 vi_ci.pVertexBindingDescriptions = nullptr;
7351 vi_ci.vertexAttributeDescriptionCount = 0;
7352 vi_ci.pVertexAttributeDescriptions = nullptr;
7353
7354 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7355 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7356 pipe_ms_state_ci.pNext = NULL;
7357 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7358 pipe_ms_state_ci.sampleShadingEnable = 0;
7359 pipe_ms_state_ci.minSampleShading = 1.0;
7360 pipe_ms_state_ci.pSampleMask = NULL;
7361
Tobin Ehlise68360f2015-10-01 11:15:13 -06007362 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007363 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7364 pipeline_layout_ci.setLayoutCount = 1;
7365 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007366
7367 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007368 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007369 ASSERT_VK_SUCCESS(err);
7370
7371 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7372 // Set scissor as dynamic to avoid second error
7373 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007374 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7375 dyn_state_ci.dynamicStateCount = 1;
7376 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007377
Cody Northropeb3a6c12015-10-05 14:44:45 -06007378 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007379 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007380
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007381 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007382 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7383 // 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 +08007384 shaderStages[0] = vs.GetStageCreateInfo();
7385 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007386
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007387 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7388 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7389 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7390 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7391 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7392 rs_state_ci.depthClampEnable = VK_FALSE;
7393 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7394 rs_state_ci.depthBiasEnable = VK_FALSE;
7395
Tobin Ehlise68360f2015-10-01 11:15:13 -06007396 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007397 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7398 gp_ci.stageCount = 2;
7399 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007400 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007401 // Not setting VP state w/o dynamic vp state should cause validation error
7402 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007403 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007404 gp_ci.pVertexInputState = &vi_ci;
7405 gp_ci.pInputAssemblyState = &ia_ci;
7406 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007407 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7408 gp_ci.layout = pipeline_layout;
7409 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007410
7411 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007412 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007413
7414 VkPipeline pipeline;
7415 VkPipelineCache pipelineCache;
7416
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007417 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007418 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007419 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007420
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007421 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007422
Chia-I Wuf7458c52015-10-26 21:10:41 +08007423 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7424 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7425 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7426 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007427}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007428
7429// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7430// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007431TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7432 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007433
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007435
Tobin Ehlise68360f2015-10-01 11:15:13 -06007436 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007437
7438 if (!m_device->phy().features().multiViewport) {
7439 printf("Device does not support multiple viewports/scissors; skipped.\n");
7440 return;
7441 }
7442
Tobin Ehlise68360f2015-10-01 11:15:13 -06007443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007444
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007445 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007446 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7447 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007448
7449 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007450 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7451 ds_pool_ci.maxSets = 1;
7452 ds_pool_ci.poolSizeCount = 1;
7453 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007454
7455 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007456 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007457 ASSERT_VK_SUCCESS(err);
7458
7459 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007460 dsl_binding.binding = 0;
7461 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7462 dsl_binding.descriptorCount = 1;
7463 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007464
7465 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007466 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7467 ds_layout_ci.bindingCount = 1;
7468 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007469
7470 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007471 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007472 ASSERT_VK_SUCCESS(err);
7473
7474 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007475 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007476 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007477 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007478 alloc_info.descriptorPool = ds_pool;
7479 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007480 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007481 ASSERT_VK_SUCCESS(err);
7482
7483 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007484 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7485 pipeline_layout_ci.setLayoutCount = 1;
7486 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007487
7488 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007489 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007490 ASSERT_VK_SUCCESS(err);
7491
7492 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007493 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7494 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007495 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007496 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007497 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007498
7499 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7500 // Set scissor as dynamic to avoid that error
7501 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007502 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7503 dyn_state_ci.dynamicStateCount = 1;
7504 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007505
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007506 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7507 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7508 pipe_ms_state_ci.pNext = NULL;
7509 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7510 pipe_ms_state_ci.sampleShadingEnable = 0;
7511 pipe_ms_state_ci.minSampleShading = 1.0;
7512 pipe_ms_state_ci.pSampleMask = NULL;
7513
Cody Northropeb3a6c12015-10-05 14:44:45 -06007514 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007515 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007516
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007517 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007518 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7519 // 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 +08007520 shaderStages[0] = vs.GetStageCreateInfo();
7521 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007522
Cody Northropf6622dc2015-10-06 10:33:21 -06007523 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7524 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7525 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007526 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007527 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007528 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007529 vi_ci.pVertexAttributeDescriptions = nullptr;
7530
7531 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7532 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7533 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7534
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007535 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007536 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007537 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007538 rs_ci.pNext = nullptr;
7539
Mark Youngc89c6312016-03-31 16:03:20 -06007540 VkPipelineColorBlendAttachmentState att = {};
7541 att.blendEnable = VK_FALSE;
7542 att.colorWriteMask = 0xf;
7543
Cody Northropf6622dc2015-10-06 10:33:21 -06007544 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7545 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7546 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007547 cb_ci.attachmentCount = 1;
7548 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007549
Tobin Ehlise68360f2015-10-01 11:15:13 -06007550 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007551 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7552 gp_ci.stageCount = 2;
7553 gp_ci.pStages = shaderStages;
7554 gp_ci.pVertexInputState = &vi_ci;
7555 gp_ci.pInputAssemblyState = &ia_ci;
7556 gp_ci.pViewportState = &vp_state_ci;
7557 gp_ci.pRasterizationState = &rs_ci;
7558 gp_ci.pColorBlendState = &cb_ci;
7559 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007560 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007561 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7562 gp_ci.layout = pipeline_layout;
7563 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007564
7565 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007566 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007567
7568 VkPipeline pipeline;
7569 VkPipelineCache pipelineCache;
7570
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007571 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007572 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007573 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007574
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007575 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007576
Tobin Ehlisd332f282015-10-02 11:00:56 -06007577 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007578 // First need to successfully create the PSO from above by setting
7579 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007580 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 -07007581
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007582 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07007583 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007584 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007585 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007586 m_commandBuffer->BeginCommandBuffer();
7587 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007588 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007589 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007590 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007591 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007592 Draw(1, 0, 0, 0);
7593
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007594 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007595
7596 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7597 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7598 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7599 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007600 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007601}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007602
7603// 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 -07007604// viewportCount
7605TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7606 VkResult err;
7607
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007609
7610 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007611
7612 if (!m_device->phy().features().multiViewport) {
7613 printf("Device does not support multiple viewports/scissors; skipped.\n");
7614 return;
7615 }
7616
Karl Schultz6addd812016-02-02 17:17:23 -07007617 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7618
7619 VkDescriptorPoolSize ds_type_count = {};
7620 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7621 ds_type_count.descriptorCount = 1;
7622
7623 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7624 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7625 ds_pool_ci.maxSets = 1;
7626 ds_pool_ci.poolSizeCount = 1;
7627 ds_pool_ci.pPoolSizes = &ds_type_count;
7628
7629 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007630 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007631 ASSERT_VK_SUCCESS(err);
7632
7633 VkDescriptorSetLayoutBinding dsl_binding = {};
7634 dsl_binding.binding = 0;
7635 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7636 dsl_binding.descriptorCount = 1;
7637 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7638
7639 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7640 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7641 ds_layout_ci.bindingCount = 1;
7642 ds_layout_ci.pBindings = &dsl_binding;
7643
7644 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007645 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007646 ASSERT_VK_SUCCESS(err);
7647
7648 VkDescriptorSet descriptorSet;
7649 VkDescriptorSetAllocateInfo alloc_info = {};
7650 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7651 alloc_info.descriptorSetCount = 1;
7652 alloc_info.descriptorPool = ds_pool;
7653 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007654 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007655 ASSERT_VK_SUCCESS(err);
7656
7657 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7658 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7659 pipeline_layout_ci.setLayoutCount = 1;
7660 pipeline_layout_ci.pSetLayouts = &ds_layout;
7661
7662 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007663 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007664 ASSERT_VK_SUCCESS(err);
7665
7666 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7667 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7668 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007669 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007670 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007671 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007672
7673 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7674 // Set scissor as dynamic to avoid that error
7675 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7676 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7677 dyn_state_ci.dynamicStateCount = 1;
7678 dyn_state_ci.pDynamicStates = &vp_state;
7679
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007680 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7681 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7682 pipe_ms_state_ci.pNext = NULL;
7683 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7684 pipe_ms_state_ci.sampleShadingEnable = 0;
7685 pipe_ms_state_ci.minSampleShading = 1.0;
7686 pipe_ms_state_ci.pSampleMask = NULL;
7687
Karl Schultz6addd812016-02-02 17:17:23 -07007688 VkPipelineShaderStageCreateInfo shaderStages[2];
7689 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7690
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007691 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007692 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7693 // 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 -07007694 shaderStages[0] = vs.GetStageCreateInfo();
7695 shaderStages[1] = fs.GetStageCreateInfo();
7696
7697 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7698 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7699 vi_ci.pNext = nullptr;
7700 vi_ci.vertexBindingDescriptionCount = 0;
7701 vi_ci.pVertexBindingDescriptions = nullptr;
7702 vi_ci.vertexAttributeDescriptionCount = 0;
7703 vi_ci.pVertexAttributeDescriptions = nullptr;
7704
7705 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7706 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7707 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7708
7709 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7710 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007711 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007712 rs_ci.pNext = nullptr;
7713
Mark Youngc89c6312016-03-31 16:03:20 -06007714 VkPipelineColorBlendAttachmentState att = {};
7715 att.blendEnable = VK_FALSE;
7716 att.colorWriteMask = 0xf;
7717
Karl Schultz6addd812016-02-02 17:17:23 -07007718 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7719 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7720 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007721 cb_ci.attachmentCount = 1;
7722 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007723
7724 VkGraphicsPipelineCreateInfo gp_ci = {};
7725 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7726 gp_ci.stageCount = 2;
7727 gp_ci.pStages = shaderStages;
7728 gp_ci.pVertexInputState = &vi_ci;
7729 gp_ci.pInputAssemblyState = &ia_ci;
7730 gp_ci.pViewportState = &vp_state_ci;
7731 gp_ci.pRasterizationState = &rs_ci;
7732 gp_ci.pColorBlendState = &cb_ci;
7733 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007734 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007735 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7736 gp_ci.layout = pipeline_layout;
7737 gp_ci.renderPass = renderPass();
7738
7739 VkPipelineCacheCreateInfo pc_ci = {};
7740 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7741
7742 VkPipeline pipeline;
7743 VkPipelineCache pipelineCache;
7744
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007745 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007746 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007747 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007748
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007749 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007750
7751 // Now hit second fail case where we set scissor w/ different count than PSO
7752 // First need to successfully create the PSO from above by setting
7753 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7755 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007756
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007757 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06007758 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007759 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007760 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007761 m_commandBuffer->BeginCommandBuffer();
7762 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007763 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007764 VkViewport viewports[1] = {};
7765 viewports[0].width = 8;
7766 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007767 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007768 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007769 Draw(1, 0, 0, 0);
7770
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007771 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007772
Chia-I Wuf7458c52015-10-26 21:10:41 +08007773 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7774 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7775 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7776 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007777 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007778}
7779
Mark Young7394fdd2016-03-31 14:56:43 -06007780TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7781 VkResult err;
7782
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007784
7785 ASSERT_NO_FATAL_FAILURE(InitState());
7786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7787
7788 VkDescriptorPoolSize ds_type_count = {};
7789 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7790 ds_type_count.descriptorCount = 1;
7791
7792 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7793 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7794 ds_pool_ci.maxSets = 1;
7795 ds_pool_ci.poolSizeCount = 1;
7796 ds_pool_ci.pPoolSizes = &ds_type_count;
7797
7798 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007799 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007800 ASSERT_VK_SUCCESS(err);
7801
7802 VkDescriptorSetLayoutBinding dsl_binding = {};
7803 dsl_binding.binding = 0;
7804 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7805 dsl_binding.descriptorCount = 1;
7806 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7807
7808 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7809 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7810 ds_layout_ci.bindingCount = 1;
7811 ds_layout_ci.pBindings = &dsl_binding;
7812
7813 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007814 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007815 ASSERT_VK_SUCCESS(err);
7816
7817 VkDescriptorSet descriptorSet;
7818 VkDescriptorSetAllocateInfo alloc_info = {};
7819 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7820 alloc_info.descriptorSetCount = 1;
7821 alloc_info.descriptorPool = ds_pool;
7822 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007823 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007824 ASSERT_VK_SUCCESS(err);
7825
7826 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7827 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7828 pipeline_layout_ci.setLayoutCount = 1;
7829 pipeline_layout_ci.pSetLayouts = &ds_layout;
7830
7831 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007832 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007833 ASSERT_VK_SUCCESS(err);
7834
7835 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7836 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7837 vp_state_ci.scissorCount = 1;
7838 vp_state_ci.pScissors = NULL;
7839 vp_state_ci.viewportCount = 1;
7840 vp_state_ci.pViewports = NULL;
7841
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007842 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007843 // Set scissor as dynamic to avoid that error
7844 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7845 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7846 dyn_state_ci.dynamicStateCount = 2;
7847 dyn_state_ci.pDynamicStates = dynamic_states;
7848
7849 VkPipelineShaderStageCreateInfo shaderStages[2];
7850 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7851
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007852 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7853 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007854 this); // TODO - We shouldn't need a fragment shader
7855 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06007856 shaderStages[0] = vs.GetStageCreateInfo();
7857 shaderStages[1] = fs.GetStageCreateInfo();
7858
7859 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7860 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7861 vi_ci.pNext = nullptr;
7862 vi_ci.vertexBindingDescriptionCount = 0;
7863 vi_ci.pVertexBindingDescriptions = nullptr;
7864 vi_ci.vertexAttributeDescriptionCount = 0;
7865 vi_ci.pVertexAttributeDescriptions = nullptr;
7866
7867 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7868 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7869 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7870
7871 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7872 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7873 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07007874 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06007875
Mark Young47107952016-05-02 15:59:55 -06007876 // Check too low (line width of -1.0f).
7877 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007878
7879 VkPipelineColorBlendAttachmentState att = {};
7880 att.blendEnable = VK_FALSE;
7881 att.colorWriteMask = 0xf;
7882
7883 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7884 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7885 cb_ci.pNext = nullptr;
7886 cb_ci.attachmentCount = 1;
7887 cb_ci.pAttachments = &att;
7888
7889 VkGraphicsPipelineCreateInfo gp_ci = {};
7890 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7891 gp_ci.stageCount = 2;
7892 gp_ci.pStages = shaderStages;
7893 gp_ci.pVertexInputState = &vi_ci;
7894 gp_ci.pInputAssemblyState = &ia_ci;
7895 gp_ci.pViewportState = &vp_state_ci;
7896 gp_ci.pRasterizationState = &rs_ci;
7897 gp_ci.pColorBlendState = &cb_ci;
7898 gp_ci.pDynamicState = &dyn_state_ci;
7899 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7900 gp_ci.layout = pipeline_layout;
7901 gp_ci.renderPass = renderPass();
7902
7903 VkPipelineCacheCreateInfo pc_ci = {};
7904 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7905
7906 VkPipeline pipeline;
7907 VkPipelineCache pipelineCache;
7908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007910 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007911 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007912
7913 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007914 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007915
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007917
7918 // Check too high (line width of 65536.0f).
7919 rs_ci.lineWidth = 65536.0f;
7920
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007922 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007923 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007924
7925 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007926 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007927
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007929
7930 dyn_state_ci.dynamicStateCount = 3;
7931
7932 rs_ci.lineWidth = 1.0f;
7933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007935 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007936 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07007937 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007938 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007939
7940 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007941 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007942 m_errorMonitor->VerifyFound();
7943
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007945
7946 // Check too high with dynamic setting.
7947 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7948 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07007949 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06007950
7951 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7952 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7953 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7954 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007955 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007956}
7957
Karl Schultz6addd812016-02-02 17:17:23 -07007958TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007959 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07007961 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007962
7963 ASSERT_NO_FATAL_FAILURE(InitState());
7964 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007965
Tony Barbour552f6c02016-12-21 14:34:07 -07007966 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007967 // Don't care about RenderPass handle b/c error should be flagged before
7968 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007969 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007970
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007971 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007972}
7973
Karl Schultz6addd812016-02-02 17:17:23 -07007974TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007975 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7977 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007978
7979 ASSERT_NO_FATAL_FAILURE(InitState());
7980 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007981
Tony Barbour552f6c02016-12-21 14:34:07 -07007982 m_commandBuffer->BeginCommandBuffer();
7983 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07007984 // Just create a dummy Renderpass that's non-NULL so we can get to the
7985 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007986 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007987
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007988 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007989}
7990
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007991TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007992 TEST_DESCRIPTION(
7993 "Begin a renderPass where clearValueCount is less than"
7994 "the number of renderPass attachments that use loadOp"
7995 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007996
7997 ASSERT_NO_FATAL_FAILURE(InitState());
7998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7999
8000 // Create a renderPass with a single attachment that uses loadOp CLEAR
8001 VkAttachmentReference attach = {};
8002 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8003 VkSubpassDescription subpass = {};
8004 subpass.inputAttachmentCount = 1;
8005 subpass.pInputAttachments = &attach;
8006 VkRenderPassCreateInfo rpci = {};
8007 rpci.subpassCount = 1;
8008 rpci.pSubpasses = &subpass;
8009 rpci.attachmentCount = 1;
8010 VkAttachmentDescription attach_desc = {};
8011 attach_desc.format = VK_FORMAT_UNDEFINED;
8012 // Set loadOp to CLEAR
8013 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8014 rpci.pAttachments = &attach_desc;
8015 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8016 VkRenderPass rp;
8017 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8018
8019 VkCommandBufferInheritanceInfo hinfo = {};
8020 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8021 hinfo.renderPass = VK_NULL_HANDLE;
8022 hinfo.subpass = 0;
8023 hinfo.framebuffer = VK_NULL_HANDLE;
8024 hinfo.occlusionQueryEnable = VK_FALSE;
8025 hinfo.queryFlags = 0;
8026 hinfo.pipelineStatistics = 0;
8027 VkCommandBufferBeginInfo info = {};
8028 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8029 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8030 info.pInheritanceInfo = &hinfo;
8031
8032 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8033 VkRenderPassBeginInfo rp_begin = {};
8034 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8035 rp_begin.pNext = NULL;
8036 rp_begin.renderPass = renderPass();
8037 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008038 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008039
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008041
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008042 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008043
8044 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008045
8046 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008047}
8048
Slawomir Cygan0808f392016-11-28 17:53:23 +01008049TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008050 TEST_DESCRIPTION(
8051 "Begin a renderPass where clearValueCount is greater than"
8052 "the number of renderPass attachments that use loadOp"
8053 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008054
8055 ASSERT_NO_FATAL_FAILURE(InitState());
8056 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8057
8058 // Create a renderPass with a single attachment that uses loadOp CLEAR
8059 VkAttachmentReference attach = {};
8060 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8061 VkSubpassDescription subpass = {};
8062 subpass.inputAttachmentCount = 1;
8063 subpass.pInputAttachments = &attach;
8064 VkRenderPassCreateInfo rpci = {};
8065 rpci.subpassCount = 1;
8066 rpci.pSubpasses = &subpass;
8067 rpci.attachmentCount = 1;
8068 VkAttachmentDescription attach_desc = {};
8069 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8070 // Set loadOp to CLEAR
8071 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8072 rpci.pAttachments = &attach_desc;
8073 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8074 VkRenderPass rp;
8075 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8076
8077 VkCommandBufferBeginInfo info = {};
8078 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8079 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8080
8081 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8082 VkRenderPassBeginInfo rp_begin = {};
8083 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8084 rp_begin.pNext = NULL;
8085 rp_begin.renderPass = renderPass();
8086 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008087 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008088
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8090 " has a clearValueCount of"
8091 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008092
8093 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8094
8095 m_errorMonitor->VerifyFound();
8096
8097 vkDestroyRenderPass(m_device->device(), rp, NULL);
8098}
8099
Cody Northrop3bb4d962016-05-09 16:15:57 -06008100TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008101 TEST_DESCRIPTION("End a command buffer with an active render pass");
8102
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8104 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008105
8106 ASSERT_NO_FATAL_FAILURE(InitState());
8107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8108
Tony Barbour552f6c02016-12-21 14:34:07 -07008109 m_commandBuffer->BeginCommandBuffer();
8110 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8111 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008112
8113 m_errorMonitor->VerifyFound();
8114
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008115 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8116 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008117}
8118
Karl Schultz6addd812016-02-02 17:17:23 -07008119TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008120 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8122 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008123
8124 ASSERT_NO_FATAL_FAILURE(InitState());
8125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008126
Tony Barbour552f6c02016-12-21 14:34:07 -07008127 m_commandBuffer->BeginCommandBuffer();
8128 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008129
8130 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008131 vk_testing::Buffer dstBuffer;
8132 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008133
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008134 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008135
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008136 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008137}
8138
Karl Schultz6addd812016-02-02 17:17:23 -07008139TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008140 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8142 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008143
8144 ASSERT_NO_FATAL_FAILURE(InitState());
8145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008146
Tony Barbour552f6c02016-12-21 14:34:07 -07008147 m_commandBuffer->BeginCommandBuffer();
8148 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008149
8150 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008151 vk_testing::Buffer dstBuffer;
8152 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008153
Karl Schultz6addd812016-02-02 17:17:23 -07008154 VkDeviceSize dstOffset = 0;
8155 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008156 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008157
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008158 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008159
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008160 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008161}
8162
Karl Schultz6addd812016-02-02 17:17:23 -07008163TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008164 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8166 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008167
8168 ASSERT_NO_FATAL_FAILURE(InitState());
8169 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008170
Tony Barbour552f6c02016-12-21 14:34:07 -07008171 m_commandBuffer->BeginCommandBuffer();
8172 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008173
Michael Lentine0a369f62016-02-03 16:51:46 -06008174 VkClearColorValue clear_color;
8175 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008176 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8177 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8178 const int32_t tex_width = 32;
8179 const int32_t tex_height = 32;
8180 VkImageCreateInfo image_create_info = {};
8181 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8182 image_create_info.pNext = NULL;
8183 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8184 image_create_info.format = tex_format;
8185 image_create_info.extent.width = tex_width;
8186 image_create_info.extent.height = tex_height;
8187 image_create_info.extent.depth = 1;
8188 image_create_info.mipLevels = 1;
8189 image_create_info.arrayLayers = 1;
8190 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8191 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8192 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008193
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008194 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008195 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008196
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008197 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008198
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008199 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008200
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008201 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008202}
8203
Karl Schultz6addd812016-02-02 17:17:23 -07008204TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008205 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8207 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008208
8209 ASSERT_NO_FATAL_FAILURE(InitState());
8210 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008211
Tony Barbour552f6c02016-12-21 14:34:07 -07008212 m_commandBuffer->BeginCommandBuffer();
8213 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008214
8215 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008216 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008217 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8218 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8219 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8220 image_create_info.extent.width = 64;
8221 image_create_info.extent.height = 64;
8222 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8223 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008224
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008225 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008226 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008227
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008228 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008229
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008230 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8231 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008232
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008233 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008234}
8235
Karl Schultz6addd812016-02-02 17:17:23 -07008236TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008237 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008238 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008239
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8241 "vkCmdClearAttachments(): This call "
8242 "must be issued inside an active "
8243 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008244
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008245 ASSERT_NO_FATAL_FAILURE(InitState());
8246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008247
8248 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008249 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008250 ASSERT_VK_SUCCESS(err);
8251
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008252 VkClearAttachment color_attachment;
8253 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8254 color_attachment.clearValue.color.float32[0] = 0;
8255 color_attachment.clearValue.color.float32[1] = 0;
8256 color_attachment.clearValue.color.float32[2] = 0;
8257 color_attachment.clearValue.color.float32[3] = 0;
8258 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008259 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008260 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008261
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008262 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008263}
8264
Chris Forbes3b97e932016-09-07 11:29:24 +12008265TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008266 TEST_DESCRIPTION(
8267 "Test that an error is produced when CmdNextSubpass is "
8268 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008269
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8271 "vkCmdNextSubpass(): Attempted to advance "
8272 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008273
8274 ASSERT_NO_FATAL_FAILURE(InitState());
8275 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8276
Tony Barbour552f6c02016-12-21 14:34:07 -07008277 m_commandBuffer->BeginCommandBuffer();
8278 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008279
8280 // error here.
8281 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8282 m_errorMonitor->VerifyFound();
8283
Tony Barbour552f6c02016-12-21 14:34:07 -07008284 m_commandBuffer->EndRenderPass();
8285 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008286}
8287
Chris Forbes6d624702016-09-07 13:57:05 +12008288TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008289 TEST_DESCRIPTION(
8290 "Test that an error is produced when CmdEndRenderPass is "
8291 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008292
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8294 "vkCmdEndRenderPass(): Called before reaching "
8295 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008296
8297 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008298 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8299 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008300
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008301 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008302
8303 VkRenderPass rp;
8304 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8305 ASSERT_VK_SUCCESS(err);
8306
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008307 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008308
8309 VkFramebuffer fb;
8310 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8311 ASSERT_VK_SUCCESS(err);
8312
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008313 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008314
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008315 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 +12008316
8317 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8318
8319 // Error here.
8320 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8321 m_errorMonitor->VerifyFound();
8322
8323 // Clean up.
8324 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8325 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8326}
8327
Karl Schultz9e66a292016-04-21 15:57:51 -06008328TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8329 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8331 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008332
8333 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008334 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008335
8336 VkBufferMemoryBarrier buf_barrier = {};
8337 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8338 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8339 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8340 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8341 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8342 buf_barrier.buffer = VK_NULL_HANDLE;
8343 buf_barrier.offset = 0;
8344 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008345 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8346 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008347
8348 m_errorMonitor->VerifyFound();
8349}
8350
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008351TEST_F(VkLayerTest, InvalidBarriers) {
8352 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8353
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008355
8356 ASSERT_NO_FATAL_FAILURE(InitState());
8357 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8358
8359 VkMemoryBarrier mem_barrier = {};
8360 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8361 mem_barrier.pNext = NULL;
8362 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8363 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008364 m_commandBuffer->BeginCommandBuffer();
8365 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008366 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008367 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008368 &mem_barrier, 0, nullptr, 0, nullptr);
8369 m_errorMonitor->VerifyFound();
8370
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008372 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008373 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 -06008374 ASSERT_TRUE(image.initialized());
8375 VkImageMemoryBarrier img_barrier = {};
8376 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8377 img_barrier.pNext = NULL;
8378 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8379 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8380 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8381 // New layout can't be UNDEFINED
8382 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8383 img_barrier.image = image.handle();
8384 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8385 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8386 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8387 img_barrier.subresourceRange.baseArrayLayer = 0;
8388 img_barrier.subresourceRange.baseMipLevel = 0;
8389 img_barrier.subresourceRange.layerCount = 1;
8390 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008391 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8392 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008393 m_errorMonitor->VerifyFound();
8394 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8395
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8397 "Subresource must have the sum of the "
8398 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008399 // baseArrayLayer + layerCount must be <= image's arrayLayers
8400 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008401 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8402 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008403 m_errorMonitor->VerifyFound();
8404 img_barrier.subresourceRange.baseArrayLayer = 0;
8405
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008407 // baseMipLevel + levelCount must be <= image's mipLevels
8408 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008409 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8410 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008411 m_errorMonitor->VerifyFound();
8412 img_barrier.subresourceRange.baseMipLevel = 0;
8413
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008414 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 -06008415 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008416 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8417 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008418 VkBufferMemoryBarrier buf_barrier = {};
8419 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8420 buf_barrier.pNext = NULL;
8421 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8422 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8423 buf_barrier.buffer = buffer.handle();
8424 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8425 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8426 buf_barrier.offset = 0;
8427 buf_barrier.size = VK_WHOLE_SIZE;
8428 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008429 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8430 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008431 m_errorMonitor->VerifyFound();
8432 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8433
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008435 buf_barrier.offset = 257;
8436 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008437 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8438 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008439 m_errorMonitor->VerifyFound();
8440 buf_barrier.offset = 0;
8441
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008443 buf_barrier.size = 257;
8444 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008445 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8446 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008447 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008448
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008449 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008450 m_errorMonitor->SetDesiredFailureMsg(
8451 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008452 "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 -06008453 VkDepthStencilObj ds_image(m_device);
8454 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8455 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008456 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8457 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008458 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008459
8460 // Not having DEPTH or STENCIL set is an error
8461 img_barrier.subresourceRange.aspectMask = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008462 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8463 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008464 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07008465
8466 // Having anything other than DEPTH or STENCIL is an error
8467 m_errorMonitor->SetDesiredFailureMsg(
8468 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8469 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8470 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
8471 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8472 nullptr, 0, nullptr, 1, &img_barrier);
8473 m_errorMonitor->VerifyFound();
8474
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008475 // Now test depth-only
8476 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008477 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8478 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008479 VkDepthStencilObj d_image(m_device);
8480 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8481 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008482 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008483 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008484 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008485
8486 // DEPTH bit must be set
8487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8488 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8489 img_barrier.subresourceRange.aspectMask = 0;
8490 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8491 0, nullptr, 0, nullptr, 1, &img_barrier);
8492 m_errorMonitor->VerifyFound();
8493
8494 // No bits other than DEPTH may be set
8495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8496 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8497 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008498 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8499 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008500 m_errorMonitor->VerifyFound();
8501 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008502
8503 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008504 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8505 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8507 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008508 VkDepthStencilObj s_image(m_device);
8509 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8510 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008511 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008512 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008513 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008514 // Use of COLOR aspect on depth image is error
8515 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008516 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8517 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008518 m_errorMonitor->VerifyFound();
8519 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008520
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008521 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008522 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008523 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 -06008524 ASSERT_TRUE(c_image.initialized());
8525 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8526 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8527 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008528
8529 // COLOR bit must be set
8530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8531 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8532 img_barrier.subresourceRange.aspectMask = 0;
8533 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8534 nullptr, 0, nullptr, 1, &img_barrier);
8535 m_errorMonitor->VerifyFound();
8536
8537 // No bits other than COLOR may be set
8538 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8539 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
8540 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008541 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8542 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008543 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008544
8545 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8546
8547 // Create command pool with incompatible queueflags
8548 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8549 uint32_t queue_family_index = UINT32_MAX;
8550 for (uint32_t i = 0; i < queue_props.size(); i++) {
8551 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8552 queue_family_index = i;
8553 break;
8554 }
8555 }
8556 if (queue_family_index == UINT32_MAX) {
8557 printf("No non-compute queue found; skipped.\n");
8558 return;
8559 }
8560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8561
8562 VkCommandPool command_pool;
8563 VkCommandPoolCreateInfo pool_create_info{};
8564 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8565 pool_create_info.queueFamilyIndex = queue_family_index;
8566 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8567 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8568
8569 // Allocate a command buffer
8570 VkCommandBuffer bad_command_buffer;
8571 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8572 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8573 command_buffer_allocate_info.commandPool = command_pool;
8574 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8575 command_buffer_allocate_info.commandBufferCount = 1;
8576 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8577
8578 VkCommandBufferBeginInfo cbbi = {};
8579 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8580 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8581 buf_barrier.offset = 0;
8582 buf_barrier.size = VK_WHOLE_SIZE;
8583 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8584 &buf_barrier, 0, nullptr);
8585 m_errorMonitor->VerifyFound();
8586
8587 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8588 vkEndCommandBuffer(bad_command_buffer);
8589 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8590 printf("The non-compute queue does not support graphics; skipped.\n");
8591 return;
8592 }
8593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8594 VkEvent event;
8595 VkEventCreateInfo event_create_info{};
8596 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8597 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8598 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8599 nullptr, 0, nullptr);
8600 m_errorMonitor->VerifyFound();
8601
8602 vkEndCommandBuffer(bad_command_buffer);
8603 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008604}
8605
Tony Barbour18ba25c2016-09-29 13:42:40 -06008606TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8607 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8608
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06008610 ASSERT_NO_FATAL_FAILURE(InitState());
8611 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008612 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 -06008613 ASSERT_TRUE(image.initialized());
8614
8615 VkImageMemoryBarrier barrier = {};
8616 VkImageSubresourceRange range;
8617 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8618 barrier.srcAccessMask = 0;
8619 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8620 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8621 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8622 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8623 barrier.image = image.handle();
8624 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8625 range.baseMipLevel = 0;
8626 range.levelCount = 1;
8627 range.baseArrayLayer = 0;
8628 range.layerCount = 1;
8629 barrier.subresourceRange = range;
8630 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8631 cmdbuf.BeginCommandBuffer();
8632 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8633 &barrier);
8634 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8635 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8636 barrier.srcAccessMask = 0;
8637 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8638 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8639 &barrier);
8640
8641 m_errorMonitor->VerifyFound();
8642}
8643
Karl Schultz6addd812016-02-02 17:17:23 -07008644TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008645 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008646 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008647
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008649
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008650 ASSERT_NO_FATAL_FAILURE(InitState());
8651 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008652 uint32_t qfi = 0;
8653 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008654 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8655 buffCI.size = 1024;
8656 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8657 buffCI.queueFamilyIndexCount = 1;
8658 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008659
8660 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008661 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008662 ASSERT_VK_SUCCESS(err);
8663
Tony Barbour552f6c02016-12-21 14:34:07 -07008664 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008665 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008666 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8667 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008668 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008669 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008670
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008671 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008672
Chia-I Wuf7458c52015-10-26 21:10:41 +08008673 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008674}
8675
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008676TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8677 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8679 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8680 "of the indices specified when the device was created, via the "
8681 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008682
8683 ASSERT_NO_FATAL_FAILURE(InitState());
8684 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8685 VkBufferCreateInfo buffCI = {};
8686 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8687 buffCI.size = 1024;
8688 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8689 buffCI.queueFamilyIndexCount = 1;
8690 // Introduce failure by specifying invalid queue_family_index
8691 uint32_t qfi = 777;
8692 buffCI.pQueueFamilyIndices = &qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008693 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008694
8695 VkBuffer ib;
8696 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8697
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008698 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008699 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008700}
8701
Karl Schultz6addd812016-02-02 17:17:23 -07008702TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008703 TEST_DESCRIPTION(
8704 "Attempt vkCmdExecuteCommands with a primary command buffer"
8705 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008706
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008707 ASSERT_NO_FATAL_FAILURE(InitState());
8708 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008709
Chris Forbesf29a84f2016-10-06 18:39:28 +13008710 // An empty primary command buffer
8711 VkCommandBufferObj cb(m_device, m_commandPool);
8712 cb.BeginCommandBuffer();
8713 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008714
Chris Forbesf29a84f2016-10-06 18:39:28 +13008715 m_commandBuffer->BeginCommandBuffer();
8716 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8717 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008718
Chris Forbesf29a84f2016-10-06 18:39:28 +13008719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8720 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008721 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008722}
8723
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008724TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008725 TEST_DESCRIPTION(
8726 "Attempt to update descriptor sets for images and buffers "
8727 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008728 VkResult err;
8729
8730 ASSERT_NO_FATAL_FAILURE(InitState());
8731 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8732 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8733 ds_type_count[i].type = VkDescriptorType(i);
8734 ds_type_count[i].descriptorCount = 1;
8735 }
8736 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8737 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8738 ds_pool_ci.pNext = NULL;
8739 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8740 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8741 ds_pool_ci.pPoolSizes = ds_type_count;
8742
8743 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008744 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008745 ASSERT_VK_SUCCESS(err);
8746
8747 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008748 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008749 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8750 dsl_binding[i].binding = 0;
8751 dsl_binding[i].descriptorType = VkDescriptorType(i);
8752 dsl_binding[i].descriptorCount = 1;
8753 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8754 dsl_binding[i].pImmutableSamplers = NULL;
8755 }
8756
8757 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8758 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8759 ds_layout_ci.pNext = NULL;
8760 ds_layout_ci.bindingCount = 1;
8761 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8762 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8763 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008765 ASSERT_VK_SUCCESS(err);
8766 }
8767 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8768 VkDescriptorSetAllocateInfo alloc_info = {};
8769 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8770 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8771 alloc_info.descriptorPool = ds_pool;
8772 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008773 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008774 ASSERT_VK_SUCCESS(err);
8775
8776 // Create a buffer & bufferView to be used for invalid updates
8777 VkBufferCreateInfo buff_ci = {};
8778 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07008779 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008780 buff_ci.size = 256;
8781 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07008782 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008783 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8784 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07008785
8786 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
8787 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
8788 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
8789 ASSERT_VK_SUCCESS(err);
8790
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008791 VkMemoryRequirements mem_reqs;
8792 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
8793 VkMemoryAllocateInfo mem_alloc_info = {};
8794 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8795 mem_alloc_info.pNext = NULL;
8796 mem_alloc_info.memoryTypeIndex = 0;
8797 mem_alloc_info.allocationSize = mem_reqs.size;
8798 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8799 if (!pass) {
8800 vkDestroyBuffer(m_device->device(), buffer, NULL);
8801 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8802 return;
8803 }
8804 VkDeviceMemory mem;
8805 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
8806 ASSERT_VK_SUCCESS(err);
8807 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8808 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008809
8810 VkBufferViewCreateInfo buff_view_ci = {};
8811 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8812 buff_view_ci.buffer = buffer;
8813 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8814 buff_view_ci.range = VK_WHOLE_SIZE;
8815 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008816 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008817 ASSERT_VK_SUCCESS(err);
8818
Tony Barbour415497c2017-01-24 10:06:09 -07008819 // Now get resources / view for storage_texel_buffer
8820 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
8821 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8822 if (!pass) {
8823 vkDestroyBuffer(m_device->device(), buffer, NULL);
8824 vkDestroyBufferView(m_device->device(), buff_view, NULL);
8825 vkFreeMemory(m_device->device(), mem, NULL);
8826 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
8827 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8828 return;
8829 }
8830 VkDeviceMemory storage_texel_buffer_mem;
8831 VkBufferView storage_texel_buffer_view;
8832 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
8833 ASSERT_VK_SUCCESS(err);
8834 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
8835 ASSERT_VK_SUCCESS(err);
8836 buff_view_ci.buffer = storage_texel_buffer;
8837 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
8838 ASSERT_VK_SUCCESS(err);
8839
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008840 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07008841 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008842 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07008843 image_ci.format = VK_FORMAT_UNDEFINED;
8844 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
8845 VkFormat format = static_cast<VkFormat>(f);
8846 VkFormatProperties fProps = m_device->format_properties(format);
8847 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
8848 image_ci.format = format;
8849 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8850 break;
8851 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
8852 image_ci.format = format;
8853 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
8854 break;
8855 }
8856 }
8857 if (image_ci.format == VK_FORMAT_UNDEFINED) {
8858 return;
8859 }
8860
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008861 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8862 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008863 image_ci.extent.width = 64;
8864 image_ci.extent.height = 64;
8865 image_ci.extent.depth = 1;
8866 image_ci.mipLevels = 1;
8867 image_ci.arrayLayers = 1;
8868 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008869 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07008870 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008871 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8872 VkImage image;
8873 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8874 ASSERT_VK_SUCCESS(err);
8875 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008876 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008877
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008878 VkMemoryAllocateInfo mem_alloc = {};
8879 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8880 mem_alloc.pNext = NULL;
8881 mem_alloc.allocationSize = 0;
8882 mem_alloc.memoryTypeIndex = 0;
8883 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8884 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008885 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008886 ASSERT_TRUE(pass);
8887 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8888 ASSERT_VK_SUCCESS(err);
8889 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8890 ASSERT_VK_SUCCESS(err);
8891 // Now create view for image
8892 VkImageViewCreateInfo image_view_ci = {};
8893 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8894 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07008895 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008896 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8897 image_view_ci.subresourceRange.layerCount = 1;
8898 image_view_ci.subresourceRange.baseArrayLayer = 0;
8899 image_view_ci.subresourceRange.levelCount = 1;
8900 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8901 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008902 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008903 ASSERT_VK_SUCCESS(err);
8904
8905 VkDescriptorBufferInfo buff_info = {};
8906 buff_info.buffer = buffer;
8907 VkDescriptorImageInfo img_info = {};
8908 img_info.imageView = image_view;
8909 VkWriteDescriptorSet descriptor_write = {};
8910 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8911 descriptor_write.dstBinding = 0;
8912 descriptor_write.descriptorCount = 1;
8913 descriptor_write.pTexelBufferView = &buff_view;
8914 descriptor_write.pBufferInfo = &buff_info;
8915 descriptor_write.pImageInfo = &img_info;
8916
8917 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008918 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008919 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
8920 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
8921 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
8922 VALIDATION_ERROR_00943, // STORAGE_IMAGE
8923 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
8924 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
8925 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
8926 VALIDATION_ERROR_00947, // STORAGE_BUFFER
8927 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
8928 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
8929 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008930 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008931 // Start loop at 1 as SAMPLER desc type has no usage bit error
8932 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07008933 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
8934 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
8935 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
8936 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008937 descriptor_write.descriptorType = VkDescriptorType(i);
8938 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008940
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008941 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008942
8943 m_errorMonitor->VerifyFound();
8944 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07008945 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
8946 descriptor_write.pTexelBufferView = &buff_view;
8947 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008948 }
Tony Barbour415497c2017-01-24 10:06:09 -07008949
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008950 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8951 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008952 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008953 vkDestroyImageView(m_device->device(), image_view, NULL);
8954 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07008955 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008956 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07008957 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008958 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07008959 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008960 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8961}
8962
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008963TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008964 TEST_DESCRIPTION(
8965 "Attempt to update buffer descriptor set that has incorrect "
8966 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8967 "1. offset value greater than buffer size\n"
8968 "2. range value of 0\n"
8969 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008970 VkResult err;
8971
8972 ASSERT_NO_FATAL_FAILURE(InitState());
8973 VkDescriptorPoolSize ds_type_count = {};
8974 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8975 ds_type_count.descriptorCount = 1;
8976
8977 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8978 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8979 ds_pool_ci.pNext = NULL;
8980 ds_pool_ci.maxSets = 1;
8981 ds_pool_ci.poolSizeCount = 1;
8982 ds_pool_ci.pPoolSizes = &ds_type_count;
8983
8984 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008985 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008986 ASSERT_VK_SUCCESS(err);
8987
8988 // Create layout with single uniform buffer descriptor
8989 VkDescriptorSetLayoutBinding dsl_binding = {};
8990 dsl_binding.binding = 0;
8991 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8992 dsl_binding.descriptorCount = 1;
8993 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8994 dsl_binding.pImmutableSamplers = NULL;
8995
8996 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8997 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8998 ds_layout_ci.pNext = NULL;
8999 ds_layout_ci.bindingCount = 1;
9000 ds_layout_ci.pBindings = &dsl_binding;
9001 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009002 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009003 ASSERT_VK_SUCCESS(err);
9004
9005 VkDescriptorSet descriptor_set = {};
9006 VkDescriptorSetAllocateInfo alloc_info = {};
9007 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9008 alloc_info.descriptorSetCount = 1;
9009 alloc_info.descriptorPool = ds_pool;
9010 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009011 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009012 ASSERT_VK_SUCCESS(err);
9013
9014 // Create a buffer to be used for invalid updates
9015 VkBufferCreateInfo buff_ci = {};
9016 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9017 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9018 buff_ci.size = 256;
9019 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9020 VkBuffer buffer;
9021 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9022 ASSERT_VK_SUCCESS(err);
9023 // Have to bind memory to buffer before descriptor update
9024 VkMemoryAllocateInfo mem_alloc = {};
9025 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9026 mem_alloc.pNext = NULL;
9027 mem_alloc.allocationSize = 256;
9028 mem_alloc.memoryTypeIndex = 0;
9029
9030 VkMemoryRequirements mem_reqs;
9031 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009032 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009033 if (!pass) {
9034 vkDestroyBuffer(m_device->device(), buffer, NULL);
9035 return;
9036 }
9037
9038 VkDeviceMemory mem;
9039 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9040 ASSERT_VK_SUCCESS(err);
9041 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9042 ASSERT_VK_SUCCESS(err);
9043
9044 VkDescriptorBufferInfo buff_info = {};
9045 buff_info.buffer = buffer;
9046 // First make offset 1 larger than buffer size
9047 buff_info.offset = 257;
9048 buff_info.range = VK_WHOLE_SIZE;
9049 VkWriteDescriptorSet descriptor_write = {};
9050 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9051 descriptor_write.dstBinding = 0;
9052 descriptor_write.descriptorCount = 1;
9053 descriptor_write.pTexelBufferView = nullptr;
9054 descriptor_write.pBufferInfo = &buff_info;
9055 descriptor_write.pImageInfo = nullptr;
9056
9057 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9058 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009060
9061 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9062
9063 m_errorMonitor->VerifyFound();
9064 // Now cause error due to range of 0
9065 buff_info.offset = 0;
9066 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009068
9069 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9070
9071 m_errorMonitor->VerifyFound();
9072 // Now cause error due to range exceeding buffer size - offset
9073 buff_info.offset = 128;
9074 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009076
9077 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9078
9079 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009080 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009081 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9082 vkDestroyBuffer(m_device->device(), buffer, NULL);
9083 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9084 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9085}
9086
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009087TEST_F(VkLayerTest, DSAspectBitsErrors) {
9088 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9089 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009090 TEST_DESCRIPTION(
9091 "Attempt to update descriptor sets for images "
9092 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009093 VkResult err;
9094
9095 ASSERT_NO_FATAL_FAILURE(InitState());
9096 VkDescriptorPoolSize ds_type_count = {};
9097 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9098 ds_type_count.descriptorCount = 1;
9099
9100 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9101 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9102 ds_pool_ci.pNext = NULL;
9103 ds_pool_ci.maxSets = 5;
9104 ds_pool_ci.poolSizeCount = 1;
9105 ds_pool_ci.pPoolSizes = &ds_type_count;
9106
9107 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009108 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009109 ASSERT_VK_SUCCESS(err);
9110
9111 VkDescriptorSetLayoutBinding dsl_binding = {};
9112 dsl_binding.binding = 0;
9113 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9114 dsl_binding.descriptorCount = 1;
9115 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9116 dsl_binding.pImmutableSamplers = NULL;
9117
9118 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9119 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9120 ds_layout_ci.pNext = NULL;
9121 ds_layout_ci.bindingCount = 1;
9122 ds_layout_ci.pBindings = &dsl_binding;
9123 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009124 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009125 ASSERT_VK_SUCCESS(err);
9126
9127 VkDescriptorSet descriptor_set = {};
9128 VkDescriptorSetAllocateInfo alloc_info = {};
9129 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9130 alloc_info.descriptorSetCount = 1;
9131 alloc_info.descriptorPool = ds_pool;
9132 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009133 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009134 ASSERT_VK_SUCCESS(err);
9135
9136 // Create an image to be used for invalid updates
9137 VkImageCreateInfo image_ci = {};
9138 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9139 image_ci.imageType = VK_IMAGE_TYPE_2D;
9140 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9141 image_ci.extent.width = 64;
9142 image_ci.extent.height = 64;
9143 image_ci.extent.depth = 1;
9144 image_ci.mipLevels = 1;
9145 image_ci.arrayLayers = 1;
9146 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9147 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9148 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9149 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9150 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9151 VkImage image;
9152 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9153 ASSERT_VK_SUCCESS(err);
9154 // Bind memory to image
9155 VkMemoryRequirements mem_reqs;
9156 VkDeviceMemory image_mem;
9157 bool pass;
9158 VkMemoryAllocateInfo mem_alloc = {};
9159 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9160 mem_alloc.pNext = NULL;
9161 mem_alloc.allocationSize = 0;
9162 mem_alloc.memoryTypeIndex = 0;
9163 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9164 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009165 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009166 ASSERT_TRUE(pass);
9167 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9168 ASSERT_VK_SUCCESS(err);
9169 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9170 ASSERT_VK_SUCCESS(err);
9171 // Now create view for image
9172 VkImageViewCreateInfo image_view_ci = {};
9173 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9174 image_view_ci.image = image;
9175 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9176 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9177 image_view_ci.subresourceRange.layerCount = 1;
9178 image_view_ci.subresourceRange.baseArrayLayer = 0;
9179 image_view_ci.subresourceRange.levelCount = 1;
9180 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009181 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009182
9183 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009184 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009185 ASSERT_VK_SUCCESS(err);
9186
9187 VkDescriptorImageInfo img_info = {};
9188 img_info.imageView = image_view;
9189 VkWriteDescriptorSet descriptor_write = {};
9190 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9191 descriptor_write.dstBinding = 0;
9192 descriptor_write.descriptorCount = 1;
9193 descriptor_write.pTexelBufferView = NULL;
9194 descriptor_write.pBufferInfo = NULL;
9195 descriptor_write.pImageInfo = &img_info;
9196 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9197 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009198 const char *error_msg =
9199 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9200 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009202
9203 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9204
9205 m_errorMonitor->VerifyFound();
9206 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9207 vkDestroyImage(m_device->device(), image, NULL);
9208 vkFreeMemory(m_device->device(), image_mem, NULL);
9209 vkDestroyImageView(m_device->device(), image_view, NULL);
9210 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9211 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9212}
9213
Karl Schultz6addd812016-02-02 17:17:23 -07009214TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009215 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009216 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009217
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9219 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9220 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009221
Tobin Ehlis3b780662015-05-28 12:11:26 -06009222 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009223 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009224 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009225 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9226 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009227
9228 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009229 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9230 ds_pool_ci.pNext = NULL;
9231 ds_pool_ci.maxSets = 1;
9232 ds_pool_ci.poolSizeCount = 1;
9233 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009234
Tobin Ehlis3b780662015-05-28 12:11:26 -06009235 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009236 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009237 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009238 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009239 dsl_binding.binding = 0;
9240 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9241 dsl_binding.descriptorCount = 1;
9242 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9243 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009244
Tony Barboureb254902015-07-15 12:50:33 -06009245 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009246 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9247 ds_layout_ci.pNext = NULL;
9248 ds_layout_ci.bindingCount = 1;
9249 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009250
Tobin Ehlis3b780662015-05-28 12:11:26 -06009251 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009252 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009253 ASSERT_VK_SUCCESS(err);
9254
9255 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009256 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009257 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009258 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009259 alloc_info.descriptorPool = ds_pool;
9260 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009261 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009262 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009263
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009264 VkSamplerCreateInfo sampler_ci = {};
9265 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9266 sampler_ci.pNext = NULL;
9267 sampler_ci.magFilter = VK_FILTER_NEAREST;
9268 sampler_ci.minFilter = VK_FILTER_NEAREST;
9269 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9270 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9271 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9272 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9273 sampler_ci.mipLodBias = 1.0;
9274 sampler_ci.anisotropyEnable = VK_FALSE;
9275 sampler_ci.maxAnisotropy = 1;
9276 sampler_ci.compareEnable = VK_FALSE;
9277 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9278 sampler_ci.minLod = 1.0;
9279 sampler_ci.maxLod = 1.0;
9280 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9281 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9282 VkSampler sampler;
9283 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9284 ASSERT_VK_SUCCESS(err);
9285
9286 VkDescriptorImageInfo info = {};
9287 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009288
9289 VkWriteDescriptorSet descriptor_write;
9290 memset(&descriptor_write, 0, sizeof(descriptor_write));
9291 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009292 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009293 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009294 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009295 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009296 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009297
9298 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9299
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009300 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009301
Chia-I Wuf7458c52015-10-26 21:10:41 +08009302 vkDestroySampler(m_device->device(), sampler, NULL);
9303 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9304 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009305}
9306
Karl Schultz6addd812016-02-02 17:17:23 -07009307TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009308 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009309 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009310
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009312
Tobin Ehlis3b780662015-05-28 12:11:26 -06009313 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009314 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009315 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009316 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9317 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009318
9319 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009320 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9321 ds_pool_ci.pNext = NULL;
9322 ds_pool_ci.maxSets = 1;
9323 ds_pool_ci.poolSizeCount = 1;
9324 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009325
Tobin Ehlis3b780662015-05-28 12:11:26 -06009326 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009327 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009328 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009329
Tony Barboureb254902015-07-15 12:50:33 -06009330 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009331 dsl_binding.binding = 0;
9332 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9333 dsl_binding.descriptorCount = 1;
9334 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9335 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009336
9337 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009338 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9339 ds_layout_ci.pNext = NULL;
9340 ds_layout_ci.bindingCount = 1;
9341 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009342
Tobin Ehlis3b780662015-05-28 12:11:26 -06009343 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009344 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009345 ASSERT_VK_SUCCESS(err);
9346
9347 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009348 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009349 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009350 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009351 alloc_info.descriptorPool = ds_pool;
9352 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009353 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009354 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009355
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009356 // Correctly update descriptor to avoid "NOT_UPDATED" error
9357 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009358 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009359 buff_info.offset = 0;
9360 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009361
9362 VkWriteDescriptorSet descriptor_write;
9363 memset(&descriptor_write, 0, sizeof(descriptor_write));
9364 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009365 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009366 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009367 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009368 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9369 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009370
9371 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9372
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009373 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009374
Chia-I Wuf7458c52015-10-26 21:10:41 +08009375 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9376 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009377}
9378
Karl Schultz6addd812016-02-02 17:17:23 -07009379TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009380 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009381 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009382
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009384
Tobin Ehlis3b780662015-05-28 12:11:26 -06009385 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009386 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009387 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009388 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9389 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009390
9391 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009392 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9393 ds_pool_ci.pNext = NULL;
9394 ds_pool_ci.maxSets = 1;
9395 ds_pool_ci.poolSizeCount = 1;
9396 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009397
Tobin Ehlis3b780662015-05-28 12:11:26 -06009398 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009399 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009400 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009401
Tony Barboureb254902015-07-15 12:50:33 -06009402 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009403 dsl_binding.binding = 0;
9404 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9405 dsl_binding.descriptorCount = 1;
9406 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9407 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009408
9409 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009410 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9411 ds_layout_ci.pNext = NULL;
9412 ds_layout_ci.bindingCount = 1;
9413 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009414 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009415 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009416 ASSERT_VK_SUCCESS(err);
9417
9418 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009419 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009420 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009421 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009422 alloc_info.descriptorPool = ds_pool;
9423 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009424 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009425 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009426
Tony Barboureb254902015-07-15 12:50:33 -06009427 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009428 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9429 sampler_ci.pNext = NULL;
9430 sampler_ci.magFilter = VK_FILTER_NEAREST;
9431 sampler_ci.minFilter = VK_FILTER_NEAREST;
9432 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9433 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9434 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9435 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9436 sampler_ci.mipLodBias = 1.0;
9437 sampler_ci.anisotropyEnable = VK_FALSE;
9438 sampler_ci.maxAnisotropy = 1;
9439 sampler_ci.compareEnable = VK_FALSE;
9440 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9441 sampler_ci.minLod = 1.0;
9442 sampler_ci.maxLod = 1.0;
9443 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9444 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009445
Tobin Ehlis3b780662015-05-28 12:11:26 -06009446 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009447 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009448 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009449
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009450 VkDescriptorImageInfo info = {};
9451 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009452
9453 VkWriteDescriptorSet descriptor_write;
9454 memset(&descriptor_write, 0, sizeof(descriptor_write));
9455 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009456 descriptor_write.dstSet = descriptorSet;
9457 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009458 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009459 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009460 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009461 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009462
9463 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9464
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009465 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009466
Chia-I Wuf7458c52015-10-26 21:10:41 +08009467 vkDestroySampler(m_device->device(), sampler, NULL);
9468 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9469 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009470}
9471
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009472TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9473 // Create layout w/ empty binding and attempt to update it
9474 VkResult err;
9475
9476 ASSERT_NO_FATAL_FAILURE(InitState());
9477
9478 VkDescriptorPoolSize ds_type_count = {};
9479 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9480 ds_type_count.descriptorCount = 1;
9481
9482 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9483 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9484 ds_pool_ci.pNext = NULL;
9485 ds_pool_ci.maxSets = 1;
9486 ds_pool_ci.poolSizeCount = 1;
9487 ds_pool_ci.pPoolSizes = &ds_type_count;
9488
9489 VkDescriptorPool ds_pool;
9490 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9491 ASSERT_VK_SUCCESS(err);
9492
9493 VkDescriptorSetLayoutBinding dsl_binding = {};
9494 dsl_binding.binding = 0;
9495 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9496 dsl_binding.descriptorCount = 0;
9497 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9498 dsl_binding.pImmutableSamplers = NULL;
9499
9500 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9501 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9502 ds_layout_ci.pNext = NULL;
9503 ds_layout_ci.bindingCount = 1;
9504 ds_layout_ci.pBindings = &dsl_binding;
9505 VkDescriptorSetLayout ds_layout;
9506 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9507 ASSERT_VK_SUCCESS(err);
9508
9509 VkDescriptorSet descriptor_set;
9510 VkDescriptorSetAllocateInfo alloc_info = {};
9511 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9512 alloc_info.descriptorSetCount = 1;
9513 alloc_info.descriptorPool = ds_pool;
9514 alloc_info.pSetLayouts = &ds_layout;
9515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9516 ASSERT_VK_SUCCESS(err);
9517
9518 VkSamplerCreateInfo sampler_ci = {};
9519 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9520 sampler_ci.magFilter = VK_FILTER_NEAREST;
9521 sampler_ci.minFilter = VK_FILTER_NEAREST;
9522 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9523 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9524 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9525 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9526 sampler_ci.mipLodBias = 1.0;
9527 sampler_ci.maxAnisotropy = 1;
9528 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9529 sampler_ci.minLod = 1.0;
9530 sampler_ci.maxLod = 1.0;
9531 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9532
9533 VkSampler sampler;
9534 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9535 ASSERT_VK_SUCCESS(err);
9536
9537 VkDescriptorImageInfo info = {};
9538 info.sampler = sampler;
9539
9540 VkWriteDescriptorSet descriptor_write;
9541 memset(&descriptor_write, 0, sizeof(descriptor_write));
9542 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9543 descriptor_write.dstSet = descriptor_set;
9544 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009545 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009546 // This is the wrong type, but empty binding error will be flagged first
9547 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9548 descriptor_write.pImageInfo = &info;
9549
9550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9551 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9552 m_errorMonitor->VerifyFound();
9553
9554 vkDestroySampler(m_device->device(), sampler, NULL);
9555 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9556 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9557}
9558
Karl Schultz6addd812016-02-02 17:17:23 -07009559TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9560 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9561 // types
9562 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009563
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009564 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 -06009565
Tobin Ehlis3b780662015-05-28 12:11:26 -06009566 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009567
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009568 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009569 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9570 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009571
9572 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009573 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9574 ds_pool_ci.pNext = NULL;
9575 ds_pool_ci.maxSets = 1;
9576 ds_pool_ci.poolSizeCount = 1;
9577 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009578
Tobin Ehlis3b780662015-05-28 12:11:26 -06009579 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009580 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009581 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009582 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009583 dsl_binding.binding = 0;
9584 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9585 dsl_binding.descriptorCount = 1;
9586 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9587 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009588
Tony Barboureb254902015-07-15 12:50:33 -06009589 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009590 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9591 ds_layout_ci.pNext = NULL;
9592 ds_layout_ci.bindingCount = 1;
9593 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009594
Tobin Ehlis3b780662015-05-28 12:11:26 -06009595 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009596 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009597 ASSERT_VK_SUCCESS(err);
9598
9599 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009600 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009601 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009602 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009603 alloc_info.descriptorPool = ds_pool;
9604 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009605 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009606 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009607
Tony Barboureb254902015-07-15 12:50:33 -06009608 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009609 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9610 sampler_ci.pNext = NULL;
9611 sampler_ci.magFilter = VK_FILTER_NEAREST;
9612 sampler_ci.minFilter = VK_FILTER_NEAREST;
9613 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9614 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9615 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9616 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9617 sampler_ci.mipLodBias = 1.0;
9618 sampler_ci.anisotropyEnable = VK_FALSE;
9619 sampler_ci.maxAnisotropy = 1;
9620 sampler_ci.compareEnable = VK_FALSE;
9621 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9622 sampler_ci.minLod = 1.0;
9623 sampler_ci.maxLod = 1.0;
9624 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9625 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009626 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009627 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009628 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009629
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009630 VkDescriptorImageInfo info = {};
9631 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009632
9633 VkWriteDescriptorSet descriptor_write;
9634 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009635 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009636 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009637 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009638 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009639 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009640 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009641
9642 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9643
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009644 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009645
Chia-I Wuf7458c52015-10-26 21:10:41 +08009646 vkDestroySampler(m_device->device(), sampler, NULL);
9647 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9648 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009649}
9650
Karl Schultz6addd812016-02-02 17:17:23 -07009651TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009652 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009653 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009654
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009656
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009657 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009658 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9659 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009660 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009661 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9662 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009663
9664 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009665 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9666 ds_pool_ci.pNext = NULL;
9667 ds_pool_ci.maxSets = 1;
9668 ds_pool_ci.poolSizeCount = 1;
9669 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009670
9671 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009672 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009673 ASSERT_VK_SUCCESS(err);
9674
9675 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009676 dsl_binding.binding = 0;
9677 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9678 dsl_binding.descriptorCount = 1;
9679 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9680 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009681
9682 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009683 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9684 ds_layout_ci.pNext = NULL;
9685 ds_layout_ci.bindingCount = 1;
9686 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009687 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009688 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009689 ASSERT_VK_SUCCESS(err);
9690
9691 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009692 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009693 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009694 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009695 alloc_info.descriptorPool = ds_pool;
9696 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009697 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009698 ASSERT_VK_SUCCESS(err);
9699
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009700 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009701
9702 VkDescriptorImageInfo descriptor_info;
9703 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9704 descriptor_info.sampler = sampler;
9705
9706 VkWriteDescriptorSet descriptor_write;
9707 memset(&descriptor_write, 0, sizeof(descriptor_write));
9708 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009709 descriptor_write.dstSet = descriptorSet;
9710 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009711 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009712 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9713 descriptor_write.pImageInfo = &descriptor_info;
9714
9715 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9716
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009717 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009718
Chia-I Wuf7458c52015-10-26 21:10:41 +08009719 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9720 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009721}
9722
Karl Schultz6addd812016-02-02 17:17:23 -07009723TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9724 // Create a single combined Image/Sampler descriptor and send it an invalid
9725 // imageView
9726 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009727
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009729
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009730 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009731 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009732 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9733 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009734
9735 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009736 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9737 ds_pool_ci.pNext = NULL;
9738 ds_pool_ci.maxSets = 1;
9739 ds_pool_ci.poolSizeCount = 1;
9740 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009741
9742 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009743 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009744 ASSERT_VK_SUCCESS(err);
9745
9746 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009747 dsl_binding.binding = 0;
9748 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9749 dsl_binding.descriptorCount = 1;
9750 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9751 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009752
9753 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009754 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9755 ds_layout_ci.pNext = NULL;
9756 ds_layout_ci.bindingCount = 1;
9757 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009758 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009759 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009760 ASSERT_VK_SUCCESS(err);
9761
9762 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009763 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009764 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009765 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009766 alloc_info.descriptorPool = ds_pool;
9767 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009768 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009769 ASSERT_VK_SUCCESS(err);
9770
9771 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009772 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9773 sampler_ci.pNext = NULL;
9774 sampler_ci.magFilter = VK_FILTER_NEAREST;
9775 sampler_ci.minFilter = VK_FILTER_NEAREST;
9776 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9777 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9778 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9779 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9780 sampler_ci.mipLodBias = 1.0;
9781 sampler_ci.anisotropyEnable = VK_FALSE;
9782 sampler_ci.maxAnisotropy = 1;
9783 sampler_ci.compareEnable = VK_FALSE;
9784 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9785 sampler_ci.minLod = 1.0;
9786 sampler_ci.maxLod = 1.0;
9787 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9788 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009789
9790 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009791 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009792 ASSERT_VK_SUCCESS(err);
9793
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009794 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009795
9796 VkDescriptorImageInfo descriptor_info;
9797 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9798 descriptor_info.sampler = sampler;
9799 descriptor_info.imageView = view;
9800
9801 VkWriteDescriptorSet descriptor_write;
9802 memset(&descriptor_write, 0, sizeof(descriptor_write));
9803 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009804 descriptor_write.dstSet = descriptorSet;
9805 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009806 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009807 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9808 descriptor_write.pImageInfo = &descriptor_info;
9809
9810 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9811
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009812 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009813
Chia-I Wuf7458c52015-10-26 21:10:41 +08009814 vkDestroySampler(m_device->device(), sampler, NULL);
9815 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9816 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009817}
9818
Karl Schultz6addd812016-02-02 17:17:23 -07009819TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9820 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9821 // into the other
9822 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009823
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9825 " binding #1 with type "
9826 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9827 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009828
Tobin Ehlis04356f92015-10-27 16:35:27 -06009829 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009830 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009831 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009832 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9833 ds_type_count[0].descriptorCount = 1;
9834 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9835 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009836
9837 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009838 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9839 ds_pool_ci.pNext = NULL;
9840 ds_pool_ci.maxSets = 1;
9841 ds_pool_ci.poolSizeCount = 2;
9842 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009843
9844 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009845 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009846 ASSERT_VK_SUCCESS(err);
9847 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009848 dsl_binding[0].binding = 0;
9849 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9850 dsl_binding[0].descriptorCount = 1;
9851 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9852 dsl_binding[0].pImmutableSamplers = NULL;
9853 dsl_binding[1].binding = 1;
9854 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9855 dsl_binding[1].descriptorCount = 1;
9856 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9857 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009858
9859 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009860 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9861 ds_layout_ci.pNext = NULL;
9862 ds_layout_ci.bindingCount = 2;
9863 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009864
9865 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009866 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009867 ASSERT_VK_SUCCESS(err);
9868
9869 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009870 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009871 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009872 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009873 alloc_info.descriptorPool = ds_pool;
9874 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009875 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009876 ASSERT_VK_SUCCESS(err);
9877
9878 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009879 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9880 sampler_ci.pNext = NULL;
9881 sampler_ci.magFilter = VK_FILTER_NEAREST;
9882 sampler_ci.minFilter = VK_FILTER_NEAREST;
9883 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9884 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9885 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9886 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9887 sampler_ci.mipLodBias = 1.0;
9888 sampler_ci.anisotropyEnable = VK_FALSE;
9889 sampler_ci.maxAnisotropy = 1;
9890 sampler_ci.compareEnable = VK_FALSE;
9891 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9892 sampler_ci.minLod = 1.0;
9893 sampler_ci.maxLod = 1.0;
9894 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9895 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009896
9897 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009898 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009899 ASSERT_VK_SUCCESS(err);
9900
9901 VkDescriptorImageInfo info = {};
9902 info.sampler = sampler;
9903
9904 VkWriteDescriptorSet descriptor_write;
9905 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9906 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009907 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009908 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009909 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009910 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9911 descriptor_write.pImageInfo = &info;
9912 // This write update should succeed
9913 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9914 // Now perform a copy update that fails due to type mismatch
9915 VkCopyDescriptorSet copy_ds_update;
9916 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9917 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9918 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009919 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009920 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009921 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
9922 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009923 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9924
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009925 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009926 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009927 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 -06009928 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9929 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9930 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009931 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009932 copy_ds_update.dstSet = descriptorSet;
9933 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009934 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009935 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9936
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009937 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009938
Tobin Ehlis04356f92015-10-27 16:35:27 -06009939 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9941 " binding#1 with offset index of 1 plus "
9942 "update array offset of 0 and update of "
9943 "5 descriptors oversteps total number "
9944 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009945
Tobin Ehlis04356f92015-10-27 16:35:27 -06009946 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9947 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9948 copy_ds_update.srcSet = descriptorSet;
9949 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009950 copy_ds_update.dstSet = descriptorSet;
9951 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009952 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009953 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9954
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009955 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009956
Chia-I Wuf7458c52015-10-26 21:10:41 +08009957 vkDestroySampler(m_device->device(), sampler, NULL);
9958 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9959 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009960}
9961
Karl Schultz6addd812016-02-02 17:17:23 -07009962TEST_F(VkLayerTest, NumSamplesMismatch) {
9963 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9964 // sampleCount
9965 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009966
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009968
Tobin Ehlis3b780662015-05-28 12:11:26 -06009969 ASSERT_NO_FATAL_FAILURE(InitState());
9970 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009971 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009972 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009973 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009974
9975 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009976 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9977 ds_pool_ci.pNext = NULL;
9978 ds_pool_ci.maxSets = 1;
9979 ds_pool_ci.poolSizeCount = 1;
9980 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009981
Tobin Ehlis3b780662015-05-28 12:11:26 -06009982 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009983 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009984 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009985
Tony Barboureb254902015-07-15 12:50:33 -06009986 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009987 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009988 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009989 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009990 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9991 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009992
Tony Barboureb254902015-07-15 12:50:33 -06009993 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9994 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9995 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009996 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009997 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009998
Tobin Ehlis3b780662015-05-28 12:11:26 -06009999 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010000 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010001 ASSERT_VK_SUCCESS(err);
10002
10003 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010004 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010005 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010006 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010007 alloc_info.descriptorPool = ds_pool;
10008 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010009 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010010 ASSERT_VK_SUCCESS(err);
10011
Tony Barboureb254902015-07-15 12:50:33 -060010012 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010013 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010014 pipe_ms_state_ci.pNext = NULL;
10015 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10016 pipe_ms_state_ci.sampleShadingEnable = 0;
10017 pipe_ms_state_ci.minSampleShading = 1.0;
10018 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010019
Tony Barboureb254902015-07-15 12:50:33 -060010020 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010021 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10022 pipeline_layout_ci.pNext = NULL;
10023 pipeline_layout_ci.setLayoutCount = 1;
10024 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010025
10026 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010027 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010028 ASSERT_VK_SUCCESS(err);
10029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010030 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010031 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 -060010032 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010033 VkPipelineObj pipe(m_device);
10034 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010035 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010036 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010037 pipe.SetMSAA(&pipe_ms_state_ci);
10038 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010039
Tony Barbour552f6c02016-12-21 14:34:07 -070010040 m_commandBuffer->BeginCommandBuffer();
10041 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010042 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010043
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010044 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10045 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10046 VkRect2D scissor = {{0, 0}, {16, 16}};
10047 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10048
Mark Young29927482016-05-04 14:38:51 -060010049 // Render triangle (the error should trigger on the attempt to draw).
10050 Draw(3, 1, 0, 0);
10051
10052 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010053 m_commandBuffer->EndRenderPass();
10054 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010055
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010056 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010057
Chia-I Wuf7458c52015-10-26 21:10:41 +080010058 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10059 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10060 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010061}
Mark Young29927482016-05-04 14:38:51 -060010062
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010063TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010064 TEST_DESCRIPTION(
10065 "Hit RenderPass incompatible cases. "
10066 "Initial case is drawing with an active renderpass that's "
10067 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010068 VkResult err;
10069
10070 ASSERT_NO_FATAL_FAILURE(InitState());
10071 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10072
10073 VkDescriptorSetLayoutBinding dsl_binding = {};
10074 dsl_binding.binding = 0;
10075 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10076 dsl_binding.descriptorCount = 1;
10077 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10078 dsl_binding.pImmutableSamplers = NULL;
10079
10080 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10081 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10082 ds_layout_ci.pNext = NULL;
10083 ds_layout_ci.bindingCount = 1;
10084 ds_layout_ci.pBindings = &dsl_binding;
10085
10086 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010087 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010088 ASSERT_VK_SUCCESS(err);
10089
10090 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10091 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10092 pipeline_layout_ci.pNext = NULL;
10093 pipeline_layout_ci.setLayoutCount = 1;
10094 pipeline_layout_ci.pSetLayouts = &ds_layout;
10095
10096 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010097 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010098 ASSERT_VK_SUCCESS(err);
10099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010100 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010101 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 -060010102 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010103 // Create a renderpass that will be incompatible with default renderpass
10104 VkAttachmentReference attach = {};
10105 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10106 VkAttachmentReference color_att = {};
10107 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10108 VkSubpassDescription subpass = {};
10109 subpass.inputAttachmentCount = 1;
10110 subpass.pInputAttachments = &attach;
10111 subpass.colorAttachmentCount = 1;
10112 subpass.pColorAttachments = &color_att;
10113 VkRenderPassCreateInfo rpci = {};
10114 rpci.subpassCount = 1;
10115 rpci.pSubpasses = &subpass;
10116 rpci.attachmentCount = 1;
10117 VkAttachmentDescription attach_desc = {};
10118 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010119 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10120 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010121 rpci.pAttachments = &attach_desc;
10122 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10123 VkRenderPass rp;
10124 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10125 VkPipelineObj pipe(m_device);
10126 pipe.AddShader(&vs);
10127 pipe.AddShader(&fs);
10128 pipe.AddColorAttachment();
10129 VkViewport view_port = {};
10130 m_viewports.push_back(view_port);
10131 pipe.SetViewport(m_viewports);
10132 VkRect2D rect = {};
10133 m_scissors.push_back(rect);
10134 pipe.SetScissor(m_scissors);
10135 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10136
10137 VkCommandBufferInheritanceInfo cbii = {};
10138 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10139 cbii.renderPass = rp;
10140 cbii.subpass = 0;
10141 VkCommandBufferBeginInfo cbbi = {};
10142 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10143 cbbi.pInheritanceInfo = &cbii;
10144 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10145 VkRenderPassBeginInfo rpbi = {};
10146 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10147 rpbi.framebuffer = m_framebuffer;
10148 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010149 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10150 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010153 // Render triangle (the error should trigger on the attempt to draw).
10154 Draw(3, 1, 0, 0);
10155
10156 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010157 m_commandBuffer->EndRenderPass();
10158 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010159
10160 m_errorMonitor->VerifyFound();
10161
10162 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10163 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10164 vkDestroyRenderPass(m_device->device(), rp, NULL);
10165}
10166
Mark Youngc89c6312016-03-31 16:03:20 -060010167TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10168 // Create Pipeline where the number of blend attachments doesn't match the
10169 // number of color attachments. In this case, we don't add any color
10170 // blend attachments even though we have a color attachment.
10171 VkResult err;
10172
10173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010174 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010175
10176 ASSERT_NO_FATAL_FAILURE(InitState());
10177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10178 VkDescriptorPoolSize ds_type_count = {};
10179 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10180 ds_type_count.descriptorCount = 1;
10181
10182 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10183 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10184 ds_pool_ci.pNext = NULL;
10185 ds_pool_ci.maxSets = 1;
10186 ds_pool_ci.poolSizeCount = 1;
10187 ds_pool_ci.pPoolSizes = &ds_type_count;
10188
10189 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010190 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010191 ASSERT_VK_SUCCESS(err);
10192
10193 VkDescriptorSetLayoutBinding dsl_binding = {};
10194 dsl_binding.binding = 0;
10195 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10196 dsl_binding.descriptorCount = 1;
10197 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10198 dsl_binding.pImmutableSamplers = NULL;
10199
10200 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10201 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10202 ds_layout_ci.pNext = NULL;
10203 ds_layout_ci.bindingCount = 1;
10204 ds_layout_ci.pBindings = &dsl_binding;
10205
10206 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010207 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010208 ASSERT_VK_SUCCESS(err);
10209
10210 VkDescriptorSet descriptorSet;
10211 VkDescriptorSetAllocateInfo alloc_info = {};
10212 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10213 alloc_info.descriptorSetCount = 1;
10214 alloc_info.descriptorPool = ds_pool;
10215 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010216 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010217 ASSERT_VK_SUCCESS(err);
10218
10219 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010220 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010221 pipe_ms_state_ci.pNext = NULL;
10222 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10223 pipe_ms_state_ci.sampleShadingEnable = 0;
10224 pipe_ms_state_ci.minSampleShading = 1.0;
10225 pipe_ms_state_ci.pSampleMask = NULL;
10226
10227 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10228 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10229 pipeline_layout_ci.pNext = NULL;
10230 pipeline_layout_ci.setLayoutCount = 1;
10231 pipeline_layout_ci.pSetLayouts = &ds_layout;
10232
10233 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010234 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010235 ASSERT_VK_SUCCESS(err);
10236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010237 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010238 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 -060010239 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010240 VkPipelineObj pipe(m_device);
10241 pipe.AddShader(&vs);
10242 pipe.AddShader(&fs);
10243 pipe.SetMSAA(&pipe_ms_state_ci);
10244 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10245
Tony Barbour552f6c02016-12-21 14:34:07 -070010246 m_commandBuffer->BeginCommandBuffer();
10247 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010248 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010249
Rene Lindsay6d5c4fe2017-01-13 09:41:19 -070010250 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10251 VkRect2D scissor = {{0, 0}, {16, 16}};
10252 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10253 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10254
Mark Young29927482016-05-04 14:38:51 -060010255 // Render triangle (the error should trigger on the attempt to draw).
10256 Draw(3, 1, 0, 0);
10257
10258 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010259 m_commandBuffer->EndRenderPass();
10260 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010261
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010262 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010263
10264 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10265 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10266 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10267}
Mark Young29927482016-05-04 14:38:51 -060010268
Mark Muellerd4914412016-06-13 17:52:06 -060010269TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010270 TEST_DESCRIPTION(
10271 "Points to a wrong colorAttachment index in a VkClearAttachment "
10272 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010273 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010274 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010275
10276 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10277 m_errorMonitor->VerifyFound();
10278}
10279
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010280TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010281 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10282 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010283
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010284 ASSERT_NO_FATAL_FAILURE(InitState());
10285 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010286
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010287 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010288 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10289 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010290
10291 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010292 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10293 ds_pool_ci.pNext = NULL;
10294 ds_pool_ci.maxSets = 1;
10295 ds_pool_ci.poolSizeCount = 1;
10296 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010297
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010298 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010299 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010300 ASSERT_VK_SUCCESS(err);
10301
Tony Barboureb254902015-07-15 12:50:33 -060010302 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010303 dsl_binding.binding = 0;
10304 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10305 dsl_binding.descriptorCount = 1;
10306 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10307 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010308
Tony Barboureb254902015-07-15 12:50:33 -060010309 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010310 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10311 ds_layout_ci.pNext = NULL;
10312 ds_layout_ci.bindingCount = 1;
10313 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010314
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010315 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010316 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010317 ASSERT_VK_SUCCESS(err);
10318
10319 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010320 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010321 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010322 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010323 alloc_info.descriptorPool = ds_pool;
10324 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010325 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010326 ASSERT_VK_SUCCESS(err);
10327
Tony Barboureb254902015-07-15 12:50:33 -060010328 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010329 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010330 pipe_ms_state_ci.pNext = NULL;
10331 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10332 pipe_ms_state_ci.sampleShadingEnable = 0;
10333 pipe_ms_state_ci.minSampleShading = 1.0;
10334 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010335
Tony Barboureb254902015-07-15 12:50:33 -060010336 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010337 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10338 pipeline_layout_ci.pNext = NULL;
10339 pipeline_layout_ci.setLayoutCount = 1;
10340 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010341
10342 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010343 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010344 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010345
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010346 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010347 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010348 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010349 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010350
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010351 VkPipelineObj pipe(m_device);
10352 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010353 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010354 pipe.SetMSAA(&pipe_ms_state_ci);
10355 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010356
Tony Barbour552f6c02016-12-21 14:34:07 -070010357 m_commandBuffer->BeginCommandBuffer();
10358 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010359
Karl Schultz6addd812016-02-02 17:17:23 -070010360 // Main thing we care about for this test is that the VkImage obj we're
10361 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010362 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010363 VkClearAttachment color_attachment;
10364 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10365 color_attachment.clearValue.color.float32[0] = 1.0;
10366 color_attachment.clearValue.color.float32[1] = 1.0;
10367 color_attachment.clearValue.color.float32[2] = 1.0;
10368 color_attachment.clearValue.color.float32[3] = 1.0;
10369 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010370 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010371
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010372 // Call for full-sized FB Color attachment prior to issuing a Draw
10373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070010374 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010375 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010376 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010377
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010378 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
10379 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
10380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
10381 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
10382 m_errorMonitor->VerifyFound();
10383
10384 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
10385 clear_rect.layerCount = 2;
10386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
10387 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010388 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010389
Chia-I Wuf7458c52015-10-26 21:10:41 +080010390 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10391 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10392 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010393}
10394
Karl Schultz6addd812016-02-02 17:17:23 -070010395TEST_F(VkLayerTest, VtxBufferBadIndex) {
10396 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010397
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10399 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010400
Tobin Ehlis502480b2015-06-24 15:53:07 -060010401 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010402 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010404
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010405 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010406 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10407 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010408
10409 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010410 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10411 ds_pool_ci.pNext = NULL;
10412 ds_pool_ci.maxSets = 1;
10413 ds_pool_ci.poolSizeCount = 1;
10414 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010415
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010416 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010417 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010418 ASSERT_VK_SUCCESS(err);
10419
Tony Barboureb254902015-07-15 12:50:33 -060010420 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010421 dsl_binding.binding = 0;
10422 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10423 dsl_binding.descriptorCount = 1;
10424 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10425 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010426
Tony Barboureb254902015-07-15 12:50:33 -060010427 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010428 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10429 ds_layout_ci.pNext = NULL;
10430 ds_layout_ci.bindingCount = 1;
10431 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010432
Tobin Ehlis502480b2015-06-24 15:53:07 -060010433 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010434 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010435 ASSERT_VK_SUCCESS(err);
10436
10437 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010438 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010439 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010440 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010441 alloc_info.descriptorPool = ds_pool;
10442 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010443 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010444 ASSERT_VK_SUCCESS(err);
10445
Tony Barboureb254902015-07-15 12:50:33 -060010446 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010447 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010448 pipe_ms_state_ci.pNext = NULL;
10449 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10450 pipe_ms_state_ci.sampleShadingEnable = 0;
10451 pipe_ms_state_ci.minSampleShading = 1.0;
10452 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010453
Tony Barboureb254902015-07-15 12:50:33 -060010454 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010455 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10456 pipeline_layout_ci.pNext = NULL;
10457 pipeline_layout_ci.setLayoutCount = 1;
10458 pipeline_layout_ci.pSetLayouts = &ds_layout;
10459 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010460
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010461 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010462 ASSERT_VK_SUCCESS(err);
10463
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010464 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010465 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 -060010466 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010467 VkPipelineObj pipe(m_device);
10468 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010469 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010470 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010471 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010472 pipe.SetViewport(m_viewports);
10473 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010474 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010475
Tony Barbour552f6c02016-12-21 14:34:07 -070010476 m_commandBuffer->BeginCommandBuffer();
10477 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010478 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010479 // Don't care about actual data, just need to get to draw to flag error
10480 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010481 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010482 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010483 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010484
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010485 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010486
Chia-I Wuf7458c52015-10-26 21:10:41 +080010487 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10488 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10489 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010490}
Mark Muellerdfe37552016-07-07 14:47:42 -060010491
Mark Mueller2ee294f2016-08-04 12:59:48 -060010492TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010493 TEST_DESCRIPTION(
10494 "Use an invalid count in a vkEnumeratePhysicalDevices call."
10495 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010496 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010497
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010498 const char *invalid_queueFamilyIndex_message =
10499 "Invalid queue create request in vkCreateDevice(). Invalid "
10500 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010502 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010503
Mark Mueller880fce52016-08-17 15:23:23 -060010504 // The following test fails with recent NVidia drivers.
10505 // By the time core_validation is reached, the NVidia
10506 // driver has sanitized the invalid condition and core_validation
10507 // is not introduced to the failure condition. This is not the case
10508 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010509 // uint32_t count = static_cast<uint32_t>(~0);
10510 // VkPhysicalDevice physical_device;
10511 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10512 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010513
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010515 float queue_priority = 0.0;
10516
10517 VkDeviceQueueCreateInfo queue_create_info = {};
10518 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10519 queue_create_info.queueCount = 1;
10520 queue_create_info.pQueuePriorities = &queue_priority;
10521 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10522
10523 VkPhysicalDeviceFeatures features = m_device->phy().features();
10524 VkDevice testDevice;
10525 VkDeviceCreateInfo device_create_info = {};
10526 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10527 device_create_info.queueCreateInfoCount = 1;
10528 device_create_info.pQueueCreateInfos = &queue_create_info;
10529 device_create_info.pEnabledFeatures = &features;
10530 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10531 m_errorMonitor->VerifyFound();
10532
10533 queue_create_info.queueFamilyIndex = 1;
10534
10535 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10536 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10537 for (unsigned i = 0; i < feature_count; i++) {
10538 if (VK_FALSE == feature_array[i]) {
10539 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010541 device_create_info.pEnabledFeatures = &features;
10542 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10543 m_errorMonitor->VerifyFound();
10544 break;
10545 }
10546 }
10547}
10548
Tobin Ehlis16edf082016-11-21 12:33:49 -070010549TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10550 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10551
10552 ASSERT_NO_FATAL_FAILURE(InitState());
10553
10554 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10555 std::vector<VkDeviceQueueCreateInfo> queue_info;
10556 queue_info.reserve(queue_props.size());
10557 std::vector<std::vector<float>> queue_priorities;
10558 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10559 VkDeviceQueueCreateInfo qi{};
10560 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10561 qi.queueFamilyIndex = i;
10562 qi.queueCount = queue_props[i].queueCount;
10563 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10564 qi.pQueuePriorities = queue_priorities[i].data();
10565 queue_info.push_back(qi);
10566 }
10567
10568 std::vector<const char *> device_extension_names;
10569
10570 VkDevice local_device;
10571 VkDeviceCreateInfo device_create_info = {};
10572 auto features = m_device->phy().features();
10573 // Intentionally disable pipeline stats
10574 features.pipelineStatisticsQuery = VK_FALSE;
10575 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10576 device_create_info.pNext = NULL;
10577 device_create_info.queueCreateInfoCount = queue_info.size();
10578 device_create_info.pQueueCreateInfos = queue_info.data();
10579 device_create_info.enabledLayerCount = 0;
10580 device_create_info.ppEnabledLayerNames = NULL;
10581 device_create_info.pEnabledFeatures = &features;
10582 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10583 ASSERT_VK_SUCCESS(err);
10584
10585 VkQueryPoolCreateInfo qpci{};
10586 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10587 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10588 qpci.queryCount = 1;
10589 VkQueryPool query_pool;
10590
10591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10592 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10593 m_errorMonitor->VerifyFound();
10594
10595 vkDestroyDevice(local_device, nullptr);
10596}
10597
Mark Mueller2ee294f2016-08-04 12:59:48 -060010598TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010599 TEST_DESCRIPTION(
10600 "Use an invalid queue index in a vkCmdWaitEvents call."
10601 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060010602
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010603 const char *invalid_queue_index =
10604 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10605 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10606 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010607
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010608 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010609
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010611
10612 ASSERT_NO_FATAL_FAILURE(InitState());
10613
10614 VkEvent event;
10615 VkEventCreateInfo event_create_info{};
10616 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10617 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10618
Mark Mueller2ee294f2016-08-04 12:59:48 -060010619 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010620 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010621
Tony Barbour552f6c02016-12-21 14:34:07 -070010622 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010623
10624 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010625 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 -060010626 ASSERT_TRUE(image.initialized());
10627 VkImageMemoryBarrier img_barrier = {};
10628 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10629 img_barrier.pNext = NULL;
10630 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10631 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10632 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10633 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10634 img_barrier.image = image.handle();
10635 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010636
10637 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10638 // that layer validation catches the case when it is not.
10639 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010640 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10641 img_barrier.subresourceRange.baseArrayLayer = 0;
10642 img_barrier.subresourceRange.baseMipLevel = 0;
10643 img_barrier.subresourceRange.layerCount = 1;
10644 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010645 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10646 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010647 m_errorMonitor->VerifyFound();
10648
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010650
10651 VkQueryPool query_pool;
10652 VkQueryPoolCreateInfo query_pool_create_info = {};
10653 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10654 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10655 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010656 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010657
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010658 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010659 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10660
10661 vkEndCommandBuffer(m_commandBuffer->handle());
10662 m_errorMonitor->VerifyFound();
10663
10664 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10665 vkDestroyEvent(m_device->device(), event, nullptr);
10666}
10667
Mark Muellerdfe37552016-07-07 14:47:42 -060010668TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010669 TEST_DESCRIPTION(
10670 "Submit a command buffer using deleted vertex buffer, "
10671 "delete a buffer twice, use an invalid offset for each "
10672 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060010673
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010674 const char *deleted_buffer_in_command_buffer =
10675 "Cannot submit cmd buffer "
10676 "using deleted buffer ";
10677 const char *invalid_offset_message =
10678 "vkBindBufferMemory(): "
10679 "memoryOffset is 0x";
10680 const char *invalid_storage_buffer_offset_message =
10681 "vkBindBufferMemory(): "
10682 "storage memoryOffset "
10683 "is 0x";
10684 const char *invalid_texel_buffer_offset_message =
10685 "vkBindBufferMemory(): "
10686 "texel memoryOffset "
10687 "is 0x";
10688 const char *invalid_uniform_buffer_offset_message =
10689 "vkBindBufferMemory(): "
10690 "uniform memoryOffset "
10691 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010692
10693 ASSERT_NO_FATAL_FAILURE(InitState());
10694 ASSERT_NO_FATAL_FAILURE(InitViewport());
10695 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10696
10697 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010698 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010699 pipe_ms_state_ci.pNext = NULL;
10700 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10701 pipe_ms_state_ci.sampleShadingEnable = 0;
10702 pipe_ms_state_ci.minSampleShading = 1.0;
10703 pipe_ms_state_ci.pSampleMask = nullptr;
10704
10705 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10706 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10707 VkPipelineLayout pipeline_layout;
10708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010709 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010710 ASSERT_VK_SUCCESS(err);
10711
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010712 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10713 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010714 VkPipelineObj pipe(m_device);
10715 pipe.AddShader(&vs);
10716 pipe.AddShader(&fs);
10717 pipe.AddColorAttachment();
10718 pipe.SetMSAA(&pipe_ms_state_ci);
10719 pipe.SetViewport(m_viewports);
10720 pipe.SetScissor(m_scissors);
10721 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10722
Tony Barbour552f6c02016-12-21 14:34:07 -070010723 m_commandBuffer->BeginCommandBuffer();
10724 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010725 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010726
10727 {
10728 // Create and bind a vertex buffer in a reduced scope, which will cause
10729 // it to be deleted upon leaving this scope
10730 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010731 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010732 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10733 draw_verticies.AddVertexInputToPipe(pipe);
10734 }
10735
10736 Draw(1, 0, 0, 0);
10737
Tony Barbour552f6c02016-12-21 14:34:07 -070010738 m_commandBuffer->EndRenderPass();
10739 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060010740
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010742 QueueCommandBuffer(false);
10743 m_errorMonitor->VerifyFound();
10744
10745 {
10746 // Create and bind a vertex buffer in a reduced scope, and delete it
10747 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010748 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010750 buffer_test.TestDoubleDestroy();
10751 }
10752 m_errorMonitor->VerifyFound();
10753
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010754 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010755 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10757 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10758 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010759 m_errorMonitor->VerifyFound();
10760 }
10761
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010762 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10763 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010764 // Create and bind a memory buffer with an invalid offset again,
10765 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10767 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10768 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010769 m_errorMonitor->VerifyFound();
10770 }
10771
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010772 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010773 // Create and bind a memory buffer with an invalid offset again, but
10774 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10776 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10777 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010778 m_errorMonitor->VerifyFound();
10779 }
10780
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010781 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010782 // Create and bind a memory buffer with an invalid offset again, but
10783 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10785 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10786 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010787 m_errorMonitor->VerifyFound();
10788 }
10789
10790 {
10791 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010793 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10794 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010795 m_errorMonitor->VerifyFound();
10796 }
10797
10798 {
10799 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010801 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10802 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010803 }
10804 m_errorMonitor->VerifyFound();
10805
10806 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10807}
10808
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010809// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10810TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010811 TEST_DESCRIPTION(
10812 "Hit all possible validation checks associated with the "
10813 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10814 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010815 // 3 in ValidateCmdBufImageLayouts
10816 // * -1 Attempt to submit cmd buf w/ deleted image
10817 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10818 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010819
10820 ASSERT_NO_FATAL_FAILURE(InitState());
10821 // Create src & dst images to use for copy operations
10822 VkImage src_image;
10823 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010824 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010825
10826 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10827 const int32_t tex_width = 32;
10828 const int32_t tex_height = 32;
10829
10830 VkImageCreateInfo image_create_info = {};
10831 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10832 image_create_info.pNext = NULL;
10833 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10834 image_create_info.format = tex_format;
10835 image_create_info.extent.width = tex_width;
10836 image_create_info.extent.height = tex_height;
10837 image_create_info.extent.depth = 1;
10838 image_create_info.mipLevels = 1;
10839 image_create_info.arrayLayers = 4;
10840 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10841 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10842 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010843 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010844 image_create_info.flags = 0;
10845
10846 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10847 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010848 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010849 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10850 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010851 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10852 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10853 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10854 ASSERT_VK_SUCCESS(err);
10855
10856 // Allocate memory
10857 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010858 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010859 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010860 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10861 mem_alloc.pNext = NULL;
10862 mem_alloc.allocationSize = 0;
10863 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010864
10865 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010866 mem_alloc.allocationSize = img_mem_reqs.size;
10867 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010868 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010869 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010870 ASSERT_VK_SUCCESS(err);
10871
10872 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010873 mem_alloc.allocationSize = img_mem_reqs.size;
10874 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010875 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010876 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010877 ASSERT_VK_SUCCESS(err);
10878
10879 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010880 mem_alloc.allocationSize = img_mem_reqs.size;
10881 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010882 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010883 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010884 ASSERT_VK_SUCCESS(err);
10885
10886 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10887 ASSERT_VK_SUCCESS(err);
10888 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10889 ASSERT_VK_SUCCESS(err);
10890 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10891 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010892
Tony Barbour552f6c02016-12-21 14:34:07 -070010893 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010894 VkImageCopy copy_region;
10895 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10896 copy_region.srcSubresource.mipLevel = 0;
10897 copy_region.srcSubresource.baseArrayLayer = 0;
10898 copy_region.srcSubresource.layerCount = 1;
10899 copy_region.srcOffset.x = 0;
10900 copy_region.srcOffset.y = 0;
10901 copy_region.srcOffset.z = 0;
10902 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10903 copy_region.dstSubresource.mipLevel = 0;
10904 copy_region.dstSubresource.baseArrayLayer = 0;
10905 copy_region.dstSubresource.layerCount = 1;
10906 copy_region.dstOffset.x = 0;
10907 copy_region.dstOffset.y = 0;
10908 copy_region.dstOffset.z = 0;
10909 copy_region.extent.width = 1;
10910 copy_region.extent.height = 1;
10911 copy_region.extent.depth = 1;
10912
10913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10914 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10915 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 -060010916 m_errorMonitor->VerifyFound();
10917 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10919 "Cannot copy from an image whose source layout is "
10920 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10921 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010922 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 -060010923 m_errorMonitor->VerifyFound();
10924 // Final src error is due to bad layout type
10925 m_errorMonitor->SetDesiredFailureMsg(
10926 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10927 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010928 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 -060010929 m_errorMonitor->VerifyFound();
10930 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10932 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010933 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 -060010934 m_errorMonitor->VerifyFound();
10935 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10937 "Cannot copy from an image whose dest layout is "
10938 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10939 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010940 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 -060010941 m_errorMonitor->VerifyFound();
10942 m_errorMonitor->SetDesiredFailureMsg(
10943 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10944 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010945 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 -060010946 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010947
Cort3b021012016-12-07 12:00:57 -080010948 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10949 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10950 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10951 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10952 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10953 transfer_dst_image_barrier[0].srcAccessMask = 0;
10954 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10955 transfer_dst_image_barrier[0].image = dst_image;
10956 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10957 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10958 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10959 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10960 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10961 transfer_dst_image_barrier[0].image = depth_image;
10962 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10963 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10964 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10965
10966 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010967 VkClearColorValue color_clear_value = {};
10968 VkImageSubresourceRange clear_range;
10969 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10970 clear_range.baseMipLevel = 0;
10971 clear_range.baseArrayLayer = 0;
10972 clear_range.layerCount = 1;
10973 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010974
Cort3b021012016-12-07 12:00:57 -080010975 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10976 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010979 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010980 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010981 // Fail due to provided layout not matching actual current layout for color clear.
10982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010983 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010984 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010985
Cort530cf382016-12-08 09:59:47 -080010986 VkClearDepthStencilValue depth_clear_value = {};
10987 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010988
10989 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10990 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010993 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010994 m_errorMonitor->VerifyFound();
10995 // Fail due to provided layout not matching actual current layout for depth clear.
10996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010997 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010998 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010999
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011000 // Now cause error due to bad image layout transition in PipelineBarrier
11001 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011002 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011003 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011004 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011005 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011006 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11007 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011008 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11010 "You cannot transition the layout of aspect 1 from "
11011 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11012 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011013 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11014 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011015 m_errorMonitor->VerifyFound();
11016
11017 // Finally some layout errors at RenderPass create time
11018 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11019 VkAttachmentReference attach = {};
11020 // perf warning for GENERAL layout w/ non-DS input attachment
11021 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11022 VkSubpassDescription subpass = {};
11023 subpass.inputAttachmentCount = 1;
11024 subpass.pInputAttachments = &attach;
11025 VkRenderPassCreateInfo rpci = {};
11026 rpci.subpassCount = 1;
11027 rpci.pSubpasses = &subpass;
11028 rpci.attachmentCount = 1;
11029 VkAttachmentDescription attach_desc = {};
11030 attach_desc.format = VK_FORMAT_UNDEFINED;
11031 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011032 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011033 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11035 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011036 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11037 m_errorMonitor->VerifyFound();
11038 // error w/ non-general layout
11039 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11040
11041 m_errorMonitor->SetDesiredFailureMsg(
11042 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11043 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11044 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11045 m_errorMonitor->VerifyFound();
11046 subpass.inputAttachmentCount = 0;
11047 subpass.colorAttachmentCount = 1;
11048 subpass.pColorAttachments = &attach;
11049 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11050 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11052 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011053 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11054 m_errorMonitor->VerifyFound();
11055 // error w/ non-color opt or GENERAL layout for color attachment
11056 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11057 m_errorMonitor->SetDesiredFailureMsg(
11058 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11059 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11060 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11061 m_errorMonitor->VerifyFound();
11062 subpass.colorAttachmentCount = 0;
11063 subpass.pDepthStencilAttachment = &attach;
11064 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11065 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11067 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011068 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11069 m_errorMonitor->VerifyFound();
11070 // error w/ non-ds opt or GENERAL layout for color attachment
11071 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11073 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11074 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011075 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11076 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011077 // For this error we need a valid renderpass so create default one
11078 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11079 attach.attachment = 0;
11080 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11081 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11082 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11083 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11084 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11085 // Can't do a CLEAR load on READ_ONLY initialLayout
11086 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11087 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11088 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11090 " with invalid first layout "
11091 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11092 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011093 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11094 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011095
Cort3b021012016-12-07 12:00:57 -080011096 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11097 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11098 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011099 vkDestroyImage(m_device->device(), src_image, NULL);
11100 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011101 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011102}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011103
Tobin Ehlise0936662016-10-11 08:10:51 -060011104TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11105 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11106 VkResult err;
11107
11108 ASSERT_NO_FATAL_FAILURE(InitState());
11109
11110 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11111 VkImageTiling tiling;
11112 VkFormatProperties format_properties;
11113 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11114 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11115 tiling = VK_IMAGE_TILING_LINEAR;
11116 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11117 tiling = VK_IMAGE_TILING_OPTIMAL;
11118 } else {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011119 printf(
11120 "Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11121 "skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011122 return;
11123 }
11124
11125 VkDescriptorPoolSize ds_type = {};
11126 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11127 ds_type.descriptorCount = 1;
11128
11129 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11130 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11131 ds_pool_ci.maxSets = 1;
11132 ds_pool_ci.poolSizeCount = 1;
11133 ds_pool_ci.pPoolSizes = &ds_type;
11134 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11135
11136 VkDescriptorPool ds_pool;
11137 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11138 ASSERT_VK_SUCCESS(err);
11139
11140 VkDescriptorSetLayoutBinding dsl_binding = {};
11141 dsl_binding.binding = 0;
11142 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11143 dsl_binding.descriptorCount = 1;
11144 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11145 dsl_binding.pImmutableSamplers = NULL;
11146
11147 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11148 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11149 ds_layout_ci.pNext = NULL;
11150 ds_layout_ci.bindingCount = 1;
11151 ds_layout_ci.pBindings = &dsl_binding;
11152
11153 VkDescriptorSetLayout ds_layout;
11154 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11155 ASSERT_VK_SUCCESS(err);
11156
11157 VkDescriptorSetAllocateInfo alloc_info = {};
11158 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11159 alloc_info.descriptorSetCount = 1;
11160 alloc_info.descriptorPool = ds_pool;
11161 alloc_info.pSetLayouts = &ds_layout;
11162 VkDescriptorSet descriptor_set;
11163 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11164 ASSERT_VK_SUCCESS(err);
11165
11166 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11167 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11168 pipeline_layout_ci.pNext = NULL;
11169 pipeline_layout_ci.setLayoutCount = 1;
11170 pipeline_layout_ci.pSetLayouts = &ds_layout;
11171 VkPipelineLayout pipeline_layout;
11172 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11173 ASSERT_VK_SUCCESS(err);
11174
11175 VkImageObj image(m_device);
11176 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11177 ASSERT_TRUE(image.initialized());
11178 VkImageView view = image.targetView(tex_format);
11179
11180 VkDescriptorImageInfo image_info = {};
11181 image_info.imageView = view;
11182 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11183
11184 VkWriteDescriptorSet descriptor_write = {};
11185 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11186 descriptor_write.dstSet = descriptor_set;
11187 descriptor_write.dstBinding = 0;
11188 descriptor_write.descriptorCount = 1;
11189 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11190 descriptor_write.pImageInfo = &image_info;
11191
11192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11193 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11194 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11195 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11196 m_errorMonitor->VerifyFound();
11197
11198 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11199 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11200 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11201 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11202}
11203
Mark Mueller93b938f2016-08-18 10:27:40 -060011204TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011205 TEST_DESCRIPTION(
11206 "Use vkCmdExecuteCommands with invalid state "
11207 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011208
11209 ASSERT_NO_FATAL_FAILURE(InitState());
11210 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11211
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011212 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011213 const char *simultaneous_use_message2 =
11214 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11215 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011216
11217 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011218 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011219 command_buffer_allocate_info.commandPool = m_commandPool;
11220 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11221 command_buffer_allocate_info.commandBufferCount = 1;
11222
11223 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011224 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011225 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11226 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011227 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011228 command_buffer_inheritance_info.renderPass = m_renderPass;
11229 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011230
Mark Mueller93b938f2016-08-18 10:27:40 -060011231 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011232 command_buffer_begin_info.flags =
11233 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011234 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11235
11236 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11237 vkEndCommandBuffer(secondary_command_buffer);
11238
Mark Mueller93b938f2016-08-18 10:27:40 -060011239 VkSubmitInfo submit_info = {};
11240 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11241 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011242 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011243
Mark Mueller4042b652016-09-05 22:52:21 -060011244 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011245 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11247 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011248 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011249 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011250 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11251 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011252
Dave Houltonfbf52152017-01-06 12:55:29 -070011253 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060011254 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070011255 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060011256
Mark Mueller4042b652016-09-05 22:52:21 -060011257 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011258 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011259 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011260
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11262 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011263 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011264 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11265 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011266
11267 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011268}
11269
Tobin Ehlisb093da82017-01-19 12:05:27 -070011270TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011271 TEST_DESCRIPTION(
11272 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
11273 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070011274
11275 ASSERT_NO_FATAL_FAILURE(InitState());
11276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11277
11278 std::vector<const char *> device_extension_names;
11279 auto features = m_device->phy().features();
11280 // Make sure gs & ts are disabled
11281 features.geometryShader = false;
11282 features.tessellationShader = false;
11283 // The sacrificial device object
11284 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11285
11286 VkCommandPoolCreateInfo pool_create_info{};
11287 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
11288 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
11289
11290 VkCommandPool command_pool;
11291 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
11292
11293 VkCommandBufferAllocateInfo cmd = {};
11294 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11295 cmd.pNext = NULL;
11296 cmd.commandPool = command_pool;
11297 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
11298 cmd.commandBufferCount = 1;
11299
11300 VkCommandBuffer cmd_buffer;
11301 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
11302 ASSERT_VK_SUCCESS(err);
11303
11304 VkEvent event;
11305 VkEventCreateInfo evci = {};
11306 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11307 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
11308 ASSERT_VK_SUCCESS(result);
11309
11310 VkCommandBufferBeginInfo cbbi = {};
11311 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11312 vkBeginCommandBuffer(cmd_buffer, &cbbi);
11313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
11314 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
11315 m_errorMonitor->VerifyFound();
11316
11317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
11318 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
11319 m_errorMonitor->VerifyFound();
11320
11321 vkDestroyEvent(test_device.handle(), event, NULL);
11322 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
11323}
11324
Mark Mueller917f6bc2016-08-30 10:57:19 -060011325TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011326 TEST_DESCRIPTION(
11327 "Use vkCmdExecuteCommands with invalid state "
11328 "in primary and secondary command buffers. "
11329 "Delete objects that are inuse. Call VkQueueSubmit "
11330 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011331
11332 ASSERT_NO_FATAL_FAILURE(InitState());
11333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011335 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011336 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011337
Tony Barbour552f6c02016-12-21 14:34:07 -070011338 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011339
11340 VkEvent event;
11341 VkEventCreateInfo event_create_info = {};
11342 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11343 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011344 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011345
Tony Barbour552f6c02016-12-21 14:34:07 -070011346 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011347 vkDestroyEvent(m_device->device(), event, nullptr);
11348
11349 VkSubmitInfo submit_info = {};
11350 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11351 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011352 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011354 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11355 m_errorMonitor->VerifyFound();
11356
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011357 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060011358 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11359
11360 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11361
Mark Mueller917f6bc2016-08-30 10:57:19 -060011362 VkSemaphoreCreateInfo semaphore_create_info = {};
11363 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11364 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011365 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011366 VkFenceCreateInfo fence_create_info = {};
11367 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11368 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011369 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011370
11371 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011372 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011373 descriptor_pool_type_count.descriptorCount = 1;
11374
11375 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11376 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11377 descriptor_pool_create_info.maxSets = 1;
11378 descriptor_pool_create_info.poolSizeCount = 1;
11379 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011380 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011381
11382 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011383 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011384
11385 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011386 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011387 descriptorset_layout_binding.descriptorCount = 1;
11388 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11389
11390 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011391 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011392 descriptorset_layout_create_info.bindingCount = 1;
11393 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11394
11395 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011396 ASSERT_VK_SUCCESS(
11397 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011398
11399 VkDescriptorSet descriptorset;
11400 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011401 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011402 descriptorset_allocate_info.descriptorSetCount = 1;
11403 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11404 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011405 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011406
Mark Mueller4042b652016-09-05 22:52:21 -060011407 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11408
11409 VkDescriptorBufferInfo buffer_info = {};
11410 buffer_info.buffer = buffer_test.GetBuffer();
11411 buffer_info.offset = 0;
11412 buffer_info.range = 1024;
11413
11414 VkWriteDescriptorSet write_descriptor_set = {};
11415 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11416 write_descriptor_set.dstSet = descriptorset;
11417 write_descriptor_set.descriptorCount = 1;
11418 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11419 write_descriptor_set.pBufferInfo = &buffer_info;
11420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011421 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011422
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011423 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11424 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011425
11426 VkPipelineObj pipe(m_device);
11427 pipe.AddColorAttachment();
11428 pipe.AddShader(&vs);
11429 pipe.AddShader(&fs);
11430
11431 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011432 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011433 pipeline_layout_create_info.setLayoutCount = 1;
11434 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11435
11436 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011437 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011438
11439 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11440
Tony Barbour552f6c02016-12-21 14:34:07 -070011441 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011442 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011443
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011444 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11445 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11446 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011447
Tony Barbour552f6c02016-12-21 14:34:07 -070011448 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011449
Mark Mueller917f6bc2016-08-30 10:57:19 -060011450 submit_info.signalSemaphoreCount = 1;
11451 submit_info.pSignalSemaphores = &semaphore;
11452 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011453 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060011454
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011456 vkDestroyEvent(m_device->device(), event, nullptr);
11457 m_errorMonitor->VerifyFound();
11458
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011460 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11461 m_errorMonitor->VerifyFound();
11462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011464 vkDestroyFence(m_device->device(), fence, nullptr);
11465 m_errorMonitor->VerifyFound();
11466
Tobin Ehlis122207b2016-09-01 08:50:06 -070011467 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011468 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11469 vkDestroyFence(m_device->device(), fence, nullptr);
11470 vkDestroyEvent(m_device->device(), event, nullptr);
11471 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011472 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011473 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11474}
11475
Tobin Ehlis2adda372016-09-01 08:51:06 -070011476TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11477 TEST_DESCRIPTION("Delete in-use query pool.");
11478
11479 ASSERT_NO_FATAL_FAILURE(InitState());
11480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11481
11482 VkQueryPool query_pool;
11483 VkQueryPoolCreateInfo query_pool_ci{};
11484 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11485 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11486 query_pool_ci.queryCount = 1;
11487 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011488 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011489 // Reset query pool to create binding with cmd buffer
11490 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11491
Tony Barbour552f6c02016-12-21 14:34:07 -070011492 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011493
11494 VkSubmitInfo submit_info = {};
11495 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11496 submit_info.commandBufferCount = 1;
11497 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11498 // Submit cmd buffer and then destroy query pool while in-flight
11499 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11500
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011502 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11503 m_errorMonitor->VerifyFound();
11504
11505 vkQueueWaitIdle(m_device->m_queue);
11506 // Now that cmd buffer done we can safely destroy query_pool
11507 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11508}
11509
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011510TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11511 TEST_DESCRIPTION("Delete in-use pipeline.");
11512
11513 ASSERT_NO_FATAL_FAILURE(InitState());
11514 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11515
11516 // Empty pipeline layout used for binding PSO
11517 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11518 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11519 pipeline_layout_ci.setLayoutCount = 0;
11520 pipeline_layout_ci.pSetLayouts = NULL;
11521
11522 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011523 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011524 ASSERT_VK_SUCCESS(err);
11525
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011527 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011528 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11529 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011530 // Store pipeline handle so we can actually delete it before test finishes
11531 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011532 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011533 VkPipelineObj pipe(m_device);
11534 pipe.AddShader(&vs);
11535 pipe.AddShader(&fs);
11536 pipe.AddColorAttachment();
11537 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11538 delete_this_pipeline = pipe.handle();
11539
Tony Barbour552f6c02016-12-21 14:34:07 -070011540 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011541 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011542 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011543
Tony Barbour552f6c02016-12-21 14:34:07 -070011544 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011545
11546 VkSubmitInfo submit_info = {};
11547 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11548 submit_info.commandBufferCount = 1;
11549 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11550 // Submit cmd buffer and then pipeline destroyed while in-flight
11551 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011552 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011553 m_errorMonitor->VerifyFound();
11554 // Make sure queue finished and then actually delete pipeline
11555 vkQueueWaitIdle(m_device->m_queue);
11556 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11557 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11558}
11559
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011560TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11561 TEST_DESCRIPTION("Delete in-use imageView.");
11562
11563 ASSERT_NO_FATAL_FAILURE(InitState());
11564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11565
11566 VkDescriptorPoolSize ds_type_count;
11567 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11568 ds_type_count.descriptorCount = 1;
11569
11570 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11571 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11572 ds_pool_ci.maxSets = 1;
11573 ds_pool_ci.poolSizeCount = 1;
11574 ds_pool_ci.pPoolSizes = &ds_type_count;
11575
11576 VkDescriptorPool ds_pool;
11577 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11578 ASSERT_VK_SUCCESS(err);
11579
11580 VkSamplerCreateInfo sampler_ci = {};
11581 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11582 sampler_ci.pNext = NULL;
11583 sampler_ci.magFilter = VK_FILTER_NEAREST;
11584 sampler_ci.minFilter = VK_FILTER_NEAREST;
11585 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11586 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11587 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11588 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11589 sampler_ci.mipLodBias = 1.0;
11590 sampler_ci.anisotropyEnable = VK_FALSE;
11591 sampler_ci.maxAnisotropy = 1;
11592 sampler_ci.compareEnable = VK_FALSE;
11593 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11594 sampler_ci.minLod = 1.0;
11595 sampler_ci.maxLod = 1.0;
11596 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11597 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11598 VkSampler sampler;
11599
11600 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11601 ASSERT_VK_SUCCESS(err);
11602
11603 VkDescriptorSetLayoutBinding layout_binding;
11604 layout_binding.binding = 0;
11605 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11606 layout_binding.descriptorCount = 1;
11607 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11608 layout_binding.pImmutableSamplers = NULL;
11609
11610 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11611 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11612 ds_layout_ci.bindingCount = 1;
11613 ds_layout_ci.pBindings = &layout_binding;
11614 VkDescriptorSetLayout ds_layout;
11615 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11616 ASSERT_VK_SUCCESS(err);
11617
11618 VkDescriptorSetAllocateInfo alloc_info = {};
11619 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11620 alloc_info.descriptorSetCount = 1;
11621 alloc_info.descriptorPool = ds_pool;
11622 alloc_info.pSetLayouts = &ds_layout;
11623 VkDescriptorSet descriptor_set;
11624 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11625 ASSERT_VK_SUCCESS(err);
11626
11627 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11628 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11629 pipeline_layout_ci.pNext = NULL;
11630 pipeline_layout_ci.setLayoutCount = 1;
11631 pipeline_layout_ci.pSetLayouts = &ds_layout;
11632
11633 VkPipelineLayout pipeline_layout;
11634 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11635 ASSERT_VK_SUCCESS(err);
11636
11637 VkImageObj image(m_device);
11638 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11639 ASSERT_TRUE(image.initialized());
11640
11641 VkImageView view;
11642 VkImageViewCreateInfo ivci = {};
11643 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11644 ivci.image = image.handle();
11645 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11646 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11647 ivci.subresourceRange.layerCount = 1;
11648 ivci.subresourceRange.baseMipLevel = 0;
11649 ivci.subresourceRange.levelCount = 1;
11650 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11651
11652 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11653 ASSERT_VK_SUCCESS(err);
11654
11655 VkDescriptorImageInfo image_info{};
11656 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11657 image_info.imageView = view;
11658 image_info.sampler = sampler;
11659
11660 VkWriteDescriptorSet descriptor_write = {};
11661 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11662 descriptor_write.dstSet = descriptor_set;
11663 descriptor_write.dstBinding = 0;
11664 descriptor_write.descriptorCount = 1;
11665 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11666 descriptor_write.pImageInfo = &image_info;
11667
11668 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11669
11670 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011671 char const *vsSource =
11672 "#version 450\n"
11673 "\n"
11674 "out gl_PerVertex { \n"
11675 " vec4 gl_Position;\n"
11676 "};\n"
11677 "void main(){\n"
11678 " gl_Position = vec4(1);\n"
11679 "}\n";
11680 char const *fsSource =
11681 "#version 450\n"
11682 "\n"
11683 "layout(set=0, binding=0) uniform sampler2D s;\n"
11684 "layout(location=0) out vec4 x;\n"
11685 "void main(){\n"
11686 " x = texture(s, vec2(1));\n"
11687 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011688 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11689 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11690 VkPipelineObj pipe(m_device);
11691 pipe.AddShader(&vs);
11692 pipe.AddShader(&fs);
11693 pipe.AddColorAttachment();
11694 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11695
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011697
Tony Barbour552f6c02016-12-21 14:34:07 -070011698 m_commandBuffer->BeginCommandBuffer();
11699 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011700 // Bind pipeline to cmd buffer
11701 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11702 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11703 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070011704
11705 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11706 VkRect2D scissor = {{0, 0}, {16, 16}};
11707 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11708 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11709
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011710 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011711 m_commandBuffer->EndRenderPass();
11712 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011713 // Submit cmd buffer then destroy sampler
11714 VkSubmitInfo submit_info = {};
11715 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11716 submit_info.commandBufferCount = 1;
11717 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11718 // Submit cmd buffer and then destroy imageView while in-flight
11719 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11720
11721 vkDestroyImageView(m_device->device(), view, nullptr);
11722 m_errorMonitor->VerifyFound();
11723 vkQueueWaitIdle(m_device->m_queue);
11724 // Now we can actually destroy imageView
11725 vkDestroyImageView(m_device->device(), view, NULL);
11726 vkDestroySampler(m_device->device(), sampler, nullptr);
11727 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11728 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11729 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11730}
11731
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011732TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11733 TEST_DESCRIPTION("Delete in-use bufferView.");
11734
11735 ASSERT_NO_FATAL_FAILURE(InitState());
11736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11737
11738 VkDescriptorPoolSize ds_type_count;
11739 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11740 ds_type_count.descriptorCount = 1;
11741
11742 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11743 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11744 ds_pool_ci.maxSets = 1;
11745 ds_pool_ci.poolSizeCount = 1;
11746 ds_pool_ci.pPoolSizes = &ds_type_count;
11747
11748 VkDescriptorPool ds_pool;
11749 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11750 ASSERT_VK_SUCCESS(err);
11751
11752 VkDescriptorSetLayoutBinding layout_binding;
11753 layout_binding.binding = 0;
11754 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11755 layout_binding.descriptorCount = 1;
11756 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11757 layout_binding.pImmutableSamplers = NULL;
11758
11759 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11760 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11761 ds_layout_ci.bindingCount = 1;
11762 ds_layout_ci.pBindings = &layout_binding;
11763 VkDescriptorSetLayout ds_layout;
11764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11765 ASSERT_VK_SUCCESS(err);
11766
11767 VkDescriptorSetAllocateInfo alloc_info = {};
11768 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11769 alloc_info.descriptorSetCount = 1;
11770 alloc_info.descriptorPool = ds_pool;
11771 alloc_info.pSetLayouts = &ds_layout;
11772 VkDescriptorSet descriptor_set;
11773 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11774 ASSERT_VK_SUCCESS(err);
11775
11776 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11777 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11778 pipeline_layout_ci.pNext = NULL;
11779 pipeline_layout_ci.setLayoutCount = 1;
11780 pipeline_layout_ci.pSetLayouts = &ds_layout;
11781
11782 VkPipelineLayout pipeline_layout;
11783 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11784 ASSERT_VK_SUCCESS(err);
11785
11786 VkBuffer buffer;
11787 uint32_t queue_family_index = 0;
11788 VkBufferCreateInfo buffer_create_info = {};
11789 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11790 buffer_create_info.size = 1024;
11791 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11792 buffer_create_info.queueFamilyIndexCount = 1;
11793 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11794
11795 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11796 ASSERT_VK_SUCCESS(err);
11797
11798 VkMemoryRequirements memory_reqs;
11799 VkDeviceMemory buffer_memory;
11800
11801 VkMemoryAllocateInfo memory_info = {};
11802 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11803 memory_info.allocationSize = 0;
11804 memory_info.memoryTypeIndex = 0;
11805
11806 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11807 memory_info.allocationSize = memory_reqs.size;
11808 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11809 ASSERT_TRUE(pass);
11810
11811 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11812 ASSERT_VK_SUCCESS(err);
11813 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11814 ASSERT_VK_SUCCESS(err);
11815
11816 VkBufferView view;
11817 VkBufferViewCreateInfo bvci = {};
11818 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11819 bvci.buffer = buffer;
11820 bvci.format = VK_FORMAT_R8_UNORM;
11821 bvci.range = VK_WHOLE_SIZE;
11822
11823 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11824 ASSERT_VK_SUCCESS(err);
11825
11826 VkWriteDescriptorSet descriptor_write = {};
11827 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11828 descriptor_write.dstSet = descriptor_set;
11829 descriptor_write.dstBinding = 0;
11830 descriptor_write.descriptorCount = 1;
11831 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11832 descriptor_write.pTexelBufferView = &view;
11833
11834 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11835
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011836 char const *vsSource =
11837 "#version 450\n"
11838 "\n"
11839 "out gl_PerVertex { \n"
11840 " vec4 gl_Position;\n"
11841 "};\n"
11842 "void main(){\n"
11843 " gl_Position = vec4(1);\n"
11844 "}\n";
11845 char const *fsSource =
11846 "#version 450\n"
11847 "\n"
11848 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11849 "layout(location=0) out vec4 x;\n"
11850 "void main(){\n"
11851 " x = imageLoad(s, 0);\n"
11852 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011853 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11854 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11855 VkPipelineObj pipe(m_device);
11856 pipe.AddShader(&vs);
11857 pipe.AddShader(&fs);
11858 pipe.AddColorAttachment();
11859 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11860
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011862
Tony Barbour552f6c02016-12-21 14:34:07 -070011863 m_commandBuffer->BeginCommandBuffer();
11864 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011865 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11866 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11867 VkRect2D scissor = {{0, 0}, {16, 16}};
11868 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11869 // Bind pipeline to cmd buffer
11870 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11871 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11872 &descriptor_set, 0, nullptr);
11873 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011874 m_commandBuffer->EndRenderPass();
11875 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011876
11877 VkSubmitInfo submit_info = {};
11878 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11879 submit_info.commandBufferCount = 1;
11880 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11881 // Submit cmd buffer and then destroy bufferView while in-flight
11882 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11883
11884 vkDestroyBufferView(m_device->device(), view, nullptr);
11885 m_errorMonitor->VerifyFound();
11886 vkQueueWaitIdle(m_device->m_queue);
11887 // Now we can actually destroy bufferView
11888 vkDestroyBufferView(m_device->device(), view, NULL);
11889 vkDestroyBuffer(m_device->device(), buffer, NULL);
11890 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11891 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11892 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11893 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11894}
11895
Tobin Ehlis209532e2016-09-07 13:52:18 -060011896TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11897 TEST_DESCRIPTION("Delete in-use sampler.");
11898
11899 ASSERT_NO_FATAL_FAILURE(InitState());
11900 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11901
11902 VkDescriptorPoolSize ds_type_count;
11903 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11904 ds_type_count.descriptorCount = 1;
11905
11906 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11907 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11908 ds_pool_ci.maxSets = 1;
11909 ds_pool_ci.poolSizeCount = 1;
11910 ds_pool_ci.pPoolSizes = &ds_type_count;
11911
11912 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011913 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011914 ASSERT_VK_SUCCESS(err);
11915
11916 VkSamplerCreateInfo sampler_ci = {};
11917 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11918 sampler_ci.pNext = NULL;
11919 sampler_ci.magFilter = VK_FILTER_NEAREST;
11920 sampler_ci.minFilter = VK_FILTER_NEAREST;
11921 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11922 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11923 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11924 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11925 sampler_ci.mipLodBias = 1.0;
11926 sampler_ci.anisotropyEnable = VK_FALSE;
11927 sampler_ci.maxAnisotropy = 1;
11928 sampler_ci.compareEnable = VK_FALSE;
11929 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11930 sampler_ci.minLod = 1.0;
11931 sampler_ci.maxLod = 1.0;
11932 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11933 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11934 VkSampler sampler;
11935
11936 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11937 ASSERT_VK_SUCCESS(err);
11938
11939 VkDescriptorSetLayoutBinding layout_binding;
11940 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011941 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011942 layout_binding.descriptorCount = 1;
11943 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11944 layout_binding.pImmutableSamplers = NULL;
11945
11946 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11947 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11948 ds_layout_ci.bindingCount = 1;
11949 ds_layout_ci.pBindings = &layout_binding;
11950 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011951 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011952 ASSERT_VK_SUCCESS(err);
11953
11954 VkDescriptorSetAllocateInfo alloc_info = {};
11955 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11956 alloc_info.descriptorSetCount = 1;
11957 alloc_info.descriptorPool = ds_pool;
11958 alloc_info.pSetLayouts = &ds_layout;
11959 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011960 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011961 ASSERT_VK_SUCCESS(err);
11962
11963 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11964 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11965 pipeline_layout_ci.pNext = NULL;
11966 pipeline_layout_ci.setLayoutCount = 1;
11967 pipeline_layout_ci.pSetLayouts = &ds_layout;
11968
11969 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011970 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011971 ASSERT_VK_SUCCESS(err);
11972
11973 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011974 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 -060011975 ASSERT_TRUE(image.initialized());
11976
11977 VkImageView view;
11978 VkImageViewCreateInfo ivci = {};
11979 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11980 ivci.image = image.handle();
11981 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11982 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11983 ivci.subresourceRange.layerCount = 1;
11984 ivci.subresourceRange.baseMipLevel = 0;
11985 ivci.subresourceRange.levelCount = 1;
11986 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11987
11988 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11989 ASSERT_VK_SUCCESS(err);
11990
11991 VkDescriptorImageInfo image_info{};
11992 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11993 image_info.imageView = view;
11994 image_info.sampler = sampler;
11995
11996 VkWriteDescriptorSet descriptor_write = {};
11997 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11998 descriptor_write.dstSet = descriptor_set;
11999 descriptor_write.dstBinding = 0;
12000 descriptor_write.descriptorCount = 1;
12001 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12002 descriptor_write.pImageInfo = &image_info;
12003
12004 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12005
12006 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012007 char const *vsSource =
12008 "#version 450\n"
12009 "\n"
12010 "out gl_PerVertex { \n"
12011 " vec4 gl_Position;\n"
12012 "};\n"
12013 "void main(){\n"
12014 " gl_Position = vec4(1);\n"
12015 "}\n";
12016 char const *fsSource =
12017 "#version 450\n"
12018 "\n"
12019 "layout(set=0, binding=0) uniform sampler2D s;\n"
12020 "layout(location=0) out vec4 x;\n"
12021 "void main(){\n"
12022 " x = texture(s, vec2(1));\n"
12023 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012024 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12025 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12026 VkPipelineObj pipe(m_device);
12027 pipe.AddShader(&vs);
12028 pipe.AddShader(&fs);
12029 pipe.AddColorAttachment();
12030 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12031
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012033
Tony Barbour552f6c02016-12-21 14:34:07 -070012034 m_commandBuffer->BeginCommandBuffer();
12035 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012036 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012037 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12038 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12039 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012040
12041 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12042 VkRect2D scissor = {{0, 0}, {16, 16}};
12043 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12044 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12045
Tobin Ehlis209532e2016-09-07 13:52:18 -060012046 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012047 m_commandBuffer->EndRenderPass();
12048 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012049 // Submit cmd buffer then destroy sampler
12050 VkSubmitInfo submit_info = {};
12051 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12052 submit_info.commandBufferCount = 1;
12053 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12054 // Submit cmd buffer and then destroy sampler while in-flight
12055 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12056
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012057 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012058 m_errorMonitor->VerifyFound();
12059 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012060
Tobin Ehlis209532e2016-09-07 13:52:18 -060012061 // Now we can actually destroy sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012062 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012063 vkDestroyImageView(m_device->device(), view, NULL);
12064 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12065 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12066 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12067}
12068
Mark Mueller1cd9f412016-08-25 13:23:52 -060012069TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012070 TEST_DESCRIPTION(
12071 "Call VkQueueSubmit with a semaphore that is already "
12072 "signaled but not waited on by the queue. Wait on a "
12073 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012074
12075 ASSERT_NO_FATAL_FAILURE(InitState());
12076 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12077
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012078 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 -070012079 const char *invalid_fence_wait_message =
12080 " which has not been submitted on a Queue or during "
12081 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012082
Tony Barbour552f6c02016-12-21 14:34:07 -070012083 m_commandBuffer->BeginCommandBuffer();
12084 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012085
12086 VkSemaphoreCreateInfo semaphore_create_info = {};
12087 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12088 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012089 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012090 VkSubmitInfo submit_info = {};
12091 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12092 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012093 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012094 submit_info.signalSemaphoreCount = 1;
12095 submit_info.pSignalSemaphores = &semaphore;
12096 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012097 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012098 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012099 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012100 m_commandBuffer->BeginCommandBuffer();
12101 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012103 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12104 m_errorMonitor->VerifyFound();
12105
Mark Mueller1cd9f412016-08-25 13:23:52 -060012106 VkFenceCreateInfo fence_create_info = {};
12107 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12108 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012109 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012110
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012112 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12113 m_errorMonitor->VerifyFound();
12114
Mark Mueller4042b652016-09-05 22:52:21 -060012115 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012116 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012117 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12118}
12119
Tobin Ehlis4af23302016-07-19 10:50:30 -060012120TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012121 TEST_DESCRIPTION(
12122 "Bind a secondary command buffer with with a framebuffer "
12123 "that does not match the framebuffer for the active "
12124 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012125 ASSERT_NO_FATAL_FAILURE(InitState());
12126 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12127
12128 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012129 VkAttachmentDescription attachment = {0,
12130 VK_FORMAT_B8G8R8A8_UNORM,
12131 VK_SAMPLE_COUNT_1_BIT,
12132 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12133 VK_ATTACHMENT_STORE_OP_STORE,
12134 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12135 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12136 VK_IMAGE_LAYOUT_UNDEFINED,
12137 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012138
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012139 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012140
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012141 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012142
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012143 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012144
12145 VkRenderPass rp;
12146 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12147 ASSERT_VK_SUCCESS(err);
12148
12149 // A compatible framebuffer.
12150 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012151 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 -060012152 ASSERT_TRUE(image.initialized());
12153
12154 VkImageViewCreateInfo ivci = {
12155 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12156 nullptr,
12157 0,
12158 image.handle(),
12159 VK_IMAGE_VIEW_TYPE_2D,
12160 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012161 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12162 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012163 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12164 };
12165 VkImageView view;
12166 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12167 ASSERT_VK_SUCCESS(err);
12168
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012169 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012170 VkFramebuffer fb;
12171 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12172 ASSERT_VK_SUCCESS(err);
12173
12174 VkCommandBufferAllocateInfo cbai = {};
12175 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12176 cbai.commandPool = m_commandPool;
12177 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12178 cbai.commandBufferCount = 1;
12179
12180 VkCommandBuffer sec_cb;
12181 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12182 ASSERT_VK_SUCCESS(err);
12183 VkCommandBufferBeginInfo cbbi = {};
12184 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130012185 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060012186 cbii.renderPass = renderPass();
12187 cbii.framebuffer = fb;
12188 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12189 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012190 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 -060012191 cbbi.pInheritanceInfo = &cbii;
12192 vkBeginCommandBuffer(sec_cb, &cbbi);
12193 vkEndCommandBuffer(sec_cb);
12194
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012195 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120012196 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12197 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012198
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012200 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012201 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12202 m_errorMonitor->VerifyFound();
12203 // Cleanup
12204 vkDestroyImageView(m_device->device(), view, NULL);
12205 vkDestroyRenderPass(m_device->device(), rp, NULL);
12206 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12207}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012208
12209TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012210 TEST_DESCRIPTION(
12211 "If logicOp is available on the device, set it to an "
12212 "invalid value. If logicOp is not available, attempt to "
12213 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012214 ASSERT_NO_FATAL_FAILURE(InitState());
12215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12216
12217 auto features = m_device->phy().features();
12218 // Set the expected error depending on whether or not logicOp available
12219 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12221 "If logic operations feature not "
12222 "enabled, logicOpEnable must be "
12223 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012224 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012226 }
12227 // Create a pipeline using logicOp
12228 VkResult err;
12229
12230 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12231 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12232
12233 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012234 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012235 ASSERT_VK_SUCCESS(err);
12236
12237 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12238 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12239 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012240 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012241 vp_state_ci.pViewports = &vp;
12242 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012243 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012244 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012245
12246 VkPipelineShaderStageCreateInfo shaderStages[2];
12247 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12248
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012249 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12250 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012251 shaderStages[0] = vs.GetStageCreateInfo();
12252 shaderStages[1] = fs.GetStageCreateInfo();
12253
12254 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12255 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12256
12257 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12258 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12259 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12260
12261 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12262 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012263 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012264
12265 VkPipelineColorBlendAttachmentState att = {};
12266 att.blendEnable = VK_FALSE;
12267 att.colorWriteMask = 0xf;
12268
12269 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12270 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12271 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12272 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012273 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012274 cb_ci.attachmentCount = 1;
12275 cb_ci.pAttachments = &att;
12276
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012277 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12278 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12279 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12280
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012281 VkGraphicsPipelineCreateInfo gp_ci = {};
12282 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12283 gp_ci.stageCount = 2;
12284 gp_ci.pStages = shaderStages;
12285 gp_ci.pVertexInputState = &vi_ci;
12286 gp_ci.pInputAssemblyState = &ia_ci;
12287 gp_ci.pViewportState = &vp_state_ci;
12288 gp_ci.pRasterizationState = &rs_ci;
12289 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012290 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012291 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12292 gp_ci.layout = pipeline_layout;
12293 gp_ci.renderPass = renderPass();
12294
12295 VkPipelineCacheCreateInfo pc_ci = {};
12296 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12297
12298 VkPipeline pipeline;
12299 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012300 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012301 ASSERT_VK_SUCCESS(err);
12302
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012303 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012304 m_errorMonitor->VerifyFound();
12305 if (VK_SUCCESS == err) {
12306 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12307 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012308 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12309 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12310}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012311#endif // DRAW_STATE_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012312
Tobin Ehlis0788f522015-05-26 16:11:58 -060012313#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012314#if GTEST_IS_THREADSAFE
12315struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012316 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012317 VkEvent event;
12318 bool bailout;
12319};
12320
Karl Schultz6addd812016-02-02 17:17:23 -070012321extern "C" void *AddToCommandBuffer(void *arg) {
12322 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012323
Mike Stroyana6d14942016-07-13 15:10:05 -060012324 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012325 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012326 if (data->bailout) {
12327 break;
12328 }
12329 }
12330 return NULL;
12331}
12332
Karl Schultz6addd812016-02-02 17:17:23 -070012333TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012334 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012335
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012337
Mike Stroyanaccf7692015-05-12 16:00:45 -060012338 ASSERT_NO_FATAL_FAILURE(InitState());
12339 ASSERT_NO_FATAL_FAILURE(InitViewport());
12340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12341
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012342 // Calls AllocateCommandBuffers
12343 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012344
12345 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012346 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012347
12348 VkEventCreateInfo event_info;
12349 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012350 VkResult err;
12351
12352 memset(&event_info, 0, sizeof(event_info));
12353 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12354
Chia-I Wuf7458c52015-10-26 21:10:41 +080012355 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012356 ASSERT_VK_SUCCESS(err);
12357
Mike Stroyanaccf7692015-05-12 16:00:45 -060012358 err = vkResetEvent(device(), event);
12359 ASSERT_VK_SUCCESS(err);
12360
12361 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012362 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012363 data.event = event;
12364 data.bailout = false;
12365 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012366
12367 // First do some correct operations using multiple threads.
12368 // Add many entries to command buffer from another thread.
12369 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12370 // Make non-conflicting calls from this thread at the same time.
12371 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012372 uint32_t count;
12373 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012374 }
12375 test_platform_thread_join(thread, NULL);
12376
12377 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012378 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012379 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012380 // Add many entries to command buffer from this thread at the same time.
12381 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012382
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012383 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012384 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012385
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012386 m_errorMonitor->SetBailout(NULL);
12387
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012388 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012389
Chia-I Wuf7458c52015-10-26 21:10:41 +080012390 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012391}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012392#endif // GTEST_IS_THREADSAFE
12393#endif // THREADING_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012394
Chris Forbes9f7ff632015-05-25 11:13:08 +120012395#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012396TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012397 TEST_DESCRIPTION(
12398 "Test that an error is produced for a spirv module "
12399 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120012400
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012402
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012403 ASSERT_NO_FATAL_FAILURE(InitState());
12404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12405
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012406 VkShaderModule module;
12407 VkShaderModuleCreateInfo moduleCreateInfo;
12408 struct icd_spv_header spv;
12409
12410 spv.magic = ICD_SPV_MAGIC;
12411 spv.version = ICD_SPV_VERSION;
12412 spv.gen_magic = 0;
12413
12414 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12415 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012416 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012417 moduleCreateInfo.codeSize = 4;
12418 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012419 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012420
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012421 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012422}
12423
Karl Schultz6addd812016-02-02 17:17:23 -070012424TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012425 TEST_DESCRIPTION(
12426 "Test that an error is produced for a spirv module "
12427 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120012428
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012430
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012431 ASSERT_NO_FATAL_FAILURE(InitState());
12432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12433
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012434 VkShaderModule module;
12435 VkShaderModuleCreateInfo moduleCreateInfo;
12436 struct icd_spv_header spv;
12437
12438 spv.magic = ~ICD_SPV_MAGIC;
12439 spv.version = ICD_SPV_VERSION;
12440 spv.gen_magic = 0;
12441
12442 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12443 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012444 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012445 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12446 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012447 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012448
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012449 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012450}
12451
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012452#if 0
12453// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012454TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012456 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012457
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012458 ASSERT_NO_FATAL_FAILURE(InitState());
12459 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12460
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012461 VkShaderModule module;
12462 VkShaderModuleCreateInfo moduleCreateInfo;
12463 struct icd_spv_header spv;
12464
12465 spv.magic = ICD_SPV_MAGIC;
12466 spv.version = ~ICD_SPV_VERSION;
12467 spv.gen_magic = 0;
12468
12469 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12470 moduleCreateInfo.pNext = NULL;
12471
Karl Schultz6addd812016-02-02 17:17:23 -070012472 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012473 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12474 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012475 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012476
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012477 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012478}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012479#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012480
Karl Schultz6addd812016-02-02 17:17:23 -070012481TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012482 TEST_DESCRIPTION(
12483 "Test that a warning is produced for a vertex output that "
12484 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012486
Chris Forbes9f7ff632015-05-25 11:13:08 +120012487 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012489
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012490 char const *vsSource =
12491 "#version 450\n"
12492 "\n"
12493 "layout(location=0) out float x;\n"
12494 "out gl_PerVertex {\n"
12495 " vec4 gl_Position;\n"
12496 "};\n"
12497 "void main(){\n"
12498 " gl_Position = vec4(1);\n"
12499 " x = 0;\n"
12500 "}\n";
12501 char const *fsSource =
12502 "#version 450\n"
12503 "\n"
12504 "layout(location=0) out vec4 color;\n"
12505 "void main(){\n"
12506 " color = vec4(1);\n"
12507 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012508
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012509 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12510 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012511
12512 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012513 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012514 pipe.AddShader(&vs);
12515 pipe.AddShader(&fs);
12516
Chris Forbes9f7ff632015-05-25 11:13:08 +120012517 VkDescriptorSetObj descriptorSet(m_device);
12518 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012519 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012520
Tony Barbour5781e8f2015-08-04 16:23:11 -060012521 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012522
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012523 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012524}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012525
Mark Mueller098c9cb2016-09-08 09:01:57 -060012526TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12527 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12528
12529 ASSERT_NO_FATAL_FAILURE(InitState());
12530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12531
12532 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012533 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012534
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012535 char const *vsSource =
12536 "#version 450\n"
12537 "\n"
12538 "out gl_PerVertex {\n"
12539 " vec4 gl_Position;\n"
12540 "};\n"
12541 "void main(){\n"
12542 " gl_Position = vec4(1);\n"
12543 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012544
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012545 char const *fsSource =
12546 "#version 450\n"
12547 "\n"
12548 "layout (constant_id = 0) const float r = 0.0f;\n"
12549 "layout(location = 0) out vec4 uFragColor;\n"
12550 "void main(){\n"
12551 " uFragColor = vec4(r,1,0,1);\n"
12552 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012553
12554 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12555 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12556
12557 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12558 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12559
12560 VkPipelineLayout pipeline_layout;
12561 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12562
12563 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12564 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12565 vp_state_create_info.viewportCount = 1;
12566 VkViewport viewport = {};
12567 vp_state_create_info.pViewports = &viewport;
12568 vp_state_create_info.scissorCount = 1;
12569 VkRect2D scissors = {};
12570 vp_state_create_info.pScissors = &scissors;
12571
12572 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12573
12574 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12575 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12576 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12577 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12578
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012579 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060012580
12581 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12582 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12583
12584 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12585 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12586 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12587
12588 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12589 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12590 rasterization_state_create_info.pNext = nullptr;
12591 rasterization_state_create_info.lineWidth = 1.0f;
12592 rasterization_state_create_info.rasterizerDiscardEnable = true;
12593
12594 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12595 color_blend_attachment_state.blendEnable = VK_FALSE;
12596 color_blend_attachment_state.colorWriteMask = 0xf;
12597
12598 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12599 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12600 color_blend_state_create_info.attachmentCount = 1;
12601 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12602
12603 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12604 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12605 graphicspipe_create_info.stageCount = 2;
12606 graphicspipe_create_info.pStages = shader_stage_create_info;
12607 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12608 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12609 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12610 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12611 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12612 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12613 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12614 graphicspipe_create_info.layout = pipeline_layout;
12615 graphicspipe_create_info.renderPass = renderPass();
12616
12617 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12618 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12619
12620 VkPipelineCache pipelineCache;
12621 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12622
12623 // This structure maps constant ids to data locations.
12624 const VkSpecializationMapEntry entry =
12625 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012626 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060012627
12628 uint32_t data = 1;
12629
12630 // Set up the info describing spec map and data
12631 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012632 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060012633 };
12634 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12635
12636 VkPipeline pipeline;
12637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12638 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12639 m_errorMonitor->VerifyFound();
12640
12641 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12643}
12644
12645TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12646 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12647
12648 ASSERT_NO_FATAL_FAILURE(InitState());
12649 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12650
12651 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12652
12653 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12654 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12655 descriptor_pool_type_count[0].descriptorCount = 1;
12656 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12657 descriptor_pool_type_count[1].descriptorCount = 1;
12658
12659 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12660 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12661 descriptor_pool_create_info.maxSets = 1;
12662 descriptor_pool_create_info.poolSizeCount = 2;
12663 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12664 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12665
12666 VkDescriptorPool descriptorset_pool;
12667 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12668
12669 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12670 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12671 descriptorset_layout_binding.descriptorCount = 1;
12672 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12673
12674 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12675 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12676 descriptorset_layout_create_info.bindingCount = 1;
12677 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12678
12679 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012680 ASSERT_VK_SUCCESS(
12681 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060012682
12683 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12684 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12685 descriptorset_allocate_info.descriptorSetCount = 1;
12686 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12687 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12688 VkDescriptorSet descriptorset;
12689 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12690
12691 // Challenge core_validation with a non uniform buffer type.
12692 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12693
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012694 char const *vsSource =
12695 "#version 450\n"
12696 "\n"
12697 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12698 " mat4 mvp;\n"
12699 "} ubuf;\n"
12700 "out gl_PerVertex {\n"
12701 " vec4 gl_Position;\n"
12702 "};\n"
12703 "void main(){\n"
12704 " gl_Position = ubuf.mvp * vec4(1);\n"
12705 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012706
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012707 char const *fsSource =
12708 "#version 450\n"
12709 "\n"
12710 "layout(location = 0) out vec4 uFragColor;\n"
12711 "void main(){\n"
12712 " uFragColor = vec4(0,1,0,1);\n"
12713 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012714
12715 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12716 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12717
12718 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12719 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12720 pipeline_layout_create_info.setLayoutCount = 1;
12721 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12722
12723 VkPipelineLayout pipeline_layout;
12724 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12725
12726 VkPipelineObj pipe(m_device);
12727 pipe.AddColorAttachment();
12728 pipe.AddShader(&vs);
12729 pipe.AddShader(&fs);
12730
12731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12732 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12733 m_errorMonitor->VerifyFound();
12734
12735 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12736 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12737 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12738}
12739
12740TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12741 TEST_DESCRIPTION(
12742 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12743
12744 ASSERT_NO_FATAL_FAILURE(InitState());
12745 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12746
12747 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12748
12749 VkDescriptorPoolSize descriptor_pool_type_count = {};
12750 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12751 descriptor_pool_type_count.descriptorCount = 1;
12752
12753 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12754 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12755 descriptor_pool_create_info.maxSets = 1;
12756 descriptor_pool_create_info.poolSizeCount = 1;
12757 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12758 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12759
12760 VkDescriptorPool descriptorset_pool;
12761 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12762
12763 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12764 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12765 descriptorset_layout_binding.descriptorCount = 1;
12766 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12767 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12768
12769 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12770 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12771 descriptorset_layout_create_info.bindingCount = 1;
12772 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12773
12774 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012775 ASSERT_VK_SUCCESS(
12776 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060012777
12778 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12779 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12780 descriptorset_allocate_info.descriptorSetCount = 1;
12781 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12782 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12783 VkDescriptorSet descriptorset;
12784 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12785
12786 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12787
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012788 char const *vsSource =
12789 "#version 450\n"
12790 "\n"
12791 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12792 " mat4 mvp;\n"
12793 "} ubuf;\n"
12794 "out gl_PerVertex {\n"
12795 " vec4 gl_Position;\n"
12796 "};\n"
12797 "void main(){\n"
12798 " gl_Position = ubuf.mvp * vec4(1);\n"
12799 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012800
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012801 char const *fsSource =
12802 "#version 450\n"
12803 "\n"
12804 "layout(location = 0) out vec4 uFragColor;\n"
12805 "void main(){\n"
12806 " uFragColor = vec4(0,1,0,1);\n"
12807 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012808
12809 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12810 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12811
12812 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12813 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12814 pipeline_layout_create_info.setLayoutCount = 1;
12815 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12816
12817 VkPipelineLayout pipeline_layout;
12818 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12819
12820 VkPipelineObj pipe(m_device);
12821 pipe.AddColorAttachment();
12822 pipe.AddShader(&vs);
12823 pipe.AddShader(&fs);
12824
12825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12826 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12827 m_errorMonitor->VerifyFound();
12828
12829 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12830 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12831 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12832}
12833
12834TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012835 TEST_DESCRIPTION(
12836 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12837 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060012838
12839 ASSERT_NO_FATAL_FAILURE(InitState());
12840 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12841
12842 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012843 "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 -060012844
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012845 char const *vsSource =
12846 "#version 450\n"
12847 "\n"
12848 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12849 "out gl_PerVertex {\n"
12850 " vec4 gl_Position;\n"
12851 "};\n"
12852 "void main(){\n"
12853 " gl_Position = vec4(consts.x);\n"
12854 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012855
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012856 char const *fsSource =
12857 "#version 450\n"
12858 "\n"
12859 "layout(location = 0) out vec4 uFragColor;\n"
12860 "void main(){\n"
12861 " uFragColor = vec4(0,1,0,1);\n"
12862 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012863
12864 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12865 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12866
12867 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12868 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12869
12870 // Set up a push constant range
12871 VkPushConstantRange push_constant_ranges = {};
12872 // Set to the wrong stage to challenge core_validation
12873 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12874 push_constant_ranges.size = 4;
12875
12876 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12877 pipeline_layout_create_info.pushConstantRangeCount = 1;
12878
12879 VkPipelineLayout pipeline_layout;
12880 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12881
12882 VkPipelineObj pipe(m_device);
12883 pipe.AddColorAttachment();
12884 pipe.AddShader(&vs);
12885 pipe.AddShader(&fs);
12886
12887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12888 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12889 m_errorMonitor->VerifyFound();
12890
12891 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12892}
12893
12894TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12895 TEST_DESCRIPTION(
12896 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12897
12898 ASSERT_NO_FATAL_FAILURE(InitState());
12899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12900
12901 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012902 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012903
12904 // Some awkward steps are required to test with custom device features.
12905 std::vector<const char *> device_extension_names;
12906 auto features = m_device->phy().features();
12907 // Disable support for 64 bit floats
12908 features.shaderFloat64 = false;
12909 // The sacrificial device object
12910 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12911
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012912 char const *vsSource =
12913 "#version 450\n"
12914 "\n"
12915 "out gl_PerVertex {\n"
12916 " vec4 gl_Position;\n"
12917 "};\n"
12918 "void main(){\n"
12919 " gl_Position = vec4(1);\n"
12920 "}\n";
12921 char const *fsSource =
12922 "#version 450\n"
12923 "\n"
12924 "layout(location=0) out vec4 color;\n"
12925 "void main(){\n"
12926 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12927 " color = vec4(green);\n"
12928 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012929
12930 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12931 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12932
12933 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012934
12935 VkPipelineObj pipe(&test_device);
12936 pipe.AddColorAttachment();
12937 pipe.AddShader(&vs);
12938 pipe.AddShader(&fs);
12939
12940 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12941 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12942 VkPipelineLayout pipeline_layout;
12943 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12944
12945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12946 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12947 m_errorMonitor->VerifyFound();
12948
12949 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12950}
12951
12952TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12953 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12954
12955 ASSERT_NO_FATAL_FAILURE(InitState());
12956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12957
12958 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12959
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012960 char const *vsSource =
12961 "#version 450\n"
12962 "\n"
12963 "out gl_PerVertex {\n"
12964 " vec4 gl_Position;\n"
12965 "};\n"
12966 "layout(xfb_buffer = 1) out;"
12967 "void main(){\n"
12968 " gl_Position = vec4(1);\n"
12969 "}\n";
12970 char const *fsSource =
12971 "#version 450\n"
12972 "\n"
12973 "layout(location=0) out vec4 color;\n"
12974 "void main(){\n"
12975 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12976 " color = vec4(green);\n"
12977 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012978
12979 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12980 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12981
12982 VkPipelineObj pipe(m_device);
12983 pipe.AddColorAttachment();
12984 pipe.AddShader(&vs);
12985 pipe.AddShader(&fs);
12986
12987 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12988 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12989 VkPipelineLayout pipeline_layout;
12990 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12991
12992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12993 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12994 m_errorMonitor->VerifyFound();
12995
12996 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12997}
12998
Karl Schultz6addd812016-02-02 17:17:23 -070012999TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013000 TEST_DESCRIPTION(
13001 "Test that an error is produced for a fragment shader input "
13002 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013005
Chris Forbes59cb88d2015-05-25 11:13:13 +120013006 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013008
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013009 char const *vsSource =
13010 "#version 450\n"
13011 "\n"
13012 "out gl_PerVertex {\n"
13013 " vec4 gl_Position;\n"
13014 "};\n"
13015 "void main(){\n"
13016 " gl_Position = vec4(1);\n"
13017 "}\n";
13018 char const *fsSource =
13019 "#version 450\n"
13020 "\n"
13021 "layout(location=0) in float x;\n"
13022 "layout(location=0) out vec4 color;\n"
13023 "void main(){\n"
13024 " color = vec4(x);\n"
13025 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013026
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013027 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13028 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013029
13030 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013031 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013032 pipe.AddShader(&vs);
13033 pipe.AddShader(&fs);
13034
Chris Forbes59cb88d2015-05-25 11:13:13 +120013035 VkDescriptorSetObj descriptorSet(m_device);
13036 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013037 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013038
Tony Barbour5781e8f2015-08-04 16:23:11 -060013039 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013040
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013041 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013042}
13043
Karl Schultz6addd812016-02-02 17:17:23 -070013044TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013045 TEST_DESCRIPTION(
13046 "Test that an error is produced for a fragment shader input "
13047 "within an interace block, which is not present in the outputs "
13048 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013050
13051 ASSERT_NO_FATAL_FAILURE(InitState());
13052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13053
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013054 char const *vsSource =
13055 "#version 450\n"
13056 "\n"
13057 "out gl_PerVertex {\n"
13058 " vec4 gl_Position;\n"
13059 "};\n"
13060 "void main(){\n"
13061 " gl_Position = vec4(1);\n"
13062 "}\n";
13063 char const *fsSource =
13064 "#version 450\n"
13065 "\n"
13066 "in block { layout(location=0) float x; } ins;\n"
13067 "layout(location=0) out vec4 color;\n"
13068 "void main(){\n"
13069 " color = vec4(ins.x);\n"
13070 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013071
13072 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13073 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13074
13075 VkPipelineObj pipe(m_device);
13076 pipe.AddColorAttachment();
13077 pipe.AddShader(&vs);
13078 pipe.AddShader(&fs);
13079
13080 VkDescriptorSetObj descriptorSet(m_device);
13081 descriptorSet.AppendDummy();
13082 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13083
13084 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13085
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013086 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013087}
13088
Karl Schultz6addd812016-02-02 17:17:23 -070013089TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013090 TEST_DESCRIPTION(
13091 "Test that an error is produced for mismatched array sizes "
13092 "across the vertex->fragment shader interface");
13093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13094 "Type mismatch on location 0.0: 'ptr to "
13095 "output arr[2] of float32' vs 'ptr to "
13096 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013097
13098 ASSERT_NO_FATAL_FAILURE(InitState());
13099 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13100
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013101 char const *vsSource =
13102 "#version 450\n"
13103 "\n"
13104 "layout(location=0) out float x[2];\n"
13105 "out gl_PerVertex {\n"
13106 " vec4 gl_Position;\n"
13107 "};\n"
13108 "void main(){\n"
13109 " x[0] = 0; x[1] = 0;\n"
13110 " gl_Position = vec4(1);\n"
13111 "}\n";
13112 char const *fsSource =
13113 "#version 450\n"
13114 "\n"
13115 "layout(location=0) in float x[1];\n"
13116 "layout(location=0) out vec4 color;\n"
13117 "void main(){\n"
13118 " color = vec4(x[0]);\n"
13119 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013120
13121 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13122 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13123
13124 VkPipelineObj pipe(m_device);
13125 pipe.AddColorAttachment();
13126 pipe.AddShader(&vs);
13127 pipe.AddShader(&fs);
13128
13129 VkDescriptorSetObj descriptorSet(m_device);
13130 descriptorSet.AppendDummy();
13131 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13132
13133 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13134
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013135 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013136}
13137
Karl Schultz6addd812016-02-02 17:17:23 -070013138TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013139 TEST_DESCRIPTION(
13140 "Test that an error is produced for mismatched types across "
13141 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013143
Chris Forbesb56af562015-05-25 11:13:17 +120013144 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013146
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013147 char const *vsSource =
13148 "#version 450\n"
13149 "\n"
13150 "layout(location=0) out int x;\n"
13151 "out gl_PerVertex {\n"
13152 " vec4 gl_Position;\n"
13153 "};\n"
13154 "void main(){\n"
13155 " x = 0;\n"
13156 " gl_Position = vec4(1);\n"
13157 "}\n";
13158 char const *fsSource =
13159 "#version 450\n"
13160 "\n"
13161 "layout(location=0) in float x;\n" /* VS writes int */
13162 "layout(location=0) out vec4 color;\n"
13163 "void main(){\n"
13164 " color = vec4(x);\n"
13165 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013166
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013167 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13168 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013169
13170 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013171 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013172 pipe.AddShader(&vs);
13173 pipe.AddShader(&fs);
13174
Chris Forbesb56af562015-05-25 11:13:17 +120013175 VkDescriptorSetObj descriptorSet(m_device);
13176 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013177 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013178
Tony Barbour5781e8f2015-08-04 16:23:11 -060013179 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013180
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013181 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013182}
13183
Karl Schultz6addd812016-02-02 17:17:23 -070013184TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013185 TEST_DESCRIPTION(
13186 "Test that an error is produced for mismatched types across "
13187 "the vertex->fragment shader interface, when the variable is contained within "
13188 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013190
13191 ASSERT_NO_FATAL_FAILURE(InitState());
13192 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13193
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013194 char const *vsSource =
13195 "#version 450\n"
13196 "\n"
13197 "out block { layout(location=0) int x; } outs;\n"
13198 "out gl_PerVertex {\n"
13199 " vec4 gl_Position;\n"
13200 "};\n"
13201 "void main(){\n"
13202 " outs.x = 0;\n"
13203 " gl_Position = vec4(1);\n"
13204 "}\n";
13205 char const *fsSource =
13206 "#version 450\n"
13207 "\n"
13208 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13209 "layout(location=0) out vec4 color;\n"
13210 "void main(){\n"
13211 " color = vec4(ins.x);\n"
13212 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013213
13214 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13215 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13216
13217 VkPipelineObj pipe(m_device);
13218 pipe.AddColorAttachment();
13219 pipe.AddShader(&vs);
13220 pipe.AddShader(&fs);
13221
13222 VkDescriptorSetObj descriptorSet(m_device);
13223 descriptorSet.AppendDummy();
13224 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13225
13226 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13227
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013228 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013229}
13230
13231TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013232 TEST_DESCRIPTION(
13233 "Test that an error is produced for location mismatches across "
13234 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
13235 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013236 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 +130013237
13238 ASSERT_NO_FATAL_FAILURE(InitState());
13239 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13240
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013241 char const *vsSource =
13242 "#version 450\n"
13243 "\n"
13244 "out block { layout(location=1) float x; } outs;\n"
13245 "out gl_PerVertex {\n"
13246 " vec4 gl_Position;\n"
13247 "};\n"
13248 "void main(){\n"
13249 " outs.x = 0;\n"
13250 " gl_Position = vec4(1);\n"
13251 "}\n";
13252 char const *fsSource =
13253 "#version 450\n"
13254 "\n"
13255 "in block { layout(location=0) float x; } ins;\n"
13256 "layout(location=0) out vec4 color;\n"
13257 "void main(){\n"
13258 " color = vec4(ins.x);\n"
13259 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013260
13261 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13262 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13263
13264 VkPipelineObj pipe(m_device);
13265 pipe.AddColorAttachment();
13266 pipe.AddShader(&vs);
13267 pipe.AddShader(&fs);
13268
13269 VkDescriptorSetObj descriptorSet(m_device);
13270 descriptorSet.AppendDummy();
13271 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13272
13273 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13274
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013275 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013276}
13277
13278TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013279 TEST_DESCRIPTION(
13280 "Test that an error is produced for component mismatches across the "
13281 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
13282 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013283 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 +130013284
13285 ASSERT_NO_FATAL_FAILURE(InitState());
13286 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13287
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013288 char const *vsSource =
13289 "#version 450\n"
13290 "\n"
13291 "out block { layout(location=0, component=0) float x; } outs;\n"
13292 "out gl_PerVertex {\n"
13293 " vec4 gl_Position;\n"
13294 "};\n"
13295 "void main(){\n"
13296 " outs.x = 0;\n"
13297 " gl_Position = vec4(1);\n"
13298 "}\n";
13299 char const *fsSource =
13300 "#version 450\n"
13301 "\n"
13302 "in block { layout(location=0, component=1) float x; } ins;\n"
13303 "layout(location=0) out vec4 color;\n"
13304 "void main(){\n"
13305 " color = vec4(ins.x);\n"
13306 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013307
13308 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13309 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13310
13311 VkPipelineObj pipe(m_device);
13312 pipe.AddColorAttachment();
13313 pipe.AddShader(&vs);
13314 pipe.AddShader(&fs);
13315
13316 VkDescriptorSetObj descriptorSet(m_device);
13317 descriptorSet.AppendDummy();
13318 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13319
13320 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13321
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013322 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013323}
13324
Chris Forbes1f3b0152016-11-30 12:48:40 +130013325TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13326 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13327
13328 ASSERT_NO_FATAL_FAILURE(InitState());
13329 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13330
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013331 char const *vsSource =
13332 "#version 450\n"
13333 "layout(location=0) out mediump float x;\n"
13334 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13335 char const *fsSource =
13336 "#version 450\n"
13337 "layout(location=0) in highp float x;\n"
13338 "layout(location=0) out vec4 color;\n"
13339 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130013340
13341 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13342 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13343
13344 VkPipelineObj pipe(m_device);
13345 pipe.AddColorAttachment();
13346 pipe.AddShader(&vs);
13347 pipe.AddShader(&fs);
13348
13349 VkDescriptorSetObj descriptorSet(m_device);
13350 descriptorSet.AppendDummy();
13351 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13352
13353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13354
13355 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13356
13357 m_errorMonitor->VerifyFound();
13358}
13359
Chris Forbes870a39e2016-11-30 12:55:56 +130013360TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13361 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13362
13363 ASSERT_NO_FATAL_FAILURE(InitState());
13364 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13365
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013366 char const *vsSource =
13367 "#version 450\n"
13368 "out block { layout(location=0) mediump float x; };\n"
13369 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13370 char const *fsSource =
13371 "#version 450\n"
13372 "in block { layout(location=0) highp float x; };\n"
13373 "layout(location=0) out vec4 color;\n"
13374 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130013375
13376 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13377 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13378
13379 VkPipelineObj pipe(m_device);
13380 pipe.AddColorAttachment();
13381 pipe.AddShader(&vs);
13382 pipe.AddShader(&fs);
13383
13384 VkDescriptorSetObj descriptorSet(m_device);
13385 descriptorSet.AppendDummy();
13386 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13387
13388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13389
13390 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13391
13392 m_errorMonitor->VerifyFound();
13393}
13394
Karl Schultz6addd812016-02-02 17:17:23 -070013395TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013396 TEST_DESCRIPTION(
13397 "Test that a warning is produced for a vertex attribute which is "
13398 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013400
Chris Forbesde136e02015-05-25 11:13:28 +120013401 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013403
13404 VkVertexInputBindingDescription input_binding;
13405 memset(&input_binding, 0, sizeof(input_binding));
13406
13407 VkVertexInputAttributeDescription input_attrib;
13408 memset(&input_attrib, 0, sizeof(input_attrib));
13409 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13410
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013411 char const *vsSource =
13412 "#version 450\n"
13413 "\n"
13414 "out gl_PerVertex {\n"
13415 " vec4 gl_Position;\n"
13416 "};\n"
13417 "void main(){\n"
13418 " gl_Position = vec4(1);\n"
13419 "}\n";
13420 char const *fsSource =
13421 "#version 450\n"
13422 "\n"
13423 "layout(location=0) out vec4 color;\n"
13424 "void main(){\n"
13425 " color = vec4(1);\n"
13426 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013427
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013428 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13429 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013430
13431 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013432 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013433 pipe.AddShader(&vs);
13434 pipe.AddShader(&fs);
13435
13436 pipe.AddVertexInputBindings(&input_binding, 1);
13437 pipe.AddVertexInputAttribs(&input_attrib, 1);
13438
Chris Forbesde136e02015-05-25 11:13:28 +120013439 VkDescriptorSetObj descriptorSet(m_device);
13440 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013441 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013442
Tony Barbour5781e8f2015-08-04 16:23:11 -060013443 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013444
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013445 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013446}
13447
Karl Schultz6addd812016-02-02 17:17:23 -070013448TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013449 TEST_DESCRIPTION(
13450 "Test that a warning is produced for a location mismatch on "
13451 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013453
13454 ASSERT_NO_FATAL_FAILURE(InitState());
13455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13456
13457 VkVertexInputBindingDescription input_binding;
13458 memset(&input_binding, 0, sizeof(input_binding));
13459
13460 VkVertexInputAttributeDescription input_attrib;
13461 memset(&input_attrib, 0, sizeof(input_attrib));
13462 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13463
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013464 char const *vsSource =
13465 "#version 450\n"
13466 "\n"
13467 "layout(location=1) in float x;\n"
13468 "out gl_PerVertex {\n"
13469 " vec4 gl_Position;\n"
13470 "};\n"
13471 "void main(){\n"
13472 " gl_Position = vec4(x);\n"
13473 "}\n";
13474 char const *fsSource =
13475 "#version 450\n"
13476 "\n"
13477 "layout(location=0) out vec4 color;\n"
13478 "void main(){\n"
13479 " color = vec4(1);\n"
13480 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013481
13482 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13483 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13484
13485 VkPipelineObj pipe(m_device);
13486 pipe.AddColorAttachment();
13487 pipe.AddShader(&vs);
13488 pipe.AddShader(&fs);
13489
13490 pipe.AddVertexInputBindings(&input_binding, 1);
13491 pipe.AddVertexInputAttribs(&input_attrib, 1);
13492
13493 VkDescriptorSetObj descriptorSet(m_device);
13494 descriptorSet.AppendDummy();
13495 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13496
13497 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13498
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013499 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013500}
13501
Karl Schultz6addd812016-02-02 17:17:23 -070013502TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013503 TEST_DESCRIPTION(
13504 "Test that an error is produced for a vertex shader input which is not "
13505 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13507 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013508
Chris Forbes62e8e502015-05-25 11:13:29 +120013509 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013510 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013511
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013512 char const *vsSource =
13513 "#version 450\n"
13514 "\n"
13515 "layout(location=0) in vec4 x;\n" /* not provided */
13516 "out gl_PerVertex {\n"
13517 " vec4 gl_Position;\n"
13518 "};\n"
13519 "void main(){\n"
13520 " gl_Position = x;\n"
13521 "}\n";
13522 char const *fsSource =
13523 "#version 450\n"
13524 "\n"
13525 "layout(location=0) out vec4 color;\n"
13526 "void main(){\n"
13527 " color = vec4(1);\n"
13528 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013529
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013530 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13531 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013532
13533 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013534 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013535 pipe.AddShader(&vs);
13536 pipe.AddShader(&fs);
13537
Chris Forbes62e8e502015-05-25 11:13:29 +120013538 VkDescriptorSetObj descriptorSet(m_device);
13539 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013540 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013541
Tony Barbour5781e8f2015-08-04 16:23:11 -060013542 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013543
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013544 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013545}
13546
Karl Schultz6addd812016-02-02 17:17:23 -070013547TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013548 TEST_DESCRIPTION(
13549 "Test that an error is produced for a mismatch between the "
13550 "fundamental type (float/int/uint) of an attribute and the "
13551 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013552 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 -060013553
Chris Forbesc97d98e2015-05-25 11:13:31 +120013554 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013555 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013556
13557 VkVertexInputBindingDescription input_binding;
13558 memset(&input_binding, 0, sizeof(input_binding));
13559
13560 VkVertexInputAttributeDescription input_attrib;
13561 memset(&input_attrib, 0, sizeof(input_attrib));
13562 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13563
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013564 char const *vsSource =
13565 "#version 450\n"
13566 "\n"
13567 "layout(location=0) in int x;\n" /* attrib provided float */
13568 "out gl_PerVertex {\n"
13569 " vec4 gl_Position;\n"
13570 "};\n"
13571 "void main(){\n"
13572 " gl_Position = vec4(x);\n"
13573 "}\n";
13574 char const *fsSource =
13575 "#version 450\n"
13576 "\n"
13577 "layout(location=0) out vec4 color;\n"
13578 "void main(){\n"
13579 " color = vec4(1);\n"
13580 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013581
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013582 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013584
13585 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013586 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013587 pipe.AddShader(&vs);
13588 pipe.AddShader(&fs);
13589
13590 pipe.AddVertexInputBindings(&input_binding, 1);
13591 pipe.AddVertexInputAttribs(&input_attrib, 1);
13592
Chris Forbesc97d98e2015-05-25 11:13:31 +120013593 VkDescriptorSetObj descriptorSet(m_device);
13594 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013595 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013596
Tony Barbour5781e8f2015-08-04 16:23:11 -060013597 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013598
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013599 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013600}
13601
Chris Forbesc68b43c2016-04-06 11:18:47 +120013602TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013603 TEST_DESCRIPTION(
13604 "Test that an error is produced for a pipeline containing multiple "
13605 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13607 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013608
13609 ASSERT_NO_FATAL_FAILURE(InitState());
13610 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13611
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013612 char const *vsSource =
13613 "#version 450\n"
13614 "\n"
13615 "out gl_PerVertex {\n"
13616 " vec4 gl_Position;\n"
13617 "};\n"
13618 "void main(){\n"
13619 " gl_Position = vec4(1);\n"
13620 "}\n";
13621 char const *fsSource =
13622 "#version 450\n"
13623 "\n"
13624 "layout(location=0) out vec4 color;\n"
13625 "void main(){\n"
13626 " color = vec4(1);\n"
13627 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013628
13629 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13630 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13631
13632 VkPipelineObj pipe(m_device);
13633 pipe.AddColorAttachment();
13634 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013635 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013636 pipe.AddShader(&fs);
13637
13638 VkDescriptorSetObj descriptorSet(m_device);
13639 descriptorSet.AppendDummy();
13640 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13641
13642 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13643
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013644 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013645}
13646
Chris Forbes82ff92a2016-09-09 10:50:24 +120013647TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120013649
13650 ASSERT_NO_FATAL_FAILURE(InitState());
13651 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13652
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013653 char const *vsSource =
13654 "#version 450\n"
13655 "out gl_PerVertex {\n"
13656 " vec4 gl_Position;\n"
13657 "};\n"
13658 "void main(){\n"
13659 " gl_Position = vec4(0);\n"
13660 "}\n";
13661 char const *fsSource =
13662 "#version 450\n"
13663 "\n"
13664 "layout(location=0) out vec4 color;\n"
13665 "void main(){\n"
13666 " color = vec4(1);\n"
13667 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120013668
13669 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13670 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13671
13672 VkPipelineObj pipe(m_device);
13673 pipe.AddColorAttachment();
13674 pipe.AddShader(&vs);
13675 pipe.AddShader(&fs);
13676
13677 VkDescriptorSetObj descriptorSet(m_device);
13678 descriptorSet.AppendDummy();
13679 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13680
13681 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13682
13683 m_errorMonitor->VerifyFound();
13684}
13685
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013686TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13688 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13689 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013690
13691 ASSERT_NO_FATAL_FAILURE(InitState());
13692 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13693
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013694 char const *vsSource =
13695 "#version 450\n"
13696 "void main(){ gl_Position = vec4(0); }\n";
13697 char const *fsSource =
13698 "#version 450\n"
13699 "\n"
13700 "layout(location=0) out vec4 color;\n"
13701 "void main(){\n"
13702 " color = vec4(1);\n"
13703 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013704
13705 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13706 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13707
13708 VkPipelineObj pipe(m_device);
13709 pipe.AddColorAttachment();
13710 pipe.AddShader(&vs);
13711 pipe.AddShader(&fs);
13712
13713 VkDescriptorSetObj descriptorSet(m_device);
13714 descriptorSet.AppendDummy();
13715 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13716
13717 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013718 {
13719 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13720 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
13721 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013722 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013723 {
13724 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13725 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
13726 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013727 },
13728 };
13729 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013730 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013731 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013732 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
13733 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013734 VkRenderPass rp;
13735 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13736 ASSERT_VK_SUCCESS(err);
13737
13738 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13739
13740 m_errorMonitor->VerifyFound();
13741
13742 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13743}
13744
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013745TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013746 TEST_DESCRIPTION(
13747 "Test that an error is produced for a variable output from "
13748 "the TCS without the patch decoration, but consumed in the TES "
13749 "with the decoration.");
13750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13751 "is per-vertex in tessellation control shader stage "
13752 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013753
13754 ASSERT_NO_FATAL_FAILURE(InitState());
13755 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13756
Chris Forbesc1e852d2016-04-04 19:26:42 +120013757 if (!m_device->phy().features().tessellationShader) {
13758 printf("Device does not support tessellation shaders; skipped.\n");
13759 return;
13760 }
13761
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013762 char const *vsSource =
13763 "#version 450\n"
13764 "void main(){}\n";
13765 char const *tcsSource =
13766 "#version 450\n"
13767 "layout(location=0) out int x[];\n"
13768 "layout(vertices=3) out;\n"
13769 "void main(){\n"
13770 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13771 " gl_TessLevelInner[0] = 1;\n"
13772 " x[gl_InvocationID] = gl_InvocationID;\n"
13773 "}\n";
13774 char const *tesSource =
13775 "#version 450\n"
13776 "layout(triangles, equal_spacing, cw) in;\n"
13777 "layout(location=0) patch in int x;\n"
13778 "out gl_PerVertex { vec4 gl_Position; };\n"
13779 "void main(){\n"
13780 " gl_Position.xyz = gl_TessCoord;\n"
13781 " gl_Position.w = x;\n"
13782 "}\n";
13783 char const *fsSource =
13784 "#version 450\n"
13785 "layout(location=0) out vec4 color;\n"
13786 "void main(){\n"
13787 " color = vec4(1);\n"
13788 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013789
13790 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13791 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13792 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13793 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13794
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013795 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13796 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013797
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013798 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013799
13800 VkPipelineObj pipe(m_device);
13801 pipe.SetInputAssembly(&iasci);
13802 pipe.SetTessellation(&tsci);
13803 pipe.AddColorAttachment();
13804 pipe.AddShader(&vs);
13805 pipe.AddShader(&tcs);
13806 pipe.AddShader(&tes);
13807 pipe.AddShader(&fs);
13808
13809 VkDescriptorSetObj descriptorSet(m_device);
13810 descriptorSet.AppendDummy();
13811 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13812
13813 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13814
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013815 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013816}
13817
Karl Schultz6addd812016-02-02 17:17:23 -070013818TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013819 TEST_DESCRIPTION(
13820 "Test that an error is produced for a vertex attribute setup where multiple "
13821 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13823 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013824
Chris Forbes280ba2c2015-06-12 11:16:41 +120013825 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013826 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013827
13828 /* Two binding descriptions for binding 0 */
13829 VkVertexInputBindingDescription input_bindings[2];
13830 memset(input_bindings, 0, sizeof(input_bindings));
13831
13832 VkVertexInputAttributeDescription input_attrib;
13833 memset(&input_attrib, 0, sizeof(input_attrib));
13834 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13835
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013836 char const *vsSource =
13837 "#version 450\n"
13838 "\n"
13839 "layout(location=0) in float x;\n" /* attrib provided float */
13840 "out gl_PerVertex {\n"
13841 " vec4 gl_Position;\n"
13842 "};\n"
13843 "void main(){\n"
13844 " gl_Position = vec4(x);\n"
13845 "}\n";
13846 char const *fsSource =
13847 "#version 450\n"
13848 "\n"
13849 "layout(location=0) out vec4 color;\n"
13850 "void main(){\n"
13851 " color = vec4(1);\n"
13852 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013853
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013854 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13855 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013856
13857 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013858 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013859 pipe.AddShader(&vs);
13860 pipe.AddShader(&fs);
13861
13862 pipe.AddVertexInputBindings(input_bindings, 2);
13863 pipe.AddVertexInputAttribs(&input_attrib, 1);
13864
Chris Forbes280ba2c2015-06-12 11:16:41 +120013865 VkDescriptorSetObj descriptorSet(m_device);
13866 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013867 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013868
Tony Barbour5781e8f2015-08-04 16:23:11 -060013869 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013870
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013871 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013872}
Chris Forbes8f68b562015-05-25 11:13:32 +120013873
Karl Schultz6addd812016-02-02 17:17:23 -070013874TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013875 TEST_DESCRIPTION(
13876 "Test that an error is produced for a fragment shader which does not "
13877 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013879
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013880 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013881
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013882 char const *vsSource =
13883 "#version 450\n"
13884 "\n"
13885 "out gl_PerVertex {\n"
13886 " vec4 gl_Position;\n"
13887 "};\n"
13888 "void main(){\n"
13889 " gl_Position = vec4(1);\n"
13890 "}\n";
13891 char const *fsSource =
13892 "#version 450\n"
13893 "\n"
13894 "void main(){\n"
13895 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013896
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013897 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13898 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013899
13900 VkPipelineObj pipe(m_device);
13901 pipe.AddShader(&vs);
13902 pipe.AddShader(&fs);
13903
Chia-I Wu08accc62015-07-07 11:50:03 +080013904 /* set up CB 0, not written */
13905 pipe.AddColorAttachment();
13906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013907
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013908 VkDescriptorSetObj descriptorSet(m_device);
13909 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013910 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013911
Tony Barbour5781e8f2015-08-04 16:23:11 -060013912 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013913
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013914 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013915}
13916
Karl Schultz6addd812016-02-02 17:17:23 -070013917TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013918 TEST_DESCRIPTION(
13919 "Test that a warning is produced for a fragment shader which provides a spurious "
13920 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013922 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013923
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013924 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013925
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013926 char const *vsSource =
13927 "#version 450\n"
13928 "\n"
13929 "out gl_PerVertex {\n"
13930 " vec4 gl_Position;\n"
13931 "};\n"
13932 "void main(){\n"
13933 " gl_Position = vec4(1);\n"
13934 "}\n";
13935 char const *fsSource =
13936 "#version 450\n"
13937 "\n"
13938 "layout(location=0) out vec4 x;\n"
13939 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13940 "void main(){\n"
13941 " x = vec4(1);\n"
13942 " y = vec4(1);\n"
13943 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013944
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013945 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13946 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013947
13948 VkPipelineObj pipe(m_device);
13949 pipe.AddShader(&vs);
13950 pipe.AddShader(&fs);
13951
Chia-I Wu08accc62015-07-07 11:50:03 +080013952 /* set up CB 0, not written */
13953 pipe.AddColorAttachment();
13954 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013955 /* FS writes CB 1, but we don't configure it */
13956
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013957 VkDescriptorSetObj descriptorSet(m_device);
13958 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013959 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013960
Tony Barbour5781e8f2015-08-04 16:23:11 -060013961 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013962
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013963 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013964}
13965
Karl Schultz6addd812016-02-02 17:17:23 -070013966TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013967 TEST_DESCRIPTION(
13968 "Test that an error is produced for a mismatch between the fundamental "
13969 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013971
Chris Forbesa36d69e2015-05-25 11:13:44 +120013972 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013973
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013974 char const *vsSource =
13975 "#version 450\n"
13976 "\n"
13977 "out gl_PerVertex {\n"
13978 " vec4 gl_Position;\n"
13979 "};\n"
13980 "void main(){\n"
13981 " gl_Position = vec4(1);\n"
13982 "}\n";
13983 char const *fsSource =
13984 "#version 450\n"
13985 "\n"
13986 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13987 "void main(){\n"
13988 " x = ivec4(1);\n"
13989 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013990
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013991 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13992 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013993
13994 VkPipelineObj pipe(m_device);
13995 pipe.AddShader(&vs);
13996 pipe.AddShader(&fs);
13997
Chia-I Wu08accc62015-07-07 11:50:03 +080013998 /* set up CB 0; type is UNORM by default */
13999 pipe.AddColorAttachment();
14000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014001
Chris Forbesa36d69e2015-05-25 11:13:44 +120014002 VkDescriptorSetObj descriptorSet(m_device);
14003 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014004 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014005
Tony Barbour5781e8f2015-08-04 16:23:11 -060014006 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014007
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014008 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014009}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014010
Karl Schultz6addd812016-02-02 17:17:23 -070014011TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014012 TEST_DESCRIPTION(
14013 "Test that an error is produced for a shader consuming a uniform "
14014 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014016
Chris Forbes556c76c2015-08-14 12:04:59 +120014017 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014018
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014019 char const *vsSource =
14020 "#version 450\n"
14021 "\n"
14022 "out gl_PerVertex {\n"
14023 " vec4 gl_Position;\n"
14024 "};\n"
14025 "void main(){\n"
14026 " gl_Position = vec4(1);\n"
14027 "}\n";
14028 char const *fsSource =
14029 "#version 450\n"
14030 "\n"
14031 "layout(location=0) out vec4 x;\n"
14032 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14033 "void main(){\n"
14034 " x = vec4(bar.y);\n"
14035 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014036
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014037 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14038 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014039
Chris Forbes556c76c2015-08-14 12:04:59 +120014040 VkPipelineObj pipe(m_device);
14041 pipe.AddShader(&vs);
14042 pipe.AddShader(&fs);
14043
14044 /* set up CB 0; type is UNORM by default */
14045 pipe.AddColorAttachment();
14046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14047
14048 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014049 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014050
14051 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14052
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014053 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014054}
14055
Chris Forbes5c59e902016-02-26 16:56:09 +130014056TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014057 TEST_DESCRIPTION(
14058 "Test that an error is produced for a shader consuming push constants "
14059 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014061
14062 ASSERT_NO_FATAL_FAILURE(InitState());
14063
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014064 char const *vsSource =
14065 "#version 450\n"
14066 "\n"
14067 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14068 "out gl_PerVertex {\n"
14069 " vec4 gl_Position;\n"
14070 "};\n"
14071 "void main(){\n"
14072 " gl_Position = vec4(consts.x);\n"
14073 "}\n";
14074 char const *fsSource =
14075 "#version 450\n"
14076 "\n"
14077 "layout(location=0) out vec4 x;\n"
14078 "void main(){\n"
14079 " x = vec4(1);\n"
14080 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014081
14082 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14083 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14084
14085 VkPipelineObj pipe(m_device);
14086 pipe.AddShader(&vs);
14087 pipe.AddShader(&fs);
14088
14089 /* set up CB 0; type is UNORM by default */
14090 pipe.AddColorAttachment();
14091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14092
14093 VkDescriptorSetObj descriptorSet(m_device);
14094 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14095
14096 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14097
14098 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014099 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014100}
14101
Chris Forbes3fb17902016-08-22 14:57:55 +120014102TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014103 TEST_DESCRIPTION(
14104 "Test that an error is produced for a shader consuming an input attachment "
14105 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14107 "consumes input attachment index 0 but not provided in subpass");
14108
14109 ASSERT_NO_FATAL_FAILURE(InitState());
14110
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014111 char const *vsSource =
14112 "#version 450\n"
14113 "\n"
14114 "out gl_PerVertex {\n"
14115 " vec4 gl_Position;\n"
14116 "};\n"
14117 "void main(){\n"
14118 " gl_Position = vec4(1);\n"
14119 "}\n";
14120 char const *fsSource =
14121 "#version 450\n"
14122 "\n"
14123 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14124 "layout(location=0) out vec4 color;\n"
14125 "void main() {\n"
14126 " color = subpassLoad(x);\n"
14127 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014128
14129 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14130 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14131
14132 VkPipelineObj pipe(m_device);
14133 pipe.AddShader(&vs);
14134 pipe.AddShader(&fs);
14135 pipe.AddColorAttachment();
14136 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014138 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14139 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014140 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014141 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014142 ASSERT_VK_SUCCESS(err);
14143
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014144 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014145 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014146 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014147 ASSERT_VK_SUCCESS(err);
14148
14149 // error here.
14150 pipe.CreateVKPipeline(pl, renderPass());
14151
14152 m_errorMonitor->VerifyFound();
14153
14154 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14155 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14156}
14157
Chris Forbes5a9a0472016-08-22 16:02:09 +120014158TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014159 TEST_DESCRIPTION(
14160 "Test that an error is produced for a shader consuming an input attachment "
14161 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120014162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14163 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14164
14165 ASSERT_NO_FATAL_FAILURE(InitState());
14166
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014167 char const *vsSource =
14168 "#version 450\n"
14169 "\n"
14170 "out gl_PerVertex {\n"
14171 " vec4 gl_Position;\n"
14172 "};\n"
14173 "void main(){\n"
14174 " gl_Position = vec4(1);\n"
14175 "}\n";
14176 char const *fsSource =
14177 "#version 450\n"
14178 "\n"
14179 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14180 "layout(location=0) out vec4 color;\n"
14181 "void main() {\n"
14182 " color = subpassLoad(x);\n"
14183 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014184
14185 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14186 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14187
14188 VkPipelineObj pipe(m_device);
14189 pipe.AddShader(&vs);
14190 pipe.AddShader(&fs);
14191 pipe.AddColorAttachment();
14192 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14193
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014194 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14195 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014196 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014197 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014198 ASSERT_VK_SUCCESS(err);
14199
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014200 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014201 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014202 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014203 ASSERT_VK_SUCCESS(err);
14204
14205 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014206 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14207 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14208 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14209 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14210 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 +120014211 };
14212 VkAttachmentReference color = {
14213 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14214 };
14215 VkAttachmentReference input = {
14216 1, VK_IMAGE_LAYOUT_GENERAL,
14217 };
14218
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014219 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014221 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014222 VkRenderPass rp;
14223 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14224 ASSERT_VK_SUCCESS(err);
14225
14226 // error here.
14227 pipe.CreateVKPipeline(pl, rp);
14228
14229 m_errorMonitor->VerifyFound();
14230
14231 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14232 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14233 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14234}
14235
Chris Forbes541f7b02016-08-22 15:30:27 +120014236TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014237 TEST_DESCRIPTION(
14238 "Test that an error is produced for a shader consuming an input attachment "
14239 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120014240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070014241 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120014242
14243 ASSERT_NO_FATAL_FAILURE(InitState());
14244
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014245 char const *vsSource =
14246 "#version 450\n"
14247 "\n"
14248 "out gl_PerVertex {\n"
14249 " vec4 gl_Position;\n"
14250 "};\n"
14251 "void main(){\n"
14252 " gl_Position = vec4(1);\n"
14253 "}\n";
14254 char const *fsSource =
14255 "#version 450\n"
14256 "\n"
14257 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
14258 "layout(location=0) out vec4 color;\n"
14259 "void main() {\n"
14260 " color = subpassLoad(xs[0]);\n"
14261 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014262
14263 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14264 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14265
14266 VkPipelineObj pipe(m_device);
14267 pipe.AddShader(&vs);
14268 pipe.AddShader(&fs);
14269 pipe.AddColorAttachment();
14270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014272 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14273 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014274 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014275 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014276 ASSERT_VK_SUCCESS(err);
14277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014278 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014279 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014280 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014281 ASSERT_VK_SUCCESS(err);
14282
14283 // error here.
14284 pipe.CreateVKPipeline(pl, renderPass());
14285
14286 m_errorMonitor->VerifyFound();
14287
14288 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14289 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14290}
14291
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014292TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014293 TEST_DESCRIPTION(
14294 "Test that an error is produced for a compute pipeline consuming a "
14295 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014297
14298 ASSERT_NO_FATAL_FAILURE(InitState());
14299
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014300 char const *csSource =
14301 "#version 450\n"
14302 "\n"
14303 "layout(local_size_x=1) in;\n"
14304 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14305 "void main(){\n"
14306 " x = vec4(1);\n"
14307 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014308
14309 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14310
14311 VkDescriptorSetObj descriptorSet(m_device);
14312 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14313
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014314 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14315 nullptr,
14316 0,
14317 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14318 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14319 descriptorSet.GetPipelineLayout(),
14320 VK_NULL_HANDLE,
14321 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014322
14323 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014324 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014325
14326 m_errorMonitor->VerifyFound();
14327
14328 if (err == VK_SUCCESS) {
14329 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14330 }
14331}
14332
Chris Forbes22a9b092016-07-19 14:34:05 +120014333TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014334 TEST_DESCRIPTION(
14335 "Test that an error is produced for a pipeline consuming a "
14336 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14338 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014339
14340 ASSERT_NO_FATAL_FAILURE(InitState());
14341
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014342 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14343 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014344 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014345 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014346 ASSERT_VK_SUCCESS(err);
14347
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014348 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014349 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014350 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014351 ASSERT_VK_SUCCESS(err);
14352
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014353 char const *csSource =
14354 "#version 450\n"
14355 "\n"
14356 "layout(local_size_x=1) in;\n"
14357 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14358 "void main() {\n"
14359 " x.x = 1.0f;\n"
14360 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014361 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14362
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014363 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14364 nullptr,
14365 0,
14366 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14367 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14368 pl,
14369 VK_NULL_HANDLE,
14370 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014371
14372 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014373 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014374
14375 m_errorMonitor->VerifyFound();
14376
14377 if (err == VK_SUCCESS) {
14378 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14379 }
14380
14381 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14382 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14383}
14384
Chris Forbes50020592016-07-27 13:52:41 +120014385TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014386 TEST_DESCRIPTION(
14387 "Test that an error is produced when an image view type "
14388 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120014389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014390 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 +120014391
14392 ASSERT_NO_FATAL_FAILURE(InitState());
14393 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14394
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014395 char const *vsSource =
14396 "#version 450\n"
14397 "\n"
14398 "out gl_PerVertex { vec4 gl_Position; };\n"
14399 "void main() { gl_Position = vec4(0); }\n";
14400 char const *fsSource =
14401 "#version 450\n"
14402 "\n"
14403 "layout(set=0, binding=0) uniform sampler3D s;\n"
14404 "layout(location=0) out vec4 color;\n"
14405 "void main() {\n"
14406 " color = texture(s, vec3(0));\n"
14407 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014408 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14409 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14410
14411 VkPipelineObj pipe(m_device);
14412 pipe.AddShader(&vs);
14413 pipe.AddShader(&fs);
14414 pipe.AddColorAttachment();
14415
14416 VkTextureObj texture(m_device, nullptr);
14417 VkSamplerObj sampler(m_device);
14418
14419 VkDescriptorSetObj descriptorSet(m_device);
14420 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14421 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14422
14423 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14424 ASSERT_VK_SUCCESS(err);
14425
Tony Barbour552f6c02016-12-21 14:34:07 -070014426 m_commandBuffer->BeginCommandBuffer();
14427 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014428
14429 m_commandBuffer->BindPipeline(pipe);
14430 m_commandBuffer->BindDescriptorSet(descriptorSet);
14431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014432 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014433 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014434 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014435 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14436
14437 // error produced here.
14438 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14439
14440 m_errorMonitor->VerifyFound();
14441
Tony Barbour552f6c02016-12-21 14:34:07 -070014442 m_commandBuffer->EndRenderPass();
14443 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014444}
14445
Chris Forbes5533bfc2016-07-27 14:12:34 +120014446TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014447 TEST_DESCRIPTION(
14448 "Test that an error is produced when a multisampled images "
14449 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014450
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014452
14453 ASSERT_NO_FATAL_FAILURE(InitState());
14454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14455
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014456 char const *vsSource =
14457 "#version 450\n"
14458 "\n"
14459 "out gl_PerVertex { vec4 gl_Position; };\n"
14460 "void main() { gl_Position = vec4(0); }\n";
14461 char const *fsSource =
14462 "#version 450\n"
14463 "\n"
14464 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14465 "layout(location=0) out vec4 color;\n"
14466 "void main() {\n"
14467 " color = texelFetch(s, ivec2(0), 0);\n"
14468 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014469 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14470 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14471
14472 VkPipelineObj pipe(m_device);
14473 pipe.AddShader(&vs);
14474 pipe.AddShader(&fs);
14475 pipe.AddColorAttachment();
14476
14477 VkTextureObj texture(m_device, nullptr);
14478 VkSamplerObj sampler(m_device);
14479
14480 VkDescriptorSetObj descriptorSet(m_device);
14481 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14482 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14483
14484 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14485 ASSERT_VK_SUCCESS(err);
14486
Tony Barbour552f6c02016-12-21 14:34:07 -070014487 m_commandBuffer->BeginCommandBuffer();
14488 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014489
14490 m_commandBuffer->BindPipeline(pipe);
14491 m_commandBuffer->BindDescriptorSet(descriptorSet);
14492
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014493 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014494 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014495 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014496 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14497
14498 // error produced here.
14499 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14500
14501 m_errorMonitor->VerifyFound();
14502
Tony Barbour552f6c02016-12-21 14:34:07 -070014503 m_commandBuffer->EndRenderPass();
14504 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014505}
14506
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014507#endif // SHADER_CHECKER_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014508
14509#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014510TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014512
14513 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014514
14515 // Create an image
14516 VkImage image;
14517
Karl Schultz6addd812016-02-02 17:17:23 -070014518 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14519 const int32_t tex_width = 32;
14520 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014521
14522 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14524 image_create_info.pNext = NULL;
14525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14526 image_create_info.format = tex_format;
14527 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014528 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014529 image_create_info.extent.depth = 1;
14530 image_create_info.mipLevels = 1;
14531 image_create_info.arrayLayers = 1;
14532 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14533 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14534 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14535 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014536
14537 // Introduce error by sending down a bogus width extent
14538 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014539 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014540
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014541 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014542}
14543
Mark Youngc48c4c12016-04-11 14:26:49 -060014544TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14546 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014547
14548 ASSERT_NO_FATAL_FAILURE(InitState());
14549
14550 // Create an image
14551 VkImage image;
14552
14553 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14554 const int32_t tex_width = 32;
14555 const int32_t tex_height = 32;
14556
14557 VkImageCreateInfo image_create_info = {};
14558 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14559 image_create_info.pNext = NULL;
14560 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14561 image_create_info.format = tex_format;
14562 image_create_info.extent.width = tex_width;
14563 image_create_info.extent.height = tex_height;
14564 image_create_info.extent.depth = 1;
14565 image_create_info.mipLevels = 1;
14566 image_create_info.arrayLayers = 1;
14567 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14568 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14569 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14570 image_create_info.flags = 0;
14571
14572 // Introduce error by sending down a bogus width extent
14573 image_create_info.extent.width = 0;
14574 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14575
14576 m_errorMonitor->VerifyFound();
14577}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014578#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014579
Tobin Ehliscde08892015-09-22 10:11:37 -060014580#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014581
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014582TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014583 TEST_DESCRIPTION(
14584 "Create a render pass with an attachment description "
14585 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014586
14587 ASSERT_NO_FATAL_FAILURE(InitState());
14588 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14589
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014591
14592 VkAttachmentReference color_attach = {};
14593 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14594 color_attach.attachment = 0;
14595 VkSubpassDescription subpass = {};
14596 subpass.colorAttachmentCount = 1;
14597 subpass.pColorAttachments = &color_attach;
14598
14599 VkRenderPassCreateInfo rpci = {};
14600 rpci.subpassCount = 1;
14601 rpci.pSubpasses = &subpass;
14602 rpci.attachmentCount = 1;
14603 VkAttachmentDescription attach_desc = {};
14604 attach_desc.format = VK_FORMAT_UNDEFINED;
14605 rpci.pAttachments = &attach_desc;
14606 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14607 VkRenderPass rp;
14608 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14609
14610 m_errorMonitor->VerifyFound();
14611
14612 if (result == VK_SUCCESS) {
14613 vkDestroyRenderPass(m_device->device(), rp, NULL);
14614 }
14615}
14616
Karl Schultz6addd812016-02-02 17:17:23 -070014617TEST_F(VkLayerTest, InvalidImageView) {
14618 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014619
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014621
Tobin Ehliscde08892015-09-22 10:11:37 -060014622 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014623
Mike Stroyana3082432015-09-25 13:39:21 -060014624 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014625 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014626
Karl Schultz6addd812016-02-02 17:17:23 -070014627 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14628 const int32_t tex_width = 32;
14629 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014630
14631 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014632 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14633 image_create_info.pNext = NULL;
14634 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14635 image_create_info.format = tex_format;
14636 image_create_info.extent.width = tex_width;
14637 image_create_info.extent.height = tex_height;
14638 image_create_info.extent.depth = 1;
14639 image_create_info.mipLevels = 1;
14640 image_create_info.arrayLayers = 1;
14641 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14642 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14643 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14644 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014645
Chia-I Wuf7458c52015-10-26 21:10:41 +080014646 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014647 ASSERT_VK_SUCCESS(err);
14648
14649 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014650 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014651 image_view_create_info.image = image;
14652 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14653 image_view_create_info.format = tex_format;
14654 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014655 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070014656 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014657 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014658
14659 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014660 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014661
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014662 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014663 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014664}
Mike Stroyana3082432015-09-25 13:39:21 -060014665
Mark Youngd339ba32016-05-30 13:28:35 -060014666TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14667 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014669 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014670
14671 ASSERT_NO_FATAL_FAILURE(InitState());
14672
14673 // Create an image and try to create a view with no memory backing the image
14674 VkImage image;
14675
14676 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14677 const int32_t tex_width = 32;
14678 const int32_t tex_height = 32;
14679
14680 VkImageCreateInfo image_create_info = {};
14681 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14682 image_create_info.pNext = NULL;
14683 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14684 image_create_info.format = tex_format;
14685 image_create_info.extent.width = tex_width;
14686 image_create_info.extent.height = tex_height;
14687 image_create_info.extent.depth = 1;
14688 image_create_info.mipLevels = 1;
14689 image_create_info.arrayLayers = 1;
14690 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14691 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14692 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14693 image_create_info.flags = 0;
14694
14695 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14696 ASSERT_VK_SUCCESS(err);
14697
14698 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014699 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014700 image_view_create_info.image = image;
14701 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14702 image_view_create_info.format = tex_format;
14703 image_view_create_info.subresourceRange.layerCount = 1;
14704 image_view_create_info.subresourceRange.baseMipLevel = 0;
14705 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014706 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014707
14708 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014709 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014710
14711 m_errorMonitor->VerifyFound();
14712 vkDestroyImage(m_device->device(), image, NULL);
14713 // If last error is success, it still created the view, so delete it.
14714 if (err == VK_SUCCESS) {
14715 vkDestroyImageView(m_device->device(), view, NULL);
14716 }
Mark Youngd339ba32016-05-30 13:28:35 -060014717}
14718
Karl Schultz6addd812016-02-02 17:17:23 -070014719TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014720 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014722
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014723 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014724
Karl Schultz6addd812016-02-02 17:17:23 -070014725 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014726 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014727 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014728 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014729
14730 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014731 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014732 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014733 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14734 image_view_create_info.format = tex_format;
14735 image_view_create_info.subresourceRange.baseMipLevel = 0;
14736 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014737 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014738 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014739 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014740
14741 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014742 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014743
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014744 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014745}
14746
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014747TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014748 VkResult err;
14749 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014750
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014752
Mike Stroyana3082432015-09-25 13:39:21 -060014753 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014754
14755 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014756 VkImage srcImage;
14757 VkImage dstImage;
14758 VkDeviceMemory srcMem;
14759 VkDeviceMemory destMem;
14760 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014761
14762 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014763 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14764 image_create_info.pNext = NULL;
14765 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14766 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14767 image_create_info.extent.width = 32;
14768 image_create_info.extent.height = 32;
14769 image_create_info.extent.depth = 1;
14770 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014771 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014772 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14773 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14774 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14775 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014776
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014777 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014778 ASSERT_VK_SUCCESS(err);
14779
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014780 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014781 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014782 ASSERT_VK_SUCCESS(err);
14783
14784 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014785 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014786 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14787 memAlloc.pNext = NULL;
14788 memAlloc.allocationSize = 0;
14789 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014790
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014791 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014792 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014793 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014794 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014795 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014796 ASSERT_VK_SUCCESS(err);
14797
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014798 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014799 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014800 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014801 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014802 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014803 ASSERT_VK_SUCCESS(err);
14804
14805 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14806 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014807 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014808 ASSERT_VK_SUCCESS(err);
14809
Tony Barbour552f6c02016-12-21 14:34:07 -070014810 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014811 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014812 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014813 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014814 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014815 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014816 copyRegion.srcOffset.x = 0;
14817 copyRegion.srcOffset.y = 0;
14818 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014819 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014820 copyRegion.dstSubresource.mipLevel = 0;
14821 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014822 // Introduce failure by forcing the dst layerCount to differ from src
14823 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014824 copyRegion.dstOffset.x = 0;
14825 copyRegion.dstOffset.y = 0;
14826 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014827 copyRegion.extent.width = 1;
14828 copyRegion.extent.height = 1;
14829 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014830 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070014831 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014832
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014833 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014834
Chia-I Wuf7458c52015-10-26 21:10:41 +080014835 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014836 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014837 vkFreeMemory(m_device->device(), srcMem, NULL);
14838 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014839}
14840
Tony Barbourd6673642016-05-05 14:46:39 -060014841TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060014842 TEST_DESCRIPTION("Creating images with unsuported formats ");
14843
14844 ASSERT_NO_FATAL_FAILURE(InitState());
14845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14846 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014847 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 -060014848 VK_IMAGE_TILING_OPTIMAL, 0);
14849 ASSERT_TRUE(image.initialized());
14850
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014851 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014852 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014853 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014854 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14855 image_create_info.format = VK_FORMAT_UNDEFINED;
14856 image_create_info.extent.width = 32;
14857 image_create_info.extent.height = 32;
14858 image_create_info.extent.depth = 1;
14859 image_create_info.mipLevels = 1;
14860 image_create_info.arrayLayers = 1;
14861 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14862 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14863 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014864
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14866 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014867
14868 VkImage localImage;
14869 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14870 m_errorMonitor->VerifyFound();
14871
Tony Barbourd6673642016-05-05 14:46:39 -060014872 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014873 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014874 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14875 VkFormat format = static_cast<VkFormat>(f);
14876 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014877 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014878 unsupported = format;
14879 break;
14880 }
14881 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014882
Tony Barbourd6673642016-05-05 14:46:39 -060014883 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014884 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014886
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014887 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014888 m_errorMonitor->VerifyFound();
14889 }
14890}
14891
14892TEST_F(VkLayerTest, ImageLayerViewTests) {
14893 VkResult ret;
14894 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14895
14896 ASSERT_NO_FATAL_FAILURE(InitState());
14897
14898 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014899 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 -060014900 VK_IMAGE_TILING_OPTIMAL, 0);
14901 ASSERT_TRUE(image.initialized());
14902
14903 VkImageView imgView;
14904 VkImageViewCreateInfo imgViewInfo = {};
14905 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14906 imgViewInfo.image = image.handle();
14907 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14908 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14909 imgViewInfo.subresourceRange.layerCount = 1;
14910 imgViewInfo.subresourceRange.baseMipLevel = 0;
14911 imgViewInfo.subresourceRange.levelCount = 1;
14912 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14913
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060014915 // View can't have baseMipLevel >= image's mipLevels - Expect
14916 // VIEW_CREATE_ERROR
14917 imgViewInfo.subresourceRange.baseMipLevel = 1;
14918 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14919 m_errorMonitor->VerifyFound();
14920 imgViewInfo.subresourceRange.baseMipLevel = 0;
14921
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060014923 // View can't have baseArrayLayer >= image's arraySize - Expect
14924 // VIEW_CREATE_ERROR
14925 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14926 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14927 m_errorMonitor->VerifyFound();
14928 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14929
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070014930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060014931 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14932 imgViewInfo.subresourceRange.levelCount = 0;
14933 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14934 m_errorMonitor->VerifyFound();
14935 imgViewInfo.subresourceRange.levelCount = 1;
14936
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014937 m_errorMonitor->SetDesiredFailureMsg(
14938 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14939 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014940 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14941 imgViewInfo.subresourceRange.layerCount = 0;
14942 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14943 m_errorMonitor->VerifyFound();
14944 imgViewInfo.subresourceRange.layerCount = 1;
14945
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14947 "Formats MUST be IDENTICAL unless "
14948 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14949 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014950 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14951 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14952 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14953 m_errorMonitor->VerifyFound();
14954 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14955
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060014957 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14958 // VIEW_CREATE_ERROR
14959 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14960 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14961 m_errorMonitor->VerifyFound();
14962 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14963
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014965 // TODO: Update framework to easily passing mutable flag into ImageObj init
14966 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070014967 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
14968 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14969 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014970 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14971 // VIEW_CREATE_ERROR
14972 VkImageCreateInfo mutImgInfo = image.create_info();
14973 VkImage mutImage;
14974 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014975 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014976 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14977 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14978 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14979 ASSERT_VK_SUCCESS(ret);
14980 imgViewInfo.image = mutImage;
14981 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14982 m_errorMonitor->VerifyFound();
14983 imgViewInfo.image = image.handle();
14984 vkDestroyImage(m_device->handle(), mutImage, NULL);
14985}
14986
14987TEST_F(VkLayerTest, MiscImageLayerTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060014988 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14989
14990 ASSERT_NO_FATAL_FAILURE(InitState());
14991
Rene Lindsay135204f2016-12-22 17:11:09 -070014992 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060014993 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070014994 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 -070014995 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060014996 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060014997 vk_testing::Buffer buffer;
14998 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070014999 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060015000 VkBufferImageCopy region = {};
15001 region.bufferRowLength = 128;
15002 region.bufferImageHeight = 128;
15003 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15004 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070015005 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015006 region.imageExtent.height = 4;
15007 region.imageExtent.width = 4;
15008 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070015009
15010 VkImageObj image2(m_device);
15011 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 -070015012 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070015013 ASSERT_TRUE(image2.initialized());
15014 vk_testing::Buffer buffer2;
15015 VkMemoryPropertyFlags reqs2 = 0;
15016 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
15017 VkBufferImageCopy region2 = {};
15018 region2.bufferRowLength = 128;
15019 region2.bufferImageHeight = 128;
15020 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15021 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15022 region2.imageSubresource.layerCount = 1;
15023 region2.imageExtent.height = 4;
15024 region2.imageExtent.width = 4;
15025 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015026 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060015027
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015028 // Image must have offset.z of 0 and extent.depth of 1
15029 // Introduce failure by setting imageExtent.depth to 0
15030 region.imageExtent.depth = 0;
15031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15032 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015033 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015034 m_errorMonitor->VerifyFound();
15035
15036 region.imageExtent.depth = 1;
15037
15038 // Image must have offset.z of 0 and extent.depth of 1
15039 // Introduce failure by setting imageOffset.z to 4
15040 region.imageOffset.z = 4;
15041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15042 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015043 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015044 m_errorMonitor->VerifyFound();
15045
15046 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015047 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15048 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070015049 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015051 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15052 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015053 m_errorMonitor->VerifyFound();
15054
15055 // BufferOffset must be a multiple of 4
15056 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070015057 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070015059 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
15060 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015061 m_errorMonitor->VerifyFound();
15062
15063 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15064 region.bufferOffset = 0;
15065 region.imageExtent.height = 128;
15066 region.imageExtent.width = 128;
15067 // Introduce failure by setting bufferRowLength > 0 but less than width
15068 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015070 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15071 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015072 m_errorMonitor->VerifyFound();
15073
15074 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15075 region.bufferRowLength = 128;
15076 // Introduce failure by setting bufferRowHeight > 0 but less than height
15077 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015079 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15080 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015081 m_errorMonitor->VerifyFound();
15082
15083 region.bufferImageHeight = 128;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15085 "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015086 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060015087 // Expect INVALID_FILTER
15088 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015089 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
15090 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015091 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015092 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15093 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015094 VkImageBlit blitRegion = {};
15095 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15096 blitRegion.srcSubresource.baseArrayLayer = 0;
15097 blitRegion.srcSubresource.layerCount = 1;
15098 blitRegion.srcSubresource.mipLevel = 0;
15099 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15100 blitRegion.dstSubresource.baseArrayLayer = 0;
15101 blitRegion.dstSubresource.layerCount = 1;
15102 blitRegion.dstSubresource.mipLevel = 0;
15103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015104 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015105 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060015106 m_errorMonitor->VerifyFound();
15107
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015108 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
15110 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15111 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015112 m_errorMonitor->VerifyFound();
15113
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060015115 VkImageMemoryBarrier img_barrier;
15116 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15117 img_barrier.pNext = NULL;
15118 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15119 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15120 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15121 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15122 img_barrier.image = image.handle();
15123 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15124 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15125 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15126 img_barrier.subresourceRange.baseArrayLayer = 0;
15127 img_barrier.subresourceRange.baseMipLevel = 0;
15128 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
15129 img_barrier.subresourceRange.layerCount = 0;
15130 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015131 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
15132 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060015133 m_errorMonitor->VerifyFound();
15134 img_barrier.subresourceRange.layerCount = 1;
15135}
15136
15137TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060015138 TEST_DESCRIPTION("Exceed the limits of image format ");
15139
Cody Northropc31a84f2016-08-22 10:41:47 -060015140 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060015142 VkImageCreateInfo image_create_info = {};
15143 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15144 image_create_info.pNext = NULL;
15145 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15146 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15147 image_create_info.extent.width = 32;
15148 image_create_info.extent.height = 32;
15149 image_create_info.extent.depth = 1;
15150 image_create_info.mipLevels = 1;
15151 image_create_info.arrayLayers = 1;
15152 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15153 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15154 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15155 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15156 image_create_info.flags = 0;
15157
15158 VkImage nullImg;
15159 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015160 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15161 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070015162 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015163 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15164 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15165 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070015166 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015167
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015169 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15170 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15171 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15172 m_errorMonitor->VerifyFound();
15173 image_create_info.mipLevels = 1;
15174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015176 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15177 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15178 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15179 m_errorMonitor->VerifyFound();
15180 image_create_info.arrayLayers = 1;
15181
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060015183 int samples = imgFmtProps.sampleCounts >> 1;
15184 image_create_info.samples = (VkSampleCountFlagBits)samples;
15185 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15186 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15187 m_errorMonitor->VerifyFound();
15188 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15189
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15191 "pCreateInfo->initialLayout, must be "
15192 "VK_IMAGE_LAYOUT_UNDEFINED or "
15193 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060015194 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15195 // Expect INVALID_LAYOUT
15196 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15197 m_errorMonitor->VerifyFound();
15198 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15199}
15200
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015201TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015202 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015204
15205 ASSERT_NO_FATAL_FAILURE(InitState());
15206
15207 VkImageObj src_image(m_device);
15208 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15209 VkImageObj dst_image(m_device);
15210 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15211
Tony Barbour552f6c02016-12-21 14:34:07 -070015212 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015213 VkImageCopy copy_region;
15214 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15215 copy_region.srcSubresource.mipLevel = 0;
15216 copy_region.srcSubresource.baseArrayLayer = 0;
15217 copy_region.srcSubresource.layerCount = 0;
15218 copy_region.srcOffset.x = 0;
15219 copy_region.srcOffset.y = 0;
15220 copy_region.srcOffset.z = 0;
15221 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15222 copy_region.dstSubresource.mipLevel = 0;
15223 copy_region.dstSubresource.baseArrayLayer = 0;
15224 copy_region.dstSubresource.layerCount = 0;
15225 copy_region.dstOffset.x = 0;
15226 copy_region.dstOffset.y = 0;
15227 copy_region.dstOffset.z = 0;
15228 copy_region.extent.width = 64;
15229 copy_region.extent.height = 64;
15230 copy_region.extent.depth = 1;
15231 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15232 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015233 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015234
15235 m_errorMonitor->VerifyFound();
15236}
15237
15238TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015239 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015241
15242 ASSERT_NO_FATAL_FAILURE(InitState());
15243
15244 VkImageObj src_image(m_device);
15245 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15246 VkImageObj dst_image(m_device);
15247 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15248
Tony Barbour552f6c02016-12-21 14:34:07 -070015249 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015250 VkImageCopy copy_region;
15251 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15252 copy_region.srcSubresource.mipLevel = 0;
15253 copy_region.srcSubresource.baseArrayLayer = 0;
15254 copy_region.srcSubresource.layerCount = 0;
15255 copy_region.srcOffset.x = 0;
15256 copy_region.srcOffset.y = 0;
15257 copy_region.srcOffset.z = 0;
15258 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15259 copy_region.dstSubresource.mipLevel = 0;
15260 copy_region.dstSubresource.baseArrayLayer = 0;
15261 copy_region.dstSubresource.layerCount = 0;
15262 copy_region.dstOffset.x = 0;
15263 copy_region.dstOffset.y = 0;
15264 copy_region.dstOffset.z = 0;
15265 copy_region.extent.width = 64;
15266 copy_region.extent.height = 64;
15267 copy_region.extent.depth = 1;
15268 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15269 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015270 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015271
15272 m_errorMonitor->VerifyFound();
15273}
15274
Karl Schultz6addd812016-02-02 17:17:23 -070015275TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015276 VkResult err;
15277 bool pass;
15278
15279 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015281
15282 ASSERT_NO_FATAL_FAILURE(InitState());
15283
15284 // Create two images of different types and try to copy between them
15285 VkImage srcImage;
15286 VkImage dstImage;
15287 VkDeviceMemory srcMem;
15288 VkDeviceMemory destMem;
15289 VkMemoryRequirements memReqs;
15290
15291 VkImageCreateInfo image_create_info = {};
15292 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15293 image_create_info.pNext = NULL;
15294 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15295 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15296 image_create_info.extent.width = 32;
15297 image_create_info.extent.height = 32;
15298 image_create_info.extent.depth = 1;
15299 image_create_info.mipLevels = 1;
15300 image_create_info.arrayLayers = 1;
15301 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15302 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15303 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15304 image_create_info.flags = 0;
15305
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015306 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015307 ASSERT_VK_SUCCESS(err);
15308
15309 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15310 // Introduce failure by creating second image with a different-sized format.
15311 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15312
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015313 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015314 ASSERT_VK_SUCCESS(err);
15315
15316 // Allocate memory
15317 VkMemoryAllocateInfo memAlloc = {};
15318 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15319 memAlloc.pNext = NULL;
15320 memAlloc.allocationSize = 0;
15321 memAlloc.memoryTypeIndex = 0;
15322
15323 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15324 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015325 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015326 ASSERT_TRUE(pass);
15327 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15328 ASSERT_VK_SUCCESS(err);
15329
15330 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15331 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015332 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015333 ASSERT_TRUE(pass);
15334 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15335 ASSERT_VK_SUCCESS(err);
15336
15337 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15338 ASSERT_VK_SUCCESS(err);
15339 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15340 ASSERT_VK_SUCCESS(err);
15341
Tony Barbour552f6c02016-12-21 14:34:07 -070015342 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015343 VkImageCopy copyRegion;
15344 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15345 copyRegion.srcSubresource.mipLevel = 0;
15346 copyRegion.srcSubresource.baseArrayLayer = 0;
15347 copyRegion.srcSubresource.layerCount = 0;
15348 copyRegion.srcOffset.x = 0;
15349 copyRegion.srcOffset.y = 0;
15350 copyRegion.srcOffset.z = 0;
15351 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15352 copyRegion.dstSubresource.mipLevel = 0;
15353 copyRegion.dstSubresource.baseArrayLayer = 0;
15354 copyRegion.dstSubresource.layerCount = 0;
15355 copyRegion.dstOffset.x = 0;
15356 copyRegion.dstOffset.y = 0;
15357 copyRegion.dstOffset.z = 0;
15358 copyRegion.extent.width = 1;
15359 copyRegion.extent.height = 1;
15360 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015361 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015362 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015363
15364 m_errorMonitor->VerifyFound();
15365
15366 vkDestroyImage(m_device->device(), srcImage, NULL);
15367 vkDestroyImage(m_device->device(), dstImage, NULL);
15368 vkFreeMemory(m_device->device(), srcMem, NULL);
15369 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015370}
15371
Karl Schultz6addd812016-02-02 17:17:23 -070015372TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15373 VkResult err;
15374 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015375
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015376 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15378 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015379
Mike Stroyana3082432015-09-25 13:39:21 -060015380 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015381
15382 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015383 VkImage srcImage;
15384 VkImage dstImage;
15385 VkDeviceMemory srcMem;
15386 VkDeviceMemory destMem;
15387 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015388
15389 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015390 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15391 image_create_info.pNext = NULL;
15392 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15393 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15394 image_create_info.extent.width = 32;
15395 image_create_info.extent.height = 32;
15396 image_create_info.extent.depth = 1;
15397 image_create_info.mipLevels = 1;
15398 image_create_info.arrayLayers = 1;
15399 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15400 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15401 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15402 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015403
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015404 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015405 ASSERT_VK_SUCCESS(err);
15406
Karl Schultzbdb75952016-04-19 11:36:49 -060015407 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15408
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015409 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015410 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015411 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015412 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015414 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015415 ASSERT_VK_SUCCESS(err);
15416
15417 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015418 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015419 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15420 memAlloc.pNext = NULL;
15421 memAlloc.allocationSize = 0;
15422 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015423
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015424 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015425 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015426 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015427 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015428 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015429 ASSERT_VK_SUCCESS(err);
15430
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015431 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015432 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015433 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015434 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015435 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015436 ASSERT_VK_SUCCESS(err);
15437
15438 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15439 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015440 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015441 ASSERT_VK_SUCCESS(err);
15442
Tony Barbour552f6c02016-12-21 14:34:07 -070015443 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015444 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015445 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015446 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015447 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015448 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015449 copyRegion.srcOffset.x = 0;
15450 copyRegion.srcOffset.y = 0;
15451 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015452 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015453 copyRegion.dstSubresource.mipLevel = 0;
15454 copyRegion.dstSubresource.baseArrayLayer = 0;
15455 copyRegion.dstSubresource.layerCount = 0;
15456 copyRegion.dstOffset.x = 0;
15457 copyRegion.dstOffset.y = 0;
15458 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015459 copyRegion.extent.width = 1;
15460 copyRegion.extent.height = 1;
15461 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015462 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015463 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015464
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015465 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015466
Chia-I Wuf7458c52015-10-26 21:10:41 +080015467 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015468 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015469 vkFreeMemory(m_device->device(), srcMem, NULL);
15470 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015471}
15472
Karl Schultz6addd812016-02-02 17:17:23 -070015473TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15474 VkResult err;
15475 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015476
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15478 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015479
Mike Stroyana3082432015-09-25 13:39:21 -060015480 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015481
15482 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015483 VkImage srcImage;
15484 VkImage dstImage;
15485 VkDeviceMemory srcMem;
15486 VkDeviceMemory destMem;
15487 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015488
15489 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015490 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15491 image_create_info.pNext = NULL;
15492 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15493 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15494 image_create_info.extent.width = 32;
15495 image_create_info.extent.height = 1;
15496 image_create_info.extent.depth = 1;
15497 image_create_info.mipLevels = 1;
15498 image_create_info.arrayLayers = 1;
15499 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15500 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15501 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15502 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015503
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015504 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015505 ASSERT_VK_SUCCESS(err);
15506
Karl Schultz6addd812016-02-02 17:17:23 -070015507 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015508
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015509 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015510 ASSERT_VK_SUCCESS(err);
15511
15512 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015513 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015514 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15515 memAlloc.pNext = NULL;
15516 memAlloc.allocationSize = 0;
15517 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015518
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015519 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015520 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015521 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015522 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015523 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015524 ASSERT_VK_SUCCESS(err);
15525
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015526 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015527 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015528 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015529 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015530 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015531 ASSERT_VK_SUCCESS(err);
15532
15533 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15534 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015535 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015536 ASSERT_VK_SUCCESS(err);
15537
Tony Barbour552f6c02016-12-21 14:34:07 -070015538 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015539 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015540 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15541 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015542 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015543 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015544 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015545 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015546 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015547 resolveRegion.srcOffset.x = 0;
15548 resolveRegion.srcOffset.y = 0;
15549 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015550 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015551 resolveRegion.dstSubresource.mipLevel = 0;
15552 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015553 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015554 resolveRegion.dstOffset.x = 0;
15555 resolveRegion.dstOffset.y = 0;
15556 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015557 resolveRegion.extent.width = 1;
15558 resolveRegion.extent.height = 1;
15559 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015560 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015561 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015562
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015563 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015564
Chia-I Wuf7458c52015-10-26 21:10:41 +080015565 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015566 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015567 vkFreeMemory(m_device->device(), srcMem, NULL);
15568 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015569}
15570
Karl Schultz6addd812016-02-02 17:17:23 -070015571TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15572 VkResult err;
15573 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015574
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15576 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015577
Mike Stroyana3082432015-09-25 13:39:21 -060015578 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015579
Chris Forbesa7530692016-05-08 12:35:39 +120015580 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015581 VkImage srcImage;
15582 VkImage dstImage;
15583 VkDeviceMemory srcMem;
15584 VkDeviceMemory destMem;
15585 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015586
15587 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015588 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15589 image_create_info.pNext = NULL;
15590 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15591 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15592 image_create_info.extent.width = 32;
15593 image_create_info.extent.height = 1;
15594 image_create_info.extent.depth = 1;
15595 image_create_info.mipLevels = 1;
15596 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015597 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015598 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15599 // Note: Some implementations expect color attachment usage for any
15600 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015601 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015602 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015603
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015604 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015605 ASSERT_VK_SUCCESS(err);
15606
Karl Schultz6addd812016-02-02 17:17:23 -070015607 // Note: Some implementations expect color attachment usage for any
15608 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015609 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015610
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015611 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015612 ASSERT_VK_SUCCESS(err);
15613
15614 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015615 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015616 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15617 memAlloc.pNext = NULL;
15618 memAlloc.allocationSize = 0;
15619 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015620
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015621 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015622 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015623 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015624 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015625 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015626 ASSERT_VK_SUCCESS(err);
15627
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015628 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015629 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015630 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015631 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015632 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015633 ASSERT_VK_SUCCESS(err);
15634
15635 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15636 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015637 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015638 ASSERT_VK_SUCCESS(err);
15639
Tony Barbour552f6c02016-12-21 14:34:07 -070015640 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015641 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015642 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15643 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015644 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015645 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015646 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015647 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015648 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015649 resolveRegion.srcOffset.x = 0;
15650 resolveRegion.srcOffset.y = 0;
15651 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015652 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015653 resolveRegion.dstSubresource.mipLevel = 0;
15654 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015655 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015656 resolveRegion.dstOffset.x = 0;
15657 resolveRegion.dstOffset.y = 0;
15658 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015659 resolveRegion.extent.width = 1;
15660 resolveRegion.extent.height = 1;
15661 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015662 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015663 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015664
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015665 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015666
Chia-I Wuf7458c52015-10-26 21:10:41 +080015667 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015668 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015669 vkFreeMemory(m_device->device(), srcMem, NULL);
15670 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015671}
15672
Karl Schultz6addd812016-02-02 17:17:23 -070015673TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15674 VkResult err;
15675 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015676
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15678 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015679
Mike Stroyana3082432015-09-25 13:39:21 -060015680 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015681
15682 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015683 VkImage srcImage;
15684 VkImage dstImage;
15685 VkDeviceMemory srcMem;
15686 VkDeviceMemory destMem;
15687 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015688
15689 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015690 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15691 image_create_info.pNext = NULL;
15692 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15693 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15694 image_create_info.extent.width = 32;
15695 image_create_info.extent.height = 1;
15696 image_create_info.extent.depth = 1;
15697 image_create_info.mipLevels = 1;
15698 image_create_info.arrayLayers = 1;
15699 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15700 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15701 // Note: Some implementations expect color attachment usage for any
15702 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015703 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015704 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015705
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015706 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015707 ASSERT_VK_SUCCESS(err);
15708
Karl Schultz6addd812016-02-02 17:17:23 -070015709 // Set format to something other than source image
15710 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15711 // Note: Some implementations expect color attachment usage for any
15712 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015713 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015714 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015715
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015716 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015717 ASSERT_VK_SUCCESS(err);
15718
15719 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015720 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015721 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15722 memAlloc.pNext = NULL;
15723 memAlloc.allocationSize = 0;
15724 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015725
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015726 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015727 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015728 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015729 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015730 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015731 ASSERT_VK_SUCCESS(err);
15732
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015733 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015734 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015735 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015736 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015737 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015738 ASSERT_VK_SUCCESS(err);
15739
15740 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15741 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015742 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015743 ASSERT_VK_SUCCESS(err);
15744
Tony Barbour552f6c02016-12-21 14:34:07 -070015745 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015746 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015747 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15748 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015749 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015750 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015751 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015752 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015753 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015754 resolveRegion.srcOffset.x = 0;
15755 resolveRegion.srcOffset.y = 0;
15756 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015757 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015758 resolveRegion.dstSubresource.mipLevel = 0;
15759 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015760 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015761 resolveRegion.dstOffset.x = 0;
15762 resolveRegion.dstOffset.y = 0;
15763 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015764 resolveRegion.extent.width = 1;
15765 resolveRegion.extent.height = 1;
15766 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015767 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015768 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015769
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015770 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015771
Chia-I Wuf7458c52015-10-26 21:10:41 +080015772 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015773 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015774 vkFreeMemory(m_device->device(), srcMem, NULL);
15775 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015776}
15777
Karl Schultz6addd812016-02-02 17:17:23 -070015778TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15779 VkResult err;
15780 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015781
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15783 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015784
Mike Stroyana3082432015-09-25 13:39:21 -060015785 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015786
15787 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015788 VkImage srcImage;
15789 VkImage dstImage;
15790 VkDeviceMemory srcMem;
15791 VkDeviceMemory destMem;
15792 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015793
15794 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015795 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15796 image_create_info.pNext = NULL;
15797 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15798 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15799 image_create_info.extent.width = 32;
15800 image_create_info.extent.height = 1;
15801 image_create_info.extent.depth = 1;
15802 image_create_info.mipLevels = 1;
15803 image_create_info.arrayLayers = 1;
15804 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15805 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15806 // Note: Some implementations expect color attachment usage for any
15807 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015808 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015809 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015810
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015811 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015812 ASSERT_VK_SUCCESS(err);
15813
Karl Schultz6addd812016-02-02 17:17:23 -070015814 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15815 // Note: Some implementations expect color attachment usage for any
15816 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015817 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015818 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015819
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015820 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015821 ASSERT_VK_SUCCESS(err);
15822
15823 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015824 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015825 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15826 memAlloc.pNext = NULL;
15827 memAlloc.allocationSize = 0;
15828 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015829
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015830 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015831 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015832 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015833 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015834 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015835 ASSERT_VK_SUCCESS(err);
15836
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015837 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015838 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015839 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015840 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015841 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015842 ASSERT_VK_SUCCESS(err);
15843
15844 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15845 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015846 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015847 ASSERT_VK_SUCCESS(err);
15848
Tony Barbour552f6c02016-12-21 14:34:07 -070015849 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015850 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015851 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15852 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015853 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015854 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015855 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015856 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015857 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015858 resolveRegion.srcOffset.x = 0;
15859 resolveRegion.srcOffset.y = 0;
15860 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015861 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015862 resolveRegion.dstSubresource.mipLevel = 0;
15863 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015864 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015865 resolveRegion.dstOffset.x = 0;
15866 resolveRegion.dstOffset.y = 0;
15867 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015868 resolveRegion.extent.width = 1;
15869 resolveRegion.extent.height = 1;
15870 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015871 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015872 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015873
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015874 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015875
Chia-I Wuf7458c52015-10-26 21:10:41 +080015876 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015877 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015878 vkFreeMemory(m_device->device(), srcMem, NULL);
15879 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015880}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015881
Karl Schultz6addd812016-02-02 17:17:23 -070015882TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015883 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015884 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15885 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015886 // The image format check comes 2nd in validation so we trigger it first,
15887 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015888 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015889
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15891 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015892
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015893 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015894
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015895 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015896 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15897 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015898
15899 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015900 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15901 ds_pool_ci.pNext = NULL;
15902 ds_pool_ci.maxSets = 1;
15903 ds_pool_ci.poolSizeCount = 1;
15904 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015905
15906 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015907 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015908 ASSERT_VK_SUCCESS(err);
15909
15910 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015911 dsl_binding.binding = 0;
15912 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15913 dsl_binding.descriptorCount = 1;
15914 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15915 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015916
15917 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015918 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15919 ds_layout_ci.pNext = NULL;
15920 ds_layout_ci.bindingCount = 1;
15921 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015922 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015923 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015924 ASSERT_VK_SUCCESS(err);
15925
15926 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015927 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015928 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015929 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015930 alloc_info.descriptorPool = ds_pool;
15931 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015932 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015933 ASSERT_VK_SUCCESS(err);
15934
Karl Schultz6addd812016-02-02 17:17:23 -070015935 VkImage image_bad;
15936 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015937 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015938 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015939 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015940 const int32_t tex_width = 32;
15941 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015942
15943 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015944 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15945 image_create_info.pNext = NULL;
15946 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15947 image_create_info.format = tex_format_bad;
15948 image_create_info.extent.width = tex_width;
15949 image_create_info.extent.height = tex_height;
15950 image_create_info.extent.depth = 1;
15951 image_create_info.mipLevels = 1;
15952 image_create_info.arrayLayers = 1;
15953 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15954 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015955 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015956 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015958 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015959 ASSERT_VK_SUCCESS(err);
15960 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015961 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15962 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015963 ASSERT_VK_SUCCESS(err);
15964
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015965 // ---Bind image memory---
15966 VkMemoryRequirements img_mem_reqs;
15967 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
15968 VkMemoryAllocateInfo image_alloc_info = {};
15969 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15970 image_alloc_info.pNext = NULL;
15971 image_alloc_info.memoryTypeIndex = 0;
15972 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015973 bool pass =
15974 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 -070015975 ASSERT_TRUE(pass);
15976 VkDeviceMemory mem;
15977 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
15978 ASSERT_VK_SUCCESS(err);
15979 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
15980 ASSERT_VK_SUCCESS(err);
15981 // -----------------------
15982
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015983 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015984 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015985 image_view_create_info.image = image_bad;
15986 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15987 image_view_create_info.format = tex_format_bad;
15988 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15989 image_view_create_info.subresourceRange.baseMipLevel = 0;
15990 image_view_create_info.subresourceRange.layerCount = 1;
15991 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015992 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015993
15994 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015995 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015996
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015997 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015998
Chia-I Wuf7458c52015-10-26 21:10:41 +080015999 vkDestroyImage(m_device->device(), image_bad, NULL);
16000 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016001 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16002 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016003
16004 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016005}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016006
16007TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016008 TEST_DESCRIPTION(
16009 "Call ClearColorImage w/ a depth|stencil image and "
16010 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016011
16012 ASSERT_NO_FATAL_FAILURE(InitState());
16013 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16014
Tony Barbour552f6c02016-12-21 14:34:07 -070016015 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016016
16017 // Color image
16018 VkClearColorValue clear_color;
16019 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16020 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16021 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16022 const int32_t img_width = 32;
16023 const int32_t img_height = 32;
16024 VkImageCreateInfo image_create_info = {};
16025 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16026 image_create_info.pNext = NULL;
16027 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16028 image_create_info.format = color_format;
16029 image_create_info.extent.width = img_width;
16030 image_create_info.extent.height = img_height;
16031 image_create_info.extent.depth = 1;
16032 image_create_info.mipLevels = 1;
16033 image_create_info.arrayLayers = 1;
16034 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16035 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16036 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16037
16038 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016039 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016041 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016042
16043 // Depth/Stencil image
16044 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016045 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016046 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16047 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16048 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16049 ds_image_create_info.extent.width = 64;
16050 ds_image_create_info.extent.height = 64;
16051 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016052 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 -060016053
16054 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016055 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016056
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016057 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 -060016058
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016061 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016062 &color_range);
16063
16064 m_errorMonitor->VerifyFound();
16065
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16067 "vkCmdClearColorImage called with "
16068 "image created without "
16069 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016070
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016071 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016072 &color_range);
16073
16074 m_errorMonitor->VerifyFound();
16075
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016076 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16078 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016079
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016080 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
16081 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016082
16083 m_errorMonitor->VerifyFound();
16084}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016085#endif // IMAGE_TESTS
Tobin Ehliscde08892015-09-22 10:11:37 -060016086
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016087// WSI Enabled Tests
16088//
Chris Forbes09368e42016-10-13 11:59:22 +130016089#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016090TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
16091
16092#if defined(VK_USE_PLATFORM_XCB_KHR)
16093 VkSurfaceKHR surface = VK_NULL_HANDLE;
16094
16095 VkResult err;
16096 bool pass;
16097 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
16098 VkSwapchainCreateInfoKHR swapchain_create_info = {};
16099 // uint32_t swapchain_image_count = 0;
16100 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
16101 // uint32_t image_index = 0;
16102 // VkPresentInfoKHR present_info = {};
16103
16104 ASSERT_NO_FATAL_FAILURE(InitState());
16105
16106 // Use the create function from one of the VK_KHR_*_surface extension in
16107 // order to create a surface, testing all known errors in the process,
16108 // before successfully creating a surface:
16109 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
16110 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
16111 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
16112 pass = (err != VK_SUCCESS);
16113 ASSERT_TRUE(pass);
16114 m_errorMonitor->VerifyFound();
16115
16116 // Next, try to create a surface with the wrong
16117 // VkXcbSurfaceCreateInfoKHR::sType:
16118 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
16119 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16121 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16122 pass = (err != VK_SUCCESS);
16123 ASSERT_TRUE(pass);
16124 m_errorMonitor->VerifyFound();
16125
16126 // Create a native window, and then correctly create a surface:
16127 xcb_connection_t *connection;
16128 xcb_screen_t *screen;
16129 xcb_window_t xcb_window;
16130 xcb_intern_atom_reply_t *atom_wm_delete_window;
16131
16132 const xcb_setup_t *setup;
16133 xcb_screen_iterator_t iter;
16134 int scr;
16135 uint32_t value_mask, value_list[32];
16136 int width = 1;
16137 int height = 1;
16138
16139 connection = xcb_connect(NULL, &scr);
16140 ASSERT_TRUE(connection != NULL);
16141 setup = xcb_get_setup(connection);
16142 iter = xcb_setup_roots_iterator(setup);
16143 while (scr-- > 0)
16144 xcb_screen_next(&iter);
16145 screen = iter.data;
16146
16147 xcb_window = xcb_generate_id(connection);
16148
16149 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
16150 value_list[0] = screen->black_pixel;
16151 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
16152
16153 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
16154 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
16155
16156 /* Magic code that will send notification when window is destroyed */
16157 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
16158 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
16159
16160 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
16161 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
16162 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
16163 free(reply);
16164
16165 xcb_map_window(connection, xcb_window);
16166
16167 // Force the x/y coordinates to 100,100 results are identical in consecutive
16168 // runs
16169 const uint32_t coords[] = { 100, 100 };
16170 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
16171
16172 // Finally, try to correctly create a surface:
16173 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
16174 xcb_create_info.pNext = NULL;
16175 xcb_create_info.flags = 0;
16176 xcb_create_info.connection = connection;
16177 xcb_create_info.window = xcb_window;
16178 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16179 pass = (err == VK_SUCCESS);
16180 ASSERT_TRUE(pass);
16181
16182 // Check if surface supports presentation:
16183
16184 // 1st, do so without having queried the queue families:
16185 VkBool32 supported = false;
16186 // TODO: Get the following error to come out:
16187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16188 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
16189 "function");
16190 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16191 pass = (err != VK_SUCCESS);
16192 // ASSERT_TRUE(pass);
16193 // m_errorMonitor->VerifyFound();
16194
16195 // Next, query a queue family index that's too large:
16196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16197 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
16198 pass = (err != VK_SUCCESS);
16199 ASSERT_TRUE(pass);
16200 m_errorMonitor->VerifyFound();
16201
16202 // Finally, do so correctly:
16203 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16204 // SUPPORTED
16205 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16206 pass = (err == VK_SUCCESS);
16207 ASSERT_TRUE(pass);
16208
16209 // Before proceeding, try to create a swapchain without having called
16210 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
16211 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16212 swapchain_create_info.pNext = NULL;
16213 swapchain_create_info.flags = 0;
16214 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16215 swapchain_create_info.surface = surface;
16216 swapchain_create_info.imageArrayLayers = 1;
16217 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
16218 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
16219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16220 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
16221 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16222 pass = (err != VK_SUCCESS);
16223 ASSERT_TRUE(pass);
16224 m_errorMonitor->VerifyFound();
16225
16226 // Get the surface capabilities:
16227 VkSurfaceCapabilitiesKHR surface_capabilities;
16228
16229 // Do so correctly (only error logged by this entrypoint is if the
16230 // extension isn't enabled):
16231 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
16232 pass = (err == VK_SUCCESS);
16233 ASSERT_TRUE(pass);
16234
16235 // Get the surface formats:
16236 uint32_t surface_format_count;
16237
16238 // First, try without a pointer to surface_format_count:
16239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
16240 "specified as NULL");
16241 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
16242 pass = (err == VK_SUCCESS);
16243 ASSERT_TRUE(pass);
16244 m_errorMonitor->VerifyFound();
16245
16246 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
16247 // correctly done a 1st try (to get the count):
16248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16249 surface_format_count = 0;
16250 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
16251 pass = (err == VK_SUCCESS);
16252 ASSERT_TRUE(pass);
16253 m_errorMonitor->VerifyFound();
16254
16255 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16256 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16257 pass = (err == VK_SUCCESS);
16258 ASSERT_TRUE(pass);
16259
16260 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16261 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
16262
16263 // Next, do a 2nd try with surface_format_count being set too high:
16264 surface_format_count += 5;
16265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16266 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16267 pass = (err == VK_SUCCESS);
16268 ASSERT_TRUE(pass);
16269 m_errorMonitor->VerifyFound();
16270
16271 // Finally, do a correct 1st and 2nd try:
16272 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16273 pass = (err == VK_SUCCESS);
16274 ASSERT_TRUE(pass);
16275 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16276 pass = (err == VK_SUCCESS);
16277 ASSERT_TRUE(pass);
16278
16279 // Get the surface present modes:
16280 uint32_t surface_present_mode_count;
16281
16282 // First, try without a pointer to surface_format_count:
16283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16284 "specified as NULL");
16285
16286 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16287 pass = (err == VK_SUCCESS);
16288 ASSERT_TRUE(pass);
16289 m_errorMonitor->VerifyFound();
16290
16291 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16292 // correctly done a 1st try (to get the count):
16293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16294 surface_present_mode_count = 0;
16295 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16296 (VkPresentModeKHR *)&surface_present_mode_count);
16297 pass = (err == VK_SUCCESS);
16298 ASSERT_TRUE(pass);
16299 m_errorMonitor->VerifyFound();
16300
16301 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16302 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16303 pass = (err == VK_SUCCESS);
16304 ASSERT_TRUE(pass);
16305
16306 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16307 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16308
16309 // Next, do a 2nd try with surface_format_count being set too high:
16310 surface_present_mode_count += 5;
16311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16312 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16313 pass = (err == VK_SUCCESS);
16314 ASSERT_TRUE(pass);
16315 m_errorMonitor->VerifyFound();
16316
16317 // Finally, do a correct 1st and 2nd try:
16318 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16319 pass = (err == VK_SUCCESS);
16320 ASSERT_TRUE(pass);
16321 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16322 pass = (err == VK_SUCCESS);
16323 ASSERT_TRUE(pass);
16324
16325 // Create a swapchain:
16326
16327 // First, try without a pointer to swapchain_create_info:
16328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16329 "specified as NULL");
16330
16331 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16332 pass = (err != VK_SUCCESS);
16333 ASSERT_TRUE(pass);
16334 m_errorMonitor->VerifyFound();
16335
16336 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16337 // sType:
16338 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16340
16341 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16342 pass = (err != VK_SUCCESS);
16343 ASSERT_TRUE(pass);
16344 m_errorMonitor->VerifyFound();
16345
16346 // Next, call with a NULL swapchain pointer:
16347 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16348 swapchain_create_info.pNext = NULL;
16349 swapchain_create_info.flags = 0;
16350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16351 "specified as NULL");
16352
16353 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16354 pass = (err != VK_SUCCESS);
16355 ASSERT_TRUE(pass);
16356 m_errorMonitor->VerifyFound();
16357
16358 // TODO: Enhance swapchain layer so that
16359 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16360
16361 // Next, call with a queue family index that's too large:
16362 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16363 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16364 swapchain_create_info.queueFamilyIndexCount = 2;
16365 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16367 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16368 pass = (err != VK_SUCCESS);
16369 ASSERT_TRUE(pass);
16370 m_errorMonitor->VerifyFound();
16371
16372 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16373 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16374 swapchain_create_info.queueFamilyIndexCount = 1;
16375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16376 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16377 "pCreateInfo->pQueueFamilyIndices).");
16378 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16379 pass = (err != VK_SUCCESS);
16380 ASSERT_TRUE(pass);
16381 m_errorMonitor->VerifyFound();
16382
16383 // Next, call with an invalid imageSharingMode:
16384 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16385 swapchain_create_info.queueFamilyIndexCount = 1;
16386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16387 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16388 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16389 pass = (err != VK_SUCCESS);
16390 ASSERT_TRUE(pass);
16391 m_errorMonitor->VerifyFound();
16392 // Fix for the future:
16393 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16394 // SUPPORTED
16395 swapchain_create_info.queueFamilyIndexCount = 0;
16396 queueFamilyIndex[0] = 0;
16397 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16398
16399 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16400 // Get the images from a swapchain:
16401 // Acquire an image from a swapchain:
16402 // Present an image to a swapchain:
16403 // Destroy the swapchain:
16404
16405 // TODOs:
16406 //
16407 // - Try destroying the device without first destroying the swapchain
16408 //
16409 // - Try destroying the device without first destroying the surface
16410 //
16411 // - Try destroying the surface without first destroying the swapchain
16412
16413 // Destroy the surface:
16414 vkDestroySurfaceKHR(instance(), surface, NULL);
16415
16416 // Tear down the window:
16417 xcb_destroy_window(connection, xcb_window);
16418 xcb_disconnect(connection);
16419
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016420#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016421 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016422#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016423}
Chris Forbes09368e42016-10-13 11:59:22 +130016424#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016425
16426//
16427// POSITIVE VALIDATION TESTS
16428//
16429// These tests do not expect to encounter ANY validation errors pass only if this is true
16430
Tobin Ehlise0006882016-11-03 10:14:28 -060016431TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016432 TEST_DESCRIPTION(
16433 "Perform an image layout transition in a secondary command buffer followed "
16434 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060016435 VkResult err;
16436 m_errorMonitor->ExpectSuccess();
16437 ASSERT_NO_FATAL_FAILURE(InitState());
16438 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16439 // Allocate a secondary and primary cmd buffer
16440 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16441 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16442 command_buffer_allocate_info.commandPool = m_commandPool;
16443 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16444 command_buffer_allocate_info.commandBufferCount = 1;
16445
16446 VkCommandBuffer secondary_command_buffer;
16447 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16448 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16449 VkCommandBuffer primary_command_buffer;
16450 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16451 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16452 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16453 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16454 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16455 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16456 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16457
16458 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16459 ASSERT_VK_SUCCESS(err);
16460 VkImageObj image(m_device);
16461 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16462 ASSERT_TRUE(image.initialized());
16463 VkImageMemoryBarrier img_barrier = {};
16464 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16465 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16466 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16467 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16468 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16469 img_barrier.image = image.handle();
16470 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16471 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16472 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16473 img_barrier.subresourceRange.baseArrayLayer = 0;
16474 img_barrier.subresourceRange.baseMipLevel = 0;
16475 img_barrier.subresourceRange.layerCount = 1;
16476 img_barrier.subresourceRange.levelCount = 1;
16477 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16478 0, nullptr, 1, &img_barrier);
16479 err = vkEndCommandBuffer(secondary_command_buffer);
16480 ASSERT_VK_SUCCESS(err);
16481
16482 // Now update primary cmd buffer to execute secondary and transitions image
16483 command_buffer_begin_info.pInheritanceInfo = nullptr;
16484 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16485 ASSERT_VK_SUCCESS(err);
16486 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16487 VkImageMemoryBarrier img_barrier2 = {};
16488 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16489 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16490 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16491 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16492 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16493 img_barrier2.image = image.handle();
16494 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16495 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16496 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16497 img_barrier2.subresourceRange.baseArrayLayer = 0;
16498 img_barrier2.subresourceRange.baseMipLevel = 0;
16499 img_barrier2.subresourceRange.layerCount = 1;
16500 img_barrier2.subresourceRange.levelCount = 1;
16501 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16502 nullptr, 1, &img_barrier2);
16503 err = vkEndCommandBuffer(primary_command_buffer);
16504 ASSERT_VK_SUCCESS(err);
16505 VkSubmitInfo submit_info = {};
16506 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16507 submit_info.commandBufferCount = 1;
16508 submit_info.pCommandBuffers = &primary_command_buffer;
16509 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16510 ASSERT_VK_SUCCESS(err);
16511 m_errorMonitor->VerifyNotFound();
16512 err = vkDeviceWaitIdle(m_device->device());
16513 ASSERT_VK_SUCCESS(err);
16514 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16515 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16516}
16517
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016518// This is a positive test. No failures are expected.
16519TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016520 TEST_DESCRIPTION(
16521 "Ensure that the vkUpdateDescriptorSets validation code "
16522 "is ignoring VkWriteDescriptorSet members that are not "
16523 "related to the descriptor type specified by "
16524 "VkWriteDescriptorSet::descriptorType. Correct "
16525 "validation behavior will result in the test running to "
16526 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016527
16528 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16529
16530 ASSERT_NO_FATAL_FAILURE(InitState());
16531
16532 // Image Case
16533 {
16534 m_errorMonitor->ExpectSuccess();
16535
16536 VkImage image;
16537 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16538 const int32_t tex_width = 32;
16539 const int32_t tex_height = 32;
16540 VkImageCreateInfo image_create_info = {};
16541 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16542 image_create_info.pNext = NULL;
16543 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16544 image_create_info.format = tex_format;
16545 image_create_info.extent.width = tex_width;
16546 image_create_info.extent.height = tex_height;
16547 image_create_info.extent.depth = 1;
16548 image_create_info.mipLevels = 1;
16549 image_create_info.arrayLayers = 1;
16550 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16551 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16552 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16553 image_create_info.flags = 0;
16554 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16555 ASSERT_VK_SUCCESS(err);
16556
16557 VkMemoryRequirements memory_reqs;
16558 VkDeviceMemory image_memory;
16559 bool pass;
16560 VkMemoryAllocateInfo memory_info = {};
16561 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16562 memory_info.pNext = NULL;
16563 memory_info.allocationSize = 0;
16564 memory_info.memoryTypeIndex = 0;
16565 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16566 memory_info.allocationSize = memory_reqs.size;
16567 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16568 ASSERT_TRUE(pass);
16569 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16570 ASSERT_VK_SUCCESS(err);
16571 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16572 ASSERT_VK_SUCCESS(err);
16573
16574 VkImageViewCreateInfo image_view_create_info = {};
16575 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16576 image_view_create_info.image = image;
16577 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16578 image_view_create_info.format = tex_format;
16579 image_view_create_info.subresourceRange.layerCount = 1;
16580 image_view_create_info.subresourceRange.baseMipLevel = 0;
16581 image_view_create_info.subresourceRange.levelCount = 1;
16582 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16583
16584 VkImageView view;
16585 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16586 ASSERT_VK_SUCCESS(err);
16587
16588 VkDescriptorPoolSize ds_type_count = {};
16589 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16590 ds_type_count.descriptorCount = 1;
16591
16592 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16593 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16594 ds_pool_ci.pNext = NULL;
16595 ds_pool_ci.maxSets = 1;
16596 ds_pool_ci.poolSizeCount = 1;
16597 ds_pool_ci.pPoolSizes = &ds_type_count;
16598
16599 VkDescriptorPool ds_pool;
16600 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16601 ASSERT_VK_SUCCESS(err);
16602
16603 VkDescriptorSetLayoutBinding dsl_binding = {};
16604 dsl_binding.binding = 0;
16605 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16606 dsl_binding.descriptorCount = 1;
16607 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16608 dsl_binding.pImmutableSamplers = NULL;
16609
16610 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16611 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16612 ds_layout_ci.pNext = NULL;
16613 ds_layout_ci.bindingCount = 1;
16614 ds_layout_ci.pBindings = &dsl_binding;
16615 VkDescriptorSetLayout ds_layout;
16616 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16617 ASSERT_VK_SUCCESS(err);
16618
16619 VkDescriptorSet descriptor_set;
16620 VkDescriptorSetAllocateInfo alloc_info = {};
16621 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16622 alloc_info.descriptorSetCount = 1;
16623 alloc_info.descriptorPool = ds_pool;
16624 alloc_info.pSetLayouts = &ds_layout;
16625 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16626 ASSERT_VK_SUCCESS(err);
16627
16628 VkDescriptorImageInfo image_info = {};
16629 image_info.imageView = view;
16630 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16631
16632 VkWriteDescriptorSet descriptor_write;
16633 memset(&descriptor_write, 0, sizeof(descriptor_write));
16634 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16635 descriptor_write.dstSet = descriptor_set;
16636 descriptor_write.dstBinding = 0;
16637 descriptor_write.descriptorCount = 1;
16638 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16639 descriptor_write.pImageInfo = &image_info;
16640
16641 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16642 // be
16643 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16644 // This will most likely produce a crash if the parameter_validation
16645 // layer
16646 // does not correctly ignore pBufferInfo.
16647 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16648 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16649
16650 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16651
16652 m_errorMonitor->VerifyNotFound();
16653
16654 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16655 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16656 vkDestroyImageView(m_device->device(), view, NULL);
16657 vkDestroyImage(m_device->device(), image, NULL);
16658 vkFreeMemory(m_device->device(), image_memory, NULL);
16659 }
16660
16661 // Buffer Case
16662 {
16663 m_errorMonitor->ExpectSuccess();
16664
16665 VkBuffer buffer;
16666 uint32_t queue_family_index = 0;
16667 VkBufferCreateInfo buffer_create_info = {};
16668 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16669 buffer_create_info.size = 1024;
16670 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16671 buffer_create_info.queueFamilyIndexCount = 1;
16672 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16673
16674 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16675 ASSERT_VK_SUCCESS(err);
16676
16677 VkMemoryRequirements memory_reqs;
16678 VkDeviceMemory buffer_memory;
16679 bool pass;
16680 VkMemoryAllocateInfo memory_info = {};
16681 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16682 memory_info.pNext = NULL;
16683 memory_info.allocationSize = 0;
16684 memory_info.memoryTypeIndex = 0;
16685
16686 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16687 memory_info.allocationSize = memory_reqs.size;
16688 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16689 ASSERT_TRUE(pass);
16690
16691 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16692 ASSERT_VK_SUCCESS(err);
16693 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16694 ASSERT_VK_SUCCESS(err);
16695
16696 VkDescriptorPoolSize ds_type_count = {};
16697 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16698 ds_type_count.descriptorCount = 1;
16699
16700 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16701 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16702 ds_pool_ci.pNext = NULL;
16703 ds_pool_ci.maxSets = 1;
16704 ds_pool_ci.poolSizeCount = 1;
16705 ds_pool_ci.pPoolSizes = &ds_type_count;
16706
16707 VkDescriptorPool ds_pool;
16708 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16709 ASSERT_VK_SUCCESS(err);
16710
16711 VkDescriptorSetLayoutBinding dsl_binding = {};
16712 dsl_binding.binding = 0;
16713 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16714 dsl_binding.descriptorCount = 1;
16715 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16716 dsl_binding.pImmutableSamplers = NULL;
16717
16718 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16719 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16720 ds_layout_ci.pNext = NULL;
16721 ds_layout_ci.bindingCount = 1;
16722 ds_layout_ci.pBindings = &dsl_binding;
16723 VkDescriptorSetLayout ds_layout;
16724 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16725 ASSERT_VK_SUCCESS(err);
16726
16727 VkDescriptorSet descriptor_set;
16728 VkDescriptorSetAllocateInfo alloc_info = {};
16729 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16730 alloc_info.descriptorSetCount = 1;
16731 alloc_info.descriptorPool = ds_pool;
16732 alloc_info.pSetLayouts = &ds_layout;
16733 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16734 ASSERT_VK_SUCCESS(err);
16735
16736 VkDescriptorBufferInfo buffer_info = {};
16737 buffer_info.buffer = buffer;
16738 buffer_info.offset = 0;
16739 buffer_info.range = 1024;
16740
16741 VkWriteDescriptorSet descriptor_write;
16742 memset(&descriptor_write, 0, sizeof(descriptor_write));
16743 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16744 descriptor_write.dstSet = descriptor_set;
16745 descriptor_write.dstBinding = 0;
16746 descriptor_write.descriptorCount = 1;
16747 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16748 descriptor_write.pBufferInfo = &buffer_info;
16749
16750 // Set pImageInfo and pTexelBufferView to invalid values, which should
16751 // be
16752 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16753 // This will most likely produce a crash if the parameter_validation
16754 // layer
16755 // does not correctly ignore pImageInfo.
16756 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16757 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16758
16759 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16760
16761 m_errorMonitor->VerifyNotFound();
16762
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016763 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16764 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16765 vkDestroyBuffer(m_device->device(), buffer, NULL);
16766 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16767 }
16768
16769 // Texel Buffer Case
16770 {
16771 m_errorMonitor->ExpectSuccess();
16772
16773 VkBuffer buffer;
16774 uint32_t queue_family_index = 0;
16775 VkBufferCreateInfo buffer_create_info = {};
16776 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16777 buffer_create_info.size = 1024;
16778 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16779 buffer_create_info.queueFamilyIndexCount = 1;
16780 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16781
16782 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16783 ASSERT_VK_SUCCESS(err);
16784
16785 VkMemoryRequirements memory_reqs;
16786 VkDeviceMemory buffer_memory;
16787 bool pass;
16788 VkMemoryAllocateInfo memory_info = {};
16789 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16790 memory_info.pNext = NULL;
16791 memory_info.allocationSize = 0;
16792 memory_info.memoryTypeIndex = 0;
16793
16794 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16795 memory_info.allocationSize = memory_reqs.size;
16796 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16797 ASSERT_TRUE(pass);
16798
16799 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16800 ASSERT_VK_SUCCESS(err);
16801 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16802 ASSERT_VK_SUCCESS(err);
16803
16804 VkBufferViewCreateInfo buff_view_ci = {};
16805 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16806 buff_view_ci.buffer = buffer;
16807 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16808 buff_view_ci.range = VK_WHOLE_SIZE;
16809 VkBufferView buffer_view;
16810 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16811
16812 VkDescriptorPoolSize ds_type_count = {};
16813 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16814 ds_type_count.descriptorCount = 1;
16815
16816 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16817 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16818 ds_pool_ci.pNext = NULL;
16819 ds_pool_ci.maxSets = 1;
16820 ds_pool_ci.poolSizeCount = 1;
16821 ds_pool_ci.pPoolSizes = &ds_type_count;
16822
16823 VkDescriptorPool ds_pool;
16824 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16825 ASSERT_VK_SUCCESS(err);
16826
16827 VkDescriptorSetLayoutBinding dsl_binding = {};
16828 dsl_binding.binding = 0;
16829 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16830 dsl_binding.descriptorCount = 1;
16831 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16832 dsl_binding.pImmutableSamplers = NULL;
16833
16834 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16835 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16836 ds_layout_ci.pNext = NULL;
16837 ds_layout_ci.bindingCount = 1;
16838 ds_layout_ci.pBindings = &dsl_binding;
16839 VkDescriptorSetLayout ds_layout;
16840 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16841 ASSERT_VK_SUCCESS(err);
16842
16843 VkDescriptorSet descriptor_set;
16844 VkDescriptorSetAllocateInfo alloc_info = {};
16845 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16846 alloc_info.descriptorSetCount = 1;
16847 alloc_info.descriptorPool = ds_pool;
16848 alloc_info.pSetLayouts = &ds_layout;
16849 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16850 ASSERT_VK_SUCCESS(err);
16851
16852 VkWriteDescriptorSet descriptor_write;
16853 memset(&descriptor_write, 0, sizeof(descriptor_write));
16854 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16855 descriptor_write.dstSet = descriptor_set;
16856 descriptor_write.dstBinding = 0;
16857 descriptor_write.descriptorCount = 1;
16858 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16859 descriptor_write.pTexelBufferView = &buffer_view;
16860
16861 // Set pImageInfo and pBufferInfo to invalid values, which should be
16862 // ignored for descriptorType ==
16863 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16864 // This will most likely produce a crash if the parameter_validation
16865 // layer
16866 // does not correctly ignore pImageInfo and pBufferInfo.
16867 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16868 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16869
16870 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16871
16872 m_errorMonitor->VerifyNotFound();
16873
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016874 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16875 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16876 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16877 vkDestroyBuffer(m_device->device(), buffer, NULL);
16878 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16879 }
16880}
16881
Tobin Ehlisf7428442016-10-25 07:58:24 -060016882TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16883 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16884
16885 ASSERT_NO_FATAL_FAILURE(InitState());
16886 // Create layout where two binding #s are "1"
16887 static const uint32_t NUM_BINDINGS = 3;
16888 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16889 dsl_binding[0].binding = 1;
16890 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16891 dsl_binding[0].descriptorCount = 1;
16892 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16893 dsl_binding[0].pImmutableSamplers = NULL;
16894 dsl_binding[1].binding = 0;
16895 dsl_binding[1].descriptorCount = 1;
16896 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16897 dsl_binding[1].descriptorCount = 1;
16898 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16899 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016900 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060016901 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16902 dsl_binding[2].descriptorCount = 1;
16903 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16904 dsl_binding[2].pImmutableSamplers = NULL;
16905
16906 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16907 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16908 ds_layout_ci.pNext = NULL;
16909 ds_layout_ci.bindingCount = NUM_BINDINGS;
16910 ds_layout_ci.pBindings = dsl_binding;
16911 VkDescriptorSetLayout ds_layout;
16912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16913 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16914 m_errorMonitor->VerifyFound();
16915}
16916
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016917TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016918 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16919
16920 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016921
Tony Barbour552f6c02016-12-21 14:34:07 -070016922 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016923
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016924 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16925
16926 {
16927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16928 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16929 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16930 m_errorMonitor->VerifyFound();
16931 }
16932
16933 {
16934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16935 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16936 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16937 m_errorMonitor->VerifyFound();
16938 }
16939
16940 {
16941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16942 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16943 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16944 m_errorMonitor->VerifyFound();
16945 }
16946
16947 {
16948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16949 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16950 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16951 m_errorMonitor->VerifyFound();
16952 }
16953
16954 {
16955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16956 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16957 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16958 m_errorMonitor->VerifyFound();
16959 }
16960
16961 {
16962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16963 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16964 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16965 m_errorMonitor->VerifyFound();
16966 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016967
16968 {
16969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16970 VkRect2D scissor = {{-1, 0}, {16, 16}};
16971 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16972 m_errorMonitor->VerifyFound();
16973 }
16974
16975 {
16976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16977 VkRect2D scissor = {{0, -2}, {16, 16}};
16978 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16979 m_errorMonitor->VerifyFound();
16980 }
16981
16982 {
16983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16984 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16985 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16986 m_errorMonitor->VerifyFound();
16987 }
16988
16989 {
16990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16991 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16992 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16993 m_errorMonitor->VerifyFound();
16994 }
16995
Tony Barbour552f6c02016-12-21 14:34:07 -070016996 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016997}
16998
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016999// This is a positive test. No failures are expected.
17000TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
17001 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
17002 VkResult err;
17003
17004 ASSERT_NO_FATAL_FAILURE(InitState());
17005 m_errorMonitor->ExpectSuccess();
17006 VkDescriptorPoolSize ds_type_count = {};
17007 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17008 ds_type_count.descriptorCount = 2;
17009
17010 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17011 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17012 ds_pool_ci.pNext = NULL;
17013 ds_pool_ci.maxSets = 1;
17014 ds_pool_ci.poolSizeCount = 1;
17015 ds_pool_ci.pPoolSizes = &ds_type_count;
17016
17017 VkDescriptorPool ds_pool;
17018 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17019 ASSERT_VK_SUCCESS(err);
17020
17021 // Create layout with two uniform buffer descriptors w/ empty binding between them
17022 static const uint32_t NUM_BINDINGS = 3;
17023 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17024 dsl_binding[0].binding = 0;
17025 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17026 dsl_binding[0].descriptorCount = 1;
17027 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
17028 dsl_binding[0].pImmutableSamplers = NULL;
17029 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017030 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017031 dsl_binding[2].binding = 2;
17032 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17033 dsl_binding[2].descriptorCount = 1;
17034 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
17035 dsl_binding[2].pImmutableSamplers = NULL;
17036
17037 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17038 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17039 ds_layout_ci.pNext = NULL;
17040 ds_layout_ci.bindingCount = NUM_BINDINGS;
17041 ds_layout_ci.pBindings = dsl_binding;
17042 VkDescriptorSetLayout ds_layout;
17043 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17044 ASSERT_VK_SUCCESS(err);
17045
17046 VkDescriptorSet descriptor_set = {};
17047 VkDescriptorSetAllocateInfo alloc_info = {};
17048 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17049 alloc_info.descriptorSetCount = 1;
17050 alloc_info.descriptorPool = ds_pool;
17051 alloc_info.pSetLayouts = &ds_layout;
17052 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17053 ASSERT_VK_SUCCESS(err);
17054
17055 // Create a buffer to be used for update
17056 VkBufferCreateInfo buff_ci = {};
17057 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17058 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17059 buff_ci.size = 256;
17060 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17061 VkBuffer buffer;
17062 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
17063 ASSERT_VK_SUCCESS(err);
17064 // Have to bind memory to buffer before descriptor update
17065 VkMemoryAllocateInfo mem_alloc = {};
17066 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17067 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017068 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017069 mem_alloc.memoryTypeIndex = 0;
17070
17071 VkMemoryRequirements mem_reqs;
17072 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17073 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
17074 if (!pass) {
17075 vkDestroyBuffer(m_device->device(), buffer, NULL);
17076 return;
17077 }
17078
17079 VkDeviceMemory mem;
17080 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17081 ASSERT_VK_SUCCESS(err);
17082 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17083 ASSERT_VK_SUCCESS(err);
17084
17085 // Only update the descriptor at binding 2
17086 VkDescriptorBufferInfo buff_info = {};
17087 buff_info.buffer = buffer;
17088 buff_info.offset = 0;
17089 buff_info.range = VK_WHOLE_SIZE;
17090 VkWriteDescriptorSet descriptor_write = {};
17091 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17092 descriptor_write.dstBinding = 2;
17093 descriptor_write.descriptorCount = 1;
17094 descriptor_write.pTexelBufferView = nullptr;
17095 descriptor_write.pBufferInfo = &buff_info;
17096 descriptor_write.pImageInfo = nullptr;
17097 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17098 descriptor_write.dstSet = descriptor_set;
17099
17100 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17101
17102 m_errorMonitor->VerifyNotFound();
17103 // Cleanup
17104 vkFreeMemory(m_device->device(), mem, NULL);
17105 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17106 vkDestroyBuffer(m_device->device(), buffer, NULL);
17107 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17108}
17109
17110// This is a positive test. No failures are expected.
17111TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
17112 VkResult err;
17113 bool pass;
17114
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017115 TEST_DESCRIPTION(
17116 "Create a buffer, allocate memory, bind memory, destroy "
17117 "the buffer, create an image, and bind the same memory to "
17118 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017119
17120 m_errorMonitor->ExpectSuccess();
17121
17122 ASSERT_NO_FATAL_FAILURE(InitState());
17123
17124 VkBuffer buffer;
17125 VkImage image;
17126 VkDeviceMemory mem;
17127 VkMemoryRequirements mem_reqs;
17128
17129 VkBufferCreateInfo buf_info = {};
17130 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17131 buf_info.pNext = NULL;
17132 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17133 buf_info.size = 256;
17134 buf_info.queueFamilyIndexCount = 0;
17135 buf_info.pQueueFamilyIndices = NULL;
17136 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17137 buf_info.flags = 0;
17138 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
17139 ASSERT_VK_SUCCESS(err);
17140
17141 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17142
17143 VkMemoryAllocateInfo alloc_info = {};
17144 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17145 alloc_info.pNext = NULL;
17146 alloc_info.memoryTypeIndex = 0;
17147
17148 // Ensure memory is big enough for both bindings
17149 alloc_info.allocationSize = 0x10000;
17150
17151 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17152 if (!pass) {
17153 vkDestroyBuffer(m_device->device(), buffer, NULL);
17154 return;
17155 }
17156
17157 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17158 ASSERT_VK_SUCCESS(err);
17159
17160 uint8_t *pData;
17161 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
17162 ASSERT_VK_SUCCESS(err);
17163
17164 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
17165
17166 vkUnmapMemory(m_device->device(), mem);
17167
17168 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17169 ASSERT_VK_SUCCESS(err);
17170
17171 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
17172 // memory. In fact, it was never used by the GPU.
17173 // Just be be sure, wait for idle.
17174 vkDestroyBuffer(m_device->device(), buffer, NULL);
17175 vkDeviceWaitIdle(m_device->device());
17176
Tobin Ehlis6a005702016-12-28 15:25:56 -070017177 // Use optimal as some platforms report linear support but then fail image creation
17178 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
17179 VkImageFormatProperties image_format_properties;
17180 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
17181 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
17182 if (image_format_properties.maxExtent.width == 0) {
17183 printf("Image format not supported; skipped.\n");
17184 vkFreeMemory(m_device->device(), mem, NULL);
17185 return;
17186 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017187 VkImageCreateInfo image_create_info = {};
17188 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17189 image_create_info.pNext = NULL;
17190 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17191 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
17192 image_create_info.extent.width = 64;
17193 image_create_info.extent.height = 64;
17194 image_create_info.extent.depth = 1;
17195 image_create_info.mipLevels = 1;
17196 image_create_info.arrayLayers = 1;
17197 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070017198 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017199 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
17200 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17201 image_create_info.queueFamilyIndexCount = 0;
17202 image_create_info.pQueueFamilyIndices = NULL;
17203 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17204 image_create_info.flags = 0;
17205
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017206 /* Create a mappable image. It will be the texture if linear images are ok
17207 * to be textures or it will be the staging image if they are not.
17208 */
17209 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17210 ASSERT_VK_SUCCESS(err);
17211
17212 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
17213
Tobin Ehlis6a005702016-12-28 15:25:56 -070017214 VkMemoryAllocateInfo mem_alloc = {};
17215 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17216 mem_alloc.pNext = NULL;
17217 mem_alloc.allocationSize = 0;
17218 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017219 mem_alloc.allocationSize = mem_reqs.size;
17220
17221 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17222 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070017223 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017224 vkDestroyImage(m_device->device(), image, NULL);
17225 return;
17226 }
17227
17228 // VALIDATION FAILURE:
17229 err = vkBindImageMemory(m_device->device(), image, mem, 0);
17230 ASSERT_VK_SUCCESS(err);
17231
17232 m_errorMonitor->VerifyNotFound();
17233
17234 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017235 vkDestroyImage(m_device->device(), image, NULL);
17236}
17237
Tobin Ehlis953e8392016-11-17 10:54:13 -070017238TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
17239 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
17240 // We previously had a bug where dynamic offset of inactive bindings was still being used
17241 VkResult err;
17242 m_errorMonitor->ExpectSuccess();
17243
17244 ASSERT_NO_FATAL_FAILURE(InitState());
17245 ASSERT_NO_FATAL_FAILURE(InitViewport());
17246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17247
17248 VkDescriptorPoolSize ds_type_count = {};
17249 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17250 ds_type_count.descriptorCount = 3;
17251
17252 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17253 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17254 ds_pool_ci.pNext = NULL;
17255 ds_pool_ci.maxSets = 1;
17256 ds_pool_ci.poolSizeCount = 1;
17257 ds_pool_ci.pPoolSizes = &ds_type_count;
17258
17259 VkDescriptorPool ds_pool;
17260 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17261 ASSERT_VK_SUCCESS(err);
17262
17263 const uint32_t BINDING_COUNT = 3;
17264 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017265 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017266 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17267 dsl_binding[0].descriptorCount = 1;
17268 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17269 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017270 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017271 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17272 dsl_binding[1].descriptorCount = 1;
17273 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17274 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017275 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017276 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17277 dsl_binding[2].descriptorCount = 1;
17278 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17279 dsl_binding[2].pImmutableSamplers = NULL;
17280
17281 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17282 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17283 ds_layout_ci.pNext = NULL;
17284 ds_layout_ci.bindingCount = BINDING_COUNT;
17285 ds_layout_ci.pBindings = dsl_binding;
17286 VkDescriptorSetLayout ds_layout;
17287 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17288 ASSERT_VK_SUCCESS(err);
17289
17290 VkDescriptorSet descriptor_set;
17291 VkDescriptorSetAllocateInfo alloc_info = {};
17292 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17293 alloc_info.descriptorSetCount = 1;
17294 alloc_info.descriptorPool = ds_pool;
17295 alloc_info.pSetLayouts = &ds_layout;
17296 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17297 ASSERT_VK_SUCCESS(err);
17298
17299 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17300 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17301 pipeline_layout_ci.pNext = NULL;
17302 pipeline_layout_ci.setLayoutCount = 1;
17303 pipeline_layout_ci.pSetLayouts = &ds_layout;
17304
17305 VkPipelineLayout pipeline_layout;
17306 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17307 ASSERT_VK_SUCCESS(err);
17308
17309 // Create two buffers to update the descriptors with
17310 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17311 uint32_t qfi = 0;
17312 VkBufferCreateInfo buffCI = {};
17313 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17314 buffCI.size = 2048;
17315 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17316 buffCI.queueFamilyIndexCount = 1;
17317 buffCI.pQueueFamilyIndices = &qfi;
17318
17319 VkBuffer dyub1;
17320 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17321 ASSERT_VK_SUCCESS(err);
17322 // buffer2
17323 buffCI.size = 1024;
17324 VkBuffer dyub2;
17325 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17326 ASSERT_VK_SUCCESS(err);
17327 // Allocate memory and bind to buffers
17328 VkMemoryAllocateInfo mem_alloc[2] = {};
17329 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17330 mem_alloc[0].pNext = NULL;
17331 mem_alloc[0].memoryTypeIndex = 0;
17332 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17333 mem_alloc[1].pNext = NULL;
17334 mem_alloc[1].memoryTypeIndex = 0;
17335
17336 VkMemoryRequirements mem_reqs1;
17337 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17338 VkMemoryRequirements mem_reqs2;
17339 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17340 mem_alloc[0].allocationSize = mem_reqs1.size;
17341 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17342 mem_alloc[1].allocationSize = mem_reqs2.size;
17343 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17344 if (!pass) {
17345 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17346 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17347 return;
17348 }
17349
17350 VkDeviceMemory mem1;
17351 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17352 ASSERT_VK_SUCCESS(err);
17353 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17354 ASSERT_VK_SUCCESS(err);
17355 VkDeviceMemory mem2;
17356 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17357 ASSERT_VK_SUCCESS(err);
17358 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17359 ASSERT_VK_SUCCESS(err);
17360 // Update descriptors
17361 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17362 buff_info[0].buffer = dyub1;
17363 buff_info[0].offset = 0;
17364 buff_info[0].range = 256;
17365 buff_info[1].buffer = dyub1;
17366 buff_info[1].offset = 256;
17367 buff_info[1].range = 512;
17368 buff_info[2].buffer = dyub2;
17369 buff_info[2].offset = 0;
17370 buff_info[2].range = 512;
17371
17372 VkWriteDescriptorSet descriptor_write;
17373 memset(&descriptor_write, 0, sizeof(descriptor_write));
17374 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17375 descriptor_write.dstSet = descriptor_set;
17376 descriptor_write.dstBinding = 0;
17377 descriptor_write.descriptorCount = BINDING_COUNT;
17378 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17379 descriptor_write.pBufferInfo = buff_info;
17380
17381 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17382
Tony Barbour552f6c02016-12-21 14:34:07 -070017383 m_commandBuffer->BeginCommandBuffer();
17384 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017385
17386 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017387 char const *vsSource =
17388 "#version 450\n"
17389 "\n"
17390 "out gl_PerVertex { \n"
17391 " vec4 gl_Position;\n"
17392 "};\n"
17393 "void main(){\n"
17394 " gl_Position = vec4(1);\n"
17395 "}\n";
17396 char const *fsSource =
17397 "#version 450\n"
17398 "\n"
17399 "layout(location=0) out vec4 x;\n"
17400 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17401 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17402 "void main(){\n"
17403 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17404 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070017405 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17406 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17407 VkPipelineObj pipe(m_device);
17408 pipe.SetViewport(m_viewports);
17409 pipe.SetScissor(m_scissors);
17410 pipe.AddShader(&vs);
17411 pipe.AddShader(&fs);
17412 pipe.AddColorAttachment();
17413 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17414
17415 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17416 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17417 // we used to have a bug in this case.
17418 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17419 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17420 &descriptor_set, BINDING_COUNT, dyn_off);
17421 Draw(1, 0, 0, 0);
17422 m_errorMonitor->VerifyNotFound();
17423
17424 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17425 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17426 vkFreeMemory(m_device->device(), mem1, NULL);
17427 vkFreeMemory(m_device->device(), mem2, NULL);
17428
17429 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17430 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17431 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17432}
17433
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017434TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017435 TEST_DESCRIPTION(
17436 "Ensure that validations handling of non-coherent memory "
17437 "mapping while using VK_WHOLE_SIZE does not cause access "
17438 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017439 VkResult err;
17440 uint8_t *pData;
17441 ASSERT_NO_FATAL_FAILURE(InitState());
17442
17443 VkDeviceMemory mem;
17444 VkMemoryRequirements mem_reqs;
17445 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017446 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017447 VkMemoryAllocateInfo alloc_info = {};
17448 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17449 alloc_info.pNext = NULL;
17450 alloc_info.memoryTypeIndex = 0;
17451
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017452 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017453 alloc_info.allocationSize = allocation_size;
17454
17455 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17456 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 -070017457 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017458 if (!pass) {
17459 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017460 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17461 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017462 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017463 pass = m_device->phy().set_memory_type(
17464 mem_reqs.memoryTypeBits, &alloc_info,
17465 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17466 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017467 if (!pass) {
17468 return;
17469 }
17470 }
17471 }
17472
17473 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17474 ASSERT_VK_SUCCESS(err);
17475
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017476 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017477 m_errorMonitor->ExpectSuccess();
17478 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17479 ASSERT_VK_SUCCESS(err);
17480 VkMappedMemoryRange mmr = {};
17481 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17482 mmr.memory = mem;
17483 mmr.offset = 0;
17484 mmr.size = VK_WHOLE_SIZE;
17485 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17486 ASSERT_VK_SUCCESS(err);
17487 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17488 ASSERT_VK_SUCCESS(err);
17489 m_errorMonitor->VerifyNotFound();
17490 vkUnmapMemory(m_device->device(), mem);
17491
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017492 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017493 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017494 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017495 ASSERT_VK_SUCCESS(err);
17496 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17497 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017498 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017499 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 with offset and size
17508 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017509 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017510 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017511 ASSERT_VK_SUCCESS(err);
17512 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17513 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017514 mmr.offset = 4 * atom_size;
17515 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017516 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17517 ASSERT_VK_SUCCESS(err);
17518 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17519 ASSERT_VK_SUCCESS(err);
17520 m_errorMonitor->VerifyNotFound();
17521 vkUnmapMemory(m_device->device(), mem);
17522
17523 // Map without offset and flush WHOLE_SIZE with two separate offsets
17524 m_errorMonitor->ExpectSuccess();
17525 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17526 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 = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017530 mmr.size = VK_WHOLE_SIZE;
17531 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17532 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017533 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017534 mmr.size = VK_WHOLE_SIZE;
17535 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17536 ASSERT_VK_SUCCESS(err);
17537 m_errorMonitor->VerifyNotFound();
17538 vkUnmapMemory(m_device->device(), mem);
17539
17540 vkFreeMemory(m_device->device(), mem, NULL);
17541}
17542
17543// This is a positive test. We used to expect error in this case but spec now allows it
17544TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17545 m_errorMonitor->ExpectSuccess();
17546 vk_testing::Fence testFence;
17547 VkFenceCreateInfo fenceInfo = {};
17548 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17549 fenceInfo.pNext = NULL;
17550
17551 ASSERT_NO_FATAL_FAILURE(InitState());
17552 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017553 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017554 VkResult result = vkResetFences(m_device->device(), 1, fences);
17555 ASSERT_VK_SUCCESS(result);
17556
17557 m_errorMonitor->VerifyNotFound();
17558}
17559
17560TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17561 m_errorMonitor->ExpectSuccess();
17562
17563 ASSERT_NO_FATAL_FAILURE(InitState());
17564 VkResult err;
17565
17566 // Record (empty!) command buffer that can be submitted multiple times
17567 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017568 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17569 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017570 m_commandBuffer->BeginCommandBuffer(&cbbi);
17571 m_commandBuffer->EndCommandBuffer();
17572
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017573 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017574 VkFence fence;
17575 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17576 ASSERT_VK_SUCCESS(err);
17577
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017578 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017579 VkSemaphore s1, s2;
17580 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17581 ASSERT_VK_SUCCESS(err);
17582 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17583 ASSERT_VK_SUCCESS(err);
17584
17585 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017586 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017587 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17588 ASSERT_VK_SUCCESS(err);
17589
17590 // Submit CB again, signaling s2.
17591 si.pSignalSemaphores = &s2;
17592 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17593 ASSERT_VK_SUCCESS(err);
17594
17595 // Wait for fence.
17596 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17597 ASSERT_VK_SUCCESS(err);
17598
17599 // CB is still in flight from second submission, but semaphore s1 is no
17600 // longer in flight. delete it.
17601 vkDestroySemaphore(m_device->device(), s1, nullptr);
17602
17603 m_errorMonitor->VerifyNotFound();
17604
17605 // Force device idle and clean up remaining objects
17606 vkDeviceWaitIdle(m_device->device());
17607 vkDestroySemaphore(m_device->device(), s2, nullptr);
17608 vkDestroyFence(m_device->device(), fence, nullptr);
17609}
17610
17611TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17612 m_errorMonitor->ExpectSuccess();
17613
17614 ASSERT_NO_FATAL_FAILURE(InitState());
17615 VkResult err;
17616
17617 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017618 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017619 VkFence f1;
17620 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17621 ASSERT_VK_SUCCESS(err);
17622
17623 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017624 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017625 VkFence f2;
17626 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17627 ASSERT_VK_SUCCESS(err);
17628
17629 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017630 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017631 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17632
17633 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017634 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017635 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17636
17637 // Should have both retired!
17638 vkDestroyFence(m_device->device(), f1, nullptr);
17639 vkDestroyFence(m_device->device(), f2, nullptr);
17640
17641 m_errorMonitor->VerifyNotFound();
17642}
17643
17644TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017645 TEST_DESCRIPTION(
17646 "Verify that creating an image view from an image with valid usage "
17647 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017648
17649 ASSERT_NO_FATAL_FAILURE(InitState());
17650
17651 m_errorMonitor->ExpectSuccess();
17652 // Verify that we can create a view with usage INPUT_ATTACHMENT
17653 VkImageObj image(m_device);
17654 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17655 ASSERT_TRUE(image.initialized());
17656 VkImageView imageView;
17657 VkImageViewCreateInfo ivci = {};
17658 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17659 ivci.image = image.handle();
17660 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17661 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17662 ivci.subresourceRange.layerCount = 1;
17663 ivci.subresourceRange.baseMipLevel = 0;
17664 ivci.subresourceRange.levelCount = 1;
17665 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17666
17667 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17668 m_errorMonitor->VerifyNotFound();
17669 vkDestroyImageView(m_device->device(), imageView, NULL);
17670}
17671
17672// This is a positive test. No failures are expected.
17673TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017674 TEST_DESCRIPTION(
17675 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17676 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017677
17678 ASSERT_NO_FATAL_FAILURE(InitState());
17679
17680 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017681 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017682
17683 m_errorMonitor->ExpectSuccess();
17684
17685 VkImage image;
17686 VkImageCreateInfo image_create_info = {};
17687 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17688 image_create_info.pNext = NULL;
17689 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17690 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17691 image_create_info.extent.width = 64;
17692 image_create_info.extent.height = 64;
17693 image_create_info.extent.depth = 1;
17694 image_create_info.mipLevels = 1;
17695 image_create_info.arrayLayers = 1;
17696 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17697 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17698 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17699 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17700 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17701 ASSERT_VK_SUCCESS(err);
17702
17703 VkMemoryRequirements memory_reqs;
17704 VkDeviceMemory memory_one, memory_two;
17705 bool pass;
17706 VkMemoryAllocateInfo memory_info = {};
17707 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17708 memory_info.pNext = NULL;
17709 memory_info.allocationSize = 0;
17710 memory_info.memoryTypeIndex = 0;
17711 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17712 // Find an image big enough to allow sparse mapping of 2 memory regions
17713 // Increase the image size until it is at least twice the
17714 // size of the required alignment, to ensure we can bind both
17715 // allocated memory blocks to the image on aligned offsets.
17716 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17717 vkDestroyImage(m_device->device(), image, nullptr);
17718 image_create_info.extent.width *= 2;
17719 image_create_info.extent.height *= 2;
17720 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17721 ASSERT_VK_SUCCESS(err);
17722 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17723 }
17724 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17725 // at the end of the first
17726 memory_info.allocationSize = memory_reqs.alignment;
17727 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17728 ASSERT_TRUE(pass);
17729 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17730 ASSERT_VK_SUCCESS(err);
17731 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17732 ASSERT_VK_SUCCESS(err);
17733 VkSparseMemoryBind binds[2];
17734 binds[0].flags = 0;
17735 binds[0].memory = memory_one;
17736 binds[0].memoryOffset = 0;
17737 binds[0].resourceOffset = 0;
17738 binds[0].size = memory_info.allocationSize;
17739 binds[1].flags = 0;
17740 binds[1].memory = memory_two;
17741 binds[1].memoryOffset = 0;
17742 binds[1].resourceOffset = memory_info.allocationSize;
17743 binds[1].size = memory_info.allocationSize;
17744
17745 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17746 opaqueBindInfo.image = image;
17747 opaqueBindInfo.bindCount = 2;
17748 opaqueBindInfo.pBinds = binds;
17749
17750 VkFence fence = VK_NULL_HANDLE;
17751 VkBindSparseInfo bindSparseInfo = {};
17752 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17753 bindSparseInfo.imageOpaqueBindCount = 1;
17754 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17755
17756 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17757 vkQueueWaitIdle(m_device->m_queue);
17758 vkDestroyImage(m_device->device(), image, NULL);
17759 vkFreeMemory(m_device->device(), memory_one, NULL);
17760 vkFreeMemory(m_device->device(), memory_two, NULL);
17761 m_errorMonitor->VerifyNotFound();
17762}
17763
17764TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017765 TEST_DESCRIPTION(
17766 "Ensure that CmdBeginRenderPass with an attachment's "
17767 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17768 "the command buffer has prior knowledge of that "
17769 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017770
17771 m_errorMonitor->ExpectSuccess();
17772
17773 ASSERT_NO_FATAL_FAILURE(InitState());
17774
17775 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017776 VkAttachmentDescription attachment = {0,
17777 VK_FORMAT_R8G8B8A8_UNORM,
17778 VK_SAMPLE_COUNT_1_BIT,
17779 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17780 VK_ATTACHMENT_STORE_OP_STORE,
17781 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17782 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17783 VK_IMAGE_LAYOUT_UNDEFINED,
17784 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017785
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017786 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017787
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017788 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017789
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017790 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017791
17792 VkRenderPass rp;
17793 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17794 ASSERT_VK_SUCCESS(err);
17795
17796 // A compatible framebuffer.
17797 VkImageObj image(m_device);
17798 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17799 ASSERT_TRUE(image.initialized());
17800
17801 VkImageViewCreateInfo ivci = {
17802 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17803 nullptr,
17804 0,
17805 image.handle(),
17806 VK_IMAGE_VIEW_TYPE_2D,
17807 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017808 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17809 VK_COMPONENT_SWIZZLE_IDENTITY},
17810 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017811 };
17812 VkImageView view;
17813 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17814 ASSERT_VK_SUCCESS(err);
17815
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017816 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017817 VkFramebuffer fb;
17818 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17819 ASSERT_VK_SUCCESS(err);
17820
17821 // Record a single command buffer which uses this renderpass twice. The
17822 // bug is triggered at the beginning of the second renderpass, when the
17823 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017824 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 -070017825 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017826 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17827 vkCmdEndRenderPass(m_commandBuffer->handle());
17828 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17829
17830 m_errorMonitor->VerifyNotFound();
17831
17832 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017833 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017834
17835 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17836 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17837 vkDestroyImageView(m_device->device(), view, nullptr);
17838}
17839
17840TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017841 TEST_DESCRIPTION(
17842 "This test should pass. Create a Framebuffer and "
17843 "command buffer, bind them together, then destroy "
17844 "command pool and framebuffer and verify there are no "
17845 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017846
17847 m_errorMonitor->ExpectSuccess();
17848
17849 ASSERT_NO_FATAL_FAILURE(InitState());
17850
17851 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017852 VkAttachmentDescription attachment = {0,
17853 VK_FORMAT_R8G8B8A8_UNORM,
17854 VK_SAMPLE_COUNT_1_BIT,
17855 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17856 VK_ATTACHMENT_STORE_OP_STORE,
17857 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17858 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17859 VK_IMAGE_LAYOUT_UNDEFINED,
17860 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017861
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017862 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017863
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017864 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017865
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017866 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017867
17868 VkRenderPass rp;
17869 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17870 ASSERT_VK_SUCCESS(err);
17871
17872 // A compatible framebuffer.
17873 VkImageObj image(m_device);
17874 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17875 ASSERT_TRUE(image.initialized());
17876
17877 VkImageViewCreateInfo ivci = {
17878 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17879 nullptr,
17880 0,
17881 image.handle(),
17882 VK_IMAGE_VIEW_TYPE_2D,
17883 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017884 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17885 VK_COMPONENT_SWIZZLE_IDENTITY},
17886 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017887 };
17888 VkImageView view;
17889 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17890 ASSERT_VK_SUCCESS(err);
17891
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017892 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017893 VkFramebuffer fb;
17894 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17895 ASSERT_VK_SUCCESS(err);
17896
17897 // Explicitly create a command buffer to bind the FB to so that we can then
17898 // destroy the command pool in order to implicitly free command buffer
17899 VkCommandPool command_pool;
17900 VkCommandPoolCreateInfo pool_create_info{};
17901 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17902 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17903 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17904 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17905
17906 VkCommandBuffer command_buffer;
17907 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17908 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17909 command_buffer_allocate_info.commandPool = command_pool;
17910 command_buffer_allocate_info.commandBufferCount = 1;
17911 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17912 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17913
17914 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017915 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 -060017916 VkCommandBufferBeginInfo begin_info{};
17917 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17918 vkBeginCommandBuffer(command_buffer, &begin_info);
17919
17920 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17921 vkCmdEndRenderPass(command_buffer);
17922 vkEndCommandBuffer(command_buffer);
17923 vkDestroyImageView(m_device->device(), view, nullptr);
17924 // Destroy command pool to implicitly free command buffer
17925 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17926 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17927 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17928 m_errorMonitor->VerifyNotFound();
17929}
17930
17931TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017932 TEST_DESCRIPTION(
17933 "Ensure that CmdBeginRenderPass applies the layout "
17934 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017935
17936 m_errorMonitor->ExpectSuccess();
17937
17938 ASSERT_NO_FATAL_FAILURE(InitState());
17939
17940 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017941 VkAttachmentDescription attachment = {0,
17942 VK_FORMAT_R8G8B8A8_UNORM,
17943 VK_SAMPLE_COUNT_1_BIT,
17944 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17945 VK_ATTACHMENT_STORE_OP_STORE,
17946 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17947 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17948 VK_IMAGE_LAYOUT_UNDEFINED,
17949 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017950
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017951 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017952
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017953 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017954
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017955 VkSubpassDependency dep = {0,
17956 0,
17957 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17958 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17959 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17960 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17961 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017962
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017963 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017964
17965 VkResult err;
17966 VkRenderPass rp;
17967 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17968 ASSERT_VK_SUCCESS(err);
17969
17970 // A compatible framebuffer.
17971 VkImageObj image(m_device);
17972 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17973 ASSERT_TRUE(image.initialized());
17974
17975 VkImageViewCreateInfo ivci = {
17976 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17977 nullptr,
17978 0,
17979 image.handle(),
17980 VK_IMAGE_VIEW_TYPE_2D,
17981 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017982 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17983 VK_COMPONENT_SWIZZLE_IDENTITY},
17984 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017985 };
17986 VkImageView view;
17987 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17988 ASSERT_VK_SUCCESS(err);
17989
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017990 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017991 VkFramebuffer fb;
17992 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17993 ASSERT_VK_SUCCESS(err);
17994
17995 // Record a single command buffer which issues a pipeline barrier w/
17996 // image memory barrier for the attachment. This detects the previously
17997 // missing tracking of the subpass layout by throwing a validation error
17998 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017999 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 -070018000 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018001 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18002
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018003 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
18004 nullptr,
18005 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18006 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18007 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18008 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18009 VK_QUEUE_FAMILY_IGNORED,
18010 VK_QUEUE_FAMILY_IGNORED,
18011 image.handle(),
18012 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018013 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018014 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18015 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018016
18017 vkCmdEndRenderPass(m_commandBuffer->handle());
18018 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018019 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018020
18021 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18022 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18023 vkDestroyImageView(m_device->device(), view, nullptr);
18024}
18025
18026TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018027 TEST_DESCRIPTION(
18028 "Validate that when an imageView of a depth/stencil image "
18029 "is used as a depth/stencil framebuffer attachment, the "
18030 "aspectMask is ignored and both depth and stencil image "
18031 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018032
18033 VkFormatProperties format_properties;
18034 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
18035 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
18036 return;
18037 }
18038
18039 m_errorMonitor->ExpectSuccess();
18040
18041 ASSERT_NO_FATAL_FAILURE(InitState());
18042
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018043 VkAttachmentDescription attachment = {0,
18044 VK_FORMAT_D32_SFLOAT_S8_UINT,
18045 VK_SAMPLE_COUNT_1_BIT,
18046 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18047 VK_ATTACHMENT_STORE_OP_STORE,
18048 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18049 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18050 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
18051 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018052
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018053 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018054
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018055 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018056
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018057 VkSubpassDependency dep = {0,
18058 0,
18059 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18060 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18061 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18062 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18063 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018064
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018065 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018066
18067 VkResult err;
18068 VkRenderPass rp;
18069 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18070 ASSERT_VK_SUCCESS(err);
18071
18072 VkImageObj image(m_device);
18073 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018074 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018075 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018076 ASSERT_TRUE(image.initialized());
18077 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
18078
18079 VkImageViewCreateInfo ivci = {
18080 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18081 nullptr,
18082 0,
18083 image.handle(),
18084 VK_IMAGE_VIEW_TYPE_2D,
18085 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018086 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
18087 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018088 };
18089 VkImageView view;
18090 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18091 ASSERT_VK_SUCCESS(err);
18092
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018093 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018094 VkFramebuffer fb;
18095 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18096 ASSERT_VK_SUCCESS(err);
18097
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018098 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 -070018099 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018100 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18101
18102 VkImageMemoryBarrier imb = {};
18103 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18104 imb.pNext = nullptr;
18105 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18106 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18107 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18108 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18109 imb.srcQueueFamilyIndex = 0;
18110 imb.dstQueueFamilyIndex = 0;
18111 imb.image = image.handle();
18112 imb.subresourceRange.aspectMask = 0x6;
18113 imb.subresourceRange.baseMipLevel = 0;
18114 imb.subresourceRange.levelCount = 0x1;
18115 imb.subresourceRange.baseArrayLayer = 0;
18116 imb.subresourceRange.layerCount = 0x1;
18117
18118 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018119 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18120 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018121
18122 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018123 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018124 QueueCommandBuffer(false);
18125 m_errorMonitor->VerifyNotFound();
18126
18127 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18128 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18129 vkDestroyImageView(m_device->device(), view, nullptr);
18130}
18131
18132TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018133 TEST_DESCRIPTION(
18134 "Ensure that layout transitions work correctly without "
18135 "errors, when an attachment reference is "
18136 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018137
18138 m_errorMonitor->ExpectSuccess();
18139
18140 ASSERT_NO_FATAL_FAILURE(InitState());
18141
18142 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018143 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018144
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018145 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018146
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018147 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018148
18149 VkRenderPass rp;
18150 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18151 ASSERT_VK_SUCCESS(err);
18152
18153 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018154 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018155 VkFramebuffer fb;
18156 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18157 ASSERT_VK_SUCCESS(err);
18158
18159 // Record a command buffer which just begins and ends the renderpass. The
18160 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018161 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 -070018162 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018163 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18164 vkCmdEndRenderPass(m_commandBuffer->handle());
18165 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018166 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018167
18168 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18169 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18170}
18171
18172// This is a positive test. No errors are expected.
18173TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018174 TEST_DESCRIPTION(
18175 "Create a stencil-only attachment with a LOAD_OP set to "
18176 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018177 VkResult result = VK_SUCCESS;
18178 VkImageFormatProperties formatProps;
18179 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018180 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
18181 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018182 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
18183 return;
18184 }
18185
18186 ASSERT_NO_FATAL_FAILURE(InitState());
18187 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
18188 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018189 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018190 VkAttachmentDescription att = {};
18191 VkAttachmentReference ref = {};
18192 att.format = depth_stencil_fmt;
18193 att.samples = VK_SAMPLE_COUNT_1_BIT;
18194 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
18195 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18196 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18197 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
18198 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18199 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18200
18201 VkClearValue clear;
18202 clear.depthStencil.depth = 1.0;
18203 clear.depthStencil.stencil = 0;
18204 ref.attachment = 0;
18205 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18206
18207 VkSubpassDescription subpass = {};
18208 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
18209 subpass.flags = 0;
18210 subpass.inputAttachmentCount = 0;
18211 subpass.pInputAttachments = NULL;
18212 subpass.colorAttachmentCount = 0;
18213 subpass.pColorAttachments = NULL;
18214 subpass.pResolveAttachments = NULL;
18215 subpass.pDepthStencilAttachment = &ref;
18216 subpass.preserveAttachmentCount = 0;
18217 subpass.pPreserveAttachments = NULL;
18218
18219 VkRenderPass rp;
18220 VkRenderPassCreateInfo rp_info = {};
18221 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18222 rp_info.attachmentCount = 1;
18223 rp_info.pAttachments = &att;
18224 rp_info.subpassCount = 1;
18225 rp_info.pSubpasses = &subpass;
18226 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
18227 ASSERT_VK_SUCCESS(result);
18228
18229 VkImageView *depthView = m_depthStencil->BindInfo();
18230 VkFramebufferCreateInfo fb_info = {};
18231 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
18232 fb_info.pNext = NULL;
18233 fb_info.renderPass = rp;
18234 fb_info.attachmentCount = 1;
18235 fb_info.pAttachments = depthView;
18236 fb_info.width = 100;
18237 fb_info.height = 100;
18238 fb_info.layers = 1;
18239 VkFramebuffer fb;
18240 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
18241 ASSERT_VK_SUCCESS(result);
18242
18243 VkRenderPassBeginInfo rpbinfo = {};
18244 rpbinfo.clearValueCount = 1;
18245 rpbinfo.pClearValues = &clear;
18246 rpbinfo.pNext = NULL;
18247 rpbinfo.renderPass = rp;
18248 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
18249 rpbinfo.renderArea.extent.width = 100;
18250 rpbinfo.renderArea.extent.height = 100;
18251 rpbinfo.renderArea.offset.x = 0;
18252 rpbinfo.renderArea.offset.y = 0;
18253 rpbinfo.framebuffer = fb;
18254
18255 VkFence fence = {};
18256 VkFenceCreateInfo fence_ci = {};
18257 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18258 fence_ci.pNext = nullptr;
18259 fence_ci.flags = 0;
18260 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
18261 ASSERT_VK_SUCCESS(result);
18262
18263 m_commandBuffer->BeginCommandBuffer();
18264 m_commandBuffer->BeginRenderPass(rpbinfo);
18265 m_commandBuffer->EndRenderPass();
18266 m_commandBuffer->EndCommandBuffer();
18267 m_commandBuffer->QueueCommandBuffer(fence);
18268
18269 VkImageObj destImage(m_device);
18270 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 -070018271 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018272 VkImageMemoryBarrier barrier = {};
18273 VkImageSubresourceRange range;
18274 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18275 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18276 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
18277 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18278 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18279 barrier.image = m_depthStencil->handle();
18280 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18281 range.baseMipLevel = 0;
18282 range.levelCount = 1;
18283 range.baseArrayLayer = 0;
18284 range.layerCount = 1;
18285 barrier.subresourceRange = range;
18286 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18287 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18288 cmdbuf.BeginCommandBuffer();
18289 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 -070018290 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018291 barrier.srcAccessMask = 0;
18292 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18293 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18294 barrier.image = destImage.handle();
18295 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18296 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 -070018297 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018298 VkImageCopy cregion;
18299 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18300 cregion.srcSubresource.mipLevel = 0;
18301 cregion.srcSubresource.baseArrayLayer = 0;
18302 cregion.srcSubresource.layerCount = 1;
18303 cregion.srcOffset.x = 0;
18304 cregion.srcOffset.y = 0;
18305 cregion.srcOffset.z = 0;
18306 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18307 cregion.dstSubresource.mipLevel = 0;
18308 cregion.dstSubresource.baseArrayLayer = 0;
18309 cregion.dstSubresource.layerCount = 1;
18310 cregion.dstOffset.x = 0;
18311 cregion.dstOffset.y = 0;
18312 cregion.dstOffset.z = 0;
18313 cregion.extent.width = 100;
18314 cregion.extent.height = 100;
18315 cregion.extent.depth = 1;
18316 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018317 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018318 cmdbuf.EndCommandBuffer();
18319
18320 VkSubmitInfo submit_info;
18321 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18322 submit_info.pNext = NULL;
18323 submit_info.waitSemaphoreCount = 0;
18324 submit_info.pWaitSemaphores = NULL;
18325 submit_info.pWaitDstStageMask = NULL;
18326 submit_info.commandBufferCount = 1;
18327 submit_info.pCommandBuffers = &cmdbuf.handle();
18328 submit_info.signalSemaphoreCount = 0;
18329 submit_info.pSignalSemaphores = NULL;
18330
18331 m_errorMonitor->ExpectSuccess();
18332 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18333 m_errorMonitor->VerifyNotFound();
18334
18335 vkQueueWaitIdle(m_device->m_queue);
18336 vkDestroyFence(m_device->device(), fence, nullptr);
18337 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18338 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18339}
18340
18341// This is a positive test. No errors should be generated.
18342TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18343 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18344
18345 m_errorMonitor->ExpectSuccess();
18346 ASSERT_NO_FATAL_FAILURE(InitState());
18347
18348 VkEvent event;
18349 VkEventCreateInfo event_create_info{};
18350 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18351 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18352
18353 VkCommandPool command_pool;
18354 VkCommandPoolCreateInfo pool_create_info{};
18355 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18356 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18357 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18358 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18359
18360 VkCommandBuffer command_buffer;
18361 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18362 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18363 command_buffer_allocate_info.commandPool = command_pool;
18364 command_buffer_allocate_info.commandBufferCount = 1;
18365 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18366 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18367
18368 VkQueue queue = VK_NULL_HANDLE;
18369 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18370
18371 {
18372 VkCommandBufferBeginInfo begin_info{};
18373 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18374 vkBeginCommandBuffer(command_buffer, &begin_info);
18375
18376 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 -070018377 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018378 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18379 vkEndCommandBuffer(command_buffer);
18380 }
18381 {
18382 VkSubmitInfo submit_info{};
18383 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18384 submit_info.commandBufferCount = 1;
18385 submit_info.pCommandBuffers = &command_buffer;
18386 submit_info.signalSemaphoreCount = 0;
18387 submit_info.pSignalSemaphores = nullptr;
18388 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18389 }
18390 { vkSetEvent(m_device->device(), event); }
18391
18392 vkQueueWaitIdle(queue);
18393
18394 vkDestroyEvent(m_device->device(), event, nullptr);
18395 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18396 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18397
18398 m_errorMonitor->VerifyNotFound();
18399}
18400// This is a positive test. No errors should be generated.
18401TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18402 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18403
18404 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018405 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018406
18407 m_errorMonitor->ExpectSuccess();
18408
18409 VkQueryPool query_pool;
18410 VkQueryPoolCreateInfo query_pool_create_info{};
18411 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18412 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18413 query_pool_create_info.queryCount = 1;
18414 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18415
18416 VkCommandPool command_pool;
18417 VkCommandPoolCreateInfo pool_create_info{};
18418 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18419 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18420 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18421 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18422
18423 VkCommandBuffer command_buffer;
18424 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18425 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18426 command_buffer_allocate_info.commandPool = command_pool;
18427 command_buffer_allocate_info.commandBufferCount = 1;
18428 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18429 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18430
18431 VkCommandBuffer secondary_command_buffer;
18432 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18433 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18434
18435 VkQueue queue = VK_NULL_HANDLE;
18436 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18437
18438 uint32_t qfi = 0;
18439 VkBufferCreateInfo buff_create_info = {};
18440 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18441 buff_create_info.size = 1024;
18442 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18443 buff_create_info.queueFamilyIndexCount = 1;
18444 buff_create_info.pQueueFamilyIndices = &qfi;
18445
18446 VkResult err;
18447 VkBuffer buffer;
18448 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18449 ASSERT_VK_SUCCESS(err);
18450 VkMemoryAllocateInfo mem_alloc = {};
18451 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18452 mem_alloc.pNext = NULL;
18453 mem_alloc.allocationSize = 1024;
18454 mem_alloc.memoryTypeIndex = 0;
18455
18456 VkMemoryRequirements memReqs;
18457 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18458 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18459 if (!pass) {
18460 vkDestroyBuffer(m_device->device(), buffer, NULL);
18461 return;
18462 }
18463
18464 VkDeviceMemory mem;
18465 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18466 ASSERT_VK_SUCCESS(err);
18467 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18468 ASSERT_VK_SUCCESS(err);
18469
18470 VkCommandBufferInheritanceInfo hinfo = {};
18471 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18472 hinfo.renderPass = VK_NULL_HANDLE;
18473 hinfo.subpass = 0;
18474 hinfo.framebuffer = VK_NULL_HANDLE;
18475 hinfo.occlusionQueryEnable = VK_FALSE;
18476 hinfo.queryFlags = 0;
18477 hinfo.pipelineStatistics = 0;
18478
18479 {
18480 VkCommandBufferBeginInfo begin_info{};
18481 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18482 begin_info.pInheritanceInfo = &hinfo;
18483 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18484
18485 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18486 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18487
18488 vkEndCommandBuffer(secondary_command_buffer);
18489
18490 begin_info.pInheritanceInfo = nullptr;
18491 vkBeginCommandBuffer(command_buffer, &begin_info);
18492
18493 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18494 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18495
18496 vkEndCommandBuffer(command_buffer);
18497 }
18498 {
18499 VkSubmitInfo submit_info{};
18500 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18501 submit_info.commandBufferCount = 1;
18502 submit_info.pCommandBuffers = &command_buffer;
18503 submit_info.signalSemaphoreCount = 0;
18504 submit_info.pSignalSemaphores = nullptr;
18505 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18506 }
18507
18508 vkQueueWaitIdle(queue);
18509
18510 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18511 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18512 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18513 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18514 vkDestroyBuffer(m_device->device(), buffer, NULL);
18515 vkFreeMemory(m_device->device(), mem, NULL);
18516
18517 m_errorMonitor->VerifyNotFound();
18518}
18519
18520// This is a positive test. No errors should be generated.
18521TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18522 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18523
18524 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018525 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018526
18527 m_errorMonitor->ExpectSuccess();
18528
18529 VkQueryPool query_pool;
18530 VkQueryPoolCreateInfo query_pool_create_info{};
18531 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18532 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18533 query_pool_create_info.queryCount = 1;
18534 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18535
18536 VkCommandPool command_pool;
18537 VkCommandPoolCreateInfo pool_create_info{};
18538 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18539 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18540 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18541 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18542
18543 VkCommandBuffer command_buffer[2];
18544 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18545 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18546 command_buffer_allocate_info.commandPool = command_pool;
18547 command_buffer_allocate_info.commandBufferCount = 2;
18548 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18549 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18550
18551 VkQueue queue = VK_NULL_HANDLE;
18552 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18553
18554 uint32_t qfi = 0;
18555 VkBufferCreateInfo buff_create_info = {};
18556 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18557 buff_create_info.size = 1024;
18558 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18559 buff_create_info.queueFamilyIndexCount = 1;
18560 buff_create_info.pQueueFamilyIndices = &qfi;
18561
18562 VkResult err;
18563 VkBuffer buffer;
18564 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18565 ASSERT_VK_SUCCESS(err);
18566 VkMemoryAllocateInfo mem_alloc = {};
18567 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18568 mem_alloc.pNext = NULL;
18569 mem_alloc.allocationSize = 1024;
18570 mem_alloc.memoryTypeIndex = 0;
18571
18572 VkMemoryRequirements memReqs;
18573 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18574 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18575 if (!pass) {
18576 vkDestroyBuffer(m_device->device(), buffer, NULL);
18577 return;
18578 }
18579
18580 VkDeviceMemory mem;
18581 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18582 ASSERT_VK_SUCCESS(err);
18583 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18584 ASSERT_VK_SUCCESS(err);
18585
18586 {
18587 VkCommandBufferBeginInfo begin_info{};
18588 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18589 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18590
18591 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18592 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18593
18594 vkEndCommandBuffer(command_buffer[0]);
18595
18596 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18597
18598 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18599
18600 vkEndCommandBuffer(command_buffer[1]);
18601 }
18602 {
18603 VkSubmitInfo submit_info{};
18604 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18605 submit_info.commandBufferCount = 2;
18606 submit_info.pCommandBuffers = command_buffer;
18607 submit_info.signalSemaphoreCount = 0;
18608 submit_info.pSignalSemaphores = nullptr;
18609 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18610 }
18611
18612 vkQueueWaitIdle(queue);
18613
18614 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18615 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18616 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18617 vkDestroyBuffer(m_device->device(), buffer, NULL);
18618 vkFreeMemory(m_device->device(), mem, NULL);
18619
18620 m_errorMonitor->VerifyNotFound();
18621}
18622
Tony Barbourc46924f2016-11-04 11:49:52 -060018623TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018624 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18625
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018626 ASSERT_NO_FATAL_FAILURE(InitState());
18627 VkEvent event;
18628 VkEventCreateInfo event_create_info{};
18629 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18630 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18631
18632 VkCommandPool command_pool;
18633 VkCommandPoolCreateInfo pool_create_info{};
18634 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18635 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18636 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18637 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18638
18639 VkCommandBuffer command_buffer;
18640 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18641 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18642 command_buffer_allocate_info.commandPool = command_pool;
18643 command_buffer_allocate_info.commandBufferCount = 1;
18644 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18645 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18646
18647 VkQueue queue = VK_NULL_HANDLE;
18648 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18649
18650 {
18651 VkCommandBufferBeginInfo begin_info{};
18652 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18653 vkBeginCommandBuffer(command_buffer, &begin_info);
18654
18655 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018656 vkEndCommandBuffer(command_buffer);
18657 }
18658 {
18659 VkSubmitInfo submit_info{};
18660 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18661 submit_info.commandBufferCount = 1;
18662 submit_info.pCommandBuffers = &command_buffer;
18663 submit_info.signalSemaphoreCount = 0;
18664 submit_info.pSignalSemaphores = nullptr;
18665 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18666 }
18667 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18669 "that is already in use by a "
18670 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018671 vkSetEvent(m_device->device(), event);
18672 m_errorMonitor->VerifyFound();
18673 }
18674
18675 vkQueueWaitIdle(queue);
18676
18677 vkDestroyEvent(m_device->device(), event, nullptr);
18678 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18679 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18680}
18681
18682// This is a positive test. No errors should be generated.
18683TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018684 TEST_DESCRIPTION(
18685 "Two command buffers with two separate fences are each "
18686 "run through a Submit & WaitForFences cycle 3 times. This "
18687 "previously revealed a bug so running this positive test "
18688 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018689 m_errorMonitor->ExpectSuccess();
18690
18691 ASSERT_NO_FATAL_FAILURE(InitState());
18692 VkQueue queue = VK_NULL_HANDLE;
18693 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18694
18695 static const uint32_t NUM_OBJECTS = 2;
18696 static const uint32_t NUM_FRAMES = 3;
18697 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18698 VkFence fences[NUM_OBJECTS] = {};
18699
18700 VkCommandPool cmd_pool;
18701 VkCommandPoolCreateInfo cmd_pool_ci = {};
18702 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18703 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18704 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18705 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18706 ASSERT_VK_SUCCESS(err);
18707
18708 VkCommandBufferAllocateInfo cmd_buf_info = {};
18709 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18710 cmd_buf_info.commandPool = cmd_pool;
18711 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18712 cmd_buf_info.commandBufferCount = 1;
18713
18714 VkFenceCreateInfo fence_ci = {};
18715 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18716 fence_ci.pNext = nullptr;
18717 fence_ci.flags = 0;
18718
18719 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18720 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18721 ASSERT_VK_SUCCESS(err);
18722 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18723 ASSERT_VK_SUCCESS(err);
18724 }
18725
18726 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18727 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18728 // Create empty cmd buffer
18729 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18730 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18731
18732 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18733 ASSERT_VK_SUCCESS(err);
18734 err = vkEndCommandBuffer(cmd_buffers[obj]);
18735 ASSERT_VK_SUCCESS(err);
18736
18737 VkSubmitInfo submit_info = {};
18738 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18739 submit_info.commandBufferCount = 1;
18740 submit_info.pCommandBuffers = &cmd_buffers[obj];
18741 // Submit cmd buffer and wait for fence
18742 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18743 ASSERT_VK_SUCCESS(err);
18744 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18745 ASSERT_VK_SUCCESS(err);
18746 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18747 ASSERT_VK_SUCCESS(err);
18748 }
18749 }
18750 m_errorMonitor->VerifyNotFound();
18751 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18752 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18753 vkDestroyFence(m_device->device(), fences[i], nullptr);
18754 }
18755}
18756// This is a positive test. No errors should be generated.
18757TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018758 TEST_DESCRIPTION(
18759 "Two command buffers, each in a separate QueueSubmit call "
18760 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018761
18762 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018763 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018764
18765 m_errorMonitor->ExpectSuccess();
18766
18767 VkSemaphore semaphore;
18768 VkSemaphoreCreateInfo semaphore_create_info{};
18769 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18770 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18771
18772 VkCommandPool command_pool;
18773 VkCommandPoolCreateInfo pool_create_info{};
18774 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18775 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18776 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18777 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18778
18779 VkCommandBuffer command_buffer[2];
18780 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18781 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18782 command_buffer_allocate_info.commandPool = command_pool;
18783 command_buffer_allocate_info.commandBufferCount = 2;
18784 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18785 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18786
18787 VkQueue queue = VK_NULL_HANDLE;
18788 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18789
18790 {
18791 VkCommandBufferBeginInfo begin_info{};
18792 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18793 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18794
18795 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 -070018796 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018797
18798 VkViewport viewport{};
18799 viewport.maxDepth = 1.0f;
18800 viewport.minDepth = 0.0f;
18801 viewport.width = 512;
18802 viewport.height = 512;
18803 viewport.x = 0;
18804 viewport.y = 0;
18805 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18806 vkEndCommandBuffer(command_buffer[0]);
18807 }
18808 {
18809 VkCommandBufferBeginInfo begin_info{};
18810 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18811 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18812
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[1], 0, 1, &viewport);
18821 vkEndCommandBuffer(command_buffer[1]);
18822 }
18823 {
18824 VkSubmitInfo submit_info{};
18825 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18826 submit_info.commandBufferCount = 1;
18827 submit_info.pCommandBuffers = &command_buffer[0];
18828 submit_info.signalSemaphoreCount = 1;
18829 submit_info.pSignalSemaphores = &semaphore;
18830 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18831 }
18832 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018833 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018834 VkSubmitInfo submit_info{};
18835 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18836 submit_info.commandBufferCount = 1;
18837 submit_info.pCommandBuffers = &command_buffer[1];
18838 submit_info.waitSemaphoreCount = 1;
18839 submit_info.pWaitSemaphores = &semaphore;
18840 submit_info.pWaitDstStageMask = flags;
18841 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18842 }
18843
18844 vkQueueWaitIdle(m_device->m_queue);
18845
18846 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18847 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18848 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18849
18850 m_errorMonitor->VerifyNotFound();
18851}
18852
18853// This is a positive test. No errors should be generated.
18854TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018855 TEST_DESCRIPTION(
18856 "Two command buffers, each in a separate QueueSubmit call "
18857 "submitted on separate queues, the second having a fence"
18858 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018859
18860 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018861 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018862
18863 m_errorMonitor->ExpectSuccess();
18864
18865 VkFence fence;
18866 VkFenceCreateInfo fence_create_info{};
18867 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18868 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18869
18870 VkSemaphore semaphore;
18871 VkSemaphoreCreateInfo semaphore_create_info{};
18872 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18873 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18874
18875 VkCommandPool command_pool;
18876 VkCommandPoolCreateInfo pool_create_info{};
18877 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18878 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18879 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18880 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18881
18882 VkCommandBuffer command_buffer[2];
18883 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18884 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18885 command_buffer_allocate_info.commandPool = command_pool;
18886 command_buffer_allocate_info.commandBufferCount = 2;
18887 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18888 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18889
18890 VkQueue queue = VK_NULL_HANDLE;
18891 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18892
18893 {
18894 VkCommandBufferBeginInfo begin_info{};
18895 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18896 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18897
18898 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 -070018899 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018900
18901 VkViewport viewport{};
18902 viewport.maxDepth = 1.0f;
18903 viewport.minDepth = 0.0f;
18904 viewport.width = 512;
18905 viewport.height = 512;
18906 viewport.x = 0;
18907 viewport.y = 0;
18908 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18909 vkEndCommandBuffer(command_buffer[0]);
18910 }
18911 {
18912 VkCommandBufferBeginInfo begin_info{};
18913 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18914 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18915
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[1], 0, 1, &viewport);
18924 vkEndCommandBuffer(command_buffer[1]);
18925 }
18926 {
18927 VkSubmitInfo submit_info{};
18928 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18929 submit_info.commandBufferCount = 1;
18930 submit_info.pCommandBuffers = &command_buffer[0];
18931 submit_info.signalSemaphoreCount = 1;
18932 submit_info.pSignalSemaphores = &semaphore;
18933 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18934 }
18935 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018936 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018937 VkSubmitInfo submit_info{};
18938 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18939 submit_info.commandBufferCount = 1;
18940 submit_info.pCommandBuffers = &command_buffer[1];
18941 submit_info.waitSemaphoreCount = 1;
18942 submit_info.pWaitSemaphores = &semaphore;
18943 submit_info.pWaitDstStageMask = flags;
18944 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18945 }
18946
18947 vkQueueWaitIdle(m_device->m_queue);
18948
18949 vkDestroyFence(m_device->device(), fence, nullptr);
18950 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18951 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18952 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18953
18954 m_errorMonitor->VerifyNotFound();
18955}
18956
18957// This is a positive test. No errors should be generated.
18958TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018959 TEST_DESCRIPTION(
18960 "Two command buffers, each in a separate QueueSubmit call "
18961 "submitted on separate queues, the second having a fence"
18962 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018963
18964 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018965 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018966
18967 m_errorMonitor->ExpectSuccess();
18968
18969 VkFence fence;
18970 VkFenceCreateInfo fence_create_info{};
18971 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18972 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18973
18974 VkSemaphore semaphore;
18975 VkSemaphoreCreateInfo semaphore_create_info{};
18976 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18977 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18978
18979 VkCommandPool command_pool;
18980 VkCommandPoolCreateInfo pool_create_info{};
18981 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18982 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18983 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18984 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18985
18986 VkCommandBuffer command_buffer[2];
18987 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18988 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18989 command_buffer_allocate_info.commandPool = command_pool;
18990 command_buffer_allocate_info.commandBufferCount = 2;
18991 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18992 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18993
18994 VkQueue queue = VK_NULL_HANDLE;
18995 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18996
18997 {
18998 VkCommandBufferBeginInfo begin_info{};
18999 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19000 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19001
19002 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 -070019003 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019004
19005 VkViewport viewport{};
19006 viewport.maxDepth = 1.0f;
19007 viewport.minDepth = 0.0f;
19008 viewport.width = 512;
19009 viewport.height = 512;
19010 viewport.x = 0;
19011 viewport.y = 0;
19012 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19013 vkEndCommandBuffer(command_buffer[0]);
19014 }
19015 {
19016 VkCommandBufferBeginInfo begin_info{};
19017 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19018 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19019
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[1], 0, 1, &viewport);
19028 vkEndCommandBuffer(command_buffer[1]);
19029 }
19030 {
19031 VkSubmitInfo submit_info{};
19032 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19033 submit_info.commandBufferCount = 1;
19034 submit_info.pCommandBuffers = &command_buffer[0];
19035 submit_info.signalSemaphoreCount = 1;
19036 submit_info.pSignalSemaphores = &semaphore;
19037 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19038 }
19039 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019040 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019041 VkSubmitInfo submit_info{};
19042 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19043 submit_info.commandBufferCount = 1;
19044 submit_info.pCommandBuffers = &command_buffer[1];
19045 submit_info.waitSemaphoreCount = 1;
19046 submit_info.pWaitSemaphores = &semaphore;
19047 submit_info.pWaitDstStageMask = flags;
19048 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19049 }
19050
19051 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19052 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19053
19054 vkDestroyFence(m_device->device(), fence, nullptr);
19055 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19056 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19057 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19058
19059 m_errorMonitor->VerifyNotFound();
19060}
19061
19062TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019063 ASSERT_NO_FATAL_FAILURE(InitState());
19064 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
19065 printf("Test requires two queues, skipping\n");
19066 return;
19067 }
19068
19069 VkResult err;
19070
19071 m_errorMonitor->ExpectSuccess();
19072
19073 VkQueue q0 = m_device->m_queue;
19074 VkQueue q1 = nullptr;
19075 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
19076 ASSERT_NE(q1, nullptr);
19077
19078 // An (empty) command buffer. We must have work in the first submission --
19079 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019080 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019081 VkCommandPool pool;
19082 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
19083 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019084 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
19085 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019086 VkCommandBuffer cb;
19087 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
19088 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019089 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019090 err = vkBeginCommandBuffer(cb, &cbbi);
19091 ASSERT_VK_SUCCESS(err);
19092 err = vkEndCommandBuffer(cb);
19093 ASSERT_VK_SUCCESS(err);
19094
19095 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019096 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019097 VkSemaphore s;
19098 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
19099 ASSERT_VK_SUCCESS(err);
19100
19101 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019102 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019103
19104 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
19105 ASSERT_VK_SUCCESS(err);
19106
19107 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019108 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019109 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019110
19111 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
19112 ASSERT_VK_SUCCESS(err);
19113
19114 // Wait for q0 idle
19115 err = vkQueueWaitIdle(q0);
19116 ASSERT_VK_SUCCESS(err);
19117
19118 // Command buffer should have been completed (it was on q0); reset the pool.
19119 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
19120
19121 m_errorMonitor->VerifyNotFound();
19122
19123 // Force device completely idle and clean up resources
19124 vkDeviceWaitIdle(m_device->device());
19125 vkDestroyCommandPool(m_device->device(), pool, nullptr);
19126 vkDestroySemaphore(m_device->device(), s, nullptr);
19127}
19128
19129// This is a positive test. No errors should be generated.
19130TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019131 TEST_DESCRIPTION(
19132 "Two command buffers, each in a separate QueueSubmit call "
19133 "submitted on separate queues, the second having a fence, "
19134 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019135
19136 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019137 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019138
19139 m_errorMonitor->ExpectSuccess();
19140
19141 ASSERT_NO_FATAL_FAILURE(InitState());
19142 VkFence fence;
19143 VkFenceCreateInfo fence_create_info{};
19144 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19145 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19146
19147 VkSemaphore semaphore;
19148 VkSemaphoreCreateInfo semaphore_create_info{};
19149 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19150 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19151
19152 VkCommandPool command_pool;
19153 VkCommandPoolCreateInfo pool_create_info{};
19154 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19155 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19156 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19157 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19158
19159 VkCommandBuffer command_buffer[2];
19160 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19161 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19162 command_buffer_allocate_info.commandPool = command_pool;
19163 command_buffer_allocate_info.commandBufferCount = 2;
19164 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19165 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19166
19167 VkQueue queue = VK_NULL_HANDLE;
19168 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19169
19170 {
19171 VkCommandBufferBeginInfo begin_info{};
19172 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19173 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19174
19175 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 -070019176 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019177
19178 VkViewport viewport{};
19179 viewport.maxDepth = 1.0f;
19180 viewport.minDepth = 0.0f;
19181 viewport.width = 512;
19182 viewport.height = 512;
19183 viewport.x = 0;
19184 viewport.y = 0;
19185 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19186 vkEndCommandBuffer(command_buffer[0]);
19187 }
19188 {
19189 VkCommandBufferBeginInfo begin_info{};
19190 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19191 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19192
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[1], 0, 1, &viewport);
19201 vkEndCommandBuffer(command_buffer[1]);
19202 }
19203 {
19204 VkSubmitInfo submit_info{};
19205 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19206 submit_info.commandBufferCount = 1;
19207 submit_info.pCommandBuffers = &command_buffer[0];
19208 submit_info.signalSemaphoreCount = 1;
19209 submit_info.pSignalSemaphores = &semaphore;
19210 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19211 }
19212 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019213 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019214 VkSubmitInfo submit_info{};
19215 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19216 submit_info.commandBufferCount = 1;
19217 submit_info.pCommandBuffers = &command_buffer[1];
19218 submit_info.waitSemaphoreCount = 1;
19219 submit_info.pWaitSemaphores = &semaphore;
19220 submit_info.pWaitDstStageMask = flags;
19221 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19222 }
19223
19224 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19225
19226 vkDestroyFence(m_device->device(), fence, nullptr);
19227 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19228 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19229 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19230
19231 m_errorMonitor->VerifyNotFound();
19232}
19233
19234// This is a positive test. No errors should be generated.
19235TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019236 TEST_DESCRIPTION(
19237 "Two command buffers, each in a separate QueueSubmit call "
19238 "on the same queue, sharing a signal/wait semaphore, the "
19239 "second having a fence, "
19240 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019241
19242 m_errorMonitor->ExpectSuccess();
19243
19244 ASSERT_NO_FATAL_FAILURE(InitState());
19245 VkFence fence;
19246 VkFenceCreateInfo fence_create_info{};
19247 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19248 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19249
19250 VkSemaphore semaphore;
19251 VkSemaphoreCreateInfo semaphore_create_info{};
19252 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19253 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19254
19255 VkCommandPool command_pool;
19256 VkCommandPoolCreateInfo pool_create_info{};
19257 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19258 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19259 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19260 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19261
19262 VkCommandBuffer command_buffer[2];
19263 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19264 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19265 command_buffer_allocate_info.commandPool = command_pool;
19266 command_buffer_allocate_info.commandBufferCount = 2;
19267 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19268 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19269
19270 {
19271 VkCommandBufferBeginInfo begin_info{};
19272 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19273 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19274
19275 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019276 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019277
19278 VkViewport viewport{};
19279 viewport.maxDepth = 1.0f;
19280 viewport.minDepth = 0.0f;
19281 viewport.width = 512;
19282 viewport.height = 512;
19283 viewport.x = 0;
19284 viewport.y = 0;
19285 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19286 vkEndCommandBuffer(command_buffer[0]);
19287 }
19288 {
19289 VkCommandBufferBeginInfo begin_info{};
19290 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19291 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19292
19293 VkViewport viewport{};
19294 viewport.maxDepth = 1.0f;
19295 viewport.minDepth = 0.0f;
19296 viewport.width = 512;
19297 viewport.height = 512;
19298 viewport.x = 0;
19299 viewport.y = 0;
19300 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19301 vkEndCommandBuffer(command_buffer[1]);
19302 }
19303 {
19304 VkSubmitInfo submit_info{};
19305 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19306 submit_info.commandBufferCount = 1;
19307 submit_info.pCommandBuffers = &command_buffer[0];
19308 submit_info.signalSemaphoreCount = 1;
19309 submit_info.pSignalSemaphores = &semaphore;
19310 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19311 }
19312 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019313 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019314 VkSubmitInfo submit_info{};
19315 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19316 submit_info.commandBufferCount = 1;
19317 submit_info.pCommandBuffers = &command_buffer[1];
19318 submit_info.waitSemaphoreCount = 1;
19319 submit_info.pWaitSemaphores = &semaphore;
19320 submit_info.pWaitDstStageMask = flags;
19321 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19322 }
19323
19324 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19325
19326 vkDestroyFence(m_device->device(), fence, nullptr);
19327 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19328 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19329 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19330
19331 m_errorMonitor->VerifyNotFound();
19332}
19333
19334// This is a positive test. No errors should be generated.
19335TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019336 TEST_DESCRIPTION(
19337 "Two command buffers, each in a separate QueueSubmit call "
19338 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19339 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019340
19341 m_errorMonitor->ExpectSuccess();
19342
19343 ASSERT_NO_FATAL_FAILURE(InitState());
19344 VkFence fence;
19345 VkFenceCreateInfo fence_create_info{};
19346 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19347 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19348
19349 VkCommandPool command_pool;
19350 VkCommandPoolCreateInfo pool_create_info{};
19351 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19352 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19353 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19354 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19355
19356 VkCommandBuffer command_buffer[2];
19357 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19358 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19359 command_buffer_allocate_info.commandPool = command_pool;
19360 command_buffer_allocate_info.commandBufferCount = 2;
19361 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19362 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19363
19364 {
19365 VkCommandBufferBeginInfo begin_info{};
19366 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19367 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19368
19369 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 -070019370 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019371
19372 VkViewport viewport{};
19373 viewport.maxDepth = 1.0f;
19374 viewport.minDepth = 0.0f;
19375 viewport.width = 512;
19376 viewport.height = 512;
19377 viewport.x = 0;
19378 viewport.y = 0;
19379 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19380 vkEndCommandBuffer(command_buffer[0]);
19381 }
19382 {
19383 VkCommandBufferBeginInfo begin_info{};
19384 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19385 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19386
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[1], 0, 1, &viewport);
19395 vkEndCommandBuffer(command_buffer[1]);
19396 }
19397 {
19398 VkSubmitInfo submit_info{};
19399 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19400 submit_info.commandBufferCount = 1;
19401 submit_info.pCommandBuffers = &command_buffer[0];
19402 submit_info.signalSemaphoreCount = 0;
19403 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19404 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19405 }
19406 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019407 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019408 VkSubmitInfo submit_info{};
19409 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19410 submit_info.commandBufferCount = 1;
19411 submit_info.pCommandBuffers = &command_buffer[1];
19412 submit_info.waitSemaphoreCount = 0;
19413 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19414 submit_info.pWaitDstStageMask = flags;
19415 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19416 }
19417
19418 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19419
19420 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19421 ASSERT_VK_SUCCESS(err);
19422
19423 vkDestroyFence(m_device->device(), fence, nullptr);
19424 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19425 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19426
19427 m_errorMonitor->VerifyNotFound();
19428}
19429
19430// This is a positive test. No errors should be generated.
19431TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019432 TEST_DESCRIPTION(
19433 "Two command buffers, each in a separate QueueSubmit call "
19434 "on the same queue, the second having a fence, followed "
19435 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019436
19437 m_errorMonitor->ExpectSuccess();
19438
19439 ASSERT_NO_FATAL_FAILURE(InitState());
19440 VkFence fence;
19441 VkFenceCreateInfo fence_create_info{};
19442 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19443 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19444
19445 VkCommandPool command_pool;
19446 VkCommandPoolCreateInfo pool_create_info{};
19447 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19448 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19449 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19450 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19451
19452 VkCommandBuffer command_buffer[2];
19453 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19454 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19455 command_buffer_allocate_info.commandPool = command_pool;
19456 command_buffer_allocate_info.commandBufferCount = 2;
19457 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19458 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19459
19460 {
19461 VkCommandBufferBeginInfo begin_info{};
19462 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19463 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19464
19465 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 -070019466 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019467
19468 VkViewport viewport{};
19469 viewport.maxDepth = 1.0f;
19470 viewport.minDepth = 0.0f;
19471 viewport.width = 512;
19472 viewport.height = 512;
19473 viewport.x = 0;
19474 viewport.y = 0;
19475 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19476 vkEndCommandBuffer(command_buffer[0]);
19477 }
19478 {
19479 VkCommandBufferBeginInfo begin_info{};
19480 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19481 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19482
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[1], 0, 1, &viewport);
19491 vkEndCommandBuffer(command_buffer[1]);
19492 }
19493 {
19494 VkSubmitInfo submit_info{};
19495 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19496 submit_info.commandBufferCount = 1;
19497 submit_info.pCommandBuffers = &command_buffer[0];
19498 submit_info.signalSemaphoreCount = 0;
19499 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19500 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19501 }
19502 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019503 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019504 VkSubmitInfo submit_info{};
19505 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19506 submit_info.commandBufferCount = 1;
19507 submit_info.pCommandBuffers = &command_buffer[1];
19508 submit_info.waitSemaphoreCount = 0;
19509 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19510 submit_info.pWaitDstStageMask = flags;
19511 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19512 }
19513
19514 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19515
19516 vkDestroyFence(m_device->device(), fence, nullptr);
19517 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19518 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19519
19520 m_errorMonitor->VerifyNotFound();
19521}
19522
19523// This is a positive test. No errors should be generated.
19524TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019525 TEST_DESCRIPTION(
19526 "Two command buffers each in a separate SubmitInfo sent in a single "
19527 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019528 ASSERT_NO_FATAL_FAILURE(InitState());
19529
19530 m_errorMonitor->ExpectSuccess();
19531
19532 VkFence fence;
19533 VkFenceCreateInfo fence_create_info{};
19534 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19535 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19536
19537 VkSemaphore semaphore;
19538 VkSemaphoreCreateInfo semaphore_create_info{};
19539 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19540 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19541
19542 VkCommandPool command_pool;
19543 VkCommandPoolCreateInfo pool_create_info{};
19544 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19545 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19546 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19547 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19548
19549 VkCommandBuffer command_buffer[2];
19550 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19551 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19552 command_buffer_allocate_info.commandPool = command_pool;
19553 command_buffer_allocate_info.commandBufferCount = 2;
19554 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19555 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19556
19557 {
19558 VkCommandBufferBeginInfo begin_info{};
19559 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19560 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19561
19562 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 -070019563 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019564
19565 VkViewport viewport{};
19566 viewport.maxDepth = 1.0f;
19567 viewport.minDepth = 0.0f;
19568 viewport.width = 512;
19569 viewport.height = 512;
19570 viewport.x = 0;
19571 viewport.y = 0;
19572 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19573 vkEndCommandBuffer(command_buffer[0]);
19574 }
19575 {
19576 VkCommandBufferBeginInfo begin_info{};
19577 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19578 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19579
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[1], 0, 1, &viewport);
19588 vkEndCommandBuffer(command_buffer[1]);
19589 }
19590 {
19591 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019592 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019593
19594 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19595 submit_info[0].pNext = NULL;
19596 submit_info[0].commandBufferCount = 1;
19597 submit_info[0].pCommandBuffers = &command_buffer[0];
19598 submit_info[0].signalSemaphoreCount = 1;
19599 submit_info[0].pSignalSemaphores = &semaphore;
19600 submit_info[0].waitSemaphoreCount = 0;
19601 submit_info[0].pWaitSemaphores = NULL;
19602 submit_info[0].pWaitDstStageMask = 0;
19603
19604 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19605 submit_info[1].pNext = NULL;
19606 submit_info[1].commandBufferCount = 1;
19607 submit_info[1].pCommandBuffers = &command_buffer[1];
19608 submit_info[1].waitSemaphoreCount = 1;
19609 submit_info[1].pWaitSemaphores = &semaphore;
19610 submit_info[1].pWaitDstStageMask = flags;
19611 submit_info[1].signalSemaphoreCount = 0;
19612 submit_info[1].pSignalSemaphores = NULL;
19613 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19614 }
19615
19616 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19617
19618 vkDestroyFence(m_device->device(), fence, nullptr);
19619 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19620 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19621 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19622
19623 m_errorMonitor->VerifyNotFound();
19624}
19625
19626TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19627 m_errorMonitor->ExpectSuccess();
19628
19629 ASSERT_NO_FATAL_FAILURE(InitState());
19630 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19631
Tony Barbour552f6c02016-12-21 14:34:07 -070019632 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019633
19634 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19635 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19636 m_errorMonitor->VerifyNotFound();
19637 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19638 m_errorMonitor->VerifyNotFound();
19639 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19640 m_errorMonitor->VerifyNotFound();
19641
19642 m_commandBuffer->EndCommandBuffer();
19643 m_errorMonitor->VerifyNotFound();
19644}
19645
19646TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019647 TEST_DESCRIPTION(
19648 "Positive test where we create a renderpass with an "
19649 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19650 "has a valid layout, and a second subpass then uses a "
19651 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019652 m_errorMonitor->ExpectSuccess();
19653 ASSERT_NO_FATAL_FAILURE(InitState());
19654
19655 VkAttachmentReference attach[2] = {};
19656 attach[0].attachment = 0;
19657 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19658 attach[1].attachment = 0;
19659 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19660 VkSubpassDescription subpasses[2] = {};
19661 // First subpass clears DS attach on load
19662 subpasses[0].pDepthStencilAttachment = &attach[0];
19663 // 2nd subpass reads in DS as input attachment
19664 subpasses[1].inputAttachmentCount = 1;
19665 subpasses[1].pInputAttachments = &attach[1];
19666 VkAttachmentDescription attach_desc = {};
19667 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19668 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19669 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19670 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19671 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19672 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19673 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19674 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19675 VkRenderPassCreateInfo rpci = {};
19676 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19677 rpci.attachmentCount = 1;
19678 rpci.pAttachments = &attach_desc;
19679 rpci.subpassCount = 2;
19680 rpci.pSubpasses = subpasses;
19681
19682 // Now create RenderPass and verify no errors
19683 VkRenderPass rp;
19684 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19685 m_errorMonitor->VerifyNotFound();
19686
19687 vkDestroyRenderPass(m_device->device(), rp, NULL);
19688}
19689
19690TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019691 TEST_DESCRIPTION(
19692 "Test that pipeline validation accepts matrices passed "
19693 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019694 m_errorMonitor->ExpectSuccess();
19695
19696 ASSERT_NO_FATAL_FAILURE(InitState());
19697 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19698
19699 VkVertexInputBindingDescription input_binding;
19700 memset(&input_binding, 0, sizeof(input_binding));
19701
19702 VkVertexInputAttributeDescription input_attribs[2];
19703 memset(input_attribs, 0, sizeof(input_attribs));
19704
19705 for (int i = 0; i < 2; i++) {
19706 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19707 input_attribs[i].location = i;
19708 }
19709
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019710 char const *vsSource =
19711 "#version 450\n"
19712 "\n"
19713 "layout(location=0) in mat2x4 x;\n"
19714 "out gl_PerVertex {\n"
19715 " vec4 gl_Position;\n"
19716 "};\n"
19717 "void main(){\n"
19718 " gl_Position = x[0] + x[1];\n"
19719 "}\n";
19720 char const *fsSource =
19721 "#version 450\n"
19722 "\n"
19723 "layout(location=0) out vec4 color;\n"
19724 "void main(){\n"
19725 " color = vec4(1);\n"
19726 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019727
19728 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19729 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19730
19731 VkPipelineObj pipe(m_device);
19732 pipe.AddColorAttachment();
19733 pipe.AddShader(&vs);
19734 pipe.AddShader(&fs);
19735
19736 pipe.AddVertexInputBindings(&input_binding, 1);
19737 pipe.AddVertexInputAttribs(input_attribs, 2);
19738
19739 VkDescriptorSetObj descriptorSet(m_device);
19740 descriptorSet.AppendDummy();
19741 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19742
19743 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19744
19745 /* expect success */
19746 m_errorMonitor->VerifyNotFound();
19747}
19748
19749TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19750 m_errorMonitor->ExpectSuccess();
19751
19752 ASSERT_NO_FATAL_FAILURE(InitState());
19753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19754
19755 VkVertexInputBindingDescription input_binding;
19756 memset(&input_binding, 0, sizeof(input_binding));
19757
19758 VkVertexInputAttributeDescription input_attribs[2];
19759 memset(input_attribs, 0, sizeof(input_attribs));
19760
19761 for (int i = 0; i < 2; i++) {
19762 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19763 input_attribs[i].location = i;
19764 }
19765
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019766 char const *vsSource =
19767 "#version 450\n"
19768 "\n"
19769 "layout(location=0) in vec4 x[2];\n"
19770 "out gl_PerVertex {\n"
19771 " vec4 gl_Position;\n"
19772 "};\n"
19773 "void main(){\n"
19774 " gl_Position = x[0] + x[1];\n"
19775 "}\n";
19776 char const *fsSource =
19777 "#version 450\n"
19778 "\n"
19779 "layout(location=0) out vec4 color;\n"
19780 "void main(){\n"
19781 " color = vec4(1);\n"
19782 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019783
19784 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19785 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19786
19787 VkPipelineObj pipe(m_device);
19788 pipe.AddColorAttachment();
19789 pipe.AddShader(&vs);
19790 pipe.AddShader(&fs);
19791
19792 pipe.AddVertexInputBindings(&input_binding, 1);
19793 pipe.AddVertexInputAttribs(input_attribs, 2);
19794
19795 VkDescriptorSetObj descriptorSet(m_device);
19796 descriptorSet.AppendDummy();
19797 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19798
19799 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19800
19801 m_errorMonitor->VerifyNotFound();
19802}
19803
19804TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019805 TEST_DESCRIPTION(
19806 "Test that pipeline validation accepts consuming a vertex attribute "
19807 "through multiple vertex shader inputs, each consuming a different "
19808 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019809 m_errorMonitor->ExpectSuccess();
19810
19811 ASSERT_NO_FATAL_FAILURE(InitState());
19812 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19813
19814 VkVertexInputBindingDescription input_binding;
19815 memset(&input_binding, 0, sizeof(input_binding));
19816
19817 VkVertexInputAttributeDescription input_attribs[3];
19818 memset(input_attribs, 0, sizeof(input_attribs));
19819
19820 for (int i = 0; i < 3; i++) {
19821 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19822 input_attribs[i].location = i;
19823 }
19824
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019825 char const *vsSource =
19826 "#version 450\n"
19827 "\n"
19828 "layout(location=0) in vec4 x;\n"
19829 "layout(location=1) in vec3 y1;\n"
19830 "layout(location=1, component=3) in float y2;\n"
19831 "layout(location=2) in vec4 z;\n"
19832 "out gl_PerVertex {\n"
19833 " vec4 gl_Position;\n"
19834 "};\n"
19835 "void main(){\n"
19836 " gl_Position = x + vec4(y1, y2) + z;\n"
19837 "}\n";
19838 char const *fsSource =
19839 "#version 450\n"
19840 "\n"
19841 "layout(location=0) out vec4 color;\n"
19842 "void main(){\n"
19843 " color = vec4(1);\n"
19844 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019845
19846 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19847 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19848
19849 VkPipelineObj pipe(m_device);
19850 pipe.AddColorAttachment();
19851 pipe.AddShader(&vs);
19852 pipe.AddShader(&fs);
19853
19854 pipe.AddVertexInputBindings(&input_binding, 1);
19855 pipe.AddVertexInputAttribs(input_attribs, 3);
19856
19857 VkDescriptorSetObj descriptorSet(m_device);
19858 descriptorSet.AppendDummy();
19859 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19860
19861 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19862
19863 m_errorMonitor->VerifyNotFound();
19864}
19865
19866TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19867 m_errorMonitor->ExpectSuccess();
19868
19869 ASSERT_NO_FATAL_FAILURE(InitState());
19870 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19871
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019872 char const *vsSource =
19873 "#version 450\n"
19874 "out gl_PerVertex {\n"
19875 " vec4 gl_Position;\n"
19876 "};\n"
19877 "void main(){\n"
19878 " gl_Position = vec4(0);\n"
19879 "}\n";
19880 char const *fsSource =
19881 "#version 450\n"
19882 "\n"
19883 "layout(location=0) out vec4 color;\n"
19884 "void main(){\n"
19885 " color = vec4(1);\n"
19886 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019887
19888 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19889 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19890
19891 VkPipelineObj pipe(m_device);
19892 pipe.AddColorAttachment();
19893 pipe.AddShader(&vs);
19894 pipe.AddShader(&fs);
19895
19896 VkDescriptorSetObj descriptorSet(m_device);
19897 descriptorSet.AppendDummy();
19898 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19899
19900 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19901
19902 m_errorMonitor->VerifyNotFound();
19903}
19904
19905TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019906 TEST_DESCRIPTION(
19907 "Test that pipeline validation accepts the relaxed type matching rules "
19908 "set out in 14.1.3: fundamental type must match, and producer side must "
19909 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019910 m_errorMonitor->ExpectSuccess();
19911
19912 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19913
19914 ASSERT_NO_FATAL_FAILURE(InitState());
19915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19916
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019917 char const *vsSource =
19918 "#version 450\n"
19919 "out gl_PerVertex {\n"
19920 " vec4 gl_Position;\n"
19921 "};\n"
19922 "layout(location=0) out vec3 x;\n"
19923 "layout(location=1) out ivec3 y;\n"
19924 "layout(location=2) out vec3 z;\n"
19925 "void main(){\n"
19926 " gl_Position = vec4(0);\n"
19927 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19928 "}\n";
19929 char const *fsSource =
19930 "#version 450\n"
19931 "\n"
19932 "layout(location=0) out vec4 color;\n"
19933 "layout(location=0) in float x;\n"
19934 "layout(location=1) flat in int y;\n"
19935 "layout(location=2) in vec2 z;\n"
19936 "void main(){\n"
19937 " color = vec4(1 + x + y + z.x);\n"
19938 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019939
19940 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19941 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19942
19943 VkPipelineObj pipe(m_device);
19944 pipe.AddColorAttachment();
19945 pipe.AddShader(&vs);
19946 pipe.AddShader(&fs);
19947
19948 VkDescriptorSetObj descriptorSet(m_device);
19949 descriptorSet.AppendDummy();
19950 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19951
19952 VkResult err = VK_SUCCESS;
19953 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19954 ASSERT_VK_SUCCESS(err);
19955
19956 m_errorMonitor->VerifyNotFound();
19957}
19958
19959TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019960 TEST_DESCRIPTION(
19961 "Test that pipeline validation accepts per-vertex variables "
19962 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019963 m_errorMonitor->ExpectSuccess();
19964
19965 ASSERT_NO_FATAL_FAILURE(InitState());
19966 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19967
19968 if (!m_device->phy().features().tessellationShader) {
19969 printf("Device does not support tessellation shaders; skipped.\n");
19970 return;
19971 }
19972
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019973 char const *vsSource =
19974 "#version 450\n"
19975 "void main(){}\n";
19976 char const *tcsSource =
19977 "#version 450\n"
19978 "layout(location=0) out int x[];\n"
19979 "layout(vertices=3) out;\n"
19980 "void main(){\n"
19981 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19982 " gl_TessLevelInner[0] = 1;\n"
19983 " x[gl_InvocationID] = gl_InvocationID;\n"
19984 "}\n";
19985 char const *tesSource =
19986 "#version 450\n"
19987 "layout(triangles, equal_spacing, cw) in;\n"
19988 "layout(location=0) in int x[];\n"
19989 "out gl_PerVertex { vec4 gl_Position; };\n"
19990 "void main(){\n"
19991 " gl_Position.xyz = gl_TessCoord;\n"
19992 " gl_Position.w = x[0] + x[1] + x[2];\n"
19993 "}\n";
19994 char const *fsSource =
19995 "#version 450\n"
19996 "layout(location=0) out vec4 color;\n"
19997 "void main(){\n"
19998 " color = vec4(1);\n"
19999 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020000
20001 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20002 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
20003 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
20004 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20005
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020006 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
20007 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020008
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020009 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020010
20011 VkPipelineObj pipe(m_device);
20012 pipe.SetInputAssembly(&iasci);
20013 pipe.SetTessellation(&tsci);
20014 pipe.AddColorAttachment();
20015 pipe.AddShader(&vs);
20016 pipe.AddShader(&tcs);
20017 pipe.AddShader(&tes);
20018 pipe.AddShader(&fs);
20019
20020 VkDescriptorSetObj descriptorSet(m_device);
20021 descriptorSet.AppendDummy();
20022 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20023
20024 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20025
20026 m_errorMonitor->VerifyNotFound();
20027}
20028
20029TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020030 TEST_DESCRIPTION(
20031 "Test that pipeline validation accepts a user-defined "
20032 "interface block passed into the geometry shader. This "
20033 "is interesting because the 'extra' array level is not "
20034 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020035 m_errorMonitor->ExpectSuccess();
20036
20037 ASSERT_NO_FATAL_FAILURE(InitState());
20038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20039
20040 if (!m_device->phy().features().geometryShader) {
20041 printf("Device does not support geometry shaders; skipped.\n");
20042 return;
20043 }
20044
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020045 char const *vsSource =
20046 "#version 450\n"
20047 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
20048 "void main(){\n"
20049 " vs_out.x = vec4(1);\n"
20050 "}\n";
20051 char const *gsSource =
20052 "#version 450\n"
20053 "layout(triangles) in;\n"
20054 "layout(triangle_strip, max_vertices=3) out;\n"
20055 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
20056 "out gl_PerVertex { vec4 gl_Position; };\n"
20057 "void main() {\n"
20058 " gl_Position = gs_in[0].x;\n"
20059 " EmitVertex();\n"
20060 "}\n";
20061 char const *fsSource =
20062 "#version 450\n"
20063 "layout(location=0) out vec4 color;\n"
20064 "void main(){\n"
20065 " color = vec4(1);\n"
20066 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020067
20068 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20069 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
20070 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20071
20072 VkPipelineObj pipe(m_device);
20073 pipe.AddColorAttachment();
20074 pipe.AddShader(&vs);
20075 pipe.AddShader(&gs);
20076 pipe.AddShader(&fs);
20077
20078 VkDescriptorSetObj descriptorSet(m_device);
20079 descriptorSet.AppendDummy();
20080 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20081
20082 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20083
20084 m_errorMonitor->VerifyNotFound();
20085}
20086
20087TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020088 TEST_DESCRIPTION(
20089 "Test that pipeline validation accepts basic use of 64bit vertex "
20090 "attributes. This is interesting because they consume multiple "
20091 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020092 m_errorMonitor->ExpectSuccess();
20093
20094 ASSERT_NO_FATAL_FAILURE(InitState());
20095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20096
20097 if (!m_device->phy().features().shaderFloat64) {
20098 printf("Device does not support 64bit vertex attributes; skipped.\n");
20099 return;
20100 }
20101
20102 VkVertexInputBindingDescription input_bindings[1];
20103 memset(input_bindings, 0, sizeof(input_bindings));
20104
20105 VkVertexInputAttributeDescription input_attribs[4];
20106 memset(input_attribs, 0, sizeof(input_attribs));
20107 input_attribs[0].location = 0;
20108 input_attribs[0].offset = 0;
20109 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20110 input_attribs[1].location = 2;
20111 input_attribs[1].offset = 32;
20112 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20113 input_attribs[2].location = 4;
20114 input_attribs[2].offset = 64;
20115 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20116 input_attribs[3].location = 6;
20117 input_attribs[3].offset = 96;
20118 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20119
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020120 char const *vsSource =
20121 "#version 450\n"
20122 "\n"
20123 "layout(location=0) in dmat4 x;\n"
20124 "out gl_PerVertex {\n"
20125 " vec4 gl_Position;\n"
20126 "};\n"
20127 "void main(){\n"
20128 " gl_Position = vec4(x[0][0]);\n"
20129 "}\n";
20130 char const *fsSource =
20131 "#version 450\n"
20132 "\n"
20133 "layout(location=0) out vec4 color;\n"
20134 "void main(){\n"
20135 " color = vec4(1);\n"
20136 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020137
20138 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20139 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20140
20141 VkPipelineObj pipe(m_device);
20142 pipe.AddColorAttachment();
20143 pipe.AddShader(&vs);
20144 pipe.AddShader(&fs);
20145
20146 pipe.AddVertexInputBindings(input_bindings, 1);
20147 pipe.AddVertexInputAttribs(input_attribs, 4);
20148
20149 VkDescriptorSetObj descriptorSet(m_device);
20150 descriptorSet.AppendDummy();
20151 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20152
20153 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20154
20155 m_errorMonitor->VerifyNotFound();
20156}
20157
20158TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
20159 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
20160 m_errorMonitor->ExpectSuccess();
20161
20162 ASSERT_NO_FATAL_FAILURE(InitState());
20163
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020164 char const *vsSource =
20165 "#version 450\n"
20166 "\n"
20167 "out gl_PerVertex {\n"
20168 " vec4 gl_Position;\n"
20169 "};\n"
20170 "void main(){\n"
20171 " gl_Position = vec4(1);\n"
20172 "}\n";
20173 char const *fsSource =
20174 "#version 450\n"
20175 "\n"
20176 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
20177 "layout(location=0) out vec4 color;\n"
20178 "void main() {\n"
20179 " color = subpassLoad(x);\n"
20180 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020181
20182 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20183 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20184
20185 VkPipelineObj pipe(m_device);
20186 pipe.AddShader(&vs);
20187 pipe.AddShader(&fs);
20188 pipe.AddColorAttachment();
20189 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20190
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020191 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
20192 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020193 VkDescriptorSetLayout dsl;
20194 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20195 ASSERT_VK_SUCCESS(err);
20196
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020197 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020198 VkPipelineLayout pl;
20199 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20200 ASSERT_VK_SUCCESS(err);
20201
20202 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020203 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20204 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20205 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
20206 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20207 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 -060020208 };
20209 VkAttachmentReference color = {
20210 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20211 };
20212 VkAttachmentReference input = {
20213 1, VK_IMAGE_LAYOUT_GENERAL,
20214 };
20215
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020216 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020217
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020218 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020219 VkRenderPass rp;
20220 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20221 ASSERT_VK_SUCCESS(err);
20222
20223 // should be OK. would go wrong here if it's going to...
20224 pipe.CreateVKPipeline(pl, rp);
20225
20226 m_errorMonitor->VerifyNotFound();
20227
20228 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20229 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20230 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20231}
20232
20233TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020234 TEST_DESCRIPTION(
20235 "Test that pipeline validation accepts a compute pipeline which declares a "
20236 "descriptor-backed resource which is not provided, but the shader does not "
20237 "statically use it. This is interesting because it requires compute pipelines "
20238 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020239 m_errorMonitor->ExpectSuccess();
20240
20241 ASSERT_NO_FATAL_FAILURE(InitState());
20242
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020243 char const *csSource =
20244 "#version 450\n"
20245 "\n"
20246 "layout(local_size_x=1) in;\n"
20247 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
20248 "void main(){\n"
20249 " // x is not used.\n"
20250 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020251
20252 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20253
20254 VkDescriptorSetObj descriptorSet(m_device);
20255 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20256
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020257 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20258 nullptr,
20259 0,
20260 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20261 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20262 descriptorSet.GetPipelineLayout(),
20263 VK_NULL_HANDLE,
20264 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020265
20266 VkPipeline pipe;
20267 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20268
20269 m_errorMonitor->VerifyNotFound();
20270
20271 if (err == VK_SUCCESS) {
20272 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20273 }
20274}
20275
20276TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020277 TEST_DESCRIPTION(
20278 "Test that pipeline validation accepts a shader consuming only the "
20279 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020280 m_errorMonitor->ExpectSuccess();
20281
20282 ASSERT_NO_FATAL_FAILURE(InitState());
20283
20284 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020285 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20286 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20287 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020288 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020289 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020290 VkDescriptorSetLayout dsl;
20291 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20292 ASSERT_VK_SUCCESS(err);
20293
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020294 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020295 VkPipelineLayout pl;
20296 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20297 ASSERT_VK_SUCCESS(err);
20298
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020299 char const *csSource =
20300 "#version 450\n"
20301 "\n"
20302 "layout(local_size_x=1) in;\n"
20303 "layout(set=0, binding=0) uniform sampler s;\n"
20304 "layout(set=0, binding=1) uniform texture2D t;\n"
20305 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20306 "void main() {\n"
20307 " x = texture(sampler2D(t, s), vec2(0));\n"
20308 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020309 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20310
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020311 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20312 nullptr,
20313 0,
20314 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20315 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20316 pl,
20317 VK_NULL_HANDLE,
20318 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020319
20320 VkPipeline pipe;
20321 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20322
20323 m_errorMonitor->VerifyNotFound();
20324
20325 if (err == VK_SUCCESS) {
20326 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20327 }
20328
20329 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20330 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20331}
20332
20333TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020334 TEST_DESCRIPTION(
20335 "Test that pipeline validation accepts a shader consuming only the "
20336 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020337 m_errorMonitor->ExpectSuccess();
20338
20339 ASSERT_NO_FATAL_FAILURE(InitState());
20340
20341 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020342 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20343 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20344 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020345 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020346 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020347 VkDescriptorSetLayout dsl;
20348 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20349 ASSERT_VK_SUCCESS(err);
20350
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020351 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020352 VkPipelineLayout pl;
20353 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20354 ASSERT_VK_SUCCESS(err);
20355
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020356 char const *csSource =
20357 "#version 450\n"
20358 "\n"
20359 "layout(local_size_x=1) in;\n"
20360 "layout(set=0, binding=0) uniform texture2D t;\n"
20361 "layout(set=0, binding=1) uniform sampler s;\n"
20362 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20363 "void main() {\n"
20364 " x = texture(sampler2D(t, s), vec2(0));\n"
20365 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020366 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20367
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020368 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20369 nullptr,
20370 0,
20371 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20372 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20373 pl,
20374 VK_NULL_HANDLE,
20375 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020376
20377 VkPipeline pipe;
20378 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20379
20380 m_errorMonitor->VerifyNotFound();
20381
20382 if (err == VK_SUCCESS) {
20383 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20384 }
20385
20386 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20387 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20388}
20389
20390TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020391 TEST_DESCRIPTION(
20392 "Test that pipeline validation accepts a shader consuming "
20393 "both the sampler and the image of a combined image+sampler "
20394 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020395 m_errorMonitor->ExpectSuccess();
20396
20397 ASSERT_NO_FATAL_FAILURE(InitState());
20398
20399 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020400 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20401 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020402 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020403 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020404 VkDescriptorSetLayout dsl;
20405 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20406 ASSERT_VK_SUCCESS(err);
20407
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020408 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020409 VkPipelineLayout pl;
20410 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20411 ASSERT_VK_SUCCESS(err);
20412
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020413 char const *csSource =
20414 "#version 450\n"
20415 "\n"
20416 "layout(local_size_x=1) in;\n"
20417 "layout(set=0, binding=0) uniform texture2D t;\n"
20418 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20419 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20420 "void main() {\n"
20421 " x = texture(sampler2D(t, s), vec2(0));\n"
20422 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020423 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20424
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020425 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20426 nullptr,
20427 0,
20428 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20429 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20430 pl,
20431 VK_NULL_HANDLE,
20432 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020433
20434 VkPipeline pipe;
20435 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20436
20437 m_errorMonitor->VerifyNotFound();
20438
20439 if (err == VK_SUCCESS) {
20440 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20441 }
20442
20443 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20444 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20445}
20446
20447TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20448 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20449
20450 ASSERT_NO_FATAL_FAILURE(InitState());
20451
20452 // Positive test to check parameter_validation and unique_objects support
20453 // for NV_dedicated_allocation
20454 uint32_t extension_count = 0;
20455 bool supports_nv_dedicated_allocation = false;
20456 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20457 ASSERT_VK_SUCCESS(err);
20458
20459 if (extension_count > 0) {
20460 std::vector<VkExtensionProperties> available_extensions(extension_count);
20461
20462 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20463 ASSERT_VK_SUCCESS(err);
20464
20465 for (const auto &extension_props : available_extensions) {
20466 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20467 supports_nv_dedicated_allocation = true;
20468 }
20469 }
20470 }
20471
20472 if (supports_nv_dedicated_allocation) {
20473 m_errorMonitor->ExpectSuccess();
20474
20475 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20476 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20477 dedicated_buffer_create_info.pNext = nullptr;
20478 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20479
20480 uint32_t queue_family_index = 0;
20481 VkBufferCreateInfo buffer_create_info = {};
20482 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20483 buffer_create_info.pNext = &dedicated_buffer_create_info;
20484 buffer_create_info.size = 1024;
20485 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20486 buffer_create_info.queueFamilyIndexCount = 1;
20487 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20488
20489 VkBuffer buffer;
20490 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20491 ASSERT_VK_SUCCESS(err);
20492
20493 VkMemoryRequirements memory_reqs;
20494 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20495
20496 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20497 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20498 dedicated_memory_info.pNext = nullptr;
20499 dedicated_memory_info.buffer = buffer;
20500 dedicated_memory_info.image = VK_NULL_HANDLE;
20501
20502 VkMemoryAllocateInfo memory_info = {};
20503 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20504 memory_info.pNext = &dedicated_memory_info;
20505 memory_info.allocationSize = memory_reqs.size;
20506
20507 bool pass;
20508 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20509 ASSERT_TRUE(pass);
20510
20511 VkDeviceMemory buffer_memory;
20512 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20513 ASSERT_VK_SUCCESS(err);
20514
20515 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20516 ASSERT_VK_SUCCESS(err);
20517
20518 vkDestroyBuffer(m_device->device(), buffer, NULL);
20519 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20520
20521 m_errorMonitor->VerifyNotFound();
20522 }
20523}
20524
20525TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20526 VkResult err;
20527
20528 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20529
20530 ASSERT_NO_FATAL_FAILURE(InitState());
20531 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20532
20533 std::vector<const char *> device_extension_names;
20534 auto features = m_device->phy().features();
20535 // Artificially disable support for non-solid fill modes
20536 features.fillModeNonSolid = false;
20537 // The sacrificial device object
20538 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20539
20540 VkRenderpassObj render_pass(&test_device);
20541
20542 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20543 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20544 pipeline_layout_ci.setLayoutCount = 0;
20545 pipeline_layout_ci.pSetLayouts = NULL;
20546
20547 VkPipelineLayout pipeline_layout;
20548 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20549 ASSERT_VK_SUCCESS(err);
20550
20551 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20552 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20553 rs_ci.pNext = nullptr;
20554 rs_ci.lineWidth = 1.0f;
20555 rs_ci.rasterizerDiscardEnable = true;
20556
20557 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20558 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20559
20560 // Set polygonMode=FILL. No error is expected
20561 m_errorMonitor->ExpectSuccess();
20562 {
20563 VkPipelineObj pipe(&test_device);
20564 pipe.AddShader(&vs);
20565 pipe.AddShader(&fs);
20566 pipe.AddColorAttachment();
20567 // Set polygonMode to a good value
20568 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20569 pipe.SetRasterization(&rs_ci);
20570 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20571 }
20572 m_errorMonitor->VerifyNotFound();
20573
20574 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20575}
20576
20577TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20578 VkResult err;
20579 ASSERT_NO_FATAL_FAILURE(InitState());
20580 ASSERT_NO_FATAL_FAILURE(InitViewport());
20581 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20582
20583 VkPipelineLayout pipeline_layout;
20584 VkPushConstantRange pc_range = {};
20585 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20586 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20587 pipeline_layout_ci.pushConstantRangeCount = 1;
20588 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20589
20590 //
20591 // Check for invalid push constant ranges in pipeline layouts.
20592 //
20593 struct PipelineLayoutTestCase {
20594 VkPushConstantRange const range;
20595 char const *msg;
20596 };
20597
20598 // Check for overlapping ranges
20599 const uint32_t ranges_per_test = 5;
20600 struct OverlappingRangeTestCase {
20601 VkPushConstantRange const ranges[ranges_per_test];
20602 char const *msg;
20603 };
20604
20605 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020606 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
20607 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
20608 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
20609 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
20610 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
20611 ""},
20612 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
20613 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
20614 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
20615 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
20616 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
20617 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020618 for (const auto &iter : overlapping_range_tests_pos) {
20619 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20620 m_errorMonitor->ExpectSuccess();
20621 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20622 m_errorMonitor->VerifyNotFound();
20623 if (VK_SUCCESS == err) {
20624 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20625 }
20626 }
20627
20628 //
20629 // CmdPushConstants tests
20630 //
20631 const uint8_t dummy_values[100] = {};
20632
Tony Barbour552f6c02016-12-21 14:34:07 -070020633 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020634
20635 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020636 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
20637 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
20638 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
20639 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
20640 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
20641 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020642
20643 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20644 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020645 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
20646 {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 -060020647 };
20648
20649 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20650 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20651 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20652 ASSERT_VK_SUCCESS(err);
20653 for (const auto &iter : cmd_overlap_tests_pos) {
20654 m_errorMonitor->ExpectSuccess();
20655 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020656 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020657 m_errorMonitor->VerifyNotFound();
20658 }
20659 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20660
Tony Barbour552f6c02016-12-21 14:34:07 -070020661 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020662}
20663
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020664#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020665TEST_F(VkPositiveLayerTest, LongFenceChain)
20666{
20667 m_errorMonitor->ExpectSuccess();
20668
20669 ASSERT_NO_FATAL_FAILURE(InitState());
20670 VkResult err;
20671
20672 std::vector<VkFence> fences;
20673
20674 const int chainLength = 32768;
20675
20676 for (int i = 0; i < chainLength; i++) {
20677 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20678 VkFence fence;
20679 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20680 ASSERT_VK_SUCCESS(err);
20681
20682 fences.push_back(fence);
20683
20684 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20685 0, nullptr, 0, nullptr };
20686 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20687 ASSERT_VK_SUCCESS(err);
20688
20689 }
20690
20691 // BOOM, stack overflow.
20692 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20693
20694 for (auto fence : fences)
20695 vkDestroyFence(m_device->device(), fence, nullptr);
20696
20697 m_errorMonitor->VerifyNotFound();
20698}
20699#endif
20700
Cody Northrop1242dfd2016-07-13 17:24:59 -060020701#if defined(ANDROID) && defined(VALIDATION_APK)
20702static bool initialized = false;
20703static bool active = false;
20704
20705// Convert Intents to argv
20706// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020707std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020708 std::vector<std::string> args;
20709 JavaVM &vm = *app.activity->vm;
20710 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020711 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020712
20713 JNIEnv &env = *p_env;
20714 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020715 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020716 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020717 jmethodID get_string_extra_method =
20718 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020719 jvalue get_string_extra_args;
20720 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020721 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020722
20723 std::string args_str;
20724 if (extra_str) {
20725 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20726 args_str = extra_utf;
20727 env.ReleaseStringUTFChars(extra_str, extra_utf);
20728 env.DeleteLocalRef(extra_str);
20729 }
20730
20731 env.DeleteLocalRef(get_string_extra_args.l);
20732 env.DeleteLocalRef(intent);
20733 vm.DetachCurrentThread();
20734
20735 // split args_str
20736 std::stringstream ss(args_str);
20737 std::string arg;
20738 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020739 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020740 }
20741
20742 return args;
20743}
20744
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020745static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020746
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020747static void processCommand(struct android_app *app, int32_t cmd) {
20748 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020749 case APP_CMD_INIT_WINDOW: {
20750 if (app->window) {
20751 initialized = true;
20752 }
20753 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020754 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020755 case APP_CMD_GAINED_FOCUS: {
20756 active = true;
20757 break;
20758 }
20759 case APP_CMD_LOST_FOCUS: {
20760 active = false;
20761 break;
20762 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020763 }
20764}
20765
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020766void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020767 app_dummy();
20768
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020769 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020770
20771 int vulkanSupport = InitVulkan();
20772 if (vulkanSupport == 0) {
20773 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20774 return;
20775 }
20776
20777 app->onAppCmd = processCommand;
20778 app->onInputEvent = processInput;
20779
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020780 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020781 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020782 struct android_poll_source *source;
20783 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020784 if (source) {
20785 source->process(app, source);
20786 }
20787
20788 if (app->destroyRequested != 0) {
20789 VkTestFramework::Finish();
20790 return;
20791 }
20792 }
20793
20794 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020795 // Use the following key to send arguments to gtest, i.e.
20796 // --es args "--gtest_filter=-VkLayerTest.foo"
20797 const char key[] = "args";
20798 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020799
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020800 std::string filter = "";
20801 if (args.size() > 0) {
20802 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20803 filter += args[0];
20804 } else {
20805 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20806 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020807
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020808 int argc = 2;
20809 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20810 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020811
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020812 // Route output to files until we can override the gtest output
20813 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20814 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020815
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020816 ::testing::InitGoogleTest(&argc, argv);
20817 VkTestFramework::InitArgs(&argc, argv);
20818 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020819
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020820 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020821
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020822 if (result != 0) {
20823 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20824 } else {
20825 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20826 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020827
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020828 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020829
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020830 fclose(stdout);
20831 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020832
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020833 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020835 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020836 }
20837 }
20838}
20839#endif
20840
Tony Barbour300a6082015-04-07 13:44:53 -060020841int main(int argc, char **argv) {
20842 int result;
20843
Cody Northrop8e54a402016-03-08 22:25:52 -070020844#ifdef ANDROID
20845 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020846 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070020847#endif
20848
Tony Barbour300a6082015-04-07 13:44:53 -060020849 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020850 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020851
20852 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20853
20854 result = RUN_ALL_TESTS();
20855
Tony Barbour6918cd52015-04-09 12:58:51 -060020856 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020857 return result;
20858}